-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.cpp
45 lines (40 loc) · 991 Bytes
/
field.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
#include "field.hpp"
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
Field::Field(){
for (int i = 0; i<WIDTH; i++){
for (int j = 0; j<HEIGHT; j++){
setBlock(EMPTY, i, j);
}
}
}
void Field::setBlock(Type t, int x, int y){
map_[x][y] = t;
}
Field::Type Field::block(int x, int y) const{
return map_[x][y];
}
void Field::draw() const {
for (int i = 0; i<WIDTH; i++){
for (int j = 0; j<HEIGHT; j++){
glColor3f(0.3, 0.8, 0.8); //color for player 1
switch (map_[i][j]) {
case EMPTY :
break;
case PLAYER1 :
glColor3f(.95, 0.6, 0.4); //color for player 2
case PLAYER2:
glBegin(GL_QUADS);
glVertex2f(i*BLOCK_WIDTH, j*BLOCK_HEIGHT);
glVertex2f((i+1)*BLOCK_WIDTH, j*BLOCK_HEIGHT);
glVertex2f((i+1)*BLOCK_WIDTH, (j+1)*BLOCK_HEIGHT);
glVertex2f(i*BLOCK_WIDTH, (j+1)*BLOCK_HEIGHT);
glEnd();
break;
}
}
}
}