// What are my possible next moves (locations) LocationID *whereCanIgo(HunterView currentView, int *numLocations, int road, int rail, int sea) { assert(currentView != NULL); assert(numLocations != NULL); // return value LocationID *ret; // check if first round if(getRound(currentView->g) == FIRST_ROUND) { // everywhere! ret = (LocationID *)(malloc(sizeof(LocationID)*NUM_MAP_LOCATIONS)); (*numLocations) = 0; int i; for(i=0;i<NUM_MAP_LOCATIONS;i++) { ret[(*numLocations)] = i; (*numLocations)++; } } else { ret = connectedLocations(currentView->g, numLocations, getLocation(currentView->g, getCurrentPlayer(currentView->g)), getCurrentPlayer(currentView->g), getRound(currentView->g), road ,rail, sea); } return ret; }
void victoryMessage(victory){ switch(victory){ case VC_DRAW: printf("Draw!\n"); break; case VC_VICTORY: if (getCurrentPlayer() == PT_WHITE) printf("White wins!\n"); else printf("Black wins!\n"); break; case VC_NO_VICTORY: printf("The game continues\n"); if (getCurrentPlayer() == PT_WHITE) printf("Now it's the turn of Black!\n"); else printf("Now it's the turn of White!\n"); break; default: break; } return; }
int readIndex (int indexType) { int x, y, index = ERROR; char moveNotation[3]; while (index < 0){ if (indexType == ORIGINE) printf("enter the piece you want to move: \n"); else printf("enter where you want to move to: \n"); scanf("%s", moveNotation); index = readNotation (moveNotation, getCurrentPlayer()); transf_index2rel(index, &x, &y); if (!controlNotation(moveNotation)){ printf("Invalid notation!\n"); index = ERROR; } if (indexType == ORIGINE){ if(getSquareContent(x,y) == PC_EMPTY){ printf("The square is empty!\n"); index = ERROR;} else if (getSquareContent(x,y) != getCurrentPlayer()+1){ printf("You are moving the opposite color!\n"); index = ERROR; } } } return index; }
// What are my possible next moves (locations) LocationID *whereCanIgo(HunterView currentView, int *numLocations, int road, int rail, int sea) { fprintf(stderr,"damPlayer:%d\n",getCurrentPlayer(currentView->g)); return whereCanTheyGo(currentView, numLocations, getCurrentPlayer(currentView->g), road, rail, sea); }
// What are my possible next moves (locations) LocationID *whereCanIgo(HunterView currentView, int *numLocations, int road, int rail, int sea) { return whereCanTheyGo(currentView, numLocations, getCurrentPlayer(currentView->game), road, rail, sea); }
/** * Reads a game in XML representation from the given device and creates a game object for it. * * @param device Device to read the game from. * @return A game representing the state of the XML. */ QSharedPointer<Game> GameReader::readGame(QIODevice* device) { this->xmlStream.setDevice(device); this->readXML(true); auto gameLogic = QSharedPointer< ::GameLogic::FourInALine::Game>::create(this->nRows, this->nColumns, this->firstMovePlayerId); gameLogic->setTimeLimit(this->timeLimit); gameLogic->setTimeoutAction(this->timeoutAction); auto game = QSharedPointer<Game>::create(gameLogic, this->firstPlayer, this->secondPlayer); game->setSaveHighscore(this->saveHighscore); game->setAllowUndo(this->allowUndo); game->setAllowHint(this->allowHint); for (auto i = this->moves.cbegin(); i != this->moves.cend(); ++i) { if (game->getCurrentPlayer()->getPlayer() != i->first) { throw ParseError("Expected other player in current move."); } game->getGameLogic()->makeMove(i->second); } return game; }
//helper function to simulate winning moves void winning_move(int* moves, int expected_winner){ int i = 0; while((winnerIs(g_board) == 0) && validMovesLeft(g_board)){ if(getCurrentPlayer(g_board) == PLAYER_ONE){ makeMove(g_board, moves[i]); ++i; } else { makeMove(g_board, getReasonedMove(g_board)); } } assert_int_equal(expected_winner, winnerIs(g_board)); /* * assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 1); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 2); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 3); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 3); //player two moves assert_int_equal(expected_winner, winnerIs(g_board)); */ }
bool chessGame::tryMove(const boardMove &bm) { if (bm.isLegal(getBoard().getLegalMoves(bm.getStart()))){ state.makeMove(bm); history.append(state); redo.clear(); emit madeMove(bm); cantStep = !getCurrentPlayer()->isHuman(); if (cantStep){ getCurrentPlayer()->think(state); } } return false; }
void UnitsManager::onUnitChosen(const QString &unitName) { if (playersComboBox->isEnabled()) { currentUnit = MechModel::getMech(unitName)->getUid(); emit playerChosen(getCurrentPlayer()); emit unitChosen(currentUnit); } }
void FAPythonFuncs::startGame() { auto world = FAWorld::World::get(); world->setLevel(0); auto level = world->getCurrentLevel(); auto player = world->getCurrentPlayer(); player->mPos = FAWorld::Position(level->upStairsPos().first, level->upStairsPos().second); mEngine.unPause(); mGuiManager.showIngameGui(); }
void AttackSystem::update() { for(auto attackComponent : m_EntitySystem.getComponentsOfType<AttackComponent>()) { if(attackComponent->canAttack()) { auto playerHealth = getCurrentPlayer()->getComponent<HealthComponent>(); playerHealth->dealDamage(attackComponent->Damage); attackComponent->startTimer(); } } }
bool Round::moneyIsDistributed(){ Player* player = getCurrentPlayer(); if (player->getBet() == 0 && player == active_players.back() ) { // last player already got his money this->roundOver = true; // round is now over; return true; } else if (player->getBet() == 0) { // player already got his money player = getNextPlayer(); } int player_score = player->getHand()->getTotal(); int dealer_score = this->dealer->getHand()->getTotal(); int player_status = player->getStatus(); int dealer_status = this->dealer->getStatus(); float player_bet = player->getBet(); if (player_status == 6 && dealer_status != 4) { // player has doubled and has blackjack AND dealer did not blackjack player->updateBalance(player_bet*2*2*1.5); } else if (player_status == 4 && (dealer_status != 5 && dealer_score < player_score) ) { // player has doubled AND dealer is not bust AND dealer has lesser score player->updateBalance(player_bet*2*2); } else if (player_status == 5 && (dealer_status != 5 && dealer_score < player_score) ) { // player has blackjack AND dealer is not bust AND dealer has lesser score player->updateBalance(player_bet*2*1.5); } else if ( (player_status != 3 && player_score > dealer_score ) || (player_status != 3 && dealer_status == 5) ){ // player isnt bust AND player has better hand OR player inst bust AND dealer is bust player->updateBalance(player_bet*2); } else if ( player_status == 3 || ( dealer_score > player_score && dealer_status != 5) ){ // player is bust OR dealer has better hand AND dealer isnt bust player->updateBalance(0); } else if ( player_score == dealer_score ){ // player hand equals dealers hand player->updateBalance(player_bet); } return false; }
bool Round::allPlayersHaveBetted(){ Player* player_betting = getCurrentPlayer(); if (player_betting == active_players.back() && player_betting->getBet() > 0){ current_player = active_players.begin(); return true; } else if (player_betting->getBet() > 0) { // current player already betted getNextPlayer(); return false; } else return false; }
int main(int argc, char * argv[]) { playerMessage messages[] = {}; printf("Test basic empty initialisation\n"); HunterView hv = newHunterView("", messages); assert(getCurrentPlayer(hv) == PLAYER_LORD_GODALMING); assert(getRound(hv) == 0); assert(getHealth(hv, PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS); assert(getHealth(hv, PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); assert(getScore(hv) == GAME_START_SCORE); assert(getLocation(hv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION); disposeHunterView(hv); printf("passed\n"); return 0; }
// Fills the trail array with the location ids of the last 6 turns void getHistory(GameView currentView, PlayerID player, LocationID trail[TRAIL_SIZE]) { assert(currentView != NULL); assert(0 <= player && player < NUM_PLAYERS); assert(trail != NULL); int i; // last round this player made a move in Round lastRoundPlayed; if(getCurrentPlayer(currentView) > player) { // moved this round already lastRoundPlayed = getRound(currentView); } else { // haven't yet made a move this round lastRoundPlayed = getRound(currentView) - 1; } // iterate over past moves for(i=0;i<TRAIL_SIZE;i++) { // round we're considering Round curRound = (Round)(lastRoundPlayed-i); if(curRound >= FIRST_ROUND) { // number of the turn (NOT type Round since it's a turn not a round) int turnNo = (curRound * NUM_PLAYERS) + player; // pointer to the start of the play; some pointer arithmetic char *startOfPlay = (currentView->pastPlays) + (turnNo * CHARS_PER_PLAY_BLOCK); // get id from the abbreviation (located in the first two characters of // start of play and store it in the trail trail[i] = (LocationID)(getNewLocation(startOfPlay + LOC_ABBREV_INDEX)); } else { // no previous location trail[i] = UNKNOWN_LOCATION; } // D("trail for player %d: %d rounds ago: %d [round %d]\n",player, i, trail[i], curRound); } }
void printBoard (){ printf(" ----------------\n"); int x,y, absX, absY; for (y = 8; y > 0; y--) { putchar('1' + (y - 1)); for(x = 1; x < 9; x++) { putchar('|'); if (getCurrentPlayer() == PT_BLACK){ absY = 9 - y; } else { absY = y;} absX = x; switch (getSquareContent(absX, absY)) { case PC_PAWN_WHITE: putchar('W'); break; case PC_PAWN_BLACK: putchar('B'); break; case PC_EMPTY: putchar('.'); break; case PC_QUEEN_WHITE: putchar('Q'); break; case PC_QUEEN_BLACK: putchar('Q'); break; default: break; } } putchar('|'); putchar('\n'); } printf(" ----------------\n"); printf(" A B C D E F G H\n"); return; }
// Given a player ID, return when the player's last turn took place int getLastRound(DracView dv, PlayerID player) { int round; round = dv->round; // If currentPlayer (ie. 2 - H..) is < player (ie 5 - Drac), // then Dracula hasn't played his turn this round, and the last // round in which played was currentRound-1, ie, round 0 // // ie.. G... S... H... M... D... (round 0) // G... S... H... (round 1) if (getCurrentPlayer(dv->gv) <= player) { round -= 1; // printf("getLastRound: player %d, round is now %d, currRound: %d\n", player, round, getRound(dv->gv)); } return round; }
// Creates a new GameView to summarise the current state of the game GameView newGameView(char *pastPlays, PlayerMessage messages[]) { assert(pastPlays != NULL); assert(messages != NULL); GameView g = malloc(sizeof(struct gameView)); assert(g != NULL); g->pastPlays = malloc(sizeof(char) * MAX_PAST_PLAYS_LENGTH); int indexAt = 0; // Initialise the hunters int i; for(i = 0; i < NUM_PLAYERS-1; i++) { g->players[i].health = GAME_START_HUNTER_LIFE_POINTS; g->players[i].position = NOWHERE; } // initialise dracula g->players[PLAYER_DRACULA].health = GAME_START_BLOOD_POINTS; g->players[PLAYER_DRACULA].position = NOWHERE; // initialise turn and score g->turns = 0; g->score = GAME_START_SCORE; // initialise the trails for(i = 0; i < TRAIL_SIZE; i++) { g->trail[i] = NOWHERE; } // make a copy of past plays strncpy(g->pastPlays, pastPlays, MAX_PAST_PLAYS_LENGTH); // process the plays while(pastPlays[indexAt] != '\0') { // D("Play to process here is "); // int x; // for(x = 0; x < CHARS_PER_PLAY; x++) { // D("%c",pastPlays[indexAt+x]); // } // D("\n"); // copy message // current turn index [0-based] is g->turns // first, allocate space for the string g->messages[g->turns] = (char *)(malloc(sizeof(char)*MAX_MESSAGE_LENGTH)); assert(g->messages[g->turns] != NULL); assert(messages[g->turns] != NULL); // copy string, using strncpy for safety strncpy(g->messages[g->turns], messages[g->turns], MAX_MESSAGE_LENGTH); // get the abbreviation for the new location char abbrev[3]; abbrev[0] = pastPlays[indexAt+1]; abbrev[1] = pastPlays[indexAt+2]; // add a NUL terminator for good measure abbrev[2] = '\0'; // try to get the place id of the current place LocationID placeID = abbrevToID(abbrev); // work out if dracula or a hunter if(pastPlays[indexAt] == 'D') { // This player is dracula // We update his position. int isAtSea; int isAtCastle; if(placeID != NOWHERE) { if(idToType(placeID) == SEA) { isAtSea = TRUE; } else { isAtSea = FALSE; } if(placeID == CASTLE_DRACULA) { isAtCastle = TRUE; } else { isAtCastle = FALSE; } pushOnTrail(g, placeID); } else { // This is not dracula's string and we do not know where he is // And cannot update his position, other than saying if he is // on land or at sea. // We still need to know if he is at sea if(abbrev[0] == 'C') { // He is in some city // That is not castle dracula isAtSea = FALSE; isAtCastle = FALSE; pushOnTrail(g, CITY_UNKNOWN); placeID = CITY_UNKNOWN; } else if(abbrev[0] == 'S') { // He is at sea isAtSea = TRUE; isAtCastle = FALSE; pushOnTrail(g, SEA_UNKNOWN); placeID = SEA_UNKNOWN; } else if(abbrev[0] == 'T') { // He is at the castle isAtSea = FALSE; isAtCastle = TRUE; pushOnTrail(g, CASTLE_DRACULA); // set placeID to be teleport placeID = TELEPORT; } else if(abbrev[0] == 'D') { // He doubled back. // Because of the game's rules, we don't be clever and // instead place only the DOUBLE_BACK_ move type onto the // trail, even though we can (and do) infer the at-sea-ness // and location of dracula int numBack = (int)(abbrev[1]-'0'); LocationID newPosition = g->trail[TRAIL_SIZE-numBack]; // D("trail:"); // for(i=0;i<TRAIL_SIZE;i++) { // D(" %d",g->trail[i]); // } // D("\n"); // D("newPosition is %d\n",newPosition); if(newPosition == CITY_UNKNOWN) { isAtSea = FALSE; isAtCastle = FALSE; } else if (newPosition == SEA_UNKNOWN) { isAtSea = TRUE; isAtCastle = FALSE; } else { // We know exactly where dracula is if (idToType(newPosition) == SEA) { isAtSea = TRUE; isAtCastle = FALSE; } else if(newPosition == CASTLE_DRACULA) { isAtSea = FALSE; isAtCastle = TRUE; } else { isAtSea = FALSE; isAtCastle = FALSE; } } pushOnTrail(g, newPosition); // for sake of the getLocation function, we'll set // Dracula's new location to be the TYPE of move as opposed // to the city he's actually at even though we know what // that is placeID = (FIRST_DOUBLE_BACK-MIN_DOUBLE_BACK) + numBack; } else if(abbrev[0] == 'H') { // He's HIDING! // push on the most recent location pushOnTrail(g, g->trail[TRAIL_SIZE-1]); // for sake of getLocation, make current location HIDE placeID = HIDE; } } // set Dracula's 'public' location (as returned by getLocation) g->players[PLAYER_DRACULA].position = placeID; // Now we figure out what exactly dracula does at the new location if(isAtSea) { g->players[PLAYER_DRACULA].health -= LIFE_LOSS_SEA; } else if(isAtCastle) { g->players[PLAYER_DRACULA].health += LIFE_GAIN_CASTLE_DRACULA; } if(pastPlays[indexAt+3] == 'T') { // Dracula placed a trap. // TODO: Processing on what to do with traps // So far, it doesn't seem like we need to do anything // Since any encounters of traps are given to us // so we don't need to know where these things are } if(pastPlays[indexAt+4] == 'V') { // Dracula placed a young vampire // TODO: See the section on traps just above } // What just left the trail? if(pastPlays[indexAt+5] == 'V') { // A vampire has matured g->score -= SCORE_LOSS_VAMPIRE_MATURES; } } else { // This player is one of the hunters PlayerID curHunter; switch (pastPlays[indexAt]) { case 'G': curHunter = PLAYER_LORD_GODALMING; break; case 'S': curHunter = PLAYER_DR_SEWARD; break; case 'H': curHunter = PLAYER_VAN_HELSING; break; case 'M': curHunter = PLAYER_MINA_HARKER; break; default: assert (FALSE && "This is not a valid identifier for a player."); } LocationID newPosition = abbrevToID(abbrev); if(g->players[curHunter].position == ST_JOSEPH_AND_ST_MARYS && g->players[curHunter].health == 0) { // Our hunter has grown his legs back now. g->players[curHunter].health = GAME_START_HUNTER_LIFE_POINTS; } // Check if some encounters were made int i; // only loop while our hunter is alive and kicking // (and dracula, of course) for(i = 3;i < CHARS_PER_PLAY && g->players[curHunter].health > 0 && g->players[PLAYER_DRACULA].health > 0; i++) { if(pastPlays[indexAt+i] == 'T') { // Encountered a trap g->players[curHunter].health -= LIFE_LOSS_TRAP_ENCOUNTER; } else if(pastPlays[indexAt+i] == 'D') { //D("ENCOUNTERED DRACULA\n"); // Encountered Dracula g->players[curHunter].health -= LIFE_LOSS_DRACULA_ENCOUNTER; g->players[PLAYER_DRACULA].health -= LIFE_LOSS_HUNTER_ENCOUNTER; } } // check if our hunter died =( if (g->players[curHunter].health <= 0) { g->players[curHunter].health = 0; g->score -= SCORE_LOSS_HUNTER_HOSPITAL; newPosition = ST_JOSEPH_AND_ST_MARYS; } else if(newPosition == g->players[curHunter].position) { // The hunter rests and regains some health // Hunters need a bit of RnR, too! g->players[curHunter].health += LIFE_GAIN_REST; // cap hunter's health at GAME_START_HUNTER_LIFE_POINTS if (g->players[curHunter].health > GAME_START_HUNTER_LIFE_POINTS) { g->players[curHunter].health = GAME_START_HUNTER_LIFE_POINTS; } } // update our hunter's position g->players[curHunter].position = newPosition; } g->turns++; // we increment this way just in case we overshoot the NUL terminator // at the end of the string indexAt += CHARS_PER_PLAY; if(pastPlays[indexAt] == PLAY_SEP_CHAR) { indexAt++; } } // A little special case to heal the current hunter if they've been // incapacitated last turn. int turnPlayer = getCurrentPlayer(g); if(g->players[turnPlayer].position == ST_JOSEPH_AND_ST_MARYS && g->players[turnPlayer].health == 0) { // The hunter has regrown his legs! g->players[turnPlayer].health = GAME_START_HUNTER_LIFE_POINTS; } // print out messages for teh luls // for(i=0;i<g->turns;i++) { // D("message for turnplay %d: %s\n",i,g->messages[i]); // } return g; }
int main() { int i; GameView gv; printf("Test basic empty initialisation\n"); PlayerMessage messages1[] = {}; gv = newGameView("", messages1); assert(getCurrentPlayer(gv) == PLAYER_LORD_GODALMING); assert(getRound(gv) == 0); assert(getHealth(gv,PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); assert(getScore(gv) == GAME_START_SCORE); assert(getLocation(gv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula trail and basic functions\n"); PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah"}; gv = newGameView("GST.... SAO.... HZU.... MBB.... DC?....", messages2); assert(getCurrentPlayer(gv) == PLAYER_LORD_GODALMING); assert(getRound(gv) == 1); assert(getLocation(gv,PLAYER_LORD_GODALMING) == STRASBOURG); assert(getLocation(gv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN); assert(getLocation(gv,PLAYER_VAN_HELSING) == ZURICH); assert(getLocation(gv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY); assert(getLocation(gv,PLAYER_DRACULA) == CITY_UNKNOWN); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); printf("passed\n"); disposeGameView(gv); printf("Test for encountering Dracula and hunter history\n"); PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!"}; gv = newGameView("GST.... SAO.... HCD.... MAO.... DGE.... GGED...", messages3); assert(getLocation(gv,PLAYER_DRACULA) == GENEVA); assert(getHealth(gv,PLAYER_LORD_GODALMING) == 5); assert(getHealth(gv,PLAYER_DRACULA) == 30); assert(getLocation(gv,PLAYER_LORD_GODALMING) == GENEVA); LocationID history[TRAIL_SIZE]; getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == GENEVA); assert(history[1] == UNKNOWN_LOCATION); getHistory(gv,PLAYER_LORD_GODALMING,history); assert(history[0] == GENEVA); assert(history[1] == STRASBOURG); assert(history[2] == UNKNOWN_LOCATION); getHistory(gv,PLAYER_DR_SEWARD,history); assert(history[0] == ATLANTIC_OCEAN); assert(history[1] == UNKNOWN_LOCATION); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula doubling back at sea, and losing blood points (Hunter View)\n"); PlayerMessage messages4[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"}; gv = newGameView("GGE.... SGE.... HGE.... MGE.... DS?.... " "GST.... SST.... HST.... MST.... DD1....", messages4); assert(getLocation(gv,PLAYER_DRACULA) == DOUBLE_BACK_1); getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == DOUBLE_BACK_1); assert(history[1] == SEA_UNKNOWN); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4); assert(getCurrentPlayer(gv) == 0); printf("passed\n"); disposeGameView(gv); printf("Test for Dracula doubling back at sea, and losing blood points (Drac View)\n"); PlayerMessage messages5[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"}; gv = newGameView("GGE.... SGE.... HGE.... MGE.... DEC.... " "GST.... SST.... HST.... MST.... DD1....", messages5); assert(getLocation(gv,PLAYER_DRACULA) == DOUBLE_BACK_1); getHistory(gv,PLAYER_DRACULA,history); assert(history[0] == DOUBLE_BACK_1); assert(history[1] == ENGLISH_CHANNEL); assert(getHealth(gv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4); assert(getCurrentPlayer(gv) == 0); printf("passed\n"); disposeGameView(gv); printf("Test for connections\n"); int size, seen[NUM_MAP_LOCATIONS], *edges; gv = newGameView("", messages1); printf("Checking Galatz road connections\n"); edges = connectedLocations(gv,&size,GALATZ,PLAYER_LORD_GODALMING,0,1,0,0); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i< size ; i++) seen[edges[i]] = 1; assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]); assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]); free(edges); printf("Checking Ionian Sea sea connections\n"); edges = connectedLocations(gv,&size,IONIAN_SEA,PLAYER_LORD_GODALMING,0,0,0,1); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i < size; i++) seen[edges[i]] = 1; assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]); assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]); assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]); free(edges); printf("Checking Athens rail connections (none)\n"); edges = connectedLocations(gv,&size,ATHENS,PLAYER_LORD_GODALMING,0,0,1,0); assert(size == 1); assert(edges[0] == ATHENS); free(edges); printf("passed\n"); disposeGameView(gv); return 0; }
/** Reconnect to the server using the saved session data. */ void PlayerManager::resumeSavedSession() { getCurrentPlayer()->requestSavedSession(); } // resumeSavedSession
// Get the id of current player PlayerID whoAmI(HunterView currentView) { return getCurrentPlayer(currentView->g); }
/** Returns the online id of the current player. * \pre User logged in (which is asserted in getID()). */ unsigned int PlayerManager::getCurrentOnlineId() { return getCurrentPlayer()->getOnlineId(); } // getCurrentOnlineId
/** Returns whether a user is signed in or not. */ bool PlayerManager::isCurrentLoggedIn() { return getCurrentPlayer()->isLoggedIn(); } // isCurrentLoggedIn
/** Returns the current online profile (which is the list of all achievements * and friends). */ Online::OnlineProfile* PlayerManager::getCurrentOnlineProfile() { return getCurrentPlayer()->getProfile(); } // getCurrentOnlineProfile
Online::XMLRequest *PlayerManager::requestSignIn(const irr::core::stringw &username, const irr::core::stringw &password) { return getCurrentPlayer()->requestSignIn(username, password); } // requestSignIn
/** Sends a message to the server that the client has been closed, if a * user is signed in. */ void PlayerManager::onSTKQuit() { if (getCurrentPlayer() && getCurrentPlayer()->isLoggedIn()) getCurrentPlayer()->requestSignOut(); } // onSTKQuit
// Creates a new GameView to summarise the current state of the game GameView newGameView(char *pastPlays, PlayerMessage messages[]) { int i,j; // Increment counters // Initalising gameView -------------------------------------------- GameView gameView = malloc(sizeof(struct gameView)); gameView->roundNumber = -1; gameView->currentPlayer = -1; gameView->score = GAME_START_SCORE; gameView->players = calloc(NUM_PLAYERS, sizeof(struct player)); // Initalising players array for (i = 0; i < NUM_PLAYERS; i++) { gameView->players[i].id = i; //initalise health based on hunter or dracula gameView->players[i].health = (i != PLAYER_DRACULA) ? GAME_START_HUNTER_LIFE_POINTS : GAME_START_BLOOD_POINTS; gameView->players[i].location = UNKNOWN_LOCATION; //Initalise trail with unknown location gameView->players[i].trail = malloc(TRAIL_SIZE * sizeof(LocationID)); for (j = 0; j < TRAIL_SIZE; j++) { gameView->players[i].trail[j] = UNKNOWN_LOCATION; } } // Initialising the map gameView->europe = newMap(); // Finished initalising -------------------------------------------- // Updating game based on history of each turn --------------------- // The while loop parses through each turn, but jumping to the // index of the pastPlays string of which the turn starts. // This is kept by the turnIndex integer variable. int turnIndex = 0; while (turnIndex < strlen(pastPlays)) { // Set currentPlayer of turn switch (pastPlays[turnIndex]) { case 'G': gameView->currentPlayer = PLAYER_LORD_GODALMING; break; case 'S': gameView->currentPlayer = PLAYER_DR_SEWARD; break; case 'H': gameView->currentPlayer = PLAYER_VAN_HELSING; break; case 'M': gameView->currentPlayer = PLAYER_MINA_HARKER; break; case 'D': gameView->currentPlayer = PLAYER_DRACULA; // "score decreases by 1 every time dracula finishes // a turn" gameView->score--; break; default: break; } // Keep a local pointer to currentPlayer player *currentPlayer = &gameView->players[gameView->currentPlayer]; // if the player is on zero health - they would have already // been to hospital, and so we increase their life points // to full if(currentPlayer->id != PLAYER_DRACULA && currentPlayer->health == 0) { currentPlayer->health = GAME_START_HUNTER_LIFE_POINTS; } // Set location for this currentPlayer. updateLocationOfPlayer(&pastPlays[turnIndex+1], currentPlayer); // locate the first action of the turn in the string int actionIndex = turnIndex+3; // update health points, score etc ----------------------------- // based on action --------------------------------------------- if (getCurrentPlayer(gameView) != PLAYER_DRACULA) { // if currentPlayer is hunter then: // for each action of the turn while (actionIndex % TURN_SIZE != 0) { switch (pastPlays[actionIndex]) { case 'T': // A trap was encountered - reduce health currentPlayer->health -= LIFE_LOSS_TRAP_ENCOUNTER; break; case 'D': // Dracula was encountered - reduce health currentPlayer->health -= LIFE_LOSS_DRACULA_ENCOUNTER; // Dracula also loses health gameView->players[PLAYER_DRACULA].health -= LIFE_LOSS_HUNTER_ENCOUNTER; break; default: break; } actionIndex++; } // ---- updating score based on location ------ // Hunter goes in hospital - will gain full life points // in next round if (currentPlayer->health <= 0) { updateLocationOfPlayer("JM", currentPlayer); currentPlayer->health = 0; gameView->score -= SCORE_LOSS_HUNTER_HOSPITAL; } //Hunter if rest if (currentPlayer->trail[0] == currentPlayer->trail[1] && currentPlayer->health != 0) { currentPlayer->health += LIFE_GAIN_REST; } // ---- finished updating score based on location ---- // If the health is more than limit, due to over achievement // reduce the score to limit if (currentPlayer->health > GAME_START_HUNTER_LIFE_POINTS) { currentPlayer->health = GAME_START_HUNTER_LIFE_POINTS; } } else { // If vampire matured (not placed) if (pastPlays[actionIndex+2] == 'V') { gameView->score -= SCORE_LOSS_VAMPIRE_MATURES; } //Dracula at sea... drop health reduceHealthIfAtSea(currentPlayer); // If at Castle Dracula at end of turn if (currentPlayer->location == CASTLE_DRACULA) { currentPlayer->health += LIFE_GAIN_CASTLE_DRACULA; } } // Updating score & health end --------------------------------- //update turn + roundNumber turnIndex += TURN_SIZE; gameView->roundNumber++; } //Set the currentPlayer to the next person after last player. gameView->currentPlayer = (gameView->currentPlayer+1)%NUM_PLAYERS; //RoundNumber was actually counting turn number //so roundNumber is modified to have the actual round number gameView->roundNumber = (gameView->roundNumber + 1) / NUM_TURNS; //GameView is now ready to be used! return gameView; }
/** Returns the online state of the current player. It can be logged out, * logging in, logged in, logging out, logged out, or guest. */ PlayerProfile::OnlineState PlayerManager::getCurrentOnlineState() { return getCurrentPlayer()->getOnlineState(); } // getCurrentOnlineState
/** Signs the current user out. */ void PlayerManager::requestSignOut() { getCurrentPlayer()->requestSignOut(); } // requestSignOut
/** Sends a request to the server to see if any new information is * available. (online friends, notifications, etc.). */ void PlayerManager::requestOnlinePoll() { getCurrentPlayer()->requestPoll(); } // requestOnlinePoll