Ejemplo n.º 1
0
void game() {

    int column;

    while (!state.is_full()) {

        draw_field();

        do {
            printf("Where to, my friend [0..%d]> ", WIDTH - 1);
            fflush(stdout);
            if (scanf("%d", &column) == -1) return;
        } while (state.play_column(PLAYER, column) == -1);

        if (state.winner() == PLAYER) {
            printf("you won!!!\n");
            draw_field();
            return;
        }

        computer_turn();
        if (state.winner() == COMPUTER) {
            printf("you lost!!!\n");
            draw_field();
            return;
        }
    }
}
Ejemplo n.º 2
0
/*
 * in game menu_loop, will called every game loop.
 * As long as this menu is displayed the gamekeys will not work.
 *
 * the drawings will be done from the main loop. So we won't
 * have to draw anything on our own.
 *
 * Pressing ESC will bring you back to the game.
 */
void
game_menu_loop (SDL_Event * event, int eventstate)
{
    int done;

    if (menu == NULL)
        return;

    menu_draw (menu);

    done = menu_event_loop (menu, event, eventstate);
    /*
     * check if one of the buttons was pressed
     */

    if (done != 0) {
        if (menu->focus->id == 2 && (GT_MP_PTPM || GT_SP)) { /* End Round */
            bman.timeout = -GAME_OVERTIMEOUT;
        }

        else if (menu->focus->id == 3) { /* End Game */
            /* send network update */
            if (GT_MP)
                net_game_send_delplayer (bman.p_nr);
            bman.state = GS_quit;
        }

        else {                  /* Quit Menu */
            menu_delete (menu);
            menu = NULL;
            gfx_blitdraw ();
            draw_field ();
        }
    }
};
Ejemplo n.º 3
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_mode(struct view *view, mode_t mode)
{
	const char *str = mkmode(mode);

	return draw_field(view, LINE_MODE, str, STRING_SIZE("-rw-r--r--"), ALIGN_LEFT, FALSE);
}
Ejemplo n.º 4
0
Archivo: branch.c Proyecto: ebruck/tig
static bool
branch_draw(struct view *view, struct line *line, unsigned int lineno)
{
	struct branch_state *state = view->private;
	struct branch *branch = line->data;
	enum line_type type = branch_is_all(branch) ? LINE_DEFAULT : get_line_type_from_ref(branch->ref);
	const char *branch_name = branch_is_all(branch) ? BRANCH_ALL_NAME : branch->ref->name;

	if (draw_lineno(view, lineno))
		return TRUE;

	if (draw_date(view, &branch->time))
		return TRUE;

	if (draw_author(view, branch->author))
		return TRUE;

	if (draw_field(view, type, branch_name, state->max_ref_length, ALIGN_LEFT, FALSE))
		return TRUE;

	if (draw_id(view, branch->ref->id))
		return TRUE;

	draw_text(view, LINE_DEFAULT, branch->title);
	return TRUE;
}
Ejemplo n.º 5
0
static bool
draw_status(struct view *view, struct view_column *column,
	    enum line_type type, const char *status)
{
	const char *label = mkstatus(status ? *status : 0, column->opt.status.display);

	return draw_field(view, type, label, column->width, ALIGN_LEFT, false);
}
Ejemplo n.º 6
0
static bool
draw_ref(struct view *view, struct view_column *column, const struct ref *ref)
{
	enum line_type type = !ref || !ref->valid ? LINE_DEFAULT : get_line_type_from_ref(ref);
	const char *name = ref ? ref->name : NULL;

	return draw_field(view, type, name, column->width, ALIGN_LEFT, false);
}
Ejemplo n.º 7
0
void init_disp()
{
    initscr();
    clear();
    crmode();
    noecho();
    nonl();
    draw_field();
}
Ejemplo n.º 8
0
/**
 * Does complete refresh of game screen
 */
