Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit #15

Open
wants to merge 6 commits into
base: Dev/Project-Setup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Array-Minesweeper/Array-Minesweeper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="source\Gameplay\Board\BoardController.cpp" />
<ClCompile Include="source\Gameplay\Board\BoardService.cpp" />
<ClCompile Include="source\Gameplay\Board\BoardView.cpp" />
<ClCompile Include="source\Gameplay\Cell\CellController.cpp" />
<ClCompile Include="source\Gameplay\Cell\CellModel.cpp" />
<ClCompile Include="source\Gameplay\Cell\CellView.cpp" />
<ClCompile Include="source\Gameplay\GameplayController.cpp" />
<ClCompile Include="source\Gameplay\GameplayService.cpp" />
<ClCompile Include="source\Time\TimeService.cpp" />
<ClCompile Include="source\UI\Gameplay\GameplayUIController.cpp" />
<ClCompile Include="source\UI\Instructions\InstructionsScreenUIController.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="source\Event\EventService.cpp" />
Expand All @@ -153,10 +163,20 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="header\Event\EventService.h" />
<ClInclude Include="header\Gameplay\Board\BoardController.h" />
<ClInclude Include="header\Gameplay\Board\BoardService.h" />
<ClInclude Include="header\Gameplay\Board\BoardView.h" />
<ClInclude Include="header\Gameplay\Cell\CellController.h" />
<ClInclude Include="header\Gameplay\Cell\CellModel.h" />
<ClInclude Include="header\Gameplay\Cell\CellView.h" />
<ClInclude Include="header\Gameplay\GameplayController.h" />
<ClInclude Include="header\Gameplay\GameplayService.h" />
<ClInclude Include="header\Main\GameService.h" />
<ClInclude Include="header\Global\Config.h" />
<ClInclude Include="header\Graphics\GraphicService.h" />
<ClInclude Include="header\Time\TimeService.h" />
<ClInclude Include="header\UI\Credits\CreditsScreenUIController.h" />
<ClInclude Include="header\UI\Gameplay\GameplayUIController.h" />
<ClInclude Include="header\UI\Interface\IUIController.h" />
<ClInclude Include="header\UI\MainMenu\MainMenuUIController.h" />
<ClInclude Include="header\Global\ServiceLocator.h" />
Expand Down
2 changes: 1 addition & 1 deletion Array-Minesweeper/SFML/include/SFML/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
////////////////////////////////////////////////////////////
#define SFML_VERSION_MAJOR 2
#define SFML_VERSION_MINOR 6
#define SFML_VERSION_PATCH 0
#define SFML_VERSION_PATCH 1


////////////////////////////////////////////////////////////
Expand Down
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-audio-s-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-audio-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-audio.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-graphics-s-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-graphics-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-graphics.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-main-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-main-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-network-s-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-network-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-network.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-system-s-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-system-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-system.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-window-s-d.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-window-s.pdb
Binary file not shown.
Binary file modified Array-Minesweeper/SFML/lib/Debug/sfml-window.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion Array-Minesweeper/SFML/lib/cmake/SFML/SFMLConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ if (NOT SFML_FOUND)
endif()

if (SFML_FOUND AND NOT SFML_FIND_QUIETLY)
message(STATUS "Found SFML 2.6.0 in ${CMAKE_CURRENT_LIST_DIR}")
message(STATUS "Found SFML 2.6.1 in ${CMAKE_CURRENT_LIST_DIR}")
endif()
6 changes: 3 additions & 3 deletions Array-Minesweeper/SFML/lib/cmake/SFML/SFMLConfigVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# The variable CVF_VERSION must be set before calling configure_file().


set(PACKAGE_VERSION "2.6.0")
set(PACKAGE_VERSION "2.6.1")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

if("2.6.0" MATCHES "^([0-9]+)\\.")
if("2.6.1" MATCHES "^([0-9]+)\\.")
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
endif()
else()
set(CVF_VERSION_MAJOR "2.6.0")
set(CVF_VERSION_MAJOR "2.6.1")
endif()

