From 1f8159534f30d3e46f53cebb788c91153103edcb Mon Sep 17 00:00:00 2001 From: Stephen Enders Date: Mon, 18 Jan 2021 16:29:23 -0500 Subject: Move helper.h to helper.hpp and reformat --- CMakeLists.txt | 2 +- helper.cpp | 2 +- helper.h | 106 --------------------------------------------------------- helper.hpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ur.cpp | 2 +- 5 files changed, 105 insertions(+), 109 deletions(-) delete mode 100644 helper.h create mode 100644 helper.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index be11c85..f7a56e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(EXECUTABLE_NAME ur) set(SFML_LIBRARIES sfml-system sfml-window sfml-graphics) find_package(SFML 2.5 REQUIRED COMPONENTS system window graphics) -add_executable(${EXECUTABLE_NAME} ur.cpp helper.h helper.cpp) +add_executable(${EXECUTABLE_NAME} ur.cpp helper.hpp helper.cpp) target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/helper.cpp b/helper.cpp index f1bb417..04c95cf 100644 --- a/helper.cpp +++ b/helper.cpp @@ -1,4 +1,4 @@ -#include "helper.h" +#include "helper.hpp" #include std::shared_ptr> diff --git a/helper.h b/helper.h deleted file mode 100644 index 74c11ca..0000000 --- a/helper.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef UR_HELPER_H -#define UR_HELPER_H - -#include -#include -#include - -// BOARD LAYOUT [0, 1, 2, 3](start) [4,5,6,7,8,9,10,11](middle), [12,13](end) - -static const unsigned int SPRITE_SIZE = 16; -static const unsigned int NUM_PIECES = 7; -static const unsigned int SAFE_SPACE = 7; // 0-indexed -static const unsigned int EXIT_SPACE = 14; // final space + 1 -static const float ZOOM = 0.5f; -static const float SPRITE_ROWS = 9.f; -static const float SPRITE_COLS = 14.f; -static const float SCR_W = SPRITE_SIZE / ZOOM * SPRITE_COLS / ZOOM; -static const float SCR_H = SPRITE_SIZE / ZOOM * SPRITE_ROWS / ZOOM; -static const int P1_PIECE = 6; -static const int P2_PIECE = 5; -static const int P1_BOARD_TILES[2] = { 0, 1 }; -static const int P2_BOARD_TILES[2] = { 2, 3 }; -static const int STAR_TILE = 4; -static const int BLANK_TILE = 9; -static const int DIE_0 = 8; -static const int DIE_1 = 7; -static const int NUMS_TILES[8] = { 10, 11, 12, 13, 14, 15, 16, 17 }; -static const int ROLL_TILES[2] = { 18, 19 }; - -static const char* TITLE = "Royal Game of Ur"; -static const sf::Color GLOBAL_MASK(255, 0, 255, 255); - -enum GameState -{ - WAITING, - ROLLING, - PLACING, - GAME_OVER -}; - -struct piece_t -{ - int id; - int position; - sf::Sprite sprite; -}; - - -struct player_t -{ - int score; - std::shared_ptr> pieces; -}; - -struct dice_t -{ - int value; - bool show; - sf::Sprite sprite; -}; - - -std::shared_ptr> -loadTextures(const char* path); - -std::shared_ptr> -createBoard(std::shared_ptr> textures); - -sf::Font loadFont(); - -std::shared_ptr -createPlayer(sf::Texture& pieceTexture); - -std::shared_ptr -createPiece(int id, sf::Texture& texture); - -std::shared_ptr> -createAllDice(sf::Texture& die0Texture, sf::Texture& die1Texture); - -std::shared_ptr> -createRollSprites(sf::Texture& t1, sf::Texture& t2); - -void makeNum( - sf::Sprite* sprite_ptr, - int num, - std::shared_ptr> textures); - -bool -clickedPiece(sf::Vector2i mousePosition, std::shared_ptr piece); - -bool -canMovePiece( - std::shared_ptr piece, - int roll, - std::shared_ptr> myPieces, - std::shared_ptr> enemyPieces); - -std::vector -getLegalMoves( - std::shared_ptr activePlayer, - std::shared_ptr opponent); - -sf::Vector2f -pos(float c, float r); -#endif - diff --git a/helper.hpp b/helper.hpp new file mode 100644 index 0000000..d0e86ce --- /dev/null +++ b/helper.hpp @@ -0,0 +1,102 @@ +#ifndef UR_HELPER_H +#define UR_HELPER_H + +#include +#include +#include + +// BOARD LAYOUT [0, 1, 2, 3](start) [4,5,6,7,8,9,10,11](middle), [12,13](end) + +static const unsigned int SPRITE_SIZE = 16; +static const unsigned int NUM_PIECES = 7; +static const unsigned int SAFE_SPACE = 7; // 0-indexed +static const unsigned int EXIT_SPACE = 14; // final space + 1 +static const float ZOOM = 0.5f; +static const float SPRITE_ROWS = 9.f; +static const float SPRITE_COLS = 14.f; +static const float SCR_W = SPRITE_SIZE / ZOOM * SPRITE_COLS / ZOOM; +static const float SCR_H = SPRITE_SIZE / ZOOM * SPRITE_ROWS / ZOOM; +static const int P1_PIECE = 6; +static const int P2_PIECE = 5; +static const int P1_BOARD_TILES[2] = { 0, 1 }; +static const int P2_BOARD_TILES[2] = { 2, 3 }; +static const int STAR_TILE = 4; +static const int BLANK_TILE = 9; +static const int DIE_0 = 8; +static const int DIE_1 = 7; +static const int NUMS_TILES[8] = { 10, 11, 12, 13, 14, 15, 16, 17 }; +static const int ROLL_TILES[2] = { 18, 19 }; + +static const char* TITLE = "Royal Game of Ur"; +static const sf::Color GLOBAL_MASK(255, 0, 255, 255); + +enum GameState +{ + WAITING, + ROLLING, + PLACING, + GAME_OVER +}; + +struct piece_t +{ + int id; + int position; + sf::Sprite sprite; +}; + +struct player_t +{ + int score; + std::shared_ptr> pieces; +}; + +struct dice_t +{ + int value; + bool show; + sf::Sprite sprite; +}; + +std::shared_ptr> +loadTextures(const char* path); + +std::shared_ptr> +createBoard(std::shared_ptr> textures); + +sf::Font +loadFont(); + +std::shared_ptr +createPlayer(sf::Texture& pieceTexture); + +std::shared_ptr +createPiece(int id, sf::Texture& texture); + +std::shared_ptr> +createAllDice(sf::Texture& die0Texture, sf::Texture& die1Texture); + +std::shared_ptr> +createRollSprites(sf::Texture& t1, sf::Texture& t2); + +void +makeNum(sf::Sprite* sprite_ptr, + int num, + std::shared_ptr> textures); + +bool +clickedPiece(sf::Vector2i mousePosition, std::shared_ptr piece); + +bool +canMovePiece(std::shared_ptr piece, + int roll, + std::shared_ptr> myPieces, + std::shared_ptr> enemyPieces); + +std::vector +getLegalMoves(std::shared_ptr activePlayer, + std::shared_ptr opponent); + +sf::Vector2f +pos(float c, float r); +#endif diff --git a/ur.cpp b/ur.cpp index d1f87ed..eb68ad7 100644 --- a/ur.cpp +++ b/ur.cpp @@ -1,4 +1,4 @@ -#include "helper.h" +#include "helper.hpp" #include #include #include -- cgit v1.2.3-54-g00ecf