void refresh_game_screen() {
	ClearVram();
	DrawMap2(0, 0, tiles_screen);
	draw_field();
	draw_molecule(SCREEN_MOLECULE_X, SCREEN_MOLECULE_Y);
	draw_statistics();
	draw_name();
	draw_cursor();
}
Ejemplo n.º 9
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_file_size(struct view *view, unsigned long size, int width, bool pad)
{
	const char *str = pad ? NULL : mkfilesize(size, opt_show_file_size);

	if (!width || opt_show_file_size == FILE_SIZE_NO)
		return FALSE;

	return draw_field(view, LINE_FILE_SIZE, str, width, ALIGN_RIGHT, FALSE);
}
Ejemplo n.º 10
0
static bool
draw_file_size(struct view *view, struct view_column *column, unsigned long size, mode_t mode)
{
	const char *str = S_ISDIR(mode) ? NULL : mkfilesize(size, column->opt.file_size.display);

	if (!column->width || column->opt.file_size.display == FILE_SIZE_NO)
		return false;

	return draw_field(view, LINE_FILE_SIZE, str, column->width, ALIGN_RIGHT, false);
}
Ejemplo n.º 11
0
static bool
draw_mode(struct view *view, struct view_column *column, mode_t mode)
{
	const char *str = mkmode(mode);

	if (!column->width || !column->opt.mode.display)
		return false;

	return draw_field(view, LINE_MODE, str, column->width, ALIGN_LEFT, false);
}
Ejemplo n.º 12
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_author(struct view *view, const struct ident *author)
{
	bool trim = author_trim(opt_author_width);
	const char *text = mkauthor(author, opt_author_width, opt_show_author);

	if (opt_show_author == AUTHOR_NO)
		return FALSE;

	return draw_field(view, LINE_AUTHOR, text, opt_author_width, ALIGN_LEFT, trim);
}
Ejemplo n.º 13
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_date(struct view *view, struct time *time)
{
	const char *date = mkdate(time, opt_show_date);
	int cols = opt_show_date == DATE_SHORT ? DATE_SHORT_WIDTH : DATE_WIDTH;

	if (opt_show_date == DATE_NO)
		return FALSE;

	return draw_field(view, LINE_DATE, date, cols, ALIGN_LEFT, FALSE);
}
Ejemplo n.º 14
0
Archivo: draw.c Proyecto: bbolli/tig
bool
draw_date(struct view *view, struct view_column *column, const struct time *time)
{
	enum date date = column->opt.date.show;
	const char *text = mkdate(time, date);

	if (date == DATE_NO)
		return FALSE;

	return draw_field(view, LINE_DATE, text, column->width, ALIGN_LEFT, FALSE);
}
Ejemplo n.º 15
0
static bool
draw_author(struct view *view, struct view_column *column, const struct ident *author)
{
	bool trim = author_trim(column->width);
	const char *text = mkauthor(author, column->opt.author.width, column->opt.author.display);

	if (column->opt.author.display == AUTHOR_NO)
		return false;

	return draw_field(view, LINE_AUTHOR, text, column->width, ALIGN_LEFT, trim);
}
Ejemplo n.º 16
0
static bool
draw_date(struct view *view, struct view_column *column, const struct time *time)
{
	enum date date = column->opt.date.display;
	const char *text = mkdate(time, date);
	enum align align = date == DATE_RELATIVE ? ALIGN_RIGHT : ALIGN_LEFT;

	if (date == DATE_NO)
		return false;

	return draw_field(view, LINE_DATE, text, column->width, align, false);
}
Ejemplo n.º 17
0
static void multi_draw_frame()
{
    glPushMatrix();
    glTranslated(-3.2f, 0.0f, -7.0f);
    glScalef(3.0f, 3.0f, 1.0f);
    glRotatef(30.0, 1.0, 0.0, 0.0);
    draw_field();
    draw_ball(ball);
    draw_racket(first_player);
    draw_racket(second_player);
    glPopMatrix();
    glPushMatrix();
    glTranslated(3.2f, 0.0f, -7.0f);
    glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
    glScalef(3.0f, 3.0f, 1.0f);
    glRotatef(-30.0, 1.0, 0.0, 0.0);
    draw_field();
    draw_ball(ball);
    draw_racket(first_player);
    draw_racket(second_player);
    glPopMatrix();
}
Ejemplo n.º 18
0
static bool
draw_filename(struct view *view, struct view_column *column, const char *filename, mode_t mode)
{
	size_t width = filename ? utf8_width(filename) : 0;
	bool trim = width >= column->width;
	enum line_type type = S_ISDIR(mode) ? LINE_DIRECTORY : LINE_FILE;
	int column_width = column->width ? column->width : width;

	if (column->opt.file_name.display == FILENAME_NO)
		return false;

	return draw_field(view, type, filename, column_width, ALIGN_LEFT, trim);
}
Ejemplo n.º 19
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_filename(struct view *view, const char *filename, bool auto_enabled)
{
	bool trim = filename && strlen(filename) >= opt_show_filename_width;

	if (opt_show_filename == FILENAME_NO)
		return FALSE;

	if (opt_show_filename == FILENAME_AUTO && !auto_enabled)
		return FALSE;

	return draw_field(view, LINE_FILENAME, filename, opt_show_filename_width, ALIGN_LEFT, trim);
}
Ejemplo n.º 20
0
int on_tic_choose(char *parameter, OUTPUT *out, MSG *msg)
{
	int i, tic, letter;
	SESS *s = NULL;
	
	if (num_of_sessions == 0 || msg->user == NULL || parameter == NULL)
	{
		return 0;
	}
	
	if (strlen(parameter) > 1 || *parameter < 'a' || *parameter > 'i')
	{
		return 0;
	}
	
  for (i = 0; i < MAXSESSIONS; i++)
  	if (sessions[i])
  	{
  		if (sessions[i]->current == msg->user && sessions[i]->out == out)
  		{
  			s = sessions[i];
  			break;
  		}
  	}

	if (s == NULL) 
	{
		eiwic->output_printf(out, "%s: No, no!\n", msg->user->nick);	
		return 0;
	}

	tic = *parameter - 'a';
	letter = (s->current == s->player1 ? PLAYER1 : PLAYER2);	

	if (*((char *)s->field + tic) == PLAYER1 ||
		*((char *)s->field + tic) == PLAYER2)
	{
		eiwic->output_printf(out, "%s: No, no!\n", msg->user->nick);	
		return 0;
	}
		
	*((char *)s->field + tic) = letter;
	
	s->tics++;
	
	s->current = (s->current == s->player1 ? s->player2 : s->player1);		

	draw_field(s);
	
	return 1;
}
Ejemplo n.º 21
0
int on_tic_start(char *parameter, OUTPUT *out, MSG *msg)
{
	USER *enemy;
	SESS *s;
	int i;
	
	if (msg->user == NULL)
	{
		return 0;
	}

	if (msg->channel == NULL)
	{
		eiwic->output_print(out, ONLYONCHANNEL);
		return 0;
	}
	
	if (parameter == NULL || ((enemy = eiwic->user_find(parameter)) == NULL))
	{
		eiwic->output_print(out, USAGE);
		return 0;
	}

	if (num_of_sessions >= MAXSESSIONS)
	{
		eiwic->output_print(out, NOMORESESSIONS);
		return 0;
	}

	s = malloc(sizeof(SESS));

	s->out = out;
	s->tics = 0;
	
	s->player1 = enemy;
	s->player2 = msg->user;
	s->current = s->player1;
	s->winner = NULL;

	memset(s->field, 0, 3*3);

	for (i = 0; sessions[i] != NULL && i < MAXSESSIONS; i++);
	
	sessions[i] = s;
	num_of_sessions++;

	eiwic->output_printf(out, "Hey, %s, %s challenged you! Do you have the balls to play?:\n",
		s->player1->nick, s->player2->nick);
	
	draw_field(s);
}
Ejemplo n.º 22
0
Archivo: draw.c Proyecto: bbolli/tig
bool
draw_filename(struct view *view, struct view_column *column, const char *filename, bool auto_enabled, mode_t mode)
{
	bool trim = filename && utf8_width(filename) >= column->width;
	enum line_type type = S_ISDIR(mode) ? LINE_DIRECTORY : LINE_FILE;

	if (column->opt.file_name.show == FILENAME_NO)
		return FALSE;

	if (column->opt.file_name.show == FILENAME_AUTO && !auto_enabled)
		return FALSE;

	return draw_field(view, type, filename, column->width, ALIGN_LEFT, trim);
}
Ejemplo n.º 23
0
static void draw_instr()
{
    U8 field_it = 0;
    gotoxy(XPOS, 0);
    textcolor(COLOR_GREEN);
    cputs("instr ");
    print_hex(VIEW_INSTR);
    gotoxy(XPOS + 8, YPOS + 1);
    textcolor(COLOR_BLUE);
    cputs("filter");
    while (field_it < FIELD_COUNT)
    {
        draw_field(field_it++);
    }
}
Ejemplo n.º 24
0
/**
 * Stellt den Initialzustand bei Level-Up her.
 * Schlange wird zurückgesetzt, Spielfeld neu gezeichnet.
 */