if(PACKAGE_FIND_VERSION_RANGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.3")
message(FATAL_ERROR "CMake >= 2.8.3 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.3...3.24)
cmake_policy(VERSION 2.8.3...3.25)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.3")
message(FATAL_ERROR "CMake >= 2.8.3 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.3...3.24)
cmake_policy(VERSION 2.8.3...3.25)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Array-Minesweeper/header/Event/EventService.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Event
bool gameWindowWasClosed();
bool hasQuitGame();
bool isKeyboardEvent();
void updateButtonsState(ButtonState& button_state);
void updateButtonsState(ButtonState& button_state, sf::Mouse::Button button_type);

public:
EventService();
Expand Down
84 changes: 84 additions & 0 deletions Array-Minesweeper/header/Gameplay/Board/BoardController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once
#include <sfml/Graphics.hpp>
#include "../../header/Gameplay/Cell/CellController.h"
#include "../../header/UI/UIElement/ButtonView.h"
#include <random>

namespace Gameplay
{
namespace Board
{
class BoardView;

enum class BoardState
{
FIRST_CELL, // The state when the player opens first cell.
PLAYING, // The game is in progress.
COMPLETED, // The game is over.
};

class BoardController
{
public:
static const int number_of_rows = 9;
static const int number_of_colums = 9;
static const int mines_count = 8;

BoardController();
~BoardController();

void initialize();
void update();
void render();

void processCellInput(Cell::CellController* cell_controller, UI::UIElement::ButtonType button_type);
void reset();

BoardState getBoardState();
void setBoardState(BoardState state);

int getMinesCount();

void flagAllMines();
void openAllCells();
void showBoard();

private:
BoardView* board_view;
Cell::CellController* board[number_of_rows][number_of_colums];

// To generate random values.
std::default_random_engine random_engine;

// To give random seed to generator.
std::random_device random_device;

BoardState board_state;
int flagged_cells;

void createBoard();
void initializeCells();

void populateBoard(sf::Vector2i cell_position);
void populateMines(sf::Vector2i cell_position);
void populateCells();
int countMinesAround(sf::Vector2i cell_position);

void flagCell(sf::Vector2i cell_position);
void openCell(sf::Vector2i cell_position);
bool areAllCellOpen();

void processCellType(sf::Vector2i cell_position);
void processEmptyCell(sf::Vector2i cell_position);
void processMineCell(sf::Vector2i cell_position);

void openEmptyCells(sf::Vector2i cell_position);
bool isValidCellPosition(sf::Vector2i cell_position);


void resetBoard();
void deleteBoard();
void destroy();
};
}
}
39 changes: 39 additions & 0 deletions Array-Minesweeper/header/Gameplay/Board/BoardService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include "../../header/Gameplay/Board/BoardController.h"
#include "../../header/Gameplay/Cell/CellController.h"
#include "../../header/UI/UIElement/ButtonView.h"


namespace Gameplay
{
enum class GameResult;

namespace Board
{
class BoardService
{
private:
Board::BoardController* board_controller;

void destroy();

public:
BoardService();
~BoardService();
void initialize();
void update();
void render();

void processCellInput(Cell::CellController* cell_controller, UI::UIElement::ButtonType button_type);

BoardState getBoardState();
void setBoardState(BoardState state);
void resetBoard();

int getMinesCount();

void flagAllMines();
void showBoard();
};
}
}
41 changes: 41 additions & 0 deletions Array-Minesweeper/header/Gameplay/Board/BoardView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once
#include "../../header/UI/UIElement/ImageView.h"

namespace Gameplay
{
namespace Board
{
class BoardController;

class BoardView
{
private:

const float board_width_offset = 115.f;
const float board_height_offset = 329.f;

const float board_width = 866.f;
const float board_height = 1080.f;

const float background_alpha = 85.f;

BoardController* board_controller;
UI::UIElement::ImageView* board_image;
UI::UIElement::ImageView* background_image;

void initializeBackgroudImage();
void initializeBoardImage();

public:
BoardView(BoardController* controller);
~BoardView();

void initialize();
void update();
void render();

float getCellWidth();
float getCellHeight();
};
}
}
45 changes: 45 additions & 0 deletions Array-Minesweeper/header/Gameplay/Cell/CellController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include <sfml/Graphics.hpp>

namespace Gameplay
{
namespace Cell
{
class CellView;
class CellModel;
enum class CellState;
enum class CellType;

class CellController
{
private:
CellView* cell_view;
CellModel* cell_model;

void destroy();

public:
CellController(sf::Vector2i grid_position);
~CellController();

void initialize(float cell_width, float cell_height);
void update();
void render();

void flagCell();
void openCell();

bool canOpenCell();
CellState getCellState();
void setCellState(CellState state);

CellType getCellType();
void setCellType(CellType type);

sf::Vector2i getCellPosition();
int getMinesAround();

void reset();
};
}
}
57 changes: 57 additions & 0 deletions Array-Minesweeper/header/Gameplay/Cell/CellModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include <sfml/Graphics.hpp>

namespace Gameplay
{
namespace Cell
{
enum class CellState
{
HIDDEN,
OPEN,
FLAGGED,
};

enum class CellType
{
EMPTY,
ONE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
MINE,
};

class CellModel
{
private:
CellState cell_state;
CellType cell_type;

sf::Vector2i position;
int mines_around;

public:
CellModel(sf::Vector2i grid_position);
~CellModel();

CellState getCellState();
void setCellState(CellState state);

CellType getCellType();
void setCellType(CellType type);

sf::Vector2i getCellPosition();
void setCellPosition(sf::Vector2i grid_position);

int getMinesAround();
void setMinesAround(int mine_count);

void reset();
};
}
}
Loading