-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.java
106 lines (91 loc) · 3.4 KB
/
main.java
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
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class main {
static Scanner in = new Scanner(System.in);
public static void saveData() throws FileNotFoundException {
Database.saveAccounts();
Database.saveGames();
}
public static void displayHomePage() throws FileNotFoundException {
int option = -1;
System.out.println("Welcome to IntelliFun Website!\nWhat do you want to do?");
while(!(option <= 3 && option >= 1)) {
System.out.println("1. Login");
System.out.println("2. Sign up");
System.out.println("3. Exit");
option = in.nextInt();
in.nextLine();
if (option == 1) Account.login(in);
else if (option == 2) Account.signup(in);
else if (option == 3) {
saveData();
System.exit(0);
} else
System.out.println("Please choose a valid number.");
}
}
public static void displayPlayGamePage() throws FileNotFoundException {
Database.listGames();
int numOfGames = Database.games.size();
int option = -1;
while(option > numOfGames || option < 1) {
System.out.println("Choose a game to play: ");
option = in.nextInt();
if (option <= numOfGames && option >= 1) {
int s = Game.playGame(Database.games.get(option - 1).name, in);
Game.updateScore(s);
}
else
System.out.println("Please choose a valid number.");
}
}
public static void displayStudentInterface() throws FileNotFoundException {
int option = -1;
while(option != 1 && option != 2) {
System.out.println("1. Play Game");
System.out.println("2. Exit");
option = in.nextInt();
in.nextLine();
if (option == 1)
displayPlayGamePage();
else if (option == 2) {
saveData();
System.exit(0);
}else
System.out.println("Please choose a valid number.");
}
}
public static void displayTeacherInterface() throws IOException {
int option = -1;
while(!(option <= 3 && option >= 1)) {
System.out.println("1. Create a game");
System.out.println("2. Play a game");
System.out.println("3. Exit");
option = in.nextInt();
in.nextLine();
if (option == 1)
Game.createGame(in);
else if (option == 2)
displayPlayGamePage();
else if (option == 3) {
saveData();
System.exit(0);
} else
System.out.println("Please choose a valid option.");
}
}
public static void main(String[] args) throws IOException {
Database.loadAccounts();
Database.loadGames();
displayHomePage();
while (true) {
if (Account.currentAccount.userType.equals("Student")) {
displayStudentInterface();
} else if (Account.currentAccount.userType.equals("Teacher")) {
displayTeacherInterface();
}
System.out.println();
}
}
}