-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMain.java
More file actions
96 lines (67 loc) · 3.1 KB
/
GameMain.java
File metadata and controls
96 lines (67 loc) · 3.1 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
package Game;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class GameMain {
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// Creates gameType object to input complex or simple
GameProperties gameType = null;
// Store score
ArrayList<Integer> totalScore = new ArrayList<>();
try {
do {
String dialogue = JOptionPane.showInputDialog(null,
"Choose a game mode: Die roll or RPS?");
switch(dialogue) {
case "die roll":
gameType = new RollDieGame("Single Player");
break;
case "rps":
gameType = new RockPaperScissor("Single Player");
break;
default:
System.out.println("Invalid choice. Exiting..");
System.exit(0);
}
modeType(gameType, scan, totalScore);
} while(replay(scan));
} catch(InputMismatchException e) {
System.out.println("Cannot be a number");
}
// Prints total scores from games played
System.out.println("end game: " + totalScore);
scan.close();
}
public static void modeType(GameProperties gameType, Scanner scan, ArrayList<Integer> totalScore) {
//if(gameType.getGameSelect().equalsIgnoreCase("Die roll")) {
if (gameType instanceof RollDieGame) {
RollDieGame die = new RollDieGame("Welcome to the die game");
// Since we implemented inheritance, RollDieGame class inherits methods from the parent class
System.out.println("\n" + die.toString());
// Calls game method
// die.dieGame();
((RollDieGame) gameType).dieGame();
// Stores user score
totalScore.add(die.getUserScore());
// prints score
System.out.println(totalScore);
} else if(gameType instanceof RockPaperScissor) {
// Calls method from RockPaperScissor class and passing scan object ;
RockPaperScissor rockScissor = new RockPaperScissor("Welcome to the rock, paper, and scissosr game!");
System.out.println("\n" + rockScissor.toString());
((RockPaperScissor) gameType).rockPapScissor();
}
}
static ArrayList<Integer> endScores(RollDieGame die) {
ArrayList<Integer> totalScore = new ArrayList<>();
totalScore.add(die.getUserScore()); // Add user score to totalScore list
totalScore.add(die.getAiScore()); // Add CPU score to totalScore list
return totalScore;
}
public static boolean replay(Scanner scan) {
System.out.println("Play again?");
return scan.nextLine().trim().equalsIgnoreCase("y");
}
}