-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.cpp
91 lines (81 loc) · 1.36 KB
/
Board.cpp
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
#include <conio.h>
#include <iostream>
#include "Board.h"
#include "Point.h"
#include "Gotoxy.h"
#include <windows.h>
using namespace std;
Board::Board()
{
for (int i = 0; i < MAX_X + 1; i++)
{
for (int j = 0; j < MAX_Y + 1; j++)
{
matrix[i][j] = false;
}
}
for (int i = MIN_Y; i < MAX_Y+1; i++) {
gotoxy(MAX_X+1, i);
cout << '|';
}
for (int i = MIN_X; i < MAX_X+2; i++) {
gotoxy(i, MAX_Y+1);
cout << '-';
}
}
bool Board ::isRowFull(int row) const
{
for (int i = MIN_X; i <= MAX_X; i++)
{
if (!(matrix[i][row]))
return false;
}
return true;
}
void Board::bombRow(int row)
{
for (int i = MIN_X; i <= MAX_X; i++)
{
for (int j = row - 1; j >= MIN_Y; j--)
{
matrix[i][j + 1] = matrix[i][j];
gotoxy(i, j + 1);
if (matrix[i][j + 1])
cout << '*';
else
cout << ' ';
}
}
for (int i = MIN_X; i <= MAX_X; i++)
{
matrix[i][MIN_Y] = false;
gotoxy(i, MIN_Y);
cout << ' ';
}
}
bool Board::setPoint(int x, int y)
{
matrix[x][y] = true;
gotoxy(x, y);
cout << '*';
if (isRowFull(y))
{
bombRow(y);
return true;
}
return false;
}
void Board::unSetPoint(int x, int y)
{
matrix[x][y] = false;
gotoxy(x, y);
cout << ' ';
}
bool Board::getPoint(int x, int y) const
{
if (y > MAX_Y)
{
return true;
}
return matrix[x][y];
}