void init_level()
{
    delay_time = START_DELAY - (level-1)*DELAY_REDUCTION;
    if(delay_time < 60)
	{
		delay_time = 60;
	}
    startup_size = INITIAL_SIZE;

    disable_interrupts();
	draw_field();
	enable_interrupts();

    init_snake();
}
Ejemplo n.º 25
0
static unsigned long
cloudlife_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;

  if (st->cycle_colors) {
    if (st->colortimer == 0) {
      st->colortimer = st->cycle_colors;
      if( st->colorindex == 0 ) 
        st->colorindex = st->ncolors;
      st->colorindex--;
      XSetForeground(st->dpy, st->fgc, st->colors[st->colorindex].pixel);
    }
    st->colortimer--;
  } 

  XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
  if (st->field->height != st->xgwa.height / (1 << st->field->cell_size) + 2 ||
      st->field->width != st->xgwa.width / (1 << st->field->cell_size) + 2) {

    resize_field(st->field, st->xgwa.width / (1 << st->field->cell_size) + 2,
                 st->xgwa.height / (1 << st->field->cell_size) + 2);
    populate_field(st->field, st->density);
  }

  draw_field(st, st->field);

  if (do_tick(st->field) < (st->field->height + st->field->width) / 4) {
    populate_field(st->field, st->density);
  }

  if (st->cycles % (st->field->max_age /2) == 0) {
    populate_edges(st->field, st->density);
    do_tick(st->field);
    populate_edges(st->field, 0);
  }

  st->cycles++;

