Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkovalch committed Feb 29, 2020
0 parents commit aeaba29
Show file tree
Hide file tree
Showing 13 changed files with 1,145 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Minesweeper.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Minesweeper", "Minesweeper\Minesweeper.vcxproj", "{CF9B0123-B090-4E61-98BE-5F2D78E6E520}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Debug|x64.ActiveCfg = Debug|x64
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Debug|x64.Build.0 = Debug|x64
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Debug|x86.ActiveCfg = Debug|Win32
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Debug|x86.Build.0 = Debug|Win32
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Release|x64.ActiveCfg = Release|x64
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Release|x64.Build.0 = Release|x64
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Release|x86.ActiveCfg = Release|Win32
{CF9B0123-B090-4E61-98BE-5F2D78E6E520}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5E067053-61F8-4E82-AB19-B5A87EECB5C6}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions Minesweeper/AbstractFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "AbstractFactory.h"
using namespace std;

Minesweeper & AbstractFactory::CreateBySize(const DefaultSize type)
{
switch (type)
{
case Small:
// Return object with small size:
return Minesweeper::CreateObject(SMALL_SIZE, SMALL_SIZE, SMALL_MINES_QUANTITY);
case Middle:
// Return object with middle size:
return Minesweeper::CreateObject(MIDDLE_SIZE, MIDDLE_SIZE, MIDDLE_MINES_QUANTITY);
case Large:
// Return object with large size:
return Minesweeper::CreateObject(LARGE_SIZE, LARGE_SIZE, LARGE_MINES_QUANTITY);
}

// Return object with default size:
return Minesweeper::CreateObject(SMALL_SIZE, SMALL_SIZE, SMALL_MINES_QUANTITY);
}
15 changes: 15 additions & 0 deletions Minesweeper/AbstractFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Minesweeper.h"
using namespace std;

enum DefaultSize
{
// All possible sizes:
Small, Middle, Large
};

class AbstractFactory
{
public:
// A static method that returns a singleton object:
static Minesweeper & CreateBySize(const DefaultSize type);
};
79 changes: 79 additions & 0 deletions Minesweeper/AdditionalFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "AdditionalFunctions.h"
using namespace std;

#pragma region Methods
void AdditionalFunctions::gotoxy(const short & x, const short & y)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { x, y };
SetConsoleCursorPosition(hStdout, position);
}

void AdditionalFunctions::SetColor(const Color & text, const Color & background)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
}

void AdditionalFunctions::SetWindowSize(const short & xSize, const short & ySize)
{
_COORD coord;
coord.X = xSize;
coord.Y = ySize;

_SMALL_RECT Rect;
Rect.Top = 0;
Rect.Left = 0;
Rect.Bottom = ySize - 1;
Rect.Right = xSize - 1;

HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleScreenBufferSize(Handle, coord);
SetConsoleWindowInfo(Handle, TRUE, &Rect);
}

void AdditionalFunctions::ShowConsoleCursor(const bool & showFlag)
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;

GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag;
SetConsoleCursorInfo(out, &cursorInfo);
}

void AdditionalFunctions::DisableResizing()
{
HWND consoleWindow = GetConsoleWindow();
SetWindowLong(consoleWindow, GWL_STYLE, GetWindowLong(consoleWindow, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);
}

void AdditionalFunctions::RemoveScrollbar()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(handle, &info);
COORD new_size
{
info.srWindow.Right - info.srWindow.Left + 1,
info.srWindow.Bottom - info.srWindow.Top + 1
};
SetConsoleScreenBufferSize(handle, new_size);
}

short AdditionalFunctions::GetWindowWidth()
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo);
return csbiInfo.dwSize.X;
}

short AdditionalFunctions::GetWindowHeight()
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo);
return csbiInfo.dwSize.Y;
}
#pragma endregion
38 changes: 38 additions & 0 deletions Minesweeper/AdditionalFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include "STLINCLUDE.h"
using namespace std;

enum Color
{
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGray = 7,
DarkGray = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
LightMagenta = 13,
Yellow = 14,
White = 15,
};

class AdditionalFunctions
{
public:
// Static additional methods:
static void gotoxy(const short & x = 0, const short & y = 0);
static void SetColor(const Color & text, const Color & background);
static void SetWindowSize(const short & xSize, const short & ySize);
static void ShowConsoleCursor(const bool & showFlag);
static void DisableResizing();
static void RemoveScrollbar();
static short GetWindowWidth();
static short GetWindowHeight();
};

