-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.java
More file actions
196 lines (182 loc) Β· 8.43 KB
/
Copy pathMainMenu.java
File metadata and controls
196 lines (182 loc) Β· 8.43 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
Name: Chelsea Wong & Annie Wong
Teacher: Ms. Basaraba
Date: January 18th, 2022
Description: This program draws the MainMenu screen for our Crossword game.
This screen is where the user navigates between options to go
to other parts/screens of the game. From here, the user can go
to the instructions screen, play the game, leaderboard screen,
and exit screen.
ISP: Crossword
*/
import java.awt.*; //gives access to java graphic related commands (ie. fonts and colors)
import hsa.*; //gives access to hsa commands
import java.io.*; //gives access to the input output commands
public class MainMenu //displays screen where the user navigates between options to go to the instructions, game, leaderboard, and exit
{
Console c; //declaration of instance variable of the Console class; the output console
char status; //character variable to store the current status
// imports the font files
public void loadFonts() throws java.awt.FontFormatException, java.io.IOException {
Font.createFont(Font.TRUETYPE_FONT, (InputStream) new FileInputStream("Fonts\\Montserrat-Regular.ttf"));
Font.createFont(Font.TRUETYPE_FONT, (InputStream) new FileInputStream("Fonts\\Montserrat-Bold.ttf"));
Font.createFont(Font.TRUETYPE_FONT, (InputStream) new FileInputStream("Fonts\\Montserrat-Italic.ttf"));
Font.createFont(Font.TRUETYPE_FONT, (InputStream) new FileInputStream("Fonts\\Montserrat-BoldItalic.ttf"));
}
// declaration of font constants [variables are in full uppercase since they are constants are do not change throughout the program]
final Font TITLE = new Font ("Montserrat Bold", Font.PLAIN, 48); // font for title text for this screen
final Font BODY = new Font ("Montserrat Regular", Font.PLAIN, 30); // font for body text for this screen
final Font SMALL = new Font ("Montserrat Regular", Font.PLAIN, 12); // font for small text for this screen
// declaration of color constants [variables are in full uppercase since they are constants are do not change throughout the program]
final Color LPURPLE = new Color(232,231,252);
final Color MPURPLE = new Color(138, 138, 223);
final Color DPURPLE = new Color(87,88,208);
final Color WHITE = new Color(255,255,255);
final Color PWHITE = new Color(246, 245, 254);
public MainMenu (Console con) throws java.awt.FontFormatException, java.io.IOException{ //constructor for the class MainMenu
c = con; //to use the Console object passed as a parameter when creating an instance of this class
status = 'i';
loadFonts();
}
//methods to draw the brackets and options so it is easier when recoloring and covering when navigating between options
public void arrowI(){
c.drawString("<", 257, 428);
c.drawString(">", 465, 428);
}
public void arrowP(){
c.drawString("<", 315, 464);
c.drawString(">", 406, 464);
}
public void arrowL(){
c.drawString("<", 255, 500);
c.drawString(">", 467, 500);
}
public void arrowE(){
c.drawString("<", 318, 535);
c.drawString(">", 402, 535);
}
public void textI(){
c.drawString("instructions", 280, 428);
}
public void textP(){
c.drawString("play", 338, 463);
}
public void textL(){
c.drawString("leaderboard", 278, 499);
}
public void textE(){
c.drawString("exit", 341, 534);
}
public void mainMenu (){
c.clear();
//drawing the background [used across all screens]
c.setColor(DPURPLE);
c.fillRoundRect(50,50,632,572,20,20);
c.setColor(LPURPLE);
c.fillRoundRect(54,54,624,564,16,16);
//the title
c.setColor(PWHITE);
c.fillRoundRect(222,362,292,25,2,2); //the highlight/underline for the title
c.setColor(DPURPLE);
c.setFont(TITLE);
c.drawString("word cross", 230, 375);
//the options
c.setFont(BODY);
c.setColor(MPURPLE);
c.drawString("instructions", 280, 428);
c.drawString("play", 338, 463);
c.drawString("leaderboard", 278, 499);
c.drawString("exit", 341, 534);
//instructions on keys
c.setFont(SMALL);
c.setColor(DPURPLE);
c.drawString("press [<] and [>] to navigate between the options, then press [enter] to select", 139, 591);
c.setFont(BODY);
while(true){
if(status == 'i'){ //if status at instructions
c.setColor(LPURPLE);
arrowP(); //cover p
arrowE(); //cover e
c.setColor(MPURPLE);
textP(); //lighten p
textE(); //lighten e
c.setColor(DPURPLE);
arrowI(); //draw i
textI(); //darken i
}
else if(status == 'p'){ //if status at play
c.setColor(LPURPLE);
arrowI(); //cover i
arrowL(); //cover l
c.setColor(MPURPLE);
textI(); //lighten i
textL(); //lighten l
c.setColor(DPURPLE);
arrowP(); //draw p
textP(); //darken p
}
else if(status == 'l'){ //if status at leaderboard
c.setColor(LPURPLE);
arrowP(); //cover p
arrowE(); //cover e
c.setColor(MPURPLE);
textP(); //lighten p
textE(); //lighten e
c.setColor(DPURPLE);
arrowL(); //draw l
textL(); //darken l
}
else if(status == 'e'){ //if status at exit
c.setColor(LPURPLE);
arrowI(); //cover i
arrowL(); //cover l
c.setColor(MPURPLE);
textI(); //lighten i
textL(); //lighten l
c.setColor(DPURPLE);
arrowE(); //draw e
textE(); //darken e
}
int input = c.getChar(); //user input key, gets keycode as integer
if(input == 10){ //if enter is pressed
break;
}
else if (input == 60 || input == 62){ //if either the [<] or [>] is pressed
if(status == 'i' && input == 60){ //if status is currently at instructions, and [<] is pressed, move status to exit
status = 'e';
continue;
}
if(status == 'i' && input == 62){ //if status is currently at instructions, and [>] is pressed, move status to play
status = 'p';
continue;
}
if(status == 'p' && input == 60){ //if status is currently at play, and [<] is pressed, move status to instructions
status = 'i';
continue;
}
if(status == 'p' && input == 62){ //if status is currently at play, and [>] is pressed, move status to leaderboard
status = 'l';
continue;
}
if(status == 'l' && input == 60){ //if status is currently at leaderboard, and [<] is pressed, move status to play
status = 'p';
continue;
}
if(status == 'l' && input == 62){ //if status is currently at leaderboard, and [>] is pressed, move status to exit
status = 'e';
continue;
}
if(status == 'e' && input == 60){ //if status is currently at exit, and [<] is pressed, move status to leaderboard
status = 'l';
continue;
}
if(status == 'e' && input == 62){ //if status is currently at exit, and [>] is pressed, move status to instructions
status = 'i';
continue;
}
} else {
new Message ("Invalid input. Please only use [<] and [>] to navigate between options and [enter] to select the option.");
}
}
}
} // MainMenu class