-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellBox.h
123 lines (101 loc) · 3.53 KB
/
CellBox.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//------------------------------------------------------------
// CellBox.h
// Cellウィジェットの定義
//------------------------------------------------------------
#ifndef CELLBOX_H_INCLUDE
#define CELLBOX_H_INCLUDE
#include <FL/Fl_Box.H>
#include <utility>
//============================================================
// CellState
// セルの状態
//============================================================
enum CellState {
CELL_CLOSE, // セルが閉じている
CELL_OPEN, // セルが開いている
CELL_FLAG, // セルが閉じていて,旗が立っている
CELL_TMPOPEN // 一時的にセルが開いている
};
//============================================================
// MouseButton
// マウスのボタン
//============================================================
enum MouseButton {
MOUSE_NONE, // ボタンが押されていない
MOUSE_LEFT, // マウスの左ボタン
MOUSE_RIGHT, // マウスの右ボタン
};
//============================================================
// Position
// セルの座標
//============================================================
typedef std::pair<int,int> Position;
//============================================================
// CellBox
// セルのWidget
//============================================================
class CellBox : public Fl_Box
{
private:
CellState state; // セルの状態
Position pos; // セルの座標
int value; // セル周囲の地雷数
bool is_mine; // 地雷かどうか
static bool is_down; // マウスボタンが押されている
public:
//----------------------------------------
// セルの大きさ
//----------------------------------------
static const int cell_size;
//----------------------------------------
// コンストラクタ
// x, y : Window上でのセルのピクセル座標
// pos : セルの盤面座標
//----------------------------------------
CellBox(int x, int y, const Position &pos);
//----------------------------------------
// セルの状態をリセットする
//----------------------------------------
void reset();
//----------------------------------------
// セルの状態を変更する
// st : 新しい状態
//----------------------------------------
void set_state(CellState st);
//----------------------------------------
// イベントハンドラ
// ev : イベントの内容
//----------------------------------------
int handle(int ev);
//----------------------------------------
// セルの地雷数を増やす
//----------------------------------------
void incr_value();
//----------------------------------------
// セルを地雷に設定する
//----------------------------------------
void set_mine();
//----------------------------------------
// セルの状態を取得
//----------------------------------------
CellState get_state() const;
//----------------------------------------
// セルの盤面座標を取得
//----------------------------------------
Position get_pos() const;
//----------------------------------------
// セルの地雷数を取得
//----------------------------------------
int get_value() const;
//----------------------------------------
// セルは地雷かどうかを取得
//----------------------------------------
bool get_is_mine() const;
//----------------------------------------
// マウスが押されているか
//----------------------------------------
static bool get_is_down();
private:
void set_state_open();
};
#endif // CELLBOX_H_INCLUDE