int Board::checkCheck(int curplyr) { int kingloc; if(curplyr == 1) { //27 is 1st player's king ID kingloc = pieces[27].getPosition(); } if(curplyr == 2) { //11 is 2nd player's king ID kingloc = pieces[11].getPosition(); } for(int i = 0; i < 32; i++) { //skip over pieces that are curplyr's.. if(pieces[i].getPlayer() == curplyr){continue;} //return 1 for check if(checkValidMove(i, kingloc)){return 1;} } return 0; } //checkCheck()
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); } } }