int do_game(){ int c, x, y, r, player, turn; char code[6], prev_code[6]; // ------------------------------------------------------------ // start! show_board(); player = first_player; turn = 0; prev_code[0] = 0; while(prompt(player, code, prev_code, !check_possibility(player, turn), turn)){ move m; int e, x_offset, y_offset; if(code[0] == 0) return TERMINATE_WRONG; // ctrl+d // retry if invalid code while(!check_code(code)){ if(interactive(player)){ prompt(player, code, prev_code, FALSE, turn); } else { printf("Invalid move on serial port.\n"); return player; } if(code[0] == 0) return TERMINATE_WRONG; } if(code[0] == 0) return TERMINATE_WRONG; // ctrl+d if(prev_code[0] == 0) strcpy(p1move1, code); if(strcmp(prev_code, "0000") == 0 && strcmp(code, "0000") == 0){ printf("Both pass!\n"); show_hint = FALSE; if(! (check_possibility(player, turn) || check_possibility(next_player(player), turn-1))){ return TERMINATE_NORMAL; } return TERMINATE_NORMAL; // is this OK? } strcpy(prev_code, code); // pass if(strcmp(code, "0000") == 0){ if(turn >= 2){ player = next_player(player); turn++; continue; } else { printf("First move must not be a pass.\n"); return player; } } m = decode_code(code); c = m.piece; r = m.rotate; x_offset = m.x-2; y_offset = m.y-2; if((e = check_move(player, turn, m)) != 0){ show_error(e); return player; } // OK, now place the move for(y=0; y<5; y++){ for(x=0; x<5; x++){ int b; b = pieces[c][0][rotate[r][y][x]]; if (b==1) board[y_offset+y][x_offset+x] = player; } } available[player-1][c] = 0; if(remaining_size(player)==0){ printf("Player %d won the game, since the player has no more pieces.\n", player); return TERMINATE_NORMAL; } // show the board & next player show_board(); player = next_player(player); turn++; } printf("Player %d timed out.\n", player); return player; }
bool Crystal_Loop::logic() { tgui::TGUIWidget *w = tgui::update(); if (w == return_button) { std::vector<Loop *> loops; loops.push_back(this); engine->fade_out(loops); engine->unblock_mini_loop(); } else if (w == player_button) { next_player(); } else { bool done = false; std::vector<Loop *> loops; loops.push_back(this); for (int x = 0; x < 3; x++) { for (int y = 0; y < /*3*/1; y++) { if (w == ability_buttons[x][y]) { if (Game_Specific_Globals::crystals <= 0) { engine->play_sample("sfx/error.ogg"); } else if (!static_cast<Crystal_Button *>(w)->filled()) { std::vector<std::string> v; v.push_back(t("REALLY_SPEND_CRYSTAL")); if (engine->yes_no_prompt(v, &loops)) { engine->play_sample("sfx/spend_crystal.ogg"); Game_Specific_Globals::crystals--; players[current_player]->get_battle_attributes().abilities.abilities[x]++; copy_abilities(); #ifdef STEAMWORKS achieve("crystal"); #endif } } done = true; break; } } } if (!done) { for (int i = 0; i < /*8*/1; i++) { if (w == hp_buttons[i]) { if (Game_Specific_Globals::crystals <= 0) { engine->play_sample("sfx/error.ogg"); } else if (!static_cast<Crystal_Button *>(w)->filled()) { std::vector<std::string> v; v.push_back(t("REALLY_SPEND_CRYSTAL")); if (engine->yes_no_prompt(v, &loops)) { engine->play_sample("sfx/spend_crystal.ogg"); Game_Specific_Globals::crystals--; players[current_player]->get_battle_attributes().abilities.hp++; players[current_player]->get_battle_attributes().max_hp += 10 * cfg.difficulty_mult(); copy_abilities(); #ifdef STEAMWORKS achieve("crystal"); #endif } } } else if (w == mp_buttons[i]) { if (Game_Specific_Globals::crystals <= 0) { engine->play_sample("sfx/error.ogg"); } else if (!static_cast<Crystal_Button *>(w)->filled()) { std::vector<std::string> v; v.push_back(t("REALLY_SPEND_CRYSTAL")); if (engine->yes_no_prompt(v, &loops)) { engine->play_sample("sfx/spend_crystal.ogg"); Game_Specific_Globals::crystals--; players[current_player]->get_battle_attributes().abilities.mp++; players[current_player]->get_battle_attributes().max_mp += 5; copy_abilities(); #ifdef STEAMWORKS achieve("crystal"); #endif } } } } } } #ifdef STEAMWORKS bool all_full = true; for (int i = 0; i < 3; i++) { if ( players[i]->get_battle_attributes().abilities.abilities[0] != 1 || players[i]->get_battle_attributes().abilities.abilities[1] != 1 || players[i]->get_battle_attributes().abilities.abilities[2] != 1 || players[i]->get_battle_attributes().abilities.hp != 1 || players[i]->get_battle_attributes().abilities.mp != 1 ) { all_full = false; break; } } if (all_full) { achieve("crystals"); } #endif return false; }