Esempio n. 1
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  if (!playing && lost) {
    restart_after_loss();
    return;
  }

  if (!playing && !lost && (load_choice < 2)) {
    setup_game();
    if (can_load && (load_choice == 1)) {
      load_game();
    }
    if (!s_timer) {
      drop_block();
      s_timer = app_timer_register(tick_time, game_tick, NULL);
    }
    return;
  }

  if (!playing && (load_choice == 2)) { // kamotswolf - had to modify several things in here to add new option
    option_shadows_buffer = !option_shadows_buffer;
    persist_write_bool(OPTION_SHADOWS_KEY, option_shadows_buffer);
    if(option_shadows_buffer) {
      text_layer_set_text(option_shadows_layer, "Drop Shadows ON");
    }
    else {
      text_layer_set_text(option_shadows_layer, "Drop Shadows OFF");
    }
    //layer_mark_dirty(s_title_pane_layer);
    return;
  }
  
  if (paused) {
    paused = false;
    s_timer = app_timer_register(tick_time, game_tick, NULL);
    layer_remove_from_parent(text_layer_get_layer(paused_label_layer));
    return;
  }

  if (blockType == -1) { return; }
  GPoint newPos[4];
  rotate_block(newPos, block, blockType, rotation);

  bool should_rotate = true;
  for (int i=0; i<4; i++) {
    if (newPos[i].x < 0 || newPos[i].x > 9) { should_rotate = false; }
    if (newPos[i].y < 0 || newPos[i].y > 19) { should_rotate = false; }
    if (grid[newPos[i].x][newPos[i].y]) { should_rotate = false; }
  }
  if (!should_rotate) { return; }

  for (int i=0; i<4; i++) {
    block[i] = newPos[i];
  }
  rotation = (rotation + 1) % 4;
  layer_mark_dirty(s_left_pane_layer);
}
Esempio n. 2
0
int main(void)
{
	setup_game();
	
	play_game();
	
	end_game();
	
	return 0;
}
Esempio n. 3
0
int main(int argc, char** argv)
{
	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	unsigned int i;

	signal(SIGPIPE, sighandler);
	signal(SIGTERM, sighandler);
	
	struct timeval tv;
	gettimeofday(&tv, NULL);
	srand(tv.tv_usec);

	if (argc < 2)
	{
		fprintf(stderr, "USAGE: %s <datafile>\n", argv[0]);
		exit(0);
	}
	gamedata = fopen(argv[1], "r");

	fscanf(gamedata, "%u %u", &NUMCOWS, &NUMROUNDS);
	for (i = 0; i < NUMCOWS; ++i)
		fscanf(gamedata, "%u", &MILKVALUES[i]);
	fscanf(gamedata, "%u", &NUMAGENTS); 

	setup_game();
	fclose(gamedata);

	if (setup_bcb_vis(NUMAGENTS, agents, &argc, &argv))
	{
		tell_all("READY", -1);
		play_game();
		close_bcb_vis();

		int maxmilk = 0;
		struct agent_t *a;
		for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
			if (a->milk > maxmilk && a->status == RUNNING)
				maxmilk = a->milk;

		for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
			if (a->milk == maxmilk && a->status == RUNNING)
				printf("Player #%u (%s) wins!\n", i, a->name);
	}

	cleanup_bots();
	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	int CONTINUE,WINNER,HUMAN,COMPUTER;

	if(argc!=4) {
		fprintf(stderr,"Usage: mnkgame <row> <col> <k>\n");
		return 1;
	}
	if(!read_parameters(argv)) return 1;

	if(!setup_game(M,N,K)) {
		fprintf(stderr,"Error: the board is too big!\n");
		return 1;
	}

	COMPUTER=1;
	HUMAN=2;

	setup_player(M,N,K);
	printf("Computer Player ready\n");
	mypause();

	CONTINUE=N*M;
  WINNER=DRAW;

	while(CONTINUE>0) {
		if(read_move(PLAYER1,HUMAN)) {
			WINNER=PLAYER1;
			CONTINUE=0;
		}
		if(--CONTINUE>0) {
			if(read_move(PLAYER2,HUMAN)) {
				WINNER=PLAYER2;
				CONTINUE=0;
			}
			--CONTINUE;
		}
	}
	system("cls");
	print_board();
	end_game(WINNER,HUMAN);


	free_player();
	free_game();

	return 0;
}
Esempio n. 5
0
void
game_init( const char *file_name, int *side_to_move ) {
  setup_game( file_name, side_to_move );
  setup_search();
  setup_midgame();
  setup_end();
  init_eval();

  clear_ponder_times();

  reset_counter( &total_nodes );

  reset_counter( &total_evaluations );

  init_flip_stack();

  total_time = 0.0;
  max_depth_reached = 0;
  last_time_used = 0.0;
  endgame_performed[BLACKSQ] = endgame_performed[WHITESQ] = FALSE;
}
Esempio n. 6
0
/*
** Animates a game until it is finished, and then cleans up allocated stuff.
** Returns final status of the game.
*/
int play_game()
{
	unsigned int status;
	int i;
	Boolean newgame;

	if (num_combatants == 0)
		return GAME_FAILED;

	/* In an ultimate game, only reset at the beginning, since we want don't
       want scores to reset after every goal. */
	if (settings.si.game == ULTIMATE_GAME) {
		init_combatants();
		newgame = TRUE;
	}
	do {
#ifdef X11
		button_up(ANIM_WIN, FALSE);
		follow_mouse(ANIM_WIN, FALSE);
#endif
		if (settings.si.game != ULTIMATE_GAME) {
			init_combatants();
			newgame = TRUE;
		}
		if (setup_game(newgame) == GAME_FAILED)
			return GAME_FAILED;
		newgame = FALSE;


		game_running = True;

#ifdef SOUND
		play_all(START_SOUND);
#endif /*SOUND*/

		do {
			status = animate();
		} while (status == GAME_RUNNING);

#ifdef SOUND
		play_all(END_SOUND);
#endif /*SOUND*/

		game_running = False;

		status = display_game_stats(status);

		game_cleanup();			/* nuking all the vehicles here is overkill */
	} while (status == GAME_RESET);

	/* Unmap battle windows and clear all other windows on all the terminals */
	for (i = 0; i < num_terminals; i++) {
		set_terminal(i);
		unmap_battle_windows();
		clear_windows();
	}

	/* Return to terminal 0 for the user interface */
	set_terminal(0);

#ifdef X11
	button_up(ANIM_WIN, TRUE);
	follow_mouse(ANIM_WIN, TRUE);
#endif

	return status;
}
Esempio n. 7
0
void game (gamedata &g){

  SDL_Event event;
  quit = false;

  // Set first tick interval
  Uint32 next_time = SDL_GetTicks() + TICK_INTERVAL;

  while (!quit){
	  if(g.winner){
		finish_game(g);
		setup_game(g);
		GameState = STATE_INTRO;
		CurrentMenu = MenuMainIntro;
		SelectedItem = menuSwitchItem(CurrentMenu, 0);
		demo = true;
	  }
	 else if (g.winner == 0){

	    Uint8 *keys = SDL_GetKeyState(NULL);

	    if (SDL_PollEvent(&event) == 1){
	      switch (event.type){

	      case SDL_QUIT: {
		printf("Quit requested, quitting.\n");
		quit = true;
	      }
	      break;
	      }
	    }

	    if(GameState == STATE_INTRO || GameState == STATE_MENU)
	    {
		    menuInput(g);
	    }
	    else if(GameState == STATE_MENU_PLANE_SELECT)
	    {
		    menuPlanes(g);
	    }
	    else if(GameState == STATE_MENU_PLAYER_CONTROL_SELECT)
	    {
		    menuSelectPlayer(g);
	    }
	    else if(GameState == STATE_GAME)
	    {
		    if ((keys[SDLK_ESCAPE] == SDL_PRESSED) || (keys[51] == SDL_PRESSED)){
			keys[SDLK_ESCAPE] = SDL_RELEASED;
			GameState = STATE_MENU;
			CurrentMenu = MenuMain;
			SelectedItem = menuSwitchItem(CurrentMenu, 0);
		      //quit = true;
		    }
	    }

	    // Go through each plane individually
	    g.p.reset();
	    while (g.p.next()){

	      // Setup virtual joystick
	      int jx = 0;

	      int jy = 0;
	      bool jb = false;

	      if (g.p().state < 2){
		control(g, keys, jx, jy, jb);
		controlJoy(g, jx, jy, jb);
	      }
	      // Then move the plane
	      act(g, jx, jy, jb);
	      // Remove expunged planes
	      if (g.p().state == 4){
		g.drakms.fighter[g.p().id-7] = false;
		g.drakms.fightersout--;
		g.dp.reset();
		while(g.dp.next()){
		  if (g.dp().id == g.p().id) g.dp.kill();
		}
		g.p.kill();
	      }

	    }

	    // Then do everything else
	    all(g);
	    drawall(g);

	    // Delay for time remaining in TICK_INTERVAL
	    SDL_Delay(time_left(next_time));
	    next_time = SDL_GetTicks() + TICK_INTERVAL;

	  }
  }
}
Esempio n. 8
0
static bool
do_main_menu (void)
{
    int selection = 0;
    MENUITEM_STRINGLIST (menu, "Rockbox Goban", NULL,
                         "New",
                         "Save",
                         "Save As",
                         "Game Info",
                         "Playback Control",
                         "Zoom Level",
                         "Options",
                         "Context Menu",
                         "Quit");

    /* for "New" in menu */
    int new_handi = 0, new_bs = MAX_BOARD_SIZE, new_komi = 15;

    char new_save_file[SAVE_FILE_LENGTH];


    bool done = false;

    while (!done)
    {
        selection = rb->do_menu (&menu, &selection, NULL, false);

        switch (selection)
        {
        case MAIN_NEW:
            rb->set_int ("board size", "lines", UNIT_INT,
                         &new_bs, NULL, 1, MIN_BOARD_SIZE, MAX_BOARD_SIZE,
                         NULL);

            rb->set_int ("handicap", "stones", UNIT_INT,
                         &new_handi, NULL, 1, 0, 9, NULL);

            if (new_handi > 0)
            {
                new_komi = 1;
            }
            else
            {
                new_komi = 13;
            }

            rb->set_int ("komi", "moku", UNIT_INT, &new_komi, NULL,
                         1, -300, 300, &komi_formatter);

            setup_game (new_bs, new_bs, new_handi, new_komi);
            draw_screen_display ();
            done = true;
            break;

        case MAIN_SAVE:
            if (!save_game (save_file))
            {
                rb->splash (2 * HZ, "Save Failed!");
            }
            else
            {
                rb->splash (2 * HZ / 3, "Saved");
            }
            done = true;
            draw_screen_display ();
            break;

        case MAIN_SAVE_AS:
            rb->strcpy (new_save_file, save_file);

            if (!rb->kbd_input (new_save_file, SAVE_FILE_LENGTH))
            {
                break;
            }

            if (!save_game (new_save_file))
            {
                rb->splash (2 * HZ, "Save Failed!");
            }
            else
            {
                rb->strcpy (save_file, new_save_file);
                rb->splash (2 * HZ / 3, "Saved");
            }

            done = true;
            draw_screen_display ();
            break;

        case MAIN_GAME_INFO:
            do_gameinfo_menu ();
            break;

        case MAIN_PLAYBACK:
            if (!audio_stolen_sgf ())
            {
                playback_control (NULL);
            }
            else
            {
                rb->splash (1 * HZ, "Audio has been disabled!");
            }
            break;

        case MAIN_ZOOM:
            if (do_zoom ())
            {
                return true;
            }
            done = true;
            draw_screen_display ();
            break;

        case MAIN_OPTIONS:
            do_options_menu();
            break;

        case MAIN_CONTEXT:
            do_context_menu ();
            done = true;
            break;

        case MAIN_QUIT:
        case MENU_ATTACHED_USB:
            return true;

        case GO_TO_ROOT:
        case GO_TO_PREVIOUS:
        default:

            done = true;
            break;
        };
    }

    return false;
}
Esempio n. 9
0
enum plugin_status
plugin_start (const void *parameter)
{
    int btn;

    rb->mkdir (DEFAULT_SAVE_DIR);

    global_setup ();

#ifdef GBN_TEST
    run_tests ();
    return PLUGIN_OK;
#endif

    if (!(parameter && load_game (parameter)))
    {
        if (parameter)
        {
            rb->splashf (2 * HZ, "Loading %s failed.", (char *) parameter);
        }

        if (!load_game (DEFAULT_SAVE))
        {
            rb->strcpy (save_file, DEFAULT_SAVE);

            if (!setup_game (MAX_BOARD_SIZE, MAX_BOARD_SIZE, 0, 0))
            {
                return PLUGIN_ERROR;
            }
        }
    }
    else
    {
        /* game loaded */
        if (rb->strcmp (save_file, DEFAULT_SAVE))
        {
            /* delete the scratch file if we loaded a game and it wasn't
             * from the scratch file
             */
            rb->remove (DEFAULT_SAVE);
        }
    }

    draw_screen_display ();

    autosave_counter = 0;
    for (;;)
    {
        btn = rb->button_get_w_tmo (HZ * 30);

        if (disable_shutdown)
        {
            /* tell rockbox we're not idle */
            rb->reset_poweroff_timer ();
        }

        bool is_idle = false;

        switch (btn)
        {

#if defined(GBN_BUTTON_NAV_MODE)
        case GBN_BUTTON_NAV_MODE:
        case GBN_BUTTON_NAV_MODE | BUTTON_REPEAT:
            if (nav_mode == NAV_MODE_TREE)
            {
                nav_mode = NAV_MODE_BOARD;
                rb->splash (2 * HZ / 3, "board navigation mode");
                draw_screen_display ();
            }
            else
            {
                nav_mode = NAV_MODE_TREE;
                rb->splash (2 * HZ / 3, "tree navigation mode");
                draw_screen_display ();
            }
            break;
#endif

#if defined(GBN_BUTTON_ADVANCE)
        case GBN_BUTTON_ADVANCE:
        case GBN_BUTTON_ADVANCE | BUTTON_REPEAT:
            if (has_more_nodes_sgf ())
            {
                if (!redo_node_sgf ())
                {
                    rb->splash (2 * HZ, "redo failed");
                }
                draw_screen_display ();
            }
            break;
#endif

#if defined(GBN_BUTTON_RETREAT)
        case GBN_BUTTON_RETREAT:
        case GBN_BUTTON_RETREAT | BUTTON_REPEAT:
            if (has_prev_nodes_sgf ())
            {
                if (!undo_node_sgf ())
                {
                    rb->splash (3 * HZ / 2, "Undo Failed");
                }
                draw_screen_display ();
            }
            break;
#endif

        case GBN_BUTTON_PLAY:
            if (play_mode == MODE_PLAY || play_mode == MODE_FORCE_PLAY)
            {
                if (!play_move_sgf (cursor_pos, current_player))
                {
                    rb->splash (HZ / 3, "Illegal Move");
                }
            }
            else if (play_mode == MODE_ADD_BLACK)
            {
                if (!add_stone_sgf (cursor_pos, BLACK))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_ADD_WHITE)
            {
                if (!add_stone_sgf (cursor_pos, WHITE))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_REMOVE)
            {
                if (!add_stone_sgf (cursor_pos, EMPTY))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_MARK)
            {
                if (!add_mark_sgf (cursor_pos, PROP_MARK))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_CIRCLE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_CIRCLE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_SQUARE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_SQUARE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_TRIANGLE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_TRIANGLE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_LABEL)
            {
                if (!add_mark_sgf (cursor_pos, PROP_LABEL))
                {
                    rb->splash (HZ / 3, "Couldn't Label");
                }
            }
            else
            {
                rb->splash (HZ, "mode not implemented");
            }

            draw_screen_display ();
            break;

        case GBN_BUTTON_RIGHT:
        case GBN_BUTTON_RIGHT | BUTTON_REPEAT:
#if defined(GBN_BUTTON_NAV_MODE)
            if (nav_mode == NAV_MODE_TREE)
            {
                if (has_more_nodes_sgf ())
                {
                    if (!redo_node_sgf ())
                    {
                        rb->splash (2 * HZ, "Redo Failed");
                    }
                    draw_screen_display ();
                }
            }
            else
            {
#endif
                cursor_pos = WRAP (EAST (cursor_pos));
                draw_screen_display ();
#if defined(GBN_BUTTON_NAV_MODE)
            }
#endif
            break;

        case GBN_BUTTON_LEFT:
        case GBN_BUTTON_LEFT | BUTTON_REPEAT:
#if defined(GBN_BUTTON_NAV_MODE)
            if (nav_mode == NAV_MODE_TREE)
            {
                if (has_prev_nodes_sgf ())
                {
                    if (!undo_node_sgf ())
                    {
                        rb->splash (2 * HZ, "Undo Failed");
                    }
                    draw_screen_display ();
                }
            }
            else
            {
#endif
                cursor_pos = WRAP (WEST (cursor_pos));
                draw_screen_display ();
#if defined(GBN_BUTTON_NAV_MODE)
            }
#endif
            break;

        case GBN_BUTTON_DOWN:
        case GBN_BUTTON_DOWN | BUTTON_REPEAT:
            cursor_pos = WRAP (SOUTH (cursor_pos));
            draw_screen_display ();
            break;

        case GBN_BUTTON_UP:
        case GBN_BUTTON_UP | BUTTON_REPEAT:
            cursor_pos = WRAP (NORTH (cursor_pos));
            draw_screen_display ();
            break;

        case GBN_BUTTON_MENU:
            if (do_main_menu ())
            {
                save_game (DEFAULT_SAVE);

                global_cleanup ();
                return PLUGIN_OK;
            }

            draw_screen_display ();
            break;

#if defined(GBN_BUTTON_CONTEXT)
        case GBN_BUTTON_CONTEXT:
            do_context_menu ();
            draw_screen_display ();
            break;
#endif

#if defined(GBN_BUTTON_NEXT_VAR)
        case GBN_BUTTON_NEXT_VAR:
        case GBN_BUTTON_NEXT_VAR | BUTTON_REPEAT:
        {
            int temp;
            if ((temp = next_variation_sgf ()) >= 0)
            {
                draw_screen_display ();
                rb->splashf (2 * HZ / 3, "%d of %d", temp,
                             num_variations_sgf ());
                draw_screen_display ();
            }
            else
            {
                if (num_variations_sgf () > 1)
                {
                    rb->splashf (HZ, "Error %d in next_variation_sgf", temp);
                }
                draw_screen_display ();
            }
            break;
        }
#endif

        case BUTTON_NONE:
            is_idle = true;
        default:
            if (rb->default_event_handler (btn) == SYS_USB_CONNECTED)
            {
                return PLUGIN_USB_CONNECTED;
            }
            break;
        };

        if (is_idle && autosave_dirty)
        {
            ++autosave_counter;

            if (autosave_time != 0 &&
                autosave_counter / 2 >= autosave_time)
                /* counter is in 30 second increments, autosave_time is in
                 * minutes
                 */
            {
                DEBUGF("autosaving\n");
                rb->splash(HZ / 4, "Autosaving...");
                save_game(DEFAULT_SAVE);
                draw_screen_display();
                autosave_counter = 0;
            }
        }
        else
        {
            autosave_counter = 0;
        }
    }

    return PLUGIN_OK;
}
Esempio n. 10
0
int main(int argc, char* argv[])
{
	// init allegro and add keyboard and optional mouse support
	allegro_init();
	install_timer();
	install_keyboard();
	if (ENABLE_MOUSE_SUPPORT)
	{
		install_mouse();
	}

	// set the video mode
	set_color_depth(WINDOW_COLOR_DEPTH);
	set_gfx_mode(
		(WINDOW_USE_FULLSCREEN) ?
			GFX_AUTODETECT_FULLSCREEN :
			GFX_AUTODETECT_WINDOWED,
		WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
	// set the window caption text
	set_window_title(WINDOW_CAPTION);

	// create the back buffer bitmap
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);

	// seed the random number generator
	srand(time(0));

	// lock the static functions and variables we need for handling timing and closing the window via the [X] button
	LOCK_FUNCTION(my_allegro_close_button_handler);
	LOCK_FUNCTION(my_allegro_timer_speed_controller);
	LOCK_VARIABLE(allegrotimerspeedcounter);

	// set the callback function for the close-button to our global handler function
	set_close_button_callback(my_allegro_close_button_handler);

	// set our FPS lock timing global function
	install_int_ex(my_allegro_timer_speed_controller, BPS_TO_TIMER(FRAME_LOCK_RATE));

	// setup the game
	if (!setup_game())
	{
		fprintf(stderr, "The game initialization has failed. Cannot continue!\n");
		exit(1);
	}

	// main loop
	bool gameover = false;
	while(!gameover)
	{
		// if our global is ever false
		if (!mainthreadisrunning)
		{
			gameover = true;
		}

		// we only draw when the FPS should be locked
		if (allegrotimerspeedcounter > 0)
		{
			// we only update during our FPS lock time
			while (allegrotimerspeedcounter > 0)
			{
				// ensure the keyboard data is current
				if (keyboard_needs_poll())
				{
					poll_keyboard();
				}

				// ensure the mosue data is current
				if (ENABLE_MOUSE_SUPPORT)
				{
					if (mouse_needs_poll())
					{
						poll_mouse();
					}
				}

				// update
				update_game();

				// decrement the global timing var so that we can leave the update loop!
				allegrotimerspeedcounter--;
			}

			// start rendering the scene
			render_game();

			if (ENABLE_MOUSE_SUPPORT)
			{
				show_mouse(backbuffer);
			}

			// make it all visible
			blit(backbuffer, screen, 0, 0, 0, 0, backbuffer->w, backbuffer->h);
		}
		else
		{
			// a little rest to keep CPU usage down ^-^
			rest(1);
		}
	}

	// shutdown the game
	shutdown_game();

	// clean up the back buffer
	if (backbuffer)
	{
		if (ENABLE_MOUSE_SUPPORT)
		{
			show_mouse(0);
		}
		destroy_bitmap(backbuffer);
	}

	return 0;
}
Esempio n. 11
0
void game_wait(int created_game) {
    int key = 0;

    dispmultiframe();

    // this prints out current users in this game
    int i = created_game; // (which also needs to be integrated with server)
    // int onlinelistoffset = 0    ;

    int p_id;
    int foxes;
    int command;
    char* buffer;

    while (1) {
        int useroffset = 1;

        if (receive(sockfd, &command, &buffer) < 0) {
            if (errno != EWOULDBLOCK && errno != EAGAIN)
                return;
        }
        else {
            switch (command) {
                case CMD_NEW_REQUEST:
                    if (confirm_request(buffer))
                        transmit(sockfd, CMD_ACCEPT_REQ, buffer);
                    else
                        transmit(sockfd, CMD_REJECT_REQ, buffer);
                    dispmultiframe();
                    break;
                case CMD_CANCEL_REQ:
                    // TODO: implement
                    break;
                case CMD_PLAYER_JOIN:
                    sscanf(buffer, "%d", &p_id);
                    for (foxes = 0; foxes < games[i].slots_total; foxes++) {
                        if (games[i].players[foxes] == EMPTY_SLOT) {
                            games[i].players[foxes] = p_id;
                            break;
                        }
                    }
                    break;
                case CMD_PLAYER_PART:
                    sscanf(buffer, "%d", &p_id);
                    for (foxes = 0; foxes < games[i].slots_total; foxes++) {
                        if (games[i].players[foxes] == p_id) {
                            games[i].players[foxes] = EMPTY_SLOT;
                            break;
                        }
                    }
                    break;
                case CMD_GAME_START: {
                    game_t game;
                    setup_game(&game);
                    setup_multiplayer(&game, games[i].slots_total, atoi(buffer), sockfd);
                    while (game.running) {
                        update_game(&game);
                        usleep(1000000 / FPS);
                    }
                    return;
                }
                case CMD_QUIT:
                case CMD_ERROR:
                    return;
            }
            free(buffer);
        }

        switch ((key = getkey())) {
            case 'q':
            case 'Q':
            case 27: // esc
                transmit(sockfd, CMD_PLAYER_PART, NULL);
                xt_par0(XT_CLEAR_SCREEN);
                return;
        }

        for (foxes = 0; foxes < games[i].slots_total; foxes++) {
            SETPOS(6 + 2 * i + useroffset, 8);
            if (games[i].players[foxes] != EMPTY_SLOT) {
                printf("%d", games[i].players[foxes]);
                useroffset++;
            }
        }

        SETPOS(2,3);
        printf("%s", games[created_game].name);
        SETPOS(ROWS, COLS);

        fflush(stdout);
        usleep(1000000 / 20);
    }
}
Esempio n. 12
0
static void
preferences_cb (GSimpleAction * action, GVariant * parameter, gpointer data)
{
  setup_game ();
}