char* action(player* pl, player* w, int in){ char* msg = ""; switch(in){ case KEY_UP: msg = playerMove(pl, UP, w); break; case KEY_DOWN: msg = playerMove(pl, DOWN, w); break; case KEY_LEFT: msg = playerMove(pl, LEFT, w); break; case KEY_RIGHT: msg = playerMove(pl, RIGHT, w); break; case KEY_SHOOT: switch(in = input()){ case KEY_DOWN: msg = playerShoot(pl, DOWN, w); break; case KEY_LEFT: msg = playerShoot(pl, LEFT, w); break; case KEY_RIGHT: msg = playerShoot(pl, RIGHT, w); break; case KEY_UP: msg = playerShoot(pl, UP, w); break; default: break; } break; case KEY_QUIT: endGame(pl, w); break; default: break; } return msg; }
void Moderator::lookForMove(){ if(gamestate==PLAYER_1_TO_MOVE) player1HasMoved(); if(gamestate==PLAYER_2_TO_MOVE) player2HasMoved(); if(gamestate==PLAYER_1_TO_MOVE && player1MadeAMove){ int move = plyr1Move; QString moveChars = QString().setNum(move); moveChars.append("\n"); player1MadeAMove = false; console(QString("Player 1's move: " + QString().setNum(move))); if(playerMove(true,move)==false){ return; } writeLineToTerminal("PLAYER1MOVE"+QString().setNum(move)+QString().setNum(currentGame.getColFill(move-1))); // 1 has already been added to colfill if(!player2->isManual){ player2->write(moveChars.toStdString().c_str()); player2->waitForBytesWritten(); } gamestate = PLAYER_2_TO_MOVE; emit(player2ToMove(player2->isManual)); timeRemaining = timePerMove; timeUntilMove = delayBeforeMove; emit timeUntilMoveChanged(timePerMove,true); emit timeUntilMoveChanged(timePerMove,false); } else{ if(gamestate==PLAYER_2_TO_MOVE && player2MadeAMove){ int move = plyr2Move; QString moveChars = QString().setNum(move); moveChars.append("\n"); player2MadeAMove = false; console(QString("Player 2's move: " + QString().setNum(move))); if(playerMove(false, move)==false){ return; } writeLineToTerminal("PLAYER2MOVE"+QString().setNum(move)+QString().setNum(currentGame.getColFill(move-1))); if(!player1->isManual){ player1->write(moveChars.toStdString().c_str()); player1->waitForBytesWritten(); } gamestate = PLAYER_1_TO_MOVE; emit(player1ToMove(player1->isManual)); timeRemaining = timePerMove; timeUntilMove = delayBeforeMove; emit timeUntilMoveChanged(timePerMove,true); emit timeUntilMoveChanged(timePerMove,false); } } }
/************************************************ update() All update logic goes in this function. update will keep track of the status and location of the player and tiles. *************************************************/ void update(int data) { if(gameActive) { background.Scroll(); //Calculates the frame rate previousTime = currentTime; currentTime = (float)glutGet(GLUT_ELAPSED_TIME); deltaTime = (currentTime - previousTime); enemyCollision(); //Check if the player has collided with an enemy playerMove(deltaTime); //Move the player if (enemies.size() < 7 && enemyCount != 48) loadEnemies(); if (enemies.size() == 1 && enemyCount == 48 && killCount < 20) cleanUp(); /* KILL COUNT FOR LEVEL ! only */ if (player[0]->lives <0) { fadeStarted = true; cleanUp(); } if(enemies.size() == 1 && enemyCount == 48 && killCount >= 20) { killCount = 0; fadeStarted = true; cleanUp(); } } //cout << "X: " << player[0]->getX() << " Y:" << player[0]->getY() << "\n"; glutPostRedisplay(); }
void Kiwi::Update(float tickDuration) { lastPosition_ = position_; auto tickVelocity = playerMove(); position_ = position_ + tickVelocity * tickDuration ; /* Debug */ if(position_.x() < 0){ position_.x() += 1; lastPosition_.x() += 1; } if(position_.y() < 0){ position_.y() += 1; lastPosition_.y() += 1; } if(position_.z() < 0){ position_.z() += 1; lastPosition_.z() += 1; } velocity_.x() *= 0.8; velocity_.y() *= 0.8; velocity_.z() += -0.005; }
int main() { int board[9] = {0,0,0,0,0,0,0,0,0}; //computer squares are 1, player squares are -1. printf("Computer: O, You: X\nPlay (1)st or (2)nd? "); int player=0; scanf("%d",&player); printf("\n"); unsigned turn; for(turn = 0; turn < 9 && win(board) == 0; ++turn) { if((turn+player) % 2 == 0) computerMove(board); else { draw(board); playerMove(board); } } switch(win(board)) { case 0: printf("A draw. How droll.\n"); break; case 1: draw(board); printf("You lose.\n"); break; case -1: printf("You win. Inconceivable!\n"); break; } }
void start() { playerMove(300, 60); playerFloor(0); playerDir(1); cameraCenterPlayer(); playerSetColor(RGBA8(128, 0, 128, 255)); // create stuff main(); }
void gameSystem::playGame() { bool isDone = false; while (!isDone) { _level.print(_player); playerMove(); } delete _dialogueTree; delete _player; }
void playerMove(char board[3][3]) { int x, y; printf("Enter board coordinate (x,y): "); scanf("%d %d", &x, &y); x = x - 1; y = y - 1; if (board[x][y] != '-') { printf("Invalid move\n"); playerMove(); } else board[x][y] = 'X'; }
int main() { printf("Go MonteCarloAI\n"); int numSimulations = 0; float millaSecondsToThink = 15000; auto b = new Board(); b->init(); UCTNode *currentNode; root = new UCTNode(-1, -1, nullptr); UCTNode::rootState = b; currentNode = root; b->show(); Patterns patterns; // patterns.init(patternsFile3x3, patternsFile5x5); GameResult result = None; while (!b->isGameOver(&result)) { if (b->turn == White) { computerMove(¤tNode, b, numSimulations, millaSecondsToThink, nullptr); // &patterns); } else { // computerMove(¤tNode, b, numSimulations, millaSecondsToThink, nullptr); // &patterns); playerMove(¤tNode, b); // randomMove(¤tNode, b); } b->show(); } if (result == Draw) { printf("Draw\n"); } else if (static_cast<Player>(result) == Black) { printf("Black Won\n"); } else { printf("White Won\n"); } float score = 0; score = b->getTaylorScore(0.5); printf("\nScore: %f\n", score); delete currentNode; delete b; return 0; }
void Engine::GameLoop() { playerMove(); if(vecBullets.size() > 0) { bulletMove(); } if(vecPU.size() >= 0) { powerUPMove(); checkPUContact(); } checkBulletContact(); }
int main(int argc, char const *argv[]) { int x = 0, y = 0; char done = '-'; char mainboard[3][3]; initBoard(mainboard); do { showBoard(mainboard); playerMove(mainboard); done = boardCheck(mainboard, 'X'); if (done != '-') break; computerMove(mainboard); done = boardCheck(mainboard,'O'); if(done!='-') break; } while (done == '-'); if (done == 'X') printf("You won\n"); else printf("Computer Won\n"); showBoard(mainboard); return 0; }
int main(int argc, char** argv) { startNewGame(); while (1) { int move; printf("Move? "); scanf("%d", &move); playerMove(move); printGameState(globalState); checkWin(globalState); computerMove(LOOK_AHEAD); printGameState(globalState); checkWin(globalState); } freeGameState(globalState); return 0; }
int startTheGame() { char choice[3], ch; int index, easyIndex, hardIndex; int position; int isFirstTurn; int i, j; int isWin; int playerEasyWinScore = 0; int playerEasyLostScore = 0; int playerEasyTieScore = 0; int playerHardWinScore = 0; int playerHardLostScore = 0; int playerHardTieScore = 0; int gameplay; // 0 - Easy gameplay, 1 - Hard gameplay int isSavedEasy, isSavedHard; char easy[3][3], hard[3][3]; FILE *userFile = fopen(FILEPATH, "r"); if(userFile == NULL) { createUserDataFile(); userFile = fopen(FILEPATH, "r"); } fscanf(userFile, "%d", &gameplay); fscanf(userFile, "%d %d %d", &playerEasyWinScore, &playerEasyLostScore, &playerEasyTieScore); fscanf(userFile, "%d %d %d", &playerHardWinScore, &playerHardLostScore, &playerHardTieScore); fscanf(userFile, "%d %d", &isSavedEasy, &isSavedHard); // Check for any saved game if(isSavedEasy) { fscanf(userFile, "%d", &easyIndex); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { ch = getc(userFile); if(ch != '\n') easy[i][j] = ch; ch = getc(userFile); if(ch != '\n') easy[i][j] = ch; } } } if(isSavedHard) { fscanf(userFile, "%d", &hardIndex); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { ch = getc(userFile); if(ch != '\n') hard[i][j] = ch; ch = getc(userFile); if(ch != '\n') hard[i][j] = ch; } } } fclose(userFile); if( (gameplay && isSavedHard) || (!gameplay && isSavedEasy) ) { system("cls"); printf("You have a saved game.\n"); printf("1. Continue\n"); printf("2. New Game\n"); printf("New Game will overwrite the saved game of current gameplay.\n"); printf("Enter your choice:(Default - Continue) "); fgets(choice, sizeof(choice), stdin); if(gameplay) { isSavedHard = 0; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(isSavedEasy) { fprintf(userFile, "%d\n", easyIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n", easy[i][j]); } fclose(userFile); } else { isSavedEasy = 0; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(isSavedHard) { fprintf(userFile, "%d\n", hardIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n", hard[i][j]); } fclose(userFile); } if( (atoi(choice)) == 2) { initializeBoard(); index = 0; } else { if(gameplay && isSavedHard) { index = hardIndex; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) base[i][j] = hard[i][j]; } else { index = easyIndex; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) base[i][j] = easy[i][j]; } } } else { initializeBoard(); index = 0; } // Start the game for(isFirstTurn = 1; index < 9; index++) { if(index % 2 == 0) { while(1) { system("cls"); displayTheBoard(); if (!isFirstTurn) { printf("AI move: %d\n", position); } else { isFirstTurn = 0; } printf("Enter the position at which you want to put X: (0: Menu) "); fgets(choice, sizeof(choice), stdin); position = atoi(choice); switch(position) { case 0: system("cls"); printf("\nDo you want to save and quit? (Default - Resume)\n"); printf("1. Resume\n2. Save and Quit\n3. Quit without saving\n\n"); printf("Enter your choice: "); fgets(choice, sizeof(choice), stdin); switch(atoi(choice)) { case 1: continue; break; case 2: if(gameplay) isSavedHard = 1; else isSavedEasy = 1; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(gameplay) { if(isSavedEasy == 1) { fprintf(userFile, "%d\n", easyIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",easy[i][j]); } fprintf(userFile, "%d\n", index); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",base[i][j]); } else { fprintf(userFile, "%d\n", index); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",base[i][j]); if(isSavedHard == 1) { fprintf(userFile, "%d\n", hardIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",hard[i][j]); } } fclose(userFile); return(0); break; case 3: return(0); break; default: continue; } break; case 1: //Fall through case 2: //Fall through case 3: //Fall through case 4: //Fall through case 5: //Fall through case 6: //Fall through case 7: //Fall through case 8: //Fall through case 9: if(checkThePlace(position)) break; else { printf("\nERROR:Position is not available.\n"); printf("Try again.\n\n"); system("pause"); continue; } break; default: printf("\nERROR:Position is not valid.\n"); printf("Try again.\n\n"); system("pause"); continue; } break; } playerMove(position, 'X'); // User's move } else { position = getThePosition(); playerMove(position, 'O'); // AI's move } system("cls"); displayTheBoard(); isWin = winCheck(); // Check the win conditions if(isWin) { if(index % 2 == 0) // User wins { printf(" == You won ==\n\n"); if(gameplay) playerHardWinScore++; else playerEasyWinScore++; } else // AI wins { printf(" = You lost! =\n\n"); if(gameplay) playerHardLostScore++; else playerEasyLostScore++; } break; } } if(!isWin) { printf(" ==== TIE ====\n\n"); if(gameplay) playerHardTieScore++; else playerEasyTieScore++; } userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fclose(userFile); printf("\nEnter 1 to retry, or press any other key to go to Main Menu: "); fgets(choice, sizeof(choice), stdin); if(atoi(choice) == 1) startTheGame(); return(0); }
void PlayerMoveList::AddMove(int _deltaX, int _deltaY, int _idSquare) { PlayerMove playerMove(_deltaX, _deltaY, _idSquare); push_back(playerMove); }
int main() { //CHARACTER const char roleName1[10] = { 'W','a','r','r','i','o','r' }; const char roleName2[10] = { 'M','a','g','e' }; const char roleName3[10] = { 'A','r','c','h','e','r' }; double playerHealth; double playerAttack; double playerMaxHealth; //CHARACTER STATS double playerMinPhysicalResistance; double playerMaxPhysicalResistance; double playerCritChance; double playerMinCritDamage; double playerMaxCritDamage; //BOSS STATS char bossName[10] = { 'S', 'i', 'l', 'v', 'a' }; double bossHealth; double bossAttack; double bossMinPhysicalResistance; double bossMaxPhysicalResistance; double bossCritChance; double bossMinCritDamage; double bossMaxCritDamage; //FUNCTION int renderOpCode = -1; double *renderArgument1 = NULL; double *renderArgument2 = NULL; renderArgument1 = malloc(sizeof(double)); renderArgument2 = malloc(sizeof(double)); introduction(); createPlayerCharacter(getUserInput(3), &playerHealth, &playerMaxHealth, &playerAttack, &playerMinPhysicalResistance, &playerMaxPhysicalResistance, &playerCritChance, &playerMinCritDamage, &playerMaxCritDamage); createBoss( &bossHealth, &bossAttack, &bossMaxPhysicalResistance, &bossMinPhysicalResistance, &bossMaxCritDamage, &bossMinCritDamage, &bossCritChance); while (1 == 1) { while (bossHealth >= 0) { int temp = playerMove(); if (temp == 1) { double amount = calculateDamageAmount( bossMinPhysicalResistance, bossMaxPhysicalResistance, playerMinCritDamage, playerMaxCritDamage, playerCritChance, playerAttack); printf("Player dealt %d to Boss.\n", (int)amount); bossHealth -= amount; printf("Boss heal is %d.\n", (int)bossHealth); } if (temp == 2) { double amount = calculateHealAmount(playerMinPhysicalResistance, playerMaxPhysicalResistance, playerMinCritDamage, playerMaxCritDamage, playerCritChance, playerAttack); printf("Player heal %d to self HP.\n", (int)amount); playerHealth += amount; printf("Player heal is %d.\n", (int)playerHealth); } double amount = calculateDamageAmount(playerMinPhysicalResistance, playerMaxPhysicalResistance, bossMinCritDamage, bossMaxCritDamage, bossCritChance, bossAttack); printf("<----------------------------------------------------------------------------->\n"); printf("Boss dealt %d to Player.\n", (int)amount); playerHealth -= amount; printf("Player heal is %d.\n", (int)playerHealth); printf("<----------------------------------------------------------------------------->\n"); } } return 0; };
int main(int argc, char* argv[]) { int stepNumber; int caseNumber = 0; bool lose; while(input()) { stepNumber = 0; lose = false; if(caseNumber) { printf("\n"); } printf("Case %d:\n",++caseNumber); while(true) { #ifdef DEBUG system("cls"); currentBoard.printBoard(); for(int i=0;i<9;++i) { printf("Move Information %d: \n",i); printf("\tPlayer Dead: %d\n",moveInformation[i].playerDead); printf("\tRobots Number: %d\n",moveInformation[i].robotsNumber); printf("\tMost Close Length: %d\n",moveInformation[i].closestLength); printf("\tRow Number: %d Column Number: %d\n",moveInformation[i].rowIndex,moveInformation[i].columnIndex); printf("\n"); } while(getchar()!='t'); #endif ++stepNumber; if(!playerMove()) { if(currentBoard.findTeleport()) { printf("Move %d: teleport to (%d,%d)\n",stepNumber,currentBoard.getPlayerX(),currentBoard.getPlayerY()); } else { if(currentBoard.robotsMove()) { lose = true; break; } } } if(currentBoard.getRobotsNumber() == 0) { break; } } if(lose) { printf("Lost game after making %d moves.\n",stepNumber); printf("Final position: (%d,%d)\n",currentBoard.getPlayerX(),currentBoard.getPlayerY()); printf("Number of cells with debris: %d\n",currentBoard.getDebrisNumber()); printf("Number of robots remaining: %d\n",currentBoard.getRobotsNumber()); } else { printf("Won game after making %d moves.\n",stepNumber); printf("Final position: (%d,%d)\n",currentBoard.getPlayerX(),currentBoard.getPlayerY()); printf("Number of cells with debris: %d\n",currentBoard.getDebrisNumber()); } } return 0; }
void newGame(int** grid, int* score, int* backToMenu, int gameMode, int delay) { int eaten_flag, skip_sleep = 0; int backup_move = KEY_RIGHT, move = KEY_RIGHT; while (1) { eaten_flag = 0; if (!skip_sleep) { if (move == KEY_RIGHT || move == KEY_LEFT) { Sleep(delay - 20); } else { Sleep(delay); } } else { skip_sleep = 0; } if (_kbhit()) { move = playerMove(); } if (move == EXIT) { while (1) { clear_screen(); pauseGraphics(); if (mainMenu(0)) { break; } else { *backToMenu = 1; return; } } move = backup_move; restoreInGameGraphics(grid, *score); continue; } if (!checkValidMove(move) || move == INVALID_MOVE) { move = backup_move; skip_sleep = 1; continue; } backup_move = move; if (gameOverCheck(move, gameMode)) { drawGameOver(); Sleep(1000); if (*score > record) { record = *score; } break; } assignSnake2Matrix(grid, 0); moveSnake(move, gameMode); eaten_flag = checkIfEaten(grid); if (eaten_flag) { fattenSnake(); } assignSnake2Matrix(grid, 1); if (eaten_flag) { addFood(grid); updateSnakeGraphics(grid, 1); *score += 1; updateScore(*score); } else { updateSnakeGraphics(grid, 0); } } }