blob: 37523d88c0e9872fd1f4f810bcbdc9bdad11443b (
plain) (
blame)
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
|
#include <ncurses.h>
#include <stdlib.h>
#include "input.h"
#include "board.h"
#define POSITION board[cursorPosX][cursorPosY]
char hand = ' ';
int turnPart = 1;
int turns = 0;
enum piece {
WHITE,
BLACK,
BOARD,
};
enum piece CheckPiece(int hand) {
if (hand >= 'A' && hand <= 'Z' ) {
return WHITE;
}
else if (hand >= 'a' && hand <= 'z' ) {
return BLACK;
}
else {
return BOARD;
}
}
void HandleInput(char board[8][8]) {
if ( hand == ' ' && POSITION != ' '){
hand = POSITION;
POSITION = ' ';
turnPart++;
}
/* Simply doing nothing with these felonius inputs */
else if ( CheckPiece(hand) == CheckPiece(POSITION) ) {}
else if ( hand == ' ' && POSITION == ' ' ) {}
else if ( hand != POSITION) {
board[cursorPosX][cursorPosY] = hand;
hand = ' ';
turnPart++;
}
else if ( hand != ' ' && POSITION == ' ') {
board[cursorPosX][cursorPosY] = hand;
hand = ' ';
turnPart++;
}
if (turnPart > 1 && turnPart & 1) turns++;
}
int InputBoard(char board[8][8], int keypress) {
/* Handle key input */
switch (keypress) {
case 'q':
endwin();
exit(0);
break;
case 'h':
hand = CheckPiece(hand);
break;
case 'p':
POSITION = CheckPiece(POSITION);
break;
case KEY_UP:
if (cursorPosX > 0) cursorPosX--;
break;
case KEY_DOWN:
if (cursorPosX < 7) cursorPosX++;
break;
case KEY_LEFT:
if (cursorPosY > 0 ) cursorPosY--;
break;
case KEY_RIGHT:
if (cursorPosY < 7) cursorPosY++;
break;
case '\n': /* This is the ENTER key. KEY_ENTER does not work */
HandleInput(board);
break;
}
return 0;
}
|