146 changes: 146 additions & 0 deletions Minesweeper/MenuOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include "MenuOptions.h"
using namespace std;

#pragma region Methods
const DefaultSize MenuOptions::GetSize()
{
// Get size:
short choice = GetMenuOption();

// Return size:
switch (choice)
{
case 1:
return Small;
case 2:
return Middle;
case 3:
return Large;
default:
return Small;
}
}

void MenuOptions::ChangeFieldSize(Minesweeper * obj)
{
DefaultSize type = MenuOptions::GetSize();

switch (type)
{
case Small:
// Set field size to small one:
obj->SetSize(SMALL_SIZE, SMALL_SIZE, SMALL_MINES_QUANTITY);
break;
case Middle:
// Set field size to middle one:
obj->SetSize(MIDDLE_SIZE, MIDDLE_SIZE, MIDDLE_MINES_QUANTITY);
break;
case Large:
// Set field size to large one:
obj->SetSize(LARGE_SIZE, LARGE_SIZE, LARGE_MINES_QUANTITY);
break;
default:
// Set field size to default:
obj->SetSize(SMALL_SIZE, SMALL_SIZE, SMALL_MINES_QUANTITY);
}
}

const short MenuOptions::GetMenuOption()
{
// Variables for storing menu items:
int menu_item = 1, current_position = 13;

const char * Levels[]
{
"EASY", "MIDDLE", "HARD"
};

// Selecting menu options:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
AdditionalFunctions::SetColor(Black, LightGray);
AdditionalFunctions::gotoxy(53, 13); cout << Levels[0] << endl;
AdditionalFunctions::SetColor(LightGray, Black);
AdditionalFunctions::gotoxy(52, 14); cout << Levels[1] << endl;
AdditionalFunctions::gotoxy(53, 15); cout << Levels[2] << endl;

do
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
system("pause>nul");

// Up button pressed:
if (GetAsyncKeyState(VK_UP) && current_position != 13)
{
if (current_position != 14)
{
AdditionalFunctions::gotoxy(53, current_position);
AdditionalFunctions::SetColor(LightGray, Black);
cout << Levels[menu_item - 1] << endl;
}
else
{
AdditionalFunctions::gotoxy(52, current_position);
AdditionalFunctions::SetColor(LightGray, Black);
cout << Levels[menu_item - 1] << endl;
}
current_position--; menu_item--;
AdditionalFunctions::SetColor(Black, LightGray);
if (current_position != 14)
{
AdditionalFunctions::gotoxy(53, current_position);
cout << Levels[menu_item - 1] << endl;

}
else
{
AdditionalFunctions::gotoxy(52, current_position);
cout << Levels[menu_item - 1] << endl;
}

AdditionalFunctions::SetColor(LightGray, Black);
continue;
}

// Down button pressed:
if (GetAsyncKeyState(VK_DOWN) && current_position != 15)
{
if (current_position != 14)
{
AdditionalFunctions::gotoxy(53, current_position);
AdditionalFunctions::SetColor(LightGray, Black);
cout << Levels[menu_item - 1] << endl;
}
else
{
AdditionalFunctions::gotoxy(52, current_position);
AdditionalFunctions::SetColor(LightGray, Black);
cout << Levels[menu_item - 1] << endl;
}

current_position++; menu_item++;
AdditionalFunctions::SetColor(Black, LightGray);
if (current_position != 14)
{
AdditionalFunctions::gotoxy(53, current_position);
cout << Levels[menu_item - 1] << endl;
}
else
{
AdditionalFunctions::gotoxy(52, current_position);
cout << Levels[menu_item - 1] << endl;
}
AdditionalFunctions::SetColor(LightGray, Black);
continue;
}

if (GetAsyncKeyState(VK_ESCAPE) && current_position != 15)
exit(EXIT_SUCCESS);

} while (!GetAsyncKeyState(VK_RETURN));

// Return menu item:
return menu_item;
}
#pragma endregion


11 changes: 11 additions & 0 deletions Minesweeper/MenuOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "AbstractFactory.h"
using namespace std;

class MenuOptions
{
public:
static const DefaultSize GetSize();
static void ChangeFieldSize(Minesweeper * obj);
static const short GetMenuOption();
};
Loading

0 comments on commit aeaba29

Please sign in to comment.