-
Notifications
You must be signed in to change notification settings - Fork 1
/
Run.java
116 lines (87 loc) · 3.4 KB
/
Run.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
107
108
109
110
111
112
113
114
115
116
import java.util.Scanner;
/**
* The main class of the game.
* This game designed for UNIX bash !.
* (may not work on windows)
*
* @author Mohammad Mahdi Malmasi
* @version 0.1.0
*/
public class Run
{
// for get the players inputs
private static Scanner inputs = new Scanner(System.in);
public static void main(String[] args)
{
// calibrate the font size of the terminal
Printer.calibrate(inputs);
// * required variables *
String holdInput; // hold the input to check that its valid or not
int numberOfPlayers; // the number of the game players
String newPlayerName, newPlayerPass; // get the new player details
// while player choose exit option
while (true)
{
// while player choose valid option
while (true)
{
// show the game menu tho the player and get his/her choice
Printer.printMenu();
holdInput = inputs.nextLine();
// check the player input
if (holdInput.length() == 1 && (holdInput.charAt(0) == '1' || holdInput.charAt(0) == '2'))
break;
else
Printer.inValidInputError(inputs);
}
switch (holdInput)
{
case "1":
// while the plahyer choose a valid int
while (true)
{
// get the player choice
Printer.getNumberOfThePlayers();
holdInput = inputs.nextLine();
// check the player input
if (holdInput.length() == 1 && holdInput.charAt(0) > '0' && holdInput.charAt(0) < '8')
break;
else
Printer.inValidInputError(inputs);
}
// set the number of the players
numberOfPlayers = (int)holdInput.charAt(0) - (int)'0';
// get the players detials
for (int n = 0; n < numberOfPlayers; n++)
{
// get the player name
Printer.getPlayerName(n+1);
newPlayerName = inputs.nextLine();
if (newPlayerName.toLowerCase().equals("bot"))
{
// creat a bot
Rules.addPlayer(new Bot(n));
}
else
{
// get the player password
Printer.getPlayerPass(newPlayerName);
newPlayerPass = inputs.nextLine();
// creat new player
Rules.addPlayer(new Player(newPlayerName, newPlayerPass));
}
}
// get the cards to the players
Rules.preparationGameCards();
Rules.distributeCards();
// run the game
Rules.runGame(inputs);
// reset the game
Rules.reset();
break;
case "2":
return;
}
}
}
}