Start Øving 10
parent
5e317b8a73
commit
130cda80fe
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.271
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Oving 10", "Oving 10\Oving 10.vcxproj", "{A4B05D49-A333-47BE-AE25-7C99915B153D}"
|
||||
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
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Debug|x64.Build.0 = Debug|x64
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Debug|x86.Build.0 = Debug|Win32
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Release|x64.ActiveCfg = Release|x64
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Release|x64.Build.0 = Release|x64
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Release|x86.ActiveCfg = Release|Win32
|
||||
{A4B05D49-A333-47BE-AE25-7C99915B153D}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {792BFF6E-EEDC-4E01-933A-306403FBD033}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,72 @@
|
|||
#include "MinesweeperWindow.h"
|
||||
|
||||
MinesweeperWindow::MinesweeperWindow(Point xy, int width, int height, int mines, const string& title) :
|
||||
Graph_lib::Window(xy, width * cellSize, height*cellSize, title), width(width), height(height), mines(mines)
|
||||
//Initialiser medlemsvariabler, bruker også konstruktøren til Windowsklassen
|
||||
{
|
||||
// Legg til alle tiles på vinduet
|
||||
for (int i = 0; i < height; ++i) {
|
||||
for (int j = 0; j < width; ++j) {
|
||||
int y = i* cellSize,
|
||||
x = j * cellSize;
|
||||
tiles.push_back(new Tile{ Point{x, y}, cellSize, cb_click });
|
||||
attach(tiles.back());
|
||||
}
|
||||
}
|
||||
|
||||
//Legg til miner på tilfeldige posisjoner
|
||||
|
||||
|
||||
// Fjern window reskalering
|
||||
resizable(nullptr);
|
||||
size_range(x_max(), y_max(), x_max(), y_max());
|
||||
}
|
||||
|
||||
int MinesweeperWindow::countMines(vector<Point> points) const {
|
||||
return 0;
|
||||
};
|
||||
vector<Point> MinesweeperWindow::adjacentPoints(Point xy) const {
|
||||
vector<Point> points;
|
||||
for (int di = -1; di <= 1; ++di) {
|
||||
for (int dj = -1; dj <= 1; ++dj) {
|
||||
if (di == 0 && dj == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Point neighbour{ xy.x + di * cellSize,xy.y + dj * cellSize };
|
||||
if (inRange(neighbour)) {
|
||||
points.push_back(neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
void MinesweeperWindow::openTile(Point xy) {
|
||||
}
|
||||
|
||||
void MinesweeperWindow::flagTile(Point xy) {
|
||||
}
|
||||
|
||||
//Kaller opentile ved venstreklikk og flagTile ved høyreklikk
|
||||
void MinesweeperWindow::cb_click(Address, Address pw)
|
||||
{
|
||||
Point xy{ Fl::event_x(),Fl::event_y() };
|
||||
MouseButton mb = static_cast<MouseButton>(Fl::event_button());
|
||||
auto& win = reference_to<MinesweeperWindow>(pw);
|
||||
|
||||
if (!win.inRange(xy)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mb) {
|
||||
case MouseButton::left:
|
||||
win.openTile(xy);
|
||||
break;
|
||||
case MouseButton::right:
|
||||
win.flagTile(xy);
|
||||
break;
|
||||
}
|
||||
win.flush();
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
#include "Window.h"
|
||||
#include "Tile.h"
|
||||
|
||||
using namespace Graph_lib;
|
||||
enum class MouseButton { left = FL_LEFT_MOUSE, right = FL_RIGHT_MOUSE }; //
|
||||
|
||||
// Minesweeper GUI
|
||||
class MinesweeperWindow : Graph_lib::Window
|
||||
{
|
||||
public:
|
||||
//størrelsen til hver rute
|
||||
static constexpr int cellSize = 30;
|
||||
MinesweeperWindow(Point xy, int width, int height, int mines, const string& title);
|
||||
private:
|
||||
|
||||
const int width;//width i miner
|
||||
const int height;//heigth i miner
|
||||
const int mines;//Antall miner
|
||||
Vector_ref<Tile> tiles; // Vektor som inneholder alle tiles
|
||||
|
||||
//Height og Width i piksler
|
||||
int Height() const { return height * cellSize; }
|
||||
int Width() const { return width * cellSize; }
|
||||
|
||||
// Få en liste med naborutene rundt en tile
|
||||
vector<Point> adjacentPoints(Point xy) const;
|
||||
//tell miner basert på liste
|
||||
int countMines(vector<Point> coords) const;
|
||||
|
||||
//Sjekk at punkt er på brettet og gjør det til Tile
|
||||
bool inRange(Point xy) const { return xy.x >= 0 && xy.x < Width() && xy.y >= 0 && xy.y < Height(); }
|
||||
Tile& at(Point xy) { return tiles[xy.x / cellSize + (xy.y / cellSize) * width]; }
|
||||
const Tile& at(Point xy) const { return tiles[xy.x / cellSize + (xy.y / cellSize) * width]; }
|
||||
|
||||
//Åpne og flagge rute
|
||||
void openTile(Point xy);
|
||||
void flagTile(Point xy);
|
||||
|
||||
//callback funksjon for tile knappen
|
||||
static void cb_click(Address, Address pw);
|
||||
};
|
|
@ -0,0 +1,164 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="MinesweeperWindow.cpp" />
|
||||
<ClCompile Include="Tile.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MinesweeperWindow.h" />
|
||||
<ClInclude Include="Tile.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{a4b05d49-a333-47be-ae25-7c99915b153d}</ProjectGuid>
|
||||
<RootNamespace>Oving_10</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MinesweeperWindow.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Tile.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MinesweeperWindow.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Tile.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
#include "Tile.h"
|
||||
|
||||
// For å sette labelfarge i henhold til hvor mange miner som er rundt
|
||||
const map<int, Color> minesToColor{ {1, Color::blue},
|
||||
{2, Color::red},
|
||||
{3,Color::dark_green},
|
||||
{4, Color::dark_magenta},
|
||||
{5, Color::dark_blue},
|
||||
{6, Color::dark_cyan},
|
||||
{7, Color::dark_red},
|
||||
{8, Color::dark_yellow} };
|
||||
|
||||
// For å sette Tilelabel i henhold til state
|
||||
const map<Cell, string> cellToSymbol{ {Cell::closed, ""},
|
||||
{Cell::open, ""},
|
||||
{Cell::flagged, "@<"} };
|
||||
|
||||
void Tile::open()
|
||||
{
|
||||
static_cast<Fl_Button*>(pw)->set();//Setter en button som trykket på, tilsvarer åpnet rute
|
||||
}
|
||||
|
||||
void Tile::flag()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#include "GUI.h"
|
||||
|
||||
using namespace Graph_lib;
|
||||
|
||||
//De forskjellige tilstandene en Tile kan være i
|
||||
enum class Cell { closed, open, flagged };
|
||||
|
||||
struct Tile : Button
|
||||
{
|
||||
Tile(Point pos, int size, Graph_lib::Callback cb)
|
||||
:Button(pos, size, size, "", cb){};
|
||||
|
||||
void set_label(string s) { label = s; redraw(); }
|
||||
void set_label_color(Color c) { pw->labelcolor(c.as_int()); redraw(); }
|
||||
|
||||
void open(); // Åpner ruten
|
||||
void flag();// Flagger en rute
|
||||
|
||||
Cell state = Cell::closed;
|
||||
};
|
|
@ -0,0 +1,16 @@
|
|||
#include "MinesweeperWindow.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
Fl::background(200, 200, 200);
|
||||
constexpr int width = 10;
|
||||
constexpr int height = 10;
|
||||
constexpr int mines = 3;
|
||||
|
||||
Point startPoint{ 200,300 };
|
||||
MinesweeperWindow mw{ startPoint, width, height, mines, "Minesweeper" };
|
||||
return gui_main();
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue