int main(int, char const**) { // Create the main window sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Minesweeper"); // Set the Icon sf::Image icon; if (!icon.loadFromFile(resourcePath() + "icon.png")) { return EXIT_FAILURE; } window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); GameBoard gameBoard(COLUMNS, ROWS, MINES); CellTextures cellTextures; FaceTextures faceTextures; sf::RectangleShape backFill; backFill.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT)); backFill.setFillColor(sf::Color(164, 164, 164)); sf::RectangleShape gridBorder; gridBorder.setPosition(sf::Vector2f(BOARD_X_OFFSET, BOARD_Y_OFFSET)); gridBorder.setSize(sf::Vector2f(COLUMNS * CELL_WIDTH + 1, ROWS * CELL_HEIGHT + 1)); gridBorder.setFillColor(sf::Color(86, 86, 86)); int score = 0; sf::Font scoreFont; scoreFont.loadFromFile(resourcePath() + "sansation.ttf"); sf::Text scoreCounter; scoreCounter.setPosition(BORDER, 0); scoreCounter.setColor(sf::Color::Black); scoreCounter.setFont(scoreFont); // Start the game loop while (window.isOpen()) { // Process events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::MouseButtonPressed) { int mouseX = event.mouseButton.x; int mouseY = event.mouseButton.y; int gridX = (mouseX - BOARD_X_OFFSET) / CELL_WIDTH; int gridY = (mouseY - BOARD_Y_OFFSET) / CELL_HEIGHT; if (gameBoard.validCoordinate(gridX, gridY)) { if (event.mouseButton.button == sf::Mouse::Button::Left) { score += gameBoard.onClick(gridX, gridY); } if (event.mouseButton.button == sf::Mouse::Button::Right) { gameBoard.onRightClick(gridX, gridY); } } else { if (mouseX >= FACE_X && mouseX <= FACE_X + FACE_WIDTH && mouseY >= FACE_Y && mouseY <= FACE_Y + FACE_HEIGHT && event.mouseButton.button == sf::Mouse::Button::Left) { /** RESTART GAME! */ score = 0; gameBoard = GameBoard(COLUMNS, ROWS, MINES); } } } // Close window : exit if (event.type == sf::Event::Closed) { window.close(); } // Escape pressed : exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { window.close(); } } // Clear screen window.clear(); window.draw(backFill); window.draw(gridBorder); scoreCounter.setString(std::to_string(score)); window.draw(scoreCounter); // Draw the grid for (int y = 0; y < gameBoard.getRows(); y++) { for (int x = 0; x < gameBoard.getColumns(); x++) { Cell cell = gameBoard.getCell(x, y); sf::Sprite sprite(*cellTextures.getCellTexture(cell, gameBoard.getNeighbouringMines(x, y))); sprite.setPosition(BOARD_X_OFFSET + x * CELL_WIDTH, BOARD_Y_OFFSET + y * CELL_HEIGHT); window.draw(sprite); } } // Draw the face sf::Sprite face(*(gameBoard.getIsGameOver() ? faceTextures.getLose() : gameBoard.getIsGameWon() ? faceTextures.getWin() : faceTextures.getPlaying())); face.setPosition(FACE_X, FACE_Y); window.draw(face); // Update the window window.display(); } return EXIT_SUCCESS; }
int main() { sf::RenderWindow window; sf::ContextSettings antiAliasing; // DATA INITIALIZATION // seed rand() with std::time srand((unsigned int) time(NULL)); // Initialize data Faction alliance("Allianz"); Faction horde("Horde"); // Initialize first player Player* player_Alliance = new Player(alliance, false); // Initialize Agent and load previously stored Q_Value_Table AI* agent_Horde = new AI(horde, NULL); //agent_Horde->createEmptyTableOfValues(); agent_Horde->load(); Data dat = Data(); GameBoard gameBoard = GameBoard(player_Alliance, agent_Horde); agent_Horde->setGameBoard(&gameBoard); // Initialize the Turns Turn gameTurn = Turn(&gameBoard, &window, &dat); // true for Player One's Turn // false for Player Two's/AI's Turn bool playerIsAtTurn = true;; antiAliasing.antialiasingLevel = 8; // Create a window (1920 x 1080) window.create(sf::VideoMode(1220, 1080), "KI_Projekt_-_World_of_Warcraft_Risiko_Prototyp", sf::Style::None, antiAliasing); window.setPosition(sf::Vector2i(0, 0)); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { // Game Loop // If agent or player won: update brain.txt with new Q_Values if(gameTurn.getGameEnd()) { agent_Horde->store(); } // Check whos at turn and get his Game-Phase if(playerIsAtTurn) { gameTurn.activateCurrentPhase(playerIsAtTurn, gameTurn.getCurrentPhaseNumber()); // End of turn? -> Next player if(gameTurn.getCurrentPhaseNumber() == 4) { playerIsAtTurn = !playerIsAtTurn; gameTurn.setCurrentPhaseNumber(1); } } if(!playerIsAtTurn) { gameTurn.activateCurrentPhase(playerIsAtTurn ,gameTurn.getCurrentPhaseNumber()); // End of turn? -> Next player if(gameTurn.getCurrentPhaseNumber() == 4) { playerIsAtTurn = !playerIsAtTurn; gameTurn.setCurrentPhaseNumber(1); } } } // update in turn integrieeren! } return 0; }