void updateGameAIPause(GUI *g, Controls *c, game_t *gm) { NOT(g); NOT(c); NOT(gm); if (!gm->player[gm->turn].aiShare.shareStart) { pthread_t thread; gm->player[gm->turn].aiShare.shareStart = true; gm->player[gm->turn].aiShare.shareEnd = false; gm->player[gm->turn].aiShare.loading = 0.f; gm->player[gm->turn].aiShare.game = gm; if (pthread_create(&thread, NULL, cbUpdateAi, &gm->player[gm->turn].aiShare) != 0) { exit(2); } } if (gm->player[gm->turn].aiShare.shareEnd) { gm->player[gm->turn].aiShare.shareStart = false; gm->player[gm->turn].aiShare.shareEnd = false; gm->player[gm->turn].aiShare.loading = 1.f; addActionToTextLog(&g->gameGui.textLog, &gm->player[gm->turn].aiShare.action); actionToLastMove(&g->gameGui.lastMove, &gm->player[gm->turn].aiShare.action); apply_action(&gm->player[gm->turn].aiShare.action, gm); next_turn(gm); g->next = nextGUIFocusByplayer_tag_t(gm->player[gm->turn].type); } }
void play_turn(void) { printf("Playing a turn.\n"); //main loop done = 0; while (!done) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: printf("Exit request caught, exiting.\n"); exit(1); break; case SDL_MOUSEBUTTONUP: xpos = event.button.x / TAILLE_CASE; ypos = event.button.y / TAILLE_CASE; render_map(); break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_n: /* go to the next turn */ next_turn(g_ccx); done = 1; break; case SDLK_q: case SDLK_ESCAPE: exit(0); break; case SDLK_RIGHT: //moveCam(&camera, CAMERA_MOVE_SIZE, 0); break; case SDLK_UP: //moveCam(&camera, 0, - CAMERA_MOVE_SIZE); break; case SDLK_DOWN: //moveCam(&camera, 0, CAMERA_MOVE_SIZE); break; case SDLK_LEFT: //moveCam(&camera, - CAMERA_MOVE_SIZE, 0); break; default: break; } // We don't break in order to redraw the map. case SDL_VIDEOEXPOSE: render_map(); break; } usleep(500); // Don't kill our CPU. } } }
void game::run() { if(DEBUG) std::cout << "color: relative pos => fixed\n"; while(!game_complete){ if(turn_complete){ turn_complete = false; msleep(game_delay/4); next_turn(game_delay - game_delay/4); } } emit close(); QThread::exit(); }
void replay_controller::play_side(const unsigned int /*team_index*/, bool){ if (recorder.at_end()){ return; } DBG_REPLAY << "Status turn number: " << turn() << "\n"; DBG_REPLAY << "Replay_Controller turn number: " << current_turn_ << "\n"; DBG_REPLAY << "Player number: " << player_number_ << "\n"; try{ // If a side is empty skip over it. if (!current_team().is_empty()) { statistics::reset_turn_stats(current_team().save_id()); play_controller::init_side(player_number_ - 1, true); DBG_REPLAY << "doing replay " << player_number_ << "\n"; do_replay(player_number_); finish_side_turn(); // This is necessary for replays in order to show possible movements. for (unit_map::iterator uit = units_.begin(); uit != units_.end(); ++uit) { if (uit->second.side() != player_number_) { uit->second.new_turn(); } } } player_number_++; if (static_cast<size_t>(player_number_) > teams_.size()) { next_turn(); finish_turn(); player_number_ = 1; current_turn_++; } update_teams(); update_gui(); } catch(end_level_exception& e){ //VICTORY/DEFEAT end_level_exception shall not return to title screen if ((e.result != VICTORY) && (e.result != DEFEAT)) { throw e; } } }
void update_guiFocusGameMenu(GUI *g, Controls *c, game_t *gm) { MenuWidget *m; NOT(g); NOT(c); NOT(gm); m = &g->gameMenu; updateMenuWidget(m, c); if (goBack(c)) { g->next = guiFocusGameGUI; return; } if (submitted(c)) { switch (m->focus) { case gameMenuFocusResume: { g->next = guiFocusGameGUI; break; } case gameMenuFocusSettings: { g->settings.previous = g->focus; g->next = guiFocusSettings; break; } case gameMenuFocusSkip: { g->transMove.type = transMoveSkipPlay; next_turn(gm); g->next = nextGUIFocusByplayer_tag_t(gm->player[gm->turn].type); break; } case gameMenuFocusQuit: { g->next = guiFocusGameAreYouSureQuit; break; } default: break; } return; } }
void next_turn(World *world, Bum *bum) { if (world->A != NULL && world->B != NULL) { buy_food(bum); scavenge(bum); if (rand() % 100 > 70) { bum->health -= (rand() % 8) + 25; } buy_booze(bum); heal_wounds(bum); cure_addiction(bum); bum->hunger += rand() % 10 + 10; if (bum->hunger > 100 || bum->health < 0 || bum->addiction > 100) { bury_bum(world, bum, bum->id); } if (bum->next != NULL) { next_turn(world, bum->next); } } }
int main() { World world; init_world(&world); srand(time(NULL)); int i; for (i = 0; i < 10 + rand() % 10; i++) { new_bum(&world); } while (1){ printf("\e[2J \e[0;0f"); shit_out(&world, world.A); getchar(); next_turn(&world, world.A); if ((rand() % 100) > 70) { new_bum(&world); } } return 0; }
void updateGameGUI(GUI *g, Controls *c, game_t *gm) { Cmd cmd; move_t m; action_t a; Log l; GameGUI *gg; TransMove *tm; NOT(g); NOT(c); NOT(gm); gg = &g->gameGui; tm = &g->transMove; if (c->hardware.key[hardwareKeyStart].type == KEY_STATE_PRESSED) { g->next = guiFocusGameMenu; return; } if (tm->type == transMoveInvalid) { resetNewGameGui(g, gm); } switch (gg->focus) { case gameGUIFocusBoard: boardWidgetControls(&cmd, gg, c); break; case gameGUIFocusRack: rackWidgetControls(&cmd, gg, c); break; default: break; } updateGameGUIViaCmd(gg, &cmd, tm->type); switch (cmd.type) { case cmdFocusTop: { if (tm->type == transMovePlace || tm->type == transMovePlaceEnd || tm->type == transMovePlacePlay) { gg->focus = gameGUIFocusBoard; } break; } case cmdFocusBottom: { if (tm->type == transMovePlaceWild) { break; } gg->focus = gameGUIFocusRack; break; } case cmdBoard: { if (tm->type == transMoveDiscard || tm->type == transMoveDiscardPlay) { break; } gg->focus = gameGUIFocusBoard; gg->boardWidget.index = cmd.data.board; break; } case cmdRack: { if (tm->type == transMoveSkip) { break; } gg->focus = gameGUIFocusRack; gg->rackWidget.index.x = cmd.data.rack; gg->rackWidget.index.y = 0; break; } default: break; } if (cmd.type == cmdInvalid) { gg->lastInput += SPF; } else { gg->lastInput = 0; } /* printCmd(&c); */ if (updateTransMove(tm, &cmd, &gm->board, &gm->player[gm->turn])) { /* printTransMove(&e->transMove); */ updateBoardWidget(&gg->boardWidget, tm, &gm->board); updateRackWidget(&gg->rackWidget, tm); if (tm->type == transMoveDiscard) { gg->focus = gameGUIFocusRack; } } transMoveToMove(&m, tm); mk_action(gm, &m, &a); apply_action(&a, gm); if (cmd.type == cmdPlay || cmd.type == cmdQuit) mkLog(&a, &l); if (a.type != ACTION_INVALID) { addActionToTextLog(&gg->textLog, &a); actionToLastMove(&gg->lastMove, &a); apply_adjust(tm->adjust.data.tile, &gm->player[a.playerIdx]); /* log action */ if (end_game(gm)) { g->next = guiFocusGameOver; /* log game over */ } else { next_turn(gm); clrTransMove(tm, gm->turn, &gm->player[gm->turn], &gm->board); g->next = nextGUIFocusByplayer_tag_t(gm->player[gm->turn].type); } tm->type = transMoveInvalid; } else { if (m.type != MOVE_INVALID) { /* printActionErr(a.type); */ } } if (cmd.type == cmdPlay) { gg->validPlay = a.type != ACTION_INVALID ? yes : no; } else { gg->validPlay = yesNoInvalid; } updateScoreBoard(&g->scoreBoard, gm, SPF); }