-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
67 lines (55 loc) · 1.58 KB
/
game.c
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
/**
* @file game.c
* @authors Adam Ross
* @date 12 Oct 2016
* @brief C program for an interactive memory game between microcontrollers - main
*/
#include "system.h"
#include "led.h"
#include "ir_uart.h"
#include "pacer.h"
#include "navswitch.h"
#include "tinygl.h"
#include "disp.h"
#include "play.h"
#include <stdbool.h>
#define PACER_RATE 300
#define SENDER '$'
#define RECEIVER 'R'
#define NO_PLAY 'V'
int main ( void ) {
system_init ();
ir_uart_init ();
navswitch_init ();
pacer_init ( PACER_RATE );
displayInit ( PACER_RATE );
led_init ();
///Boolean initialisers for whether the game is won and for confirmed receptions of infra-red transmitted data
bool gameWon = false, parametersTransmitted = false;
///Char initialiser for game-play turn
char play = NO_PLAY;
while ( 1 ) {
pacer_wait ();
tinygl_update ();
navswitch_update ();
while ( !gameWon ) {
pacer_wait ();
tinygl_update ();
if ( play == RECEIVER ) {
if ( !parametersTransmitted ) {
setGameParameters ( ¶metersTransmitted );
}
if ( parametersTransmitted ) {
playerTurnReceiver ( &gameWon, ¶metersTransmitted, &play );
}
}
if ( play == SENDER ) {
playerTurnSender ( ¶metersTransmitted, &play );
}
if ( play == NO_PLAY ) {
gameStart ( &play, PACER_RATE );
}
}
gameWin ( &gameWon, &play );
}
}