-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.h
65 lines (59 loc) · 1.75 KB
/
Pawn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Board.h"
using namespace std;
class Tile;
class Team;
class Pawn
{
int id{};
bool isAtBase;
bool isAtTarget;
bool isTargetVisible = false;
bool isPossibleVisible = false;
Team* team;
Tile* currentTile;
sf::Texture texture;
sf::Sprite sprite;
sf::Texture targetTexture;
sf::Sprite target;
sf::Texture possibleTexture;
sf::Sprite possible;
public:
Pawn() = delete;
Pawn(int id, Team* team, Tile* currentTile);
void draw(Tile* tile, sf::RenderWindow* window);
bool handleClick(int dice, sf::RenderWindow* window, Board* board);
void handleMouseOver(int dice, sf::RenderWindow* window, Board* board);
void setTeam(Team* team);
void setAtBase(sf::RenderWindow* window, Board* board);
void setIsAtBase(bool isAtBase);
void setIsTargetVisible(bool isTargetVisible);
bool setIsPossibleVisible(int currentTeamId, int dice, sf::RenderWindow* window, Board* board);
bool canMove(int dice, Board* board);
int getId() const;
Team* getTeam();
Tile* getCurrentTile();
Tile* getDesiredTile(int dice, Board* board);
int getDistanceFromStart(Board* board);
bool getIsAtBase() const;
bool getIsAtTarget() const;
bool canMoveFurther(int tiles, Board* board);
inline bool isClicked(sf::Event event) const {
return this->sprite
.getGlobalBounds()
.contains(sf::Vector2f(event.mouseButton.x, event.mouseButton.y));
}
inline bool isMouseOver(sf::Event event) const {
return this->sprite
.getGlobalBounds()
.contains(sf::Vector2f(event.mouseMove.x, event.mouseMove.y));
}
private:
void initSprite();
bool move(Tile* tile, sf::RenderWindow* window, Board* board);
bool deploy(int dice, sf::RenderWindow* window, Board* board);
int getNextTileId(int currentId);
void checkIsAtTarget();
};