State onPlayersTurn(Game* game) { /* added clear screen -Cesar 1/27 */ char cmd[255]; char choice = 0; char userInput[255]; char promotionChoice; char maxTurnUserInput; int result; int ox, oy, dx, dy; clearScreen(); assert(game); printBoard(game); printf("Turn number: %d, ", game->turn+1); if(game->turn%2 == 0) printf("WHITE's turn\n"); else printf("BLACK's turn\n"); printUserMenu(game); getGameInput(cmd); choice = cmd[0]; if(check500Turns(game)) return MainMenu; /* added by Cesar 1/26 */ switch(choice) { case '0': return MainMenu; case '1': printHints(game); return TurnPlayer; case '2': redo(game); return TurnPlayer; case '3': printLog(game); return TurnPlayer; case '4': replay(game); return TurnPlayer; case '5': printf("Enter the file name you want to save \n"); scanf("%s", userInput); saveLog(game, userInput); fseek(stdin,0,SEEK_END); return TurnPlayer; case '6': printf("Enter the file name you want to save: "); scanf("%s", userInput); printf("\n"); fseek(stdin,0,SEEK_END); saveGame(game, userInput); return TurnPlayer; case '7': gameOptions(game); return TurnPlayer; default: break; } ox = cmd[0] - 97; oy = cmd[1] - 49; dx = cmd[2] - 97; dy = cmd[3] - 49; if((!checkBoarder(ox, oy))||(!checkBoarder(dx, dy)) || (isValidMove(game, ox, oy, dx, dy) <= 0)) { printf("INVALID MOVE DETECTED"); if(game->setting->allowIllegalMove == 1) { printf(", TRY AGAIN\n\n"); return TurnPlayer; } else { printf(", GAME OVER!\n\n"); return MainMenu; } } result = gameLogic(game, cmd); if(result == 9 || result == 10) { promotionChoice = ' '; while(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B') { printf("Pawn promotion, enter the promotion choice (char to represent piece): "); scanf("%c", &promotionChoice); fseek(stdin,0,SEEK_END); if(promotionChoice=='q') promotionChoice='Q'; else if(promotionChoice=='r') promotionChoice='R'; else if(promotionChoice=='n') promotionChoice='N'; else if(promotionChoice=='b') promotionChoice='B'; printf("%c\n",promotionChoice); if(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B') printf("Invalid input, try again.\n"); } result = promotion(game, cmd, promotionChoice); } if(result == 7) { printf("CHECKMATE\n"); getchar(); return MainMenu; } else if(result == 8) { printf("STALEMATE\n"); getchar(); return MainMenu; } if(game->setting->gameMode == 0) return TurnAI; else if(game->setting->gameMode == 1) return TurnPlayer; else return MainMenu; /* game logic returns 0 meaning the game is end */ }
bool Console::processEvent(Events::Event &event) { if (!isVisible()) return false; if ((event.type == Events::kEventMouseDown) && ((event.button.button != SDL_BUTTON_WHEELUP) && (event.button.button != SDL_BUTTON_WHEELDOWN))) { const uint8 button = event.button.button; const uint8 pasteMask1 = SDL_BUTTON_MMASK; const uint8 pasteMask2 = SDL_BUTTON_LMASK | SDL_BUTTON_RMASK; if (((button & pasteMask1) == pasteMask1) || ((button & pasteMask2) == pasteMask2)) { _readLine->addInput(_console->getHighlight()); _console->setInput(_readLine->getCurrentLine(), _readLine->getCursorPosition(), _readLine->getOverwrite()); return true; } if (button & SDL_BUTTON_LMASK) { _console->startHighlight(event.button.x, event.button.y); return true; } } if ((event.type == Events::kEventMouseMove) && ((event.button.button != SDL_BUTTON_WHEELUP) && (event.button.button != SDL_BUTTON_WHEELDOWN))) { if (event.motion.state & SDL_BUTTON_LMASK) { _console->stopHighlight(event.button.x, event.button.y); return true; } } if ((event.type == Events::kEventMouseUp) && ((event.button.button != SDL_BUTTON_WHEELUP) && (event.button.button != SDL_BUTTON_WHEELDOWN))) { uint32 curTime = EventMan.getTimestamp(); if (((curTime - _lastClickTime) < kDoubleClickTime) && (_lastClickButton == event.button.button) && (_lastClickX == event.button.x) && (_lastClickY == event.button.y)) _lastClickCount = (_lastClickCount + 1) % 3; else _lastClickCount = 0; _lastClickButton = event.button.button; _lastClickTime = curTime; _lastClickX = event.button.x; _lastClickY = event.button.y; if (event.button.button & SDL_BUTTON_LMASK) { if (_lastClickCount == 0) _console->stopHighlight(event.button.x, event.button.y); else if (_lastClickCount == 1) _console->highlightWord(event.button.x, event.button.y); else if (_lastClickCount == 2) _console->highlightLine(event.button.x, event.button.y); return true; } } if (event.type == Events::kEventKeyDown) { _console->clearHighlight(); if (event.key.keysym.sym != SDLK_TAB) { _tabCount = 0; _printedCompleteWarning = false; } else _tabCount++; if (event.key.keysym.sym == SDLK_ESCAPE) { hide(); return true; } if ((event.key.keysym.sym == SDLK_l) && (event.key.keysym.mod & KMOD_CTRL)) { clear(); return true; } if ((event.key.keysym.sym == SDLK_PAGEUP) && (event.key.keysym.mod & KMOD_SHIFT)) { _console->scrollUp(kConsoleLines / 2); return true; } if ((event.key.keysym.sym == SDLK_PAGEDOWN) && (event.key.keysym.mod & KMOD_SHIFT)) { _console->scrollDown(kConsoleLines / 2); return true; } if (event.key.keysym.sym == SDLK_PAGEUP) { _console->scrollUp(); return true; } if (event.key.keysym.sym == SDLK_PAGEDOWN) { _console->scrollDown(); return true; } if ((event.key.keysym.sym == SDLK_HOME) && (event.key.keysym.mod & KMOD_SHIFT)) { _console->scrollTop(); return true; } if ((event.key.keysym.sym == SDLK_END) && (event.key.keysym.mod & KMOD_SHIFT)) { _console->scrollBottom(); return true; } } else if (event.type == Events::kEventMouseDown) { if (event.button.button == SDL_BUTTON_WHEELUP) { _console->scrollUp(); return true; } if (event.button.button == SDL_BUTTON_WHEELDOWN) { _console->scrollDown(); return true; } } Common::UString command; if (!_readLine->processEvent(event, command)) return false; _console->setInput(_readLine->getCurrentLine(), _readLine->getCursorPosition(), _readLine->getOverwrite()); // Check whether we have tab-completion hints if (printHints(command)) return true; execute(command); return true; }