-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.cpp
More file actions
145 lines (143 loc) · 4.31 KB
/
Copy pathscreen.cpp
File metadata and controls
145 lines (143 loc) · 4.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Project: Screen displays
In this file, the functions will be used to display the Win/Lose/Start screens
and will allow for the transition between these screens and select different game modes.
*/
#include "screen.h"
// Check if the player has touched the screen and if so, determine which mode is selected
void checkTouchMode(){
TSPoint touch = ts.getPoint();
if (touch.z < MINPRESSURE || touch.z > MAXPRESSURE){
return;
}
touchY = map(touch.x, TS_MINX, TS_MAXX, 0, TFT_HEIGHT - 1);
touchX = map(touch.y, TS_MINY, TS_MAXY, TFT_WIDTH - 1, 0);
// Based on where the names are displayed, the first if will select PvP Mode
if (touchX > TFT_WIDTH/2 -90 && touchX < TFT_WIDTH/2 + 90 && touchY > 115 && touchY <155 ){
mode = 0; // Switch to PvP Mode
screenLoop = 0;
}
else if (touchX > TFT_WIDTH/2 -100 && touchX < TFT_WIDTH/2 + 100 && touchY > 175 && touchY < 215 ){
mode = 5; // Switch to Player Vs AI Mode
screenLoop = 0;
}
}
// This will display the Start screen
void startScreen(){
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x8811);
tft.print("ConnectFour");
tft.setCursor(TFT_WIDTH/2 -115,55);
tft.setTextSize(3);
tft.print(" Pick a mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.setTextSize(4);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// Displays the Player vs AI Win/Lose screen
void ScreenAI(){
// Turn == 1 means that the player wins
if (turn == 1){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU WIN");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// Means the AI Won
else if (turn == 2){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU LOSE");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
}
// Displays the Win/Lose Screen for the Player vs Player mode
void Screen(){
// If tieNum == 7 then the board is full and no cains of 4 were obtain so display a tie screen
if (tieNum == 7){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU TIED");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// On Arduino 1 and turn 1, then player 1 wins
else if (turn == 1 && digitalRead(digitalInPin) == HIGH){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU WIN");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// On Arduino 1 and turn 2, then player 1 loses
else if (turn == 2 && digitalRead(digitalInPin) == HIGH){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU LOSE");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// On Arduino 2 and turn 2, then player 2 wins
else if (turn == 2 && digitalRead(digitalInPin) == LOW){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU WIN");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
// On Arduino 2 and turn 1, then player 2 loses
else if (turn == 1 && digitalRead(digitalInPin) == LOW){
tft.fillRect(0, 0, TFT_WIDTH, 16, ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(4);
tft.setTextColor(0x07E0);
tft.print("YOU LOSE");
tft.setCursor(0,50);
tft.print(" Next G-mode");
tft.setCursor(TFT_WIDTH/2 -70,120);
tft.print("P Vs P");
tft.setCursor(TFT_WIDTH/2 - 80,180);
tft.print("P Vs AI");
}
}