-
Notifications
You must be signed in to change notification settings - Fork 0
/
opponent.h
61 lines (48 loc) · 1.54 KB
/
opponent.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
#ifndef OPPONENT_H
#define OPPONENT_H
#include <QObject>
#include <QRandomGenerator>
#include "tile.h"
/**
* @brief The Opponent class. Contains the logic for the computer opponent
*/
class Opponent : public QObject
{
public:
/**
* @brief Opponent class. Contains the logic for the computer opponent
* @param parent. parent object
* @param playerArea. list which contains the player Area tiles
* @param gridSize. size of the area
*/
Opponent(QWidget *parent = nullptr,QList<Tile*> *playerArea = nullptr, size_t gridSize = 0);
virtual ~Opponent();
public slots:
/**
* @brief bombATile. bombs a tile on the player area. the computer doesn't cheat
*/
void bombATile();
private:
/**
* @brief The Position struct. contains coordinates
*/
struct Position {
size_t x;
size_t y;
};
/**
* @brief bombRandomPlayerTile. bombs a random player tile
*/
void bombRandomPlayerTile();
/**
* @brief tryToSinkShip. trys to find ship tiles next to ship tiles which were already bombed. this method is not aware of the shapes of the ships
* @param x. x coordinate of the ship tile which was already bombed
* @param y. y coordinate of the ship tile which was already bombed
* @return returns false if all 4 neighboring tiles were already bombed
*/
bool tryToSinkShip(size_t x, size_t y);
QList<Tile*> *m_playerArea;
QList<Position> *m_bombedPlayerShipTiles = new QList<Position>;
size_t m_gridSize;
};
#endif // OPPONENT_H