-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.java
More file actions
158 lines (128 loc) · 7.6 KB
/
Copy pathmain.java
File metadata and controls
158 lines (128 loc) · 7.6 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
import java.util.ArrayList;
import java.util.List;
public class main {
// public class WelcomeUno {
// ANSI colors
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String WHITE = "\u001B[37m";
public String reset = "\u001B[0m";
public static void showWelcome() {
System.out.println(" ╔════════════════════════════════════════════╗");
System.out.println(" ║ ║");
System.out.println(" ║ ██ ██ ██ ██ ██████ ║");
System.out.println(" ║ ██ ██ ████ ██ ██ ██ ║");
System.out.println(" ║ ██ ██ ██ ██ ██ ██ ██ ║");
System.out.println(" ║ ██ ██ ██ ██ ██ ██ ██ ║");
System.out.println(" ║ ██████ ██ ████ ██████ ║");
System.out.println(" ║ ║");
System.out.println(" ║ ║");
System.out.println(" ║ " + RED + " W E L C O M E" + BLUE + " T O " + WHITE
+ " ║");
System.out.println(
" ║ " + GREEN + " T H E G A M E" + WHITE + " ║");
System.out.println(" ║ ║");
System.out.println(" " + WHITE + "║" + " " + RED + "■■" + GREEN + "■■" + YELLOW + "■■"
+ BLUE + "■■" + YELLOW + " LET'S PLAY! " +
BLUE + "■■" + YELLOW + "■■" + GREEN + "■■" + RED + "■■" + WHITE + " ║");
System.out.println(" ║ ║");
System.out.println(" ╚════════════════════════════════════════════╝" + RESET);
}
public static void main(String[] args) {
List<String> players = new ArrayList<>();
showWelcome();
// menu switch
// System.out.println(" WELCOME TO THE UNO CARD CONSOLE GAME!");
System.out.print(
" ========== MENU =========== \n 1.Multiplayer\n 2.Singleplayer\n Choose an option: ");
int option;
java.util.Scanner scanner = new java.util.Scanner(System.in);
option = scanner.nextInt();
switch (option) {
case 1:
System.out.println(" Multiplayer mode selected.");
System.out.println(" How many players ? ");
int numPlayers = scanner.nextInt();
for (int i = 1; i <= numPlayers; i++) {
System.out.print(" Enter name for Player " + i + ": ");
String playerName = scanner.next();
players.add(playerName);
}
gameManagement game = new gameManagement(players);
// n7ato la 1ere carte f discard pile (not wild)
card firstCard;
do {
firstCard = game.getDeck().drawplus(1);
if (firstCard instanceof nonregular &&
(((nonregular) firstCard).gettype() == type.wild ||
((nonregular) firstCard).gettype() == type.wild_4_plus)) {
// put wild card back to the drawpile
game.getDeck().addtodraw(firstCard);
}
} while (firstCard instanceof nonregular &&
(((nonregular) firstCard).gettype() == type.wild ||
((nonregular) firstCard).gettype() == type.wild_4_plus));
//first card after verification ofc
game.getDeck().addtodiscard(firstCard);
System.out.println(" First card on discard:");
firstCard.logo();
// Game loop where players take turns w kda
while (!game.isGameOver()) {
player current = game.getCurrentPlayer();
System.out.println("\n --- " + current.getName() + "'s turn ---");
// show top discard
card topDiscard = game.getTopDiscard();
System.out.println(" Top discard:");
topDiscard.logo();
// hna on controle le tour pour chaque joueur
card playedCard = current.showcards(game.getDeck());
if (playedCard != null) {
game.applyEffect(playedCard);
}
game.nextPlayer();
}
game.announceWinner();
break;
case 2:
System.out.println(" Singleplayer mode selected.");
gameManagement game2 = new gameManagement();
// n7ato la 1ere carte f discard pile (not wild)
card firstCard2;
do {
firstCard2 = game2.getDeck().drawplus(1);
if (firstCard2 instanceof nonregular &&
(((nonregular) firstCard2).gettype() == type.wild ||
((nonregular) firstCard2).gettype() == type.wild_4_plus)) {
// put wild card back to the drawpile
game2.getDeck().addtodraw(firstCard2);
}
} while (firstCard2 instanceof nonregular &&
(((nonregular) firstCard2).gettype() == type.wild ||
((nonregular) firstCard2).gettype() == type.wild_4_plus));
//hna n7to la carte mor la verification :3
game2.getDeck().addtodiscard(firstCard2);
System.out.println(" First card on discard:");
firstCard2.logo();
// Game loop where players take turns w kda
while (!game2.isGameOver()) {
player current = game2.getCurrentPlayer();
System.out.println("\n --- " + current.getName() + "'s turn ---");
// Show top discard
card topDiscard2 = game2.getTopDiscard();
System.out.println(" Top discard:");
topDiscard2.logo();
// hna on controle le tour pour chaque joueur
card playedCard2 = current.showcards(game2.getDeck());
if (playedCard2 != null) {
game2.applyEffect(playedCard2);
}
game2.nextPlayer();
}
game2.announceWinner();
break;
}
}
}// ya khawti rni khaletha, zdt bzaf 3fays hhhhhh mais mzal ma drt bot