int main() { char GameBoard[GameHeigth][GameWidth] = {" "}; //Skapar plan-arrayen int NumberOfTurns = 0,Starter; //Antal rundor, vem som startar int MaxRounds = GameHeigth*GameWidth; //Antal maxrundor=bredd*höjd unsigned seed; seed = (unsigned)time(NULL); //Seed för random srand(seed); Starter = 1+(rand()%2); if(Starter==1) //Om spelaren ska börja { printf("You start!\n"); for(; ; ) //Manuellt exitad loop { PrintBoard(GameBoard); //Skriv ut planen PlayerMove(GameBoard); //Be spelaren lägga ut en markör CheckWin(GameBoard); //Kolla om någon vunnit NumberOfTurns++; if(NumberOfTurns == MaxRounds) //Om antalet rundor = maxrundor avsluta spelet { printf("Draw!"); break; } ComputerMove(GameBoard); //Slumpa en position åt datorn CheckWin(GameBoard); //Kolla om någon vunnit NumberOfTurns++; } } else if(Starter==2) //Om datorn ska börja { printf("Ai starts!\n"); for(; ; ) { ComputerMove(GameBoard); CheckWin(GameBoard); NumberOfTurns++; if(NumberOfTurns == MaxRounds) { printf("Draw"); break; } PrintBoard(GameBoard); PlayerMove(GameBoard); CheckWin(GameBoard); NumberOfTurns++; } } return 0; }
int Connect4Player::Chance(int player) { system("cls"); ShowBoard(); int row=PlayerMove(Turn(),player); while(!(row>=0)) { system("cls"); cout<<" Wrong move try again\n "; system("Pause"); system("cls"); ShowBoard(); row=PlayerMove(Turn(),player); } return row; }
//----------------------------------------------------------------------------- // Purpose: Overridden to allow players to run faster than the maxspeed //----------------------------------------------------------------------------- void CTFGameMovement::ProcessMovement( CBasePlayer *pBasePlayer, CMoveData *pMove ) { // Verify data. Assert( pBasePlayer ); Assert( pMove ); if ( !pBasePlayer || !pMove ) return; // Reset point contents for water check. ResetGetPointContentsCache(); // Cropping movement speed scales mv->m_fForwardSpeed etc. globally // Once we crop, we don't want to recursively crop again, so we set the crop // flag globally here once per usercmd cycle. m_iSpeedCropped = SPEED_CROPPED_RESET; // Get the current TF player. m_pTFPlayer = ToTFPlayer( pBasePlayer ); player = m_pTFPlayer; mv = pMove; // The max speed is currently set to the scout - if this changes we need to change this! mv->m_flMaxSpeed = TF_MAX_SPEED; /*tf_maxspeed.GetFloat();*/ // Run the command. PlayerMove(); FinishMove(); }
void KalahContainers::KeepMoving() { while (true) { int Num; int RetVal; do { Output(); INPUT: cout << "Determine the house number(1 ~ 6): "; string StrNum; cin >> StrNum; try { Num = std::stoi(StrNum); } catch (const exception &e) { cout << "Non-numeric characters detected!\n"; goto INPUT; } RetVal = PlayerMove(Num); if (RetVal == INVALID_INPUT) cout << "Invalid number detected! Do it again!\n"<<endl; else{ cout << "The player has chosen the " << Num << "th house" <<endl; Output(); } if (RetVal == GOOD_LUCK){ cout << "Good Job, You have an extra move!\n"<<endl; } } while (RetVal == GOOD_LUCK || RetVal == INVALID_INPUT); if (IsOver(PlayerHouses)) return; do { cout << "############################################" << endl<<endl; cout << "Computer is thinking ......."<<endl<<endl; cout << "############################################" << endl<<endl; // Num = ComputerThinking(); Num = ComputerStrategy() + 1; cout << "Computer takes the " <<Length - Num + 1 << "th house!\n"<<endl; RetVal = ComputerMove(Num); if (RetVal == GOOD_LUCK){ Output(); cout << "Computer have an extra move!\n"<<endl; } } while (RetVal == GOOD_LUCK || RetVal == INVALID_INPUT); if (IsOver(ComputerHouses)) return; } }
// constructs a snake of size 8 moving upwards to start Snake::Snake() { size = 8; head = new SnakeBody(sf::Vector2f(20 * pixelSizeX, 12 * pixelSizeY), playerMove.getDirection()); tail = head; for (unsigned i = 1; i < size; i++) { Vector2f nextPos = head->shape.getPosition(); nextPos.y -= pixelSizeY; SnakeBody* nextBody = new SnakeBody(nextPos, playerMove.getDirection()); head->prev = nextBody; nextBody->next = head; head = nextBody; } headShape.setRadius((pixelSizeX / 2) - 10); headShape.setFillColor(sf::Color::Black); headShape.setPosition(head->shape.getPosition()); playerMove = PlayerMove(); }
int main() { int x, y; //플레이어의 실시간좌표 setcursortype(NOCURSOR); LoadingStage(); Round = 0; while (1) { memcpy(stage, StageData[Round], sizeof(stage)); clrscr(); for (y = 0; y < 18; y++) { for (x = 0; x < 20; x++) { if (stage[y][x] == '@') { Rx = x; //플레이어 좌표지정 Ry = y; //플레이어 좌표지정 stage[y][x] = ' '; //공백으로 지우기 } } } while (1) { DrawStage(); PlayerMove(); } } getchar(); return 0; }
//----------------------------------------------------------------------------- // Purpose: // Input : *pMove - //----------------------------------------------------------------------------- void CPortalGameMovement::ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMove ) { Assert( pMove && pPlayer ); float flStoreFrametime = gpGlobals->frametime; //!!HACK HACK: Adrian - slow down all player movement by this factor. //!!Blame Yahn for this one. gpGlobals->frametime *= pPlayer->GetLaggedMovementValue(); // ResetGetPointContentsCache(); // Cropping movement speed scales mv->m_fForwardSpeed etc. globally // Once we crop, we don't want to recursively crop again, so we set the crop // flag globally here once per usercmd cycle. m_bSpeedCropped = false; player = pPlayer; mv = pMove; mv->m_flMaxSpeed = sv_maxspeed.GetFloat(); m_bInPortalEnv = (((CPortal_Player *)pPlayer)->m_hPortalEnvironment != NULL); g_bAllowForcePortalTrace = m_bInPortalEnv; g_bForcePortalTrace = m_bInPortalEnv; // Run the command. PlayerMove(); FinishMove(); g_bAllowForcePortalTrace = false; g_bForcePortalTrace = false; #ifndef CLIENT_DLL pPlayer->UnforceButtons( IN_DUCK ); pPlayer->UnforceButtons( IN_JUMP ); #endif //This is probably not needed, but just in case. gpGlobals->frametime = flStoreFrametime; }
/* ============== CL_PredictUsercmd ============== */ void CL_PredictUsercmd(player_state_t *from, player_state_t *to, usercmd_t *u, qboolean spectator) { // split up very long moves if (u->msec > 50) { player_state_t temp; usercmd_t split; split = *u; split.msec /= 2; CL_PredictUsercmd(from, &temp, &split, spectator); CL_PredictUsercmd(&temp, to, &split, spectator); return; } VectorCopy(from->origin, pmove.origin); // VectorCopy (from->viewangles, pmove.angles); VectorCopy(u->angles, pmove.angles); VectorCopy(from->velocity, pmove.velocity); pmove.oldbuttons = from->oldbuttons; pmove.waterjumptime = from->waterjumptime; pmove.dead = cl.stats[STAT_HEALTH] <= 0; pmove.spectator = spectator; pmove.cmd = *u; PlayerMove(); //for (i=0 ; i<3 ; i++) //pmove.origin[i] = ((int)(pmove.origin[i]*8))*0.125; to->waterjumptime = pmove.waterjumptime; to->oldbuttons = pmove.cmd.buttons; VectorCopy(pmove.origin, to->origin); VectorCopy(pmove.angles, to->viewangles); VectorCopy(pmove.velocity, to->velocity); to->onground = onground; to->weaponframe = from->weaponframe; }
char PlayerMove(char GameBoard[GameHeigth][GameWidth]) //Funktion för att placera ut användarens val { int x, y; printf("\nEnter X,Y coordinates for your move(EX: 1 1): "); fflush(stdin); scanf("%d", &x); //Scannar in x + y koordinater scanf("%d", &y); x-- ,y--; //Tar bort 1 från båda talen så de kommer in på rätt plats i arrayen if(GameBoard[x][y]=='X'||GameBoard[x][y]=='O') //Om positionen spelaren angett är upptagen { printf("Invalid move, try again.\n"); PlayerMove(GameBoard); } else //Om positionen inte är upptagen placera ut spelarens markör GameBoard[x][y] = 'X'; return GameBoard; }
int turn( char board[ROWS][COLS], char mark, int cumulative_tries ) { int row; int col; int status; // Display current board // Query message before entering rows and cols clear_screen(); printf("%c's turn! Go go go, %c!\n\n", mark, mark); DisplayBoard(board); printf("\n"); row = enter_row(); col = enter_col(); printf("\n"); status = 0; status = PlayerMove(row, col, board, mark); printf("\n"); if ( status == 0 ) { if ( cumulative_tries == 3 ) { // Print something about not having forfeited turn return 1; } clear_screen(); return turn( board, mark, cumulative_tries + 1 ); } // Push back if invalid position was entered // display the board clear_screen(); DisplayBoard(board); // display victory message return DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); }
int main() { // declare variables char board[ROWS][COLS]; // initialize board InitializeBoard(board); // populate the board with moves PlayerMove( 1, 1, board, MARKONE ); PlayerMove( 1, 2, board, MARKONE ); PlayerMove( 4, 3, board, MARKONE ); PlayerMove( 1, 1, board, MARKTWO ); PlayerMove( 6, 2, board, MARKTWO ); PlayerMove( 4, 12, board, MARKTWO ); // display the board DisplayBoard(board); // exit program return 0; }
/******************************************************************************************************* * GANE ENGINE - handles the looping of the game *******************************************************************************************************/ void GameEngine() { // user input variables const int userInputLimit = 11; char userInput[userInputLimit] = {}; bool humanFinished = false; bool moveHuman = false; StringOO humanMove = "move south"; int loopCount = 0; // location variables const int locationNum = 11; Location *Locations[locationNum] = {}; int prevLocation = 0; int newLocation = 0; int finishLocation = locationNum - 1; // human player variables int humanLoc = 0; StringOO name = "Bruce"; int strength = 10; int health = 100; int luck = 10; int intellegence = 10; // enemy variables const int enemyNum = 5; Enemy * Enemies[enemyNum] = {}; // challenges variables const int challengeNum = 16; Challenge *Challenges[challengeNum] = {}; // initialise Locations InitLocations(Locations); // initialise human Human Human(humanLoc, name, strength, health, luck, intellegence); // initialise Enemies InitEnemies(Enemies, enemyNum); // initialise Challenges InitChallenges(Challenges); //AllocateChallenges(Locations, locationNum); AllocateChallengesManually(Locations, locationNum); AddEnemyToChallenge(Challenges, enemyNum, challengeNum); // initial splash screen SetConsole(); StartText(Human); // Game loop while (!humanFinished) { // print out details of room std::cout << Locations[Human.GetLocation()]->GetDescription() << std::endl; while (!moveHuman) { // get user to enter move std::cout << "+ "; std::cin.getline(userInput, userInputLimit); std::cout << std::endl; humanMove = userInput; if (loopCount == 5) { std::cout << "\n ENOUGH ALREADY...YOUR MOVING SOUTH!! \n\n"; //bored of guesses humanMove = "move south"; loopCount = 0; } // determine the new location newLocation = PlayerMove(Human, humanMove, Locations[Human.GetLocation()]->GetAjacentLoc()); // validate users move and if validate change their location if (ValidateMove(newLocation, prevLocation)) { // set challenge user has to perform before progrogressing to the next room Human.SetChallenge(Locations[Human.GetLocation()]->GetPathChallenge(Human.GetHeading())); // challenge User Challenge *ChallengePtr = Challenges[Human.GetChallenge()]; ApplyChallenge(ChallengePtr, Human, Enemies); // move user to new location prevLocation = Human.GetLocation(); Human.SetPrevHeading(Human.GetHeading()); Human.SetLocation(newLocation); moveHuman = true; loopCount = 0; std::cout << "\n***----------------------------* pop! *-------------------------------------**\n\n"; } else { // invalid move try again moveHuman = false; loopCount++; } } // reset move moveHuman = false; //check if user is in the finish location if (Human.GetLocation() == finishLocation) { humanFinished = true; std::cout << Locations[Human.GetLocation()]->GetDescription() << std::endl; FinishText(Human); } } //DestroyEnemies(Enemies, enemyNum); for (int i = 0; i < enemyNum; i++) { delete Enemies[i]; } //DestroyChallenges(Challenges, challengeNum); for (int i = 0; i < challengeNum; i++) { delete Challenges[i]; } //DestroyLocations(Locations, locationNum); for (int i = 0; i < locationNum; i++) { delete Locations[i]; } }
/* =========== SV_RunCmd =========== */ static void SV_RunCmd (usercmd_t *ucmd) { edict_t *ent; int i, n; int oldmsec; cmd = *ucmd; // chop up very long commands if (cmd.msec > 50) { oldmsec = ucmd->msec; cmd.msec = oldmsec/2; SV_RunCmd (&cmd); cmd.msec = oldmsec/2; cmd.impulse = 0; SV_RunCmd (&cmd); return; } if (!sv_player->v.fixangle) VectorCopy (ucmd->angles, sv_player->v.v_angle); sv_player->v.button0 = ucmd->buttons & 1; sv_player->v.button2 = (ucmd->buttons & 2)>>1; if (ucmd->buttons & 4 || sv_player->v.playerclass == CLASS_DWARF) // crouched? sv_player->v.flags2 = ((int)sv_player->v.flags2) | FL2_CROUCHED; else sv_player->v.flags2 = ((int)sv_player->v.flags2) & (~FL2_CROUCHED); if (ucmd->impulse) sv_player->v.impulse = ucmd->impulse; // // angles // show 1/3 the pitch angle and all the roll angle if (sv_player->v.health > 0) { if (!sv_player->v.fixangle) { sv_player->v.angles[PITCH] = -sv_player->v.v_angle[PITCH]/3; sv_player->v.angles[YAW] = sv_player->v.v_angle[YAW]; } sv_player->v.angles[ROLL] = V_CalcRoll (sv_player->v.angles, sv_player->v.velocity)*4; } host_frametime = ucmd->msec * 0.001; if (host_frametime > HX_FRAME_TIME) host_frametime = HX_FRAME_TIME; if (!host_client->spectator) { pr_global_struct->frametime = host_frametime; pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (pr_global_struct->PlayerPreThink); SV_RunThink (sv_player); } for (i = 0; i < 3; i++) pmove.origin[i] = sv_player->v.origin[i] + (sv_player->v.mins[i] - player_mins[i]); VectorCopy (sv_player->v.velocity, pmove.velocity); VectorCopy (sv_player->v.v_angle, pmove.angles); pmove.spectator = host_client->spectator; // pmove.waterjumptime = sv_player->v.teleport_time; pmove.numphysent = 1; pmove.physents[0].model = sv.worldmodel; pmove.cmd = *ucmd; pmove.dead = sv_player->v.health <= 0; pmove.oldbuttons = host_client->oldbuttons; pmove.hasted = sv_player->v.hasted; pmove.movetype = sv_player->v.movetype; pmove.crouched = (sv_player->v.hull == HULL_CROUCH); pmove.teleport_time = realtime + (sv_player->v.teleport_time - sv.time); // movevars.entgravity = host_client->entgravity; movevars.entgravity = sv_player->v.gravity; movevars.maxspeed = host_client->maxspeed; for (i = 0; i < 3; i++) { pmove_mins[i] = pmove.origin[i] - 256; pmove_maxs[i] = pmove.origin[i] + 256; } #if 1 AddLinksToPmove ( sv_areanodes ); #else AddAllEntsToPmove (); #endif #if 0 { int before, after; before = PM_TestPlayerPosition (pmove.origin); PlayerMove (); after = PM_TestPlayerPosition (pmove.origin); if (sv_player->v.health > 0 && before && !after ) Con_Printf ("player %s got stuck in playermove!!!!\n", host_client->name); } #else PlayerMove (); #endif host_client->oldbuttons = pmove.oldbuttons; // sv_player->v.teleport_time = pmove.waterjumptime; sv_player->v.waterlevel = waterlevel; sv_player->v.watertype = watertype; if (onground != -1) { sv_player->v.flags = (int)sv_player->v.flags | FL_ONGROUND; sv_player->v.groundentity = EDICT_TO_PROG(EDICT_NUM(pmove.physents[onground].info)); } else sv_player->v.flags = (int)sv_player->v.flags & ~FL_ONGROUND; for (i = 0; i < 3; i++) sv_player->v.origin[i] = pmove.origin[i] - (sv_player->v.mins[i] - player_mins[i]); #if 0 // truncate velocity the same way the net protocol will for (i = 0; i < 3; i++) sv_player->v.velocity[i] = (int)pmove.velocity[i]; #else VectorCopy (pmove.velocity, sv_player->v.velocity); #endif VectorCopy (pmove.angles, sv_player->v.v_angle); if (!host_client->spectator) { // link into place and touch triggers SV_LinkEdict (sv_player, true); // touch other objects for (i = 0; i < pmove.numtouch; i++) { n = pmove.physents[pmove.touchindex[i]].info; ent = EDICT_NUM(n); // Why not just do an SV_Impact here? // SV_Impact(sv_player,ent); if (sv_player->v.touch) { pr_global_struct->self = EDICT_TO_PROG(sv_player); pr_global_struct->other = EDICT_TO_PROG(ent); PR_ExecuteProgram (sv_player->v.touch); } if (!ent->v.touch || (playertouch[n/8]&(1<<(n%8)))) continue; pr_global_struct->self = EDICT_TO_PROG(ent); pr_global_struct->other = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (ent->v.touch); playertouch[n/8] |= 1 << (n%8); } } }
void Update() { clock_t CurTime = clock(); // 현재 시각 PlayerMove(CurTime); }
int main() { // declare variables char board[ROWS][COLS]; // Produce a NoWin condition // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a horizontal victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); PlayerMove(1, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a vertical victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKTWO); PlayerMove(2, 1, board, MARKTWO); PlayerMove(3, 1, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a diagonal-down victory // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(2, 2, board, MARKONE); PlayerMove(3, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a diagonal-up victory // initialize board InitializeBoard(board); // populate board PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a multiple player victory // initialize board InitializeBoard(board); // populate board PlayerMove(4, 1, board, MARKONE); PlayerMove(4, 2, board, MARKONE); PlayerMove(4, 3, board, MARKONE); PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // Produce a tie // initialize board // InitializeBoard(board); // populate board // for (int k = 0; k < COLS; ) { /* code */ // k % 2 == 0 ? k+=1 : k += 3; // } // display the board // DisplayBoard(board); // display victory message // DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // exit program return 0; }
void tictactoe::on_btnBR_clicked() { PlayerMove(BR); }
void tictactoe::on_btnBC_clicked() { PlayerMove(BC); }
void CBPGameMovement::ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMove ) { Assert( pMove && pPlayer ); float flStoreFrametime = gpGlobals->frametime; //!!HACK HACK: Adrian - slow down all player movement by this factor. //!!Blame Yahn for this one. gpGlobals->frametime *= pPlayer->GetLaggedMovementValue(); ResetGetPointContentsCache(); Assert( player == pPlayer ); player = pPlayer; mv = pMove; bpmv = (CBPMoveData*) pMove ; mv->m_flMaxSpeed = pPlayer->GetPlayerMaxSpeed(); // Add trigger to history for interp stuff m_flInterpLTrigger.AddToTail( float_time( bpmv->m_flLTrigger, gpGlobals->curtime ) ); m_flInterpRTrigger.AddToTail( float_time( bpmv->m_flRTrigger, gpGlobals->curtime ) ); m_flLTriggerAvg = 0; for ( int i = 0; i < m_flInterpLTrigger.Count(); i++ ) m_flLTriggerAvg += m_flInterpLTrigger[i].m_flValue; m_flLTriggerAvg /= m_flInterpLTrigger.Count(); m_flLTriggerDiff = bpmv->m_flLTrigger - m_flLTriggerAvg; //DevMsg("Diff = %.2f - %.2f = %.2f\n",bpmv->m_flLTrigger,lDiff, m_flLTriggerDiff,m_flLTriggerDiff); m_flRTriggerAvg = 0; for ( int i = 0; i < m_flInterpRTrigger.Count(); i++ ) m_flRTriggerAvg += m_flInterpRTrigger[i].m_flValue; m_flRTriggerAvg /= m_flInterpRTrigger.Count(); m_flRTriggerDiff = bpmv->m_flRTrigger - m_flRTriggerAvg; int iCount = m_flInterpLTrigger.Count(); for ( int i = iCount-1; i >= 0; i-- ) { if ( m_flInterpLTrigger[i].m_flTime < gpGlobals->curtime-0.15 ) m_flInterpLTrigger.Remove(i); } iCount = m_flInterpRTrigger.Count(); for ( int i = iCount-1; i >= 0; i-- ) { if ( m_flInterpRTrigger[i].m_flTime < gpGlobals->curtime-0.15 ) m_flInterpRTrigger.Remove(i); } DiffPrint( "start %f %f %f", mv->GetAbsOrigin().x, mv->GetAbsOrigin().y, mv->GetAbsOrigin().z ); // Run the command. PlayerMove(); FinishMove(); DiffPrint( "end %f %f %f", mv->GetAbsOrigin().x, mv->GetAbsOrigin().y, mv->GetAbsOrigin().z ); //This is probably not needed, but just in case. gpGlobals->frametime = flStoreFrametime; }
void tictactoe::on_btnMR_clicked() { PlayerMove(MR); }
void tictactoe::on_btnMC_clicked() { PlayerMove(MC); }
void tictactoe::on_btnML_clicked() { PlayerMove(ML); }
void tictactoe::on_btnTR_clicked() { PlayerMove(TR); }
void ProcessGame(void) { COORD movement; int monster, monstersAlive; movement.X = 0, movement.Y = 0; /* 移动玩家 */ switch(iLastAction) { case 's': case 'S': Save(); break; case VK_UP: movement.Y = -1; break; case VK_DOWN: movement.Y = 1; break; case VK_RIGHT: movement.X = 1; break; case VK_LEFT: movement.X = -1; break; case VK_HOME: movement.X = -1; movement.Y = -1; break; case VK_PRIOR: movement.X = 1; movement.Y = -1; break; case VK_END: movement.X = -1; movement.Y = 1; break; case VK_NEXT: movement.Y = 1; movement.Y = 1; break; case VK_INSERT: if(PlayerGetLeaps() > 0) { PlayerRandomLeap(cdArena); PlayerSetLeaps(PlayerGetLeaps() - 1); } break; case VK_ESCAPE: EndGame(); iGameStatus = GameMainMenu; break; default: break; }/* switch */ /* 移动 */ if(movement.X != 0 || movement.Y != 0) { COORD playerPosition; PlayerGetPosition(&playerPosition); /* 如果在范围内,就相应的移动娃娃你家 */ if(movement.X + playerPosition.X > 0 && movement.Y + playerPosition.Y > 0 && movement.X + playerPosition.X < cdArena.X && movement.Y + playerPosition.Y < cdArena.Y) { PlayerMove(movement); } /* 编写怪物人工智能,检测是否会发生碰撞 */ MoveMonsters(); CheckCollisions(); /* 检测是否还有怪物活着 */ monstersAlive = 0; for(monster = 0; monster < iMonstersNumber; monster++) { /* 检验怪物是否死了 */ if(cdpMonsters[monster].X == 0) continue; monstersAlive = 1; break; }/* end for */ if(monstersAlive == 0) { iGameStatus = GameWon; } }/* 移动 if */ }
void tictactoe::on_btnTL_clicked() { PlayerMove(TL); }
void tictactoe::on_btnBL_clicked() { PlayerMove(BL); }
void tictactoe::on_btnTC_clicked() { PlayerMove(TC); }
int main() { sf::RenderWindow App(sf::VideoMode(800, 600, 32), "MyDemo"); App.PreserveOpenGLStates(true); sf::Clock Clock; sf::Vector3f CamPos; // ======= Create some players ======= Player p1; p1.SetRace('b'); p1.SetID((int) Players.size()); p1.SetCellPosition(0, 10); Players.push_back(p1); Player p2; p2.SetRace('a'); p2.SetID((int) Players.size()); p2.SetCellPosition(10, 10); Players.push_back(p2); // ======== Calculate 1/2 of map size ========== HalfMapSpaceSize = (int) Players.size() * CellsPerPlayer * (CellWidth / 2); HalfMapCellSize = (int) Players.size() * (CellsPerPlayer / 2); PreapareGrid(); // ======== Place players in random corners of the map ======== for (unsigned int i = 0; i < Players.size(); i++) { int a = i % 3, b = i / 3; Players[i].SetCellPosition(((HalfMapCellSize * 2) - 1) * ((a > 1) ? 1 : a), ((HalfMapCellSize * 2) - 1) * ((b > 1) ? 1 : b)); } // ======= OpenGL settings ======= glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glClearDepth(1.f); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.f, 1.f, 1.f, 500.f); glClearColor(0.0f, 0.5f, 1.0f, 0.5f); // ======= Set camera position ======= CamPos = sf::Vector3f(0, 100, 75); App.ShowMouseCursor(false); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Resized) glViewport(0, 0, Event.Size.Width, Event.Size.Height); if (Event.Type == sf::Event::Closed || App.GetInput().IsKeyDown(sf::Key::Escape)) App.Close(); if (App.GetInput().IsKeyDown(sf::Key::W)) CamPos.z -= 3; if (App.GetInput().IsKeyDown(sf::Key::S)) CamPos.z += 3; if (App.GetInput().IsKeyDown(sf::Key::A)) CamPos.x -= 3; if (App.GetInput().IsKeyDown(sf::Key::D)) CamPos.x += 3; if (Event.Type == sf::Event::MouseButtonReleased) { if (Event.MouseButton.Button == sf::Mouse::Left) { sf::Vector3f v = ScreenToSpace(App.GetInput().GetMouseX(), App.GetInput().GetMouseY()); int x1, z1; // cell indexes float x2, z2; // cell normal basis SpaceToCell(v.x, v.z, x1, z1, x2, z2); PlayerMove(x1, z1, Players[0]); } } } // ======= Clear OpenGL state ======= glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (true) { // ======= Update camera view ======= /*gluLookAt(Players[0].Model.GetPosition().GetX(), Players[0].Model.GetPosition().GetY() + 100, Players[0].Model.GetPosition().GetZ() + 75, Players[0].Model.GetPosition().GetX(), Players[0].Model.GetPosition().GetY(), Players[0].Model.GetPosition().GetZ(), 0, 1, 0);*/ gluLookAt(CamPos.x, CamPos.y, CamPos.z, CamPos.x, CamPos.y - 100, CamPos.z - 75, 0, 1, 0); DrawGrid(); // ======= Pick terrain point at mouse cursor position ======= { sf::Vector3f v = ScreenToSpace(App.GetInput().GetMouseX(), App.GetInput().GetMouseY()); int x1, z1; // cell indexes float x2, z2; // cell normal basis SpaceToCell(v.x, v.z, x1, z1); CellToSpace(x1, z1, x2, z2); // ======= Draw normal ======= glBegin(GL_LINES); glVertex3f(x2, 0, z2); glVertex3f(x2, 150, z2); glEnd(); } // ======= Render models ======= for (unsigned int i = 0; i < Players.size(); i++) { float x1, x2; float time = Clock.GetElapsedTime(); CellToSpace(Players[i].GetXCell(), Players[i].GetYCell(), x1, x2); Players[i].SetSpacePosition(x1, (float) (Players[i].GetModel().GetSize().GetY() / 4.f) + 6.5f, x2); HighlightSquare(Players[i].GetXCell(), Players[i].GetYCell(), Players[i].GetWRadius(), sf::Color(1, 1, 0), 1); HighlightSquare(Players[i].GetXCell(), Players[i].GetYCell(), Players[i].GetARadius(), sf::Color(1, 0, 0), 2); Players[i].Draw(time); } } App.Display(); } return EXIT_SUCCESS; }