void Game1Scene::oneRound(){ //核心游戏逻辑 //1. 移动且消除Tile moveAllTile(); //2. 随机生成新Tile createOneTile(); //3. 播放声音 //4. 界面UI变化,分数等 //在mergeTile方法里面实现 //5. 死亡逻辑判断 if(!isGameOver && totalTiles == GAME1_ROWS * GAME1_COLS){ gameOverCheck(); if (isGameOver) { this->getChildByTag(999)->getChildByTag(3)->setVisible(true); } } }
void* networking::createGame(void *arg){ struct gameData gd = *((struct gameData*)arg); game Game; pthread_detach(pthread_self()); notifyPlayers(gd); while(!gameOverCheck(gd, Game)) { while(!winConditionCheck(gd, Game)) { sendGameState(gd, Game.serialize()); getMove(gd, Game); Game.changePlayer(); } Game.incrementScore(); Game.resetBoard(); sendGameState(gd, Game.serialize()); } close(gd.player1); close(gd.player2); return NULL; }
void gamePlay() { // detect the movement of the cursor int initHoriz = analogRead(HORIZ); int initVerti = analogRead(VERT); while(true) { oldCursorX = cursorX; oldCursorY = cursorY; int finalHoriz = analogRead(HORIZ); int finalVerti = analogRead(VERT); int select = digitalRead(SEL); // HIGH(1) if not pressed, LOW(0) if pressed int deltaHoriz = (finalHoriz - initHoriz)/100; int deltaVerti = -(finalVerti - initVerti)/100; cursorX += deltaHoriz; cursorY += deltaVerti; int whetherFull = full(); //int whetherMove = blockMoved(); // cursur has moved if (oldCursorX!=cursorX || oldCursorY!=cursorY) { // backup the current grid before updating the tiles, for undo() function gridBackup(); updateTile(deltaVerti, deltaHoriz); // check if any further movements can be made if(whetherFull && noMoreAdd) {continueGame = 0;} else { continueGame = 1; createNew(); } displayGrid(); delay(50); } // Undo: button of joystick has been pressed if (select == 0) { score-=plus; undo(); displayGrid(); } // if the game is over, display game over screen and break the while loop int gameEnd = gameOverCheck(); if (gameEnd) {break;} // test: print out the values of coordinates to serial-mon //Serial.print(" whetherMove: "); //Serial.print(whetherMove); Serial.print(" continueGame: "); Serial.print(continueGame); Serial.print(" cursorX: "); Serial.print(cursorX); Serial.print(" cursorY: "); Serial.print(cursorY); Serial.print(" SEL= "); Serial.print(select,DEC); Serial.println(); delay(10); } }
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); } } }