diff --git a/Oving 10/Oving 10.sln b/Oving 10/Oving 10.sln new file mode 100644 index 0000000..40e4302 --- /dev/null +++ b/Oving 10/Oving 10.sln @@ -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 diff --git a/Oving 10/Oving 10/MinesweeperWindow.cpp b/Oving 10/Oving 10/MinesweeperWindow.cpp new file mode 100644 index 0000000..fdacee6 --- /dev/null +++ b/Oving 10/Oving 10/MinesweeperWindow.cpp @@ -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 points) const { + return 0; +}; +vector MinesweeperWindow::adjacentPoints(Point xy) const { + vector 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(Fl::event_button()); + auto& win = reference_to(pw); + + if (!win.inRange(xy)) { + return; + } + + switch (mb) { + case MouseButton::left: + win.openTile(xy); + break; + case MouseButton::right: + win.flagTile(xy); + break; + } + win.flush(); +} diff --git a/Oving 10/Oving 10/MinesweeperWindow.h b/Oving 10/Oving 10/MinesweeperWindow.h new file mode 100644 index 0000000..5211347 --- /dev/null +++ b/Oving 10/Oving 10/MinesweeperWindow.h @@ -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 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 adjacentPoints(Point xy) const; + //tell miner basert på liste + int countMines(vector 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); +}; diff --git a/Oving 10/Oving 10/Oving 10.vcxproj b/Oving 10/Oving 10/Oving 10.vcxproj new file mode 100644 index 0000000..22b32b1 --- /dev/null +++ b/Oving 10/Oving 10/Oving 10.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + 15.0 + {a4b05d49-a333-47be-ae25-7c99915b153d} + Oving_10 + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath) + + + + Level3 + Disabled + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + 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) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + Disabled + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + 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) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + MaxSpeed + true + true + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + 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) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + MaxSpeed + true + true + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + 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) + /ignore:4099 %(AdditionalOptions) + + + + + + \ No newline at end of file diff --git a/Oving 10/Oving 10/Oving 10.vcxproj.filters b/Oving 10/Oving 10/Oving 10.vcxproj.filters new file mode 100644 index 0000000..1b424cc --- /dev/null +++ b/Oving 10/Oving 10/Oving 10.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Oving 10/Oving 10/Tile.cpp b/Oving 10/Oving 10/Tile.cpp new file mode 100644 index 0000000..23e0465 --- /dev/null +++ b/Oving 10/Oving 10/Tile.cpp @@ -0,0 +1,25 @@ +#include "Tile.h" + +// For å sette labelfarge i henhold til hvor mange miner som er rundt +const map 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 cellToSymbol{ {Cell::closed, ""}, + {Cell::open, ""}, + {Cell::flagged, "@<"} }; + +void Tile::open() +{ + static_cast(pw)->set();//Setter en button som trykket på, tilsvarer åpnet rute +} + +void Tile::flag() +{ +} diff --git a/Oving 10/Oving 10/Tile.h b/Oving 10/Oving 10/Tile.h new file mode 100644 index 0000000..5c94341 --- /dev/null +++ b/Oving 10/Oving 10/Tile.h @@ -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; +}; \ No newline at end of file diff --git a/Oving 10/Oving 10/main.cpp b/Oving 10/Oving 10/main.cpp new file mode 100644 index 0000000..7816eca --- /dev/null +++ b/Oving 10/Oving 10/main.cpp @@ -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(); + +} + \ No newline at end of file diff --git a/Oving 10/Utdelt_Kode.zip b/Oving 10/Utdelt_Kode.zip new file mode 100644 index 0000000..5cb4e49 Binary files /dev/null and b/Oving 10/Utdelt_Kode.zip differ diff --git a/Oving 10/Øving10.pdf b/Oving 10/Øving10.pdf new file mode 100644 index 0000000..c3d7f1e Binary files /dev/null and b/Oving 10/Øving10.pdf differ