void MainWindow::createMenu() { gameMenu = new QMenu(trUtf8("&Partie"), this); menuBar()->addMenu(gameMenu); newGameAction = new QAction(trUtf8("&Nouvelle partie"), this); gameMenu->addAction(newGameAction); gameMenu->addSeparator(); connect(newGameAction, SIGNAL(triggered(bool)), this, SLOT(newGame())); quitAction = new QAction(trUtf8("&Quitter"), this); gameMenu->addAction(quitAction); connect(quitAction, SIGNAL(triggered(bool)), qApp, SLOT(quit())); optionMenu = new QMenu(trUtf8("&Options"), this); menuBar()->addMenu(optionMenu); setFirstPlayer(); setSecondPlayer(); setRulesOptions(); }
/* * Executes a command given by the user * * @params: (command) - the command given by the user * @return: relevant exitcode */ int executeCommand(char* command){ char str[64]; sscanf(command, "%s", str); if (str_equals(str, "quit")){ exit(0); } if (state == SETTINGS){ if (str_equals(str, "game_mode")){ return setGameMode(command); } if (str_equals(str, "difficulty")){ return setDifficulty(command); } if (str_equals(str, "user_color")){ return setUserColor(command); } if (str_equals(str, "load")){ return loadGameByCommand(command); } if (str_equals(str, "clear")){ Board_clear(&board); PieceCounter_reset(counter); return 0; } if (str_equals(str, "next_player")){ return setFirstPlayer(command); } if (str_equals(str, "rm")){ return removePiece(command); } if (str_equals(str, "set")){ return setPiece(command); } if (str_equals(str, "print")){ display(); return 0; } if (str_equals(str, "start")){ if(PieceCounter_kingIsMissing(counter)){ return -7; } turn = first; state = GAME; return 2; //special value to break the humanTurn loop so the initial board will always be checked for immediate loss or tie conditions } } else{ if (str_equals(str, "get_moves")){ return printMovesOfPiece(command); } if (str_equals(str, "move")){ return movePiece(command); } if (str_equals(str, "castle")){ return castleRook(command); } if (str_equals(str, "get_best_moves")){ return printBestMoves(command); } if (str_equals(str, "get_score")){ return printMoveValue(command); } if (str_equals(str,"save")){ return saveGameByCommand(command); } } return -1; }