-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardTextView.cpp
More file actions
78 lines (67 loc) · 2 KB
/
BoardTextView.cpp
File metadata and controls
78 lines (67 loc) · 2 KB
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
//
// Created by pmi03 on 01.05.2023.
//
#include "BoardTextView.h"
#include <iostream>
#include <ctime>
BoardTextView::BoardTextView(int Width, int Height) {
srand(time(NULL));
width = Width;
height = Height;
board.resize(board.size() + width*height);
// oznaczenie pozycji jabłka na planszy
// int x = rand() % (width-2)+1;
// int y = rand() % (height-2)+1;
// board[x + y * width] = 2;
}
void BoardTextView :: debug_display() const{
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (board[y * width + x] == 0) {
if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
cout << " W "; // pole na granicy planszy
} else {
cout << " "; // puste pole
}
} else if (board[y * width + x] == 1) {
cout << " 1 "; // pozycja węża
} else if (board[y * width + x] == 2) {
cout << " O "; // pozycja jedzenia
} else if (board[y * width + x] == 4) {
cout << " 1 ";
}
}
cout << endl;
}
}
int BoardTextView :: getBoardWidth() const
{
return width;
}
int BoardTextView :: getBoardHeight() const
{
return height;
}
char BoardTextView ::getFieldInfo(int x, int y) const{
int width=getBoardWidth();
int height=getBoardHeight();
if (board[y * width + x] == 1) { // wąż
return 'S';
} else if (board[y * width + x] == 2) { // jabłko
return 'A';
} else if (board[y * width + x] == 4) { // Wąż na polu z jablkiem
return 'S';
} else if (x == 0 || x == width - 1 || y == 0 || y == height - 1) { // ściana
return '#';
} else { // puste pole
return ' ';
}
}
void BoardTextView ::display() {
for (int i = 0; i < getBoardHeight(); i++) {
for (int j = 0; j < getBoardWidth(); j++) {
cout << " " << getFieldInfo(j, i) << " ";
}
cout << endl;
}
}