/** * Activates next player. */ void WindowLocations::nextPlayer() { Player *player; playerInTurn++; player = gameEngine.getPlayer(playerInTurn); if (playerInTurn < gameEngine.getPlayerCount()) { this->textPlayer->setText(gameEngine.getPlayer(playerInTurn)->getName()); } else { //If this was the last player this->textPlayer->clear(); this->textTip->clear(); this->butNext->setText("Finish"); } //If it's an AI, let it choose it's position if (player) { Ai *ai; ai = player->getAI(); if (ai) { ai->selectStartingLocation(); nextPlayer(); } } }
int main() { getNames(); setCombinationNames(); while (gameFinished() == false) { printf("\n%s ist dran!\n\n", players[currentPlayer].name); pause(); for (int i = 1; i <= 3; i++) { //Every time we may throw three times throwDices(); if (i < 3) { if (ask("Nochmal wuerfeln?")) { keepDices(); } else { break; } } } selectCombination(); nextPlayer(); } showPlayerEvalution(); return 0; }
void Model::playCard(int i) { HumanPlayer* humanPointer = static_cast <HumanPlayer*> (players_[currentPlayer]); Card* played = humanPointer->playCard(i); playedCard(played); int index = played->getRank()+played->getSuit()*13; nextPlayer(index); }
int betRound() { int bet; P_PLAYER playerOnTurn = game.flow.pCurrentPlayer; if (game.flow.round == 0) playerOnTurn = game.bet.smallBlindPlayer; //auto-bets if (game.flow.round == 0) { smallBlindBet(playerOnTurn); playerOnTurn = nextPlayer(); bigBlindBet(playerOnTurn); playerOnTurn = nextPlayer(); } //manual bets for (int i = 0; i < MAX_PLAYERS; i++) { printf("Player on turn: %s - %d\n", playerOnTurn->name, i); if (playerOnTurn->isInGame && !playerOnTurn->allIn) { if (isPlayer(playerOnTurn)) bet = betPlayer(playerOnTurn); else bet = betAI(playerOnTurn); switch (bet) { case -1: //fold playerOnTurn->isInGame = 0; break; case 0: //check break; default: //raise - resatrt bet round i = -1; break; } } playerOnTurn = nextPlayer(); //end betting if other players folded if (countPlayersInGame() < 2) return 0; } return 1; }
/** * Handles mouse up events */ void WindowLocations::mouseUp(SDL_MouseButtonEvent button) { if (button.x > 824 && this->scrollMode == false) { //Clicking sidebar. Find out if a component was hit. UIComponent *component = findComponent(button.x, button.y); //'Next player' button if (component == butNext) { if (playerInTurn >= gameEngine.getPlayerCount()) this->startGame(); else this->nextPlayer(); } //'Back to main menu' button else if (component == butQuit) { this->close(0); } } else { //Clicking game area //Convert to world coordinates Coordinates* coords = this->graphics.getWorldCoordinates(button.x, button.y); Player *player; Ai *ai = NULL; player = gameEngine.getPlayer(playerInTurn); if (player) ai = player->getAI(); //If AI is in turn, disable controls if (ai) player = NULL; //Set location if (player && this->dragDistance < 5) { if (player->setLocation(coords->getX(), coords->getY()) == 0) { this->sounds.playSound(SOUND_CLICK); nextPlayer(); } else { this->sounds.playSound(SOUND_TICK); } } delete coords; } //Deactivate scroll mode if (this->scrollMode) { SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); this->scrollMode = false; } }
void nextPlayer () { resetDicesHolder(); currentPlayer++; if (currentPlayer >= AmountOfPlayers) { if (PlayerFinished(currentPlayer) == true && gameFinished() == false) { printf("%s ist fertig!\n", players[currentPlayer].name); nextPlayer(); } else { currentPlayer = 0; } } }
//DONE void throwDice (Game g, int diceScore) { //function protection assert(g != NULL); assert(diceScore >= 2 && diceScore <= 12); //store dicescore //increase turn //next player //increment students //^convert if number = 7 to scrub students g->diceScore = diceScore; g->currentTurn++; nextPlayer(g); addStudents(g); }
void Yahtzee::update() { Player& thisPlayer = players.at(currentPlayer); std::cout << "\n**" << thisPlayer.name() << "'s turn**\n\n"; do { thisPlayer.roll(); } while (!thisPlayer.turnOver()); thisPlayer.scoreDice(); thisPlayer.printScoresheet(); nextPlayer(); }
void playerLeave(int p) { player[p].active = 0; if(p == currentPlayer) { nextPlayer(); } for(p = 0; p < conf.maxPlayers; ++p) { player[p].valid = 0; player[p].timeout = conf.timeout * 2; if((conf.mode & GM_ENERGY) == 0) { player[p].velocity = 10.0; } killflash = 1.0; } }
void stepSimulation(void) { if(conf.debug & 1) printf("stepSimulation: %s:%d currentPlayer=%d currentPlayer.energy=%.4f currentPlayer.velocity=%.4f\n",__FILE__,__LINE__,currentPlayer,player[currentPlayer].energy, player[currentPlayer].velocity); if( ( player[currentPlayer].active && ( player[currentPlayer].shot[player[currentPlayer].currentShot].missile.live == 0 && (conf.mode & GM_MULTIMISSILE) == 0 ) && ( ( player[currentPlayer].didShoot && (conf.mode & GM_MULTIMISSILE) == 0) || ( player[currentPlayer].energy < player[currentPlayer].velocity && (conf.mode & GM_ENERGY) != 0 ) ) ) || player[currentPlayer].timeout == 0 || player[currentPlayer].watch ) { if( player[currentPlayer].timeout == 0 && !player[currentPlayer].watch ) player[currentPlayer].timeoutcnt++; if(conf.debug & 1) printf("stepSimulation: %s:%d call nextPlayer\n",__FILE__,__LINE__); nextPlayer(); } if(player[currentPlayer].active && player[currentPlayer].valid && !player[currentPlayer].didShoot && (player[currentPlayer].energy >= player[currentPlayer].velocity || (conf.mode & GM_ENERGY) == 0) ) { player[currentPlayer].currentShot = (player[currentPlayer].currentShot + 1) % conf.numShots; initShot(currentPlayer); player[currentPlayer].valid = 0; if((conf.mode & GM_ENERGY) == 0) { player[currentPlayer].velocity = 10.0; player[currentPlayer].oldVelocity = 10.0; } player[currentPlayer].didShoot = 1; } simulate(); killflash *= 0.95; }
/* * === FUNCTION ====================================================================== * Name: parseMessage * Description: * ===================================================================================== */ void parseMessage ( char buffer[1024] ) { Pos p; sscanf( buffer, "%d %d", &p.x, &p.y ); printf("New point: (%d, %d)\n", p.x, p.y); if ( p.x < 0 || p.x >= BOARD_SIZE || p.y < 0 || p.y >= BOARD_SIZE ) { printf("Error: Incorrect coordenates! (must be two integers from 0 to 999 separated by a space)\n"); exit(1); } /* Store point */ storePoint( p ); /* Next player */ nextPlayer( ); }
bool Game::nextTurn() { bool ret(true); // find next player GameData::PlayerID nextPlayer(getNextPlayer(mCurrentPlayerID)); if (SIZE_MAX != nextPlayer) { // update current player mCurrentPlayerID = nextPlayer; mGameData.currentPlayer = mPlayers[mCurrentPlayerID]->name(); // tell everyone current state of game sendUpdatesToEveryone(); // get input from current player InputData input(mPlayers[mCurrentPlayerID]->getInput(InputData::NEED_GUESS)); // determine if guess is correct if (input.guess < mSecretNumber) { ret = false; mGameData.lastGuess = GameData::LAST_GUESS_LOW; } else if (input.guess > mSecretNumber) { ret = false; mGameData.lastGuess = GameData::LAST_GUESS_HIGH; } else { mGameData.lastGuess = GameData::LAST_GUESS_CORRECT; // let everyone know who won sendUpdatesToEveryone(); } mGameData.guesses.push_back(input.guess); } return ret; }
/** * Constructor */ WindowLocations::WindowLocations(Graphics &graphics, Sounds &sounds, GameEngine &engine) : Window(graphics, sounds), gameEngine(engine) { this->scrollMode = false; //Create UI components this->textTip = new UIText(*this, "Choose location for", 300, 20); this->textPlayer = new UIText(*this, 460, 20); this->textPlayers = new UIText(*this, 865, 100); this->butNext = new UIButton(*this, "Skip round", 858, 300); this->butQuit = new UIButton(*this, "Back to main menu", 858, 730); //Read player names Player *player; string names; for (int i = 0; i < gameEngine.getPlayerCount(); i++) { player = gameEngine.getPlayer(i); if (player) { names.append(player->getName()); names.append("\n"); } } this->textPlayers->setText(names); addComponent(textPlayer); addComponent(textTip); addComponent(textPlayers); addComponent(butNext); addComponent(butQuit); //Activate first player this->playerInTurn = -1; nextPlayer(); }
shared_ptr<Trick> Game::playTrick() { shared_ptr<Card> refCard; shared_ptr<Card> playedCard; currentTrick = make_shared<Trick>( nullptr ); for( unsigned int gamer = 0; gamer < players.size(); ++gamer ) { if( gamer == 0) { refCard = next->playCard( nullptr, nullptr ); playedCard = refCard; currentTrick->setCard( next, refCard ); } else if( gamer == 1 && refCard->isFool() ) { refCard = next->playCard( refCard, nullptr ); playedCard = refCard; currentTrick->setCard( next, refCard ); } else { playedCard = next->playCard( refCard, currentTrick->getGreaterTrump() ); currentTrick->setCard( next, playedCard ); } if( !kingFound ) isCardCalled( playedCard, next ); nextPlayer(); } update(); return currentTrick; }
void Game::dealCards() { int indexCard = 0; set<int> indexDog; int newIndex; // choose dogSize number of cards to compose the dog. do { newIndex = rand() % 78; indexDog.insert( newIndex ); } while( indexDog.size() < dogSize ); // deal cards to the dog for( auto& dogCardIndex : indexDog ) dog.insert( deck.cards[ dogCardIndex ] ); // deal cards to players for( int round = 0; round < cardsPerPlayer; round += consecutiveDealing ) for( unsigned int gamers = 0; gamers < players.size(); ++gamers ) { for( int card = 0 ; card < consecutiveDealing ; ) { if( indexDog.find( indexCard ) == indexDog.end() ) { next->addCard( deck.cards[ indexCard ] ); ++card; } ++indexCard; } nextPlayer(); } }
static void playerHit(SimShot* s, int p, int p2) { int pl; if(p == p2) { player[p].selfkills++; } else { player[p].kills++; player[p2].deaths++; } missileEnd(s); initPlayer(p2, 0); allSendPlayerPos(p2); for(pl = 0; pl < conf.maxPlayers; ++pl) { player[pl].valid = 0; player[pl].timeout = conf.timeout * 2; if((conf.mode & GM_ENERGY) == 0) { player[pl].velocity = 10.0; } killflash = 1.0; } sprintf(deathMessage, "%s killed %s", player[p].name, player[p2].name); nextPlayer(); /* not nice here, think about this more */ }
void Server::playedCard(QString message, Player *pl) { qDebug() << "Server::playedCard"; QString num; QString suit; int value; if (message == "0") { num = pl->card(0)->number(); suit = pl->card(0)->suit(); value = pl->card(0)->value(); } else if (message == "1") { num = pl->card(1)->number(); suit = pl->card(1)->suit(); value = pl->card(1)->value(); } else { num = pl->card(2)->number(); suit = pl->card(2)->suit(); value = pl->card(2)->value(); } QString newMessage; QString code; code = "04"; //code for played card. newMessage = num + suit; qDebug() << newMessage; if (numberOfPlayers == 4) { if (players[0] == pl) { players[1]->sendMessage(code + "03" + newMessage); players[2]->sendMessage(code + "02" + newMessage); players[3]->sendMessage(code + "01" + newMessage); players[0]->setPlayed(true); players[0]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[0] = value; if (getRound() == 1) cardsOfRoundTwo[0] = value; if (getRound() == 2) cardsOfRoundThree[0] = value; } else if (players[1] == pl) { players[0]->sendMessage(code + "01" + newMessage); players[2]->sendMessage(code + "03" + newMessage); players[3]->sendMessage(code + "02" + newMessage); players[1]->setPlayed(true); players[1]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[1] = value; if (getRound() == 1) cardsOfRoundTwo[1] = value; if (getRound() == 2) cardsOfRoundThree[1] = value; } else if (players[2] == pl) { players[0]->sendMessage(code + "02" + newMessage); players[1]->sendMessage(code + "01" + newMessage); players[3]->sendMessage(code + "03" + newMessage); players[2]->setPlayed(true); players[2]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[2] = value; if (getRound() == 1) cardsOfRoundTwo[2] = value; if (getRound() == 2) cardsOfRoundThree[2] = value; } else { players[0]->sendMessage(code + "03" + newMessage); players[1]->sendMessage(code + "02" + newMessage); players[2]->sendMessage(code + "01" + newMessage); players[3]->setPlayed(true); players[3]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[3] = value; if (getRound() == 1) cardsOfRoundTwo[3] = value; if (getRound() == 2) cardsOfRoundThree[3] = value; } if (players[0]->hasPlayed() && players[1]->hasPlayed() && players[2]->hasPlayed() && players[3]->hasPlayed()) { checkGame(); } else { nextPlayer(); } } else { if (players[0] == pl) { players[1]->sendMessage(code + "02" + newMessage); players[1]->setPlayed(true); players[1]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[0] = value; if (getRound() == 1) cardsOfRoundTwo[0] = value; if (getRound() == 2) cardsOfRoundThree[0] = value; } else { players[0]->sendMessage(code + "02" + newMessage); players[0]->setPlayed(true); players[0]->setPlayedCardValue(value); if (getRound() == 0) cardsOfRoundOne[1] = value; if (getRound() == 1) cardsOfRoundTwo[1] = value; if (getRound() == 2) cardsOfRoundThree[1] = value; } if (players[0]->hasPlayed() && players[1]->hasPlayed()) { qDebug() << "All players have played!"; checkGame(); } else { qDebug() << "Someone not have played yet, going to next player"; nextPlayer(); } } }
/** * pick the landlord * Inputs: NONE * Return: int */ int landlord(){ int i; int choice; int opcode; while(!isCurrentPlayer()){ recvchar(&opcode); usleep(50); switch(opcode){ case 1: nextPlayer(); break; case 5: if(PCS==1){ firstchoice=1; } else if(PCS==2){ secondchoice=1; } else { thirdchoice=1; } break; case 6: if(PCS==1){ firstchoice=2; } else if(PCS==2){ secondchoice=2; } else { thirdchoice=2; } break; case 7: if(PCS==1){ firstchoice=3; } else if(PCS==2){ secondchoice=3; } else { thirdchoice=3; } break; } } alt_printf("Pick a score from 1, 2 or 3. The score you choose will determine who will be landlord and multiplier\n"); alt_printf("Make your choice #%d player!",PCS); scanf (" %d",&choice); printf("your choice is %d\n",choice); if(choice==1) { sendchar(5|0x40); usleep(250); if(PCS==1){ firstchoice=1; } else if(PCS==2){ secondchoice=1; } else { thirdchoice=1; } } else if (choice ==2) { sendchar(6|0x40); usleep(250); if(PCS==1){ firstchoice=2; } else if(PCS==2){ secondchoice=2; } else { thirdchoice=2; } } else if(choice == 3) { sendchar(7|0x40); usleep(250); if(PCS==1){ firstchoice=3; } else if(PCS==2){ secondchoice=3; } else { thirdchoice=3; } } usleep(250); nextPlayer(); usleep(250); incPCS(); while(PCS!=1){ recvchar(&opcode); usleep(50); switch(opcode){ case 1: nextPlayer(); break; case 5: if(PCS==1){ firstchoice=1; } else if(PCS==2){ secondchoice=1; } else { thirdchoice=1; } break; case 6: if(PCS==1){ firstchoice=2; } else if(PCS==2){ secondchoice=2; } else { thirdchoice=2; } break; case 7: if(PCS==1){ firstchoice=3; } else if(PCS==2){ secondchoice=3; } else { thirdchoice=3; } break; } } alt_printf("current player: %x\n", PCS); alt_printf("first player chooses %d\n",firstchoice); alt_printf("second player chooses %d\n",secondchoice); alt_printf("third player chooses %d\n",thirdchoice); return 0; }
int main(int argc, char** argv){ char* outPl[NB_PLAYER] = {NULL, NULL}; // Les sorties pour chaque joueur linkedlist_t listResp = NULL; int pipeW; int J1 = 0; int J2 = 1; int i; int jGagne = -1; int jPerdu; int plein = 0; int choix; char caract[NB_PLAYER]; caract[0] = 'X'; caract[1] = 'O'; char plateau[HAUTEUR][LARGEUR]; if(argc >= 1){ pipeW = atoi(argv[0]); } else{ perror("Erreur, arguments incorrects.\n"); exit(EXIT_FAILURE); } init_plateau(plateau); while(jGagne == -1 && !plein){ for(i=0; i < NB_PLAYER; i++){ systemc(&outPl[J1], "clear"); outc(&outPl[J1], "%s", "======= Morpion =======\n\n"); dessinerPlateau(&outPl[J1], plateau); outc(&outPl[J1], "%s", "Entrez un numero de case (1, 2, ...) : "); inc(&outPl[J1], "%d"); systemc(&outPl[J2], "clear"); outc(&outPl[J2], "%s", "======= Morpion =======\n\n"); dessinerPlateau(&outPl[J2], plateau); outc(&outPl[J2], "%s", "C'est a votre adversaire de jouer.\n"); flushc(pipeW, outPl, NB_PLAYER); choix = (int)getResp(&listResp, INT); if(jouer(plateau, choix, caract[J1])){ if(gagner(plateau, caract[J1])){ jGagne = J1; break; } if(estPlein(plateau)){ plein = 1; break; } } reversePlayer(&J1, &J2); } } systemc(&outPl[J1], "clear"); systemc(&outPl[J2], "clear"); if(!plein && jGagne != -1){ jPerdu = nextPlayer(jGagne); outc(&outPl[jGagne], "%s", "======= Morpion =======\n\n"); outc(&outPl[jGagne], "%s", "Vous avez gagne, felicitation !!\n"); outc(&outPl[jPerdu], "%s", "======= Morpion =======\n\n"); outc(&outPl[jPerdu], "%s", "Vous avez perdu, votre adversaire etait peut etre plus intelligent...\n"); } else{ outc(&outPl[J1], "%s", "======= Morpion =======\n\n"); outc(&outPl[J1], "%s", "Vous etes aussi fort (ou mauvais) que votre adversaire...\n"); outc(&outPl[J2], "%s", "======= Morpion =======\n\n"); outc(&outPl[J2], "%s", "Vous etes aussi fort (ou mauvais) que votre adversaire...\n"); } flushc(pipeW, outPl, NB_PLAYER); // On attend un peut avant de quitter waitc(&outPl[J1], 3); waitc(&outPl[J2], 3); quitc(&outPl[J1]); // Fermera le jeu pour le client quitc(&outPl[J2]); flushc(pipeW, outPl, NB_PLAYER); quit(pipeW); close(pipeW); close_out_players(outPl, NB_PLAYER); return EXIT_SUCCESS; }
void Model::discardCard(int i) { HumanPlayer* humanPointer = static_cast <HumanPlayer*> (players_[currentPlayer]); humanPointer->discard(i); nextPlayer(-1); }
int main(int argc, char *argv[]) { char **playersNameList; int totalPlayersNumber; int turn, i; char buffer[BUFF_SIZE]; FILE *configFile; /* legge gli argomenti */ char **name1, **name2; if (argc < 4) { fprintf(stderr, "ERROR: Wrong number of arguments. \n USAGE: %s\n", USAGE); exit(EXIT_FAILURE); } playersNameList = argv + 3; totalPlayersNumber = argc - 3; /* controlla se ci sono due giocatori con lo stesso nome */ for (name1 = playersNameList; *name1; name1++) for (name2 = name1 + 1; *name2; name2++) if (strcmp(*name1, *name2) == 0) { fprintf(stderr, "ERROR: found two player with the" "same name \"%s\"\n", *name1); exit(EXIT_FAILURE); } initIoInterface(argv[2]); /* crea e inizializza le strutture dati per i giocatori */ initPlayersManager(totalPlayersNumber); for (; *playersNameList; playersNameList++) addPlayer(*playersNameList); initBoard(); /* * legge il file di configurazione secondo il formato: * numero_casella:descrizione della prova\n * e aggiunge le descrizioni al tabellone */ if ((configFile = fopen(argv[1], "r")) == NULL) { printErr("ERROR: error while opening configuration file\n"); exit(EXIT_FAILURE); } while (fgets(buffer, BUFF_SIZE, configFile)) { char *description; int boxNumber; /* legge il numero di casella */ if ((boxNumber = atoi(buffer)) <= 0) { printErr("ERROR:invalid box num(\"%s\") in" " configuration file\n", buffer); exit(EXIT_FAILURE); } /* aggiunge una nuova casella con la relativa descrizione */ if ((description = strchr(buffer, ':')) == NULL) { printErr("ERROR: missing ':' in configuration file\n"); exit(EXIT_FAILURE); } addBox(boxNumber, description + 1); } if (getTotalBoxesNumber() == 0) { printErr("ERROR: invalid configuration file\n"); exit(EXIT_FAILURE); } fclose(configFile); printBoard(); showGame(); /* avvia la simulazione del gioco */ srand(time(NULL)); for (turn = 0; !allPlayersDone(); turn++) { if (!nextStep()) return EXIT_SUCCESS; printMessage("\n**************************************\n"); printMessage("turno %d", turn + 1); printMessage("\n**************************************\n"); showGame(); /* * per ogni giocatore G che non ha terminato il gioco: * 1. se G e' fermo per un turno cambia il suo stato in * modo che al turno successivo venga rimesso in gioco * 2. altrimenti viene lanciato il dado, mosso il giocatore * e visualizzata la sua prova */ while (nextPlayer()) { int state = getPlayerState(); if (state == ACTIVE || state == TEST_PASSED || state == TO_BE_ACTIVATED) { if (state != ACTIVE) setPlayerState(ACTIVE, 0); movePlayer((rand() % 6) + 1); if (getPlayerBox() > getTotalBoxesNumber()) setPlayerState(DONE, turn); else printMessage("player %s: \"%s\"\n", getPlayerName(), getDescription(getPlayerBox())); } else if (state == OUT_OF_TURN) setPlayerState(TO_BE_ACTIVATED, 0); } showGame(); /* * Legge e registra l'esito di tutte le prove sostenute nel * turno corrente dai giocatori */ for (i = getActivePlayersNumber(); i > 0; i--) { int playerNumber; bool result; do { result = askPlayerResult(&playerNumber); if (playerNumber > totalPlayersNumber) printErr("WARNING: player number %d out of " "bounds [1; %d]\n", playerNumber, totalPlayersNumber); else { setCurrentPlayer(playerNumber); if (getPlayerState() != ACTIVE) printErr("WARNING: player number %d not " "valid because player:" "\n\t-won" "\n\t-is out of turn" "\n\t-already passed the test\n", playerNumber); } } while (playerNumber > totalPlayersNumber || getPlayerState() != ACTIVE); if (result) setPlayerState(TEST_PASSED, 0); else setPlayerState(OUT_OF_TURN, 0); } } printScore(); closeIoInterface(); return EXIT_SUCCESS; }
// do-loop for gaming till one player has lost (starting at 1) const unsigned int Game::doStart(const bool contest) { do { #ifdef DEBUG std::cout << "Player's " << m_currentPlayer+1 << " turn!" << std::endl; #endif if ( !writeData() ) { break; } #ifdef DEBUG // print game field m_field.print(); #endif if ( !contest ) { std::cout << "Manually save result.dat and hit enter!" << std::endl; getchar(); } else { // call routine for AI if ( 0 == m_currentPlayer ) { if ( system ("./fm-ai1.bin") ) { std::cout << "Game::doStart() error: calling fm-ai1 failed" << std::endl; // this player will loose the contest m_player[m_currentPlayer].looseAllLife(); break; } } else { if ( system ("./fm-ai2.bin") ) { std::cout << "Game::doStart() error: calling fm-ai2 failed" << std::endl; // this player will loose the contest m_player[m_currentPlayer].looseAllLife(); break; } } } // now we must read the result that has stored to positions FieldPos pos1, pos2; if ( !readResult(pos1, pos2) ) { // file could not be read break; } #ifdef DEBUG std::cout << "Game::doStart() info: swap " << pos1.x() << " " << pos1.y() << " with " << pos2.x() << " " << pos2.y() << std::endl; #endif // delete files deleteFiles(); // switch positions on game field if ( m_field.swapTiles(pos1, pos2) ) { // remove all matching tiles if ( !cascade(contest) ) { break; } } else { #ifdef DEBUG std::cout << "Game::doStart() Illegal move: loose 5 life" << std::endl; #endif m_player[m_currentPlayer].looseLife(5); // getchar(); } // set next player (if necessary) nextPlayer(); // check if gamefield is playable and remove lower lines // until the game is playable again if ( !checkIfPlayable(contest) ) { break; } #ifdef DEBUG // print player info printPlayers(); #endif // getchar(); } while ( !isOnePlayerDead() ); return checkWhosDead(); }
int play(){ int pass=0; Boolean firstRound=FALSE; // true if first round if(ll==myNum) firstRound=TRUE; // use for "for loop" int i; // number of cards played int number = 0; // pattern code int pattern=0; //sync int temp; //for sync // current card played, no need to init char ccp[20]; // key value of card played int key=CUTOFF; //sync char card[3]; Boolean check; //checkPattern printf("Current Player: %d\n", PCS); while(!haveWinner()){ if(isCurrentPlayer()){ check=TRUE; do{ if(!check) printf("Your Inputs Are Illegal, Please Input Again\n"); check=FALSE; //input to ccp, check num here display(); printf("hey player, tell me the number of cards you want to play this round." "You can input 0 if you want to give up\n"); scanf(" %d", &number); for(i=0;i<number;i++) { if(!i) printf("please tell me the card you want to play this round. One by One please. \n"); else printf("please tell me the next card you want to play. \n"); scanf("%s", card); switch(card[0]){ case 'a': case 'A': ccp[i]=11; break; case '2': ccp[i]=12; break; case '3': ccp[i]=0; break; case '4': ccp[i]=1; break; case '5': ccp[i]=2; break; case '6': ccp[i]=3; break; case '7': ccp[i]=4; break; case '8': ccp[i]=5; break; case '9': ccp[i]=6; break; case '1': ccp[i]=7; break; case 'j': case 'J': ccp[i]=8; break; case 'q': case 'Q': ccp[i]=9; break; case 'k': case 'K': ccp[i]=10; break; case 'b': case 'B': ccp[i]=13; break; case 'r': case 'R': ccp[i]=14; break; } } if(number && checkCards(number, ccp)) check=checkPatternAndValue(&pattern, ccp, number, &key); printf("check: %d\nkey: %d\n", pattern, key); }while((number && !check) || (!number && firstRound)); if(!number){ sendchar(CUTOFF | 0x40); usleep(10000); } else{ if(firstRound) firstRound=!firstRound; sendchar(key | 0x40); usleep(1000); sendchar((pattern & 0x3f) | 0x40); usleep(1000); sendchar((pattern >> 6) | 0x40); usleep(1000); deleteCards(number, ccp); temp=sramread(CHNP+myNum-1); sramwrite(CHNP+myNum-1, temp-pattern/10); usleep(1000); sendchar(sramread(CHNP) | 0x40); usleep(1000); sendchar(sramread(CHNP+1) | 0x40); usleep(1000); sendchar(sramread(CHNP+2) | 0x40); usleep(1000); } } else{ recvchar(&temp); usleep(80); if(temp!=CUTOFF){ key=temp; recvchar(&pattern); //last 6 bits usleep(80); recvchar(&temp); //11-6 bits of pattern usleep(80); pattern+=temp*64; recvchar(&temp); usleep(80); sramwrite(CHNP, temp); recvchar(&temp); usleep(80); sramwrite(CHNP+1, temp); recvchar(&temp); usleep(80); sramwrite(CHNP+2, temp); } else{ pass++; if(pass==2){ pass=0; pattern=0; key=0; } } } if(pattern==42) multiplier*=2; temp=sramread(CHNP); printf("Pattern Is: %d\nKey Is: %d\nPlayer1 Num Remainds: %d\n", pattern, (key+3)%14+(key==11)+(key==12)+12*(key==13)+12*(key==14), temp); temp=sramread(CHNP+1); printf("Player2 Num Remainds: %d\n", temp); temp=sramread(CHNP+2); printf("Player3 Num Remainds: %d\n", temp); nextPlayer(); }
int main(int argc, char** argv){ char* outPl[NB_PLAYER] = {NULL, NULL}; // Les sorties pour chaque joueur linkedlist_t listResp = NULL; int pipeW; int J1 = 0; int J2 = 1; int i; int nbTry = 0; int jGagne = -1; // Le numéro du joueur qui a gagné la partie int jPerdu; int nbLettre; char* word[NB_PLAYER]; char* hiddenWord[NB_PLAYER]; char* choice; // Le mot que le joueur a essayer if(argc >= 1){ pipeW = atoi(argv[0]); } else{ perror("Erreur, arguments incorrects.\n"); exit(EXIT_FAILURE); } for(i=0; i < NB_PLAYER; i++){ systemc(&outPl[J1], "clear"); systemc(&outPl[J2], "clear"); outc(&outPl[J1], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J1], "%s", "Entrez un mot(10 carct max): "); inc(&outPl[J1], "%s"); outc(&outPl[J2], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J2], "%s", "Attendez que l'autre joueur choisisse un mot...\n"); flushc(pipeW, outPl, NB_PLAYER); word[J1] = (char*)getResp(&listResp, STRING); upperWord(word[J1]); hiddenWord[J1] = initHiddenWord(word[J1]); //printf("Les mot choisi est : %s\n", word[J1]); reversePlayer(&J1, &J2); fflush(stdout); } systemc(&outPl[J2], "clear"); outc(&outPl[J2], "%s", "======= Jeu du pendu =======\n\n"); while(jGagne == -1){ for(i=0; i < NB_PLAYER && jGagne == -1; i++){ systemc(&outPl[J1], "clear"); outc(&outPl[J1], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J1], "%s %d %s", "Nombre d'essais : ", nbTry, "\n"); outc(&outPl[J1], "%s %s %s", "Le mot a trouver : ", hiddenWord[J2], "\n"); outc(&outPl[J1], "%s", "C'est a vous, entrez une lettre ou un mot : "); inc(&outPl[J1], "%s"); outc(&outPl[J2], "%s", "\nC'est a votre adversaire de jouer...\n"); flushc(pipeW, outPl, NB_PLAYER); choice = (char*)getResp(&listResp, STRING); if(strlen(choice) > 1){ upperWord(choice); if(strcmp(word[J2], choice) == 0){ outc(&outPl[J1], "%s", "Votre mot est le bon.\n"); jGagne = J1; } else{ outc(&outPl[J1], "%s", "Votre mot ne correspond pas.\n"); } } else{ // Si le joueur a entré un seul caractère nbLettre = searchInHidden(hiddenWord[J2], word[J2], choice[0]); if(nbLettre == 0){ outc(&outPl[J1], "%s", "Cette lettre n'est pas presente dans le mot.\n"); } else{ outc(&outPl[J1], "%s %d %s", "Cette lettre a ete trouve ", nbLettre, " fois dans le mot.\n"); } if(strcmp(word[J2], hiddenWord[J2]) == 0){ jGagne = J1; } } free(choice); reversePlayer(&J1, &J2); } nbTry++; } //printf("Pendu : Le joueur %d a gagne.\n", jGagne+1); jPerdu = nextPlayer(jGagne); systemc(&outPl[J1], "clear"); systemc(&outPl[J2], "clear"); outc(&outPl[jGagne], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[jGagne], "%s %s %s", "Le mot etait bien : ", word[jPerdu], "\n"); outc(&outPl[jGagne], "%s %d %s", "Vous avez gagne en ", nbTry, " essais, felicitation !!\n"); outc(&outPl[jPerdu], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[jPerdu], "%s", "Vous avez perdu, votre adversaire a ete plus rapide..\n"); outc(&outPl[jPerdu], "%s %s %s", "Le mot etait : ", word[jGagne],"\n"); flushc(pipeW, outPl, NB_PLAYER); for(i=0; i < NB_PLAYER; i++){ free(hiddenWord[i]); free(word[i]); } // On attend un peut avant de quitter waitc(&outPl[J1], 2); waitc(&outPl[J2], 2); quitc(&outPl[J1]); // Fermera le jeu pour le client quitc(&outPl[J2]); flushc(pipeW, outPl, NB_PLAYER); quit(pipeW); close(pipeW); close_out_players(outPl, NB_PLAYER); return EXIT_SUCCESS; }