-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement.cpp
71 lines (71 loc) · 1.76 KB
/
movement.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
#include<stdio.h>
#include"movement.h"
#define SIZE 8
void moveDown(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i;
for (i = pos[0] + 1; i<SIZE; i++) {
if (map[i][pos[1]] == elseTurn) map[i][pos[1]] = turn;
else break;
}
}
void moveUp(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i;
for (i = pos[0] - 1; i>-1; i--) {
if (map[i][pos[1]] == elseTurn) map[i][pos[1]] = turn;
else break;
}
}
void moveRight(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i;
for (i = pos[1] + 1; i<SIZE; i++) {
if (map[pos[0]][i] == elseTurn) map[pos[0]][i] = turn;
else break;
}
}
void moveLeft(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i;
for (i = pos[1] - 1; i>-1; i--) {
if (map[pos[0]][i] == elseTurn) map[pos[0]][i] = turn;
else break;
}
}
void moveUpRight(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i, j;
j = pos[1] + 1;
for (i = pos[0] - 1; i>-1; i--) {
if (j >= SIZE)break;
else if (map[i][j] == elseTurn) map[i][j] = turn;
else break;
j++;
}
}
void moveDownLeft(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i, j;
j = pos[1] - 1;
for (i = pos[0] + 1; i<SIZE; i++) {
if (j<0)break;
else if (map[i][j] == elseTurn) map[i][j] = turn;
else break;
j--;
}
}
void moveDownRight(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i, j;
i = pos[0] + 1;
for (j = pos[1] + 1; j<SIZE; j++) {
if (i >= SIZE)break;
else if (map[i][j] == elseTurn) map[i][j] = turn;
else break;
i++;
}
}
void moveUpLeft(char turn, char elseTurn, int pos[2], char map[SIZE][SIZE]) {
int i, j;
i = pos[0] - 1;
for (j = pos[1] - 1; j>-1; j--) {
if (i<0)break;
else if (map[i][j] == elseTurn) map[i][j] = turn;
else break;
i--;
}
}