/
RushHour2.java
106 lines (97 loc) · 2.84 KB
/
RushHour2.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
import java.util.Scanner;
import java.util.Random;
public class RushHour2 {
static Random rd = new Random();
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
int levelChoice = 0;
boolean lock = false;
System.out.println("----------- RUSHHOUR ------------");
// Player Name Input
Player player;
System.out.println(" ==> Entrez votre nom ");
if(!(sc.hasNextLine()))
{
System.out.println("Exiting the game...");
System.exit(1);
}
player = new Player(sc.nextLine());
// Main Menu Input
System.out.println("-------------------- MAIN MENU --------------------");
System.out.println(" I . Pick a specific parking configuration");
System.out.println(" II. Pick a level & let the computer decide the configuration");
System.out.println(" III.Let fate decide !");
int menuChoice=0;
lock = false;
do
{
try{
System.out.println(" ==> Your choice (1, 2 or 3) ");
menuChoice = sc.nextInt();
}catch(Exception e)
{
lock = true;
}
}while(lock);
if(menuChoice > 0 && menuChoice < 3)
{
// Level Input
System.out.println("-------------------- LEVEL MENU --------------------");
System.out.println(" 1. Beginner");
System.out.println(" 2. Intermediate");
System.out.println(" 3. Advanced");
System.out.println(" 4. Expert");
System.out.println(" 5. Grand-Master");
lock = false;
do
{
try{
System.out.println(" ==> Your choice (1, 2, 3, 4 or 5 ) ");
levelChoice = sc.nextInt();
}catch(Exception e)
{
lock = true;
}
}while(lock);
}else
levelChoice = player.randomLevel();
int configChoice = 0, nbConfig = 0;
if(menuChoice == 1)
{
try{
//TODO : ParkingFactory.getNbConfig()
ParkingFactory parkFact = ParkingFactory.getParkingFactory();
nbConfig = parkFact.getNbConfig(levelChoice);
}catch(Exception e)
{
System.out.println("Entree utilisateur illegale detectee.");
System.out.println("Arret du processus...");
System.exit(1);
}
// Configuration Input
System.out.println("-------------------- CONF MENU --------------------");
for(int i = 0; i<nbConfig;i++)
System.out.println("Level " +(i + 1) +(
(player.getScore(levelChoice, i) == -1)? "[]" : "[x]"));
lock = false;
do
{
try{
System.out.println(" ==> Your choice ? ");
configChoice = sc.nextInt();
}catch(Exception e)
{
lock = true;
}
}while(lock);
}else
configChoice = rd.nextInt(nbConfig) + 1;
// Actual game
player.play(levelChoice, configChoice);
// Victory !!
System.out.println("-------------------- VICTORY !! --------------------");
System.out.println(" Score Saved !!");
System.out.println("Bye bye :) !!");
}
}