diff --git a/TTT/.vscode/settings.json b/TTT/.vscode/settings.json index 1568bed..15bf385 100644 --- a/TTT/.vscode/settings.json +++ b/TTT/.vscode/settings.json @@ -3,6 +3,48 @@ "xstring": "cpp", "xutility": "cpp", "map": "cpp", - "vector": "cpp" + "vector": "cpp", + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "xfacet": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocinfo": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp" } } \ No newline at end of file diff --git a/TTT/App.cpp b/TTT/App.cpp index 835bb31..e1fbd49 100644 --- a/TTT/App.cpp +++ b/TTT/App.cpp @@ -16,7 +16,7 @@ App::App(int width, int height) : m_WindowHeight, m_WindowHeight, 0); // Initialize grid. Look at this transposed. - auto pair = std::pair(); + std::pair pair = std::pair(); pair.second = WALL; m_Grid = { { pair, pair, pair, pair, pair }, @@ -26,8 +26,9 @@ App::App(int width, int height) : { pair, pair, pair, pair, pair } }; - m_Grid[0][0].second = NONE; + // m_Grid[0][0].second = NONE; + m_Board = std::make_shared(); // triggers the program that controls // your graphics hardware and sets flags @@ -51,25 +52,6 @@ App::App(int width, int height) : SDL_FreeSurface(symbol_x_surface); SDL_FreeSurface(symbol_o_surface); - // let us control our image position - // so that we can move it with our keyboard. - SDL_Rect dest; - SDL_Rect dest2; - // connects our texture with dest to control position - SDL_QueryTexture(m_Textures[TTT::WALL], NULL, NULL, &dest.w, &dest.h); - SDL_QueryTexture(m_Textures[TTT::SYMBOL_O], NULL, NULL, &dest2.w, &dest2.h); - - // adjust height and width of our image box. - // dest.w /= 6; - // dest.h /= 6; - - // sets initial x-position of object - dest.x = (m_WindowWidth - dest.w) / 2; - dest2.x = (m_WindowWidth - dest2.w) / 2; - // sets initial y-position of object - dest.y = (m_WindowHeight - dest.h) / 2; - dest2.y = (m_WindowHeight - dest2.h) / 2; - DrawGrid(); // speed of box @@ -105,46 +87,21 @@ App::App(int width, int height) : break; case SDL_SCANCODE_W: case SDL_SCANCODE_UP: - dest.y -= speed / 30; break; case SDL_SCANCODE_A: case SDL_SCANCODE_LEFT: - dest.x -= speed / 30; break; case SDL_SCANCODE_S: case SDL_SCANCODE_DOWN: - dest.y += speed / 30; break; case SDL_SCANCODE_D: case SDL_SCANCODE_RIGHT: - dest.x += speed / 30; break; default: break; } } } - - // right boundary - if (dest.x + dest.w > 1000) - dest.x = 1000 - dest.w; - - // left boundary - if (dest.x < 0) - dest.x = 0; - - // bottom boundary - if (dest.y + dest.h > 1000) - dest.y = 1000 - dest.h; - - // upper boundary - if (dest.y < 0) - dest.y = 0; - - // clears the screen - SDL_RenderClear(m_Renderer); - SDL_RenderCopy(m_Renderer, m_Textures[TTT::WALL], NULL, &dest); - SDL_RenderCopy(m_Renderer, m_Textures[TTT::SYMBOL_O], NULL, &dest2); GridRenderCopy(); // triggers the double buffers @@ -181,9 +138,8 @@ void App::DrawGrid() // m_Grid[i][j].first.x = (m_WindowWidth - m_Grid[i][j].first.w) / 2; // m_Grid[i][j].first.y = (m_WindowHeight - m_Grid[i][j].first.h) / 2; - - m_Grid[i][j].first.w = CELL_WIDTH; - m_Grid[i][j].first.h = CELL_HEIGHT; + m_Grid[i][j].first.w = CELL_WIDTH/8; + m_Grid[i][j].first.h = CELL_HEIGHT/8; m_Grid[i][j].first.x = m_Grid[i][j].first.w * i; m_Grid[i][j].first.y = m_Grid[i][j].first.h * j; } diff --git a/TTT/App.hh b/TTT/App.hh index a315487..ba66b06 100644 --- a/TTT/App.hh +++ b/TTT/App.hh @@ -7,17 +7,14 @@ #include #include +#include + +#include "Typedef.hh" +#include "Board.hh" namespace TTT { -enum TEXTURE { - NONE, - WALL, - SYMBOL_X, - SYMBOL_O -}; - class App { private: @@ -31,6 +28,7 @@ private: SDL_Surface* m_Surface; std::map m_Textures; std::vector>> m_Grid; + std::shared_ptr m_Board; public: App(int width, int height); diff --git a/TTT/Board.cpp b/TTT/Board.cpp new file mode 100644 index 0000000..6d4cd9c --- /dev/null +++ b/TTT/Board.cpp @@ -0,0 +1,18 @@ +#include "Board.hh" + +namespace TTT +{ + +Board::Board() +{ + m_Grid = { + {}, + + }; +} + +Board::~Board() +{ +} + +} // namespace TTT diff --git a/TTT/Board.hh b/TTT/Board.hh new file mode 100644 index 0000000..6a6b338 --- /dev/null +++ b/TTT/Board.hh @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "Typedef.hh" + +namespace TTT +{ + +class Board +{ +private: + std::vector> m_Grid; +public: + Board(); + ~Board(); +}; + +} // namespace TTT diff --git a/TTT/CMakeLists.txt b/TTT/CMakeLists.txt index 79a1cfa..1f9d274 100644 --- a/TTT/CMakeLists.txt +++ b/TTT/CMakeLists.txt @@ -5,7 +5,7 @@ find_package(SDL2 CONFIG REQUIRED) find_package(SDL2_image CONFIG REQUIRED) find_package(sdl2-gfx CONFIG REQUIRED) -add_executable(Tic-Tac-Toe main.cpp App.cpp App.hh) +add_executable(Tic-Tac-Toe main.cpp App.cpp App.hh Board.cpp Board.hh Typedef.hh) target_link_libraries(Tic-Tac-Toe PRIVATE diff --git a/TTT/Typedef.hh b/TTT/Typedef.hh new file mode 100644 index 0000000..f8db2ea --- /dev/null +++ b/TTT/Typedef.hh @@ -0,0 +1,13 @@ +#pragma once + +namespace TTT +{ + +enum TEXTURE { + NONE, + WALL, + SYMBOL_X, + SYMBOL_O +}; + +} // namespace TTT