This repository was archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameDraw.cpp
More file actions
79 lines (67 loc) · 2.34 KB
/
gameDraw.cpp
File metadata and controls
79 lines (67 loc) · 2.34 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
79
//
// Created by alane on 02.01.2018.
//
#include "gameDraw.h"
#include "stdafx.h"
#include "snakeTypes.h"
#include "helpers.h"
#include "map.h"
void setupDraw() {
loeschen();
groesse(BOARD_SIZE, BOARD_SIZE);
formen(const_cast<char *>("s"));
farben(BLACK);
}
void initialSnakeDraw(struct Snake *snakes, int count) {
for (int a = 0; a < count; a++) {
Snake *snake = &snakes[a];
for (int b = 0; b < (*snake).currSize; b++) {
if((*snake).isPlayer) {
int color = a == 0 ? RED : GREEN;
drawSnakePart((*snake).positions[b][0], (*snake).positions[b][1], color);
} else {
drawSnakePart((*snake).positions[b][0], (*snake).positions[b][1], WHITE);
}
}
}
}
void initialDraw(struct Snake *playerSnakes) {
initialSnakeDraw(playerSnakes, gPlayerCount + gEnemyCount);
}
void drawSnakePart(int x, int y, int color) {
farbe2(x, y, color);
}
void drawReward(int x, int y) {
farbe2(x, y, GREEN);
}
void resetField(int x, int y) {
farbe2(x, y, BLACK);
}
int isCollidingWithOtherSnake(struct Snake *tmpSnake, int isPlayer, int snakeIndex) {
int xPos = (*tmpSnake).positions[(*tmpSnake).currSize - 1][0];
int yPos = (*tmpSnake).positions[(*tmpSnake).currSize - 1][1];
for(int a = 0; a < gPlayerCount; a++) {
}
}
SnakeMoveResult moveSnake(struct Snake *tmpSnake, int color, const int currRewardPos[]) {
resetField((*tmpSnake).positions[0][0], (*tmpSnake).positions[0][1]);
int x = (*tmpSnake).positions[(*tmpSnake).currSize - 1][0];
int y = (*tmpSnake).positions[(*tmpSnake).currSize - 1][1];
if ((*tmpSnake).currDirection == RIGHT) x++;
if ((*tmpSnake).currDirection == LEFT) x--;
if ((*tmpSnake).currDirection == UP) y++;
if ((*tmpSnake).currDirection == DOWN) y--;
int gotReward = false;
if (x == currRewardPos[0] && y == currRewardPos[1]) {
gotReward = true;
(*tmpSnake).currSize++;
resetField(currRewardPos[0], currRewardPos[1]);
}
if (!gotReward) deleteFirstObject(tmpSnake);
(*tmpSnake).positions[(*tmpSnake).currSize - 1][0] = x;
(*tmpSnake).positions[(*tmpSnake).currSize - 1][1] = y;
drawSnakePart(x, y, color);
if (x == -1 || x == BOARD_SIZE || y == -1 || y == BOARD_SIZE) return HIT_WALL;
if(gotReward) return GOT_REWARD;
return NOTHING;
}