#ifdef TIME_ME
  if (st->cycles % st->field->max_age == 0) {
    printf("%g s.\n",
           ((time(NULL) - st->start_time) * 1000.0) / st->cycles);
  }
#endif

  return (st->cycle_delay);
}
Ejemplo n.º 26
0
void		search_render(t_search *search)
{
	t_select *select;

	if (!search->i)
	{
		term_show_cursor(FALSE);
		return ;
	}
	select = search->select;
	term_go_home();
	term_mode_off();
	draw_bar(CGREY, select->size.ws_col);
	draw_field(search);
	term_write(EOC);
}
Ejemplo n.º 27
0
static bool
draw_id(struct view *view, struct view_column *column, const char *id)
{
	enum line_type type = LINE_ID;

	if (!column->opt.id.display)
		return false;

	if (column->opt.id.color && id) {
		hashval_t color = iterative_hash(id, SIZEOF_REV - 1, 0);

		type = palette_colors[color % ARRAY_SIZE(palette_colors)];
	}

	return draw_field(view, type, id, column->width, ALIGN_LEFT, false);
}
Ejemplo n.º 28
0
Archivo: draw.c Proyecto: bbolli/tig
bool
draw_id(struct view *view, struct view_column *column, const char *id)
{
	static const enum line_type colors[] = {
		LINE_PALETTE_0,
		LINE_PALETTE_1,
		LINE_PALETTE_2,
		LINE_PALETTE_3,
		LINE_PALETTE_4,
		LINE_PALETTE_5,
		LINE_PALETTE_6,
	};
	enum line_type type = LINE_ID;

	if (!column->opt.id.show)
		return FALSE;

	if (column->opt.id.color)
		type = colors[((long) id) % ARRAY_SIZE(colors)];

	return draw_field(view, type, id, column->width, ALIGN_LEFT, FALSE);
}
Ejemplo n.º 29
0
/**
 * Game loop
 */
void game() {
	while (level < LEVEL_COUNT) {
		level++;
	MENU:
		menu();

		load_level();
		refresh_game_screen();

		while (!is_level_done()) {

			int buttons = ReadJoypad(0);
			char* cursor_field_ptr = &(level_field[cursor_x + cursor_y * LEVEL_FIELD_WIDTH]);

			if (holding_atom) {
				if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) {
					while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {};
					*cursor_field_ptr = holding_atom;
					holding_atom = false;
					draw_field();
					play_sound(SOUND_LEVEL_RELEASE);
				}
				if (buttons & BTN_LEFT) {
					draw_field();
					if (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].x--;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_x--;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_RIGHT) {
					draw_field();
					if (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].x++;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_x++;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_UP) {
					draw_field();
					if (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].y--;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_y--;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_DOWN) {
					draw_field();
					if (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
						moves++;
						while (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) {
							play_sound(SOUND_LEVEL_MOVE);
							for (uint8_t i = 0; i < TILE_WIDTH; i++) {
								sprites[SPRITE_CURSOR].y++;
								draw_statistics();
								WaitVsync(1);
							}
							cursor_y++;
							distance++;
						}
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
			} else {
				if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) {
					if ((*cursor_field_ptr >= TILE_FIRST_ATOM) && (*cursor_field_ptr <= TILE_LAST_ATOM)) {
						while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {};
						holding_atom = *cursor_field_ptr;
						*cursor_field_ptr = TILE_FLOOR;
						draw_field();
						play_sound(SOUND_LEVEL_CATCH);
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_LEFT) {
					if (cursor_x > 0) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].x--;
							WaitVsync(1);
						}
						cursor_x--;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_RIGHT) {
					if (cursor_x < LEVEL_FIELD_WIDTH - 1) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].x++;
							WaitVsync(1);
						}
						cursor_x++;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_UP) {
					if (cursor_y > 0) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].y--;
							WaitVsync(1);
						}
						cursor_y--;
					} else {
						play_sound(SOUND_LEVEL_CANT_MOVE);
					}
				}
				if (buttons & BTN_DOWN) {
					if (cursor_y < LEVEL_FIELD_HEIGHT - 1) {
						for (uint8_t i = 0; i < TILE_WIDTH; i++) {
							sprites[SPRITE_CURSOR].y++;
							WaitVsync(1);
						}
						cursor_y++;
					} else {
						play_sound(1);
					}
				}
			}
			if (buttons & BTN_SELECT) {
				play_sound(SOUND_MENU_SELECT);
				goto MENU;
			}
			if (buttons & BTN_START) {
				play_sound(SOUND_MENU_SELECT);
				while (ReadJoypad(0) & BTN_START);
				load_level();
				refresh_game_screen();
			}

			draw_cursor();
			draw_statistics();
			WaitVsync(5);
		}

		hide_sprites();
		play_sound(SOUND_LEVEL_CLEARED);
		WaitVsync(60);

		// mark level as cleared
		eeprom_data.data[level / 8] |= 1 << (level % 8);
		EepromWriteBlock(&eeprom_data);
	}
}
Ejemplo n.º 30
0
Archivo: draw.c Proyecto: jlsandell/tig
bool
draw_id_custom(struct view *view, enum line_type type, const char *id, int width)
{
	return draw_field(view, type, id, width, ALIGN_LEFT, FALSE);
}