-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
196 lines (173 loc) · 8.82 KB
/
Main.java
File metadata and controls
196 lines (173 loc) · 8.82 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import java.util.Scanner;
import java.util.Random;
// set PATH=%PATH%;C:\Program Files\Java\jdk-22\bin
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random rand = new Random();
Player player = new Player("Anon"); // default username
while (true) {
displayWelcomeScreen();
if ((sc.nextLine()).compareToIgnoreCase("n") == 0) {
System.out.println("Thanks for visiting. Goodbye!");
break; // Exit
}
startGame(sc, rand, player);
}
}
public static void displayWelcomeScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
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(" )\\ ) )\\ )\\))( ( | / ");
System.out.println("(()/( ((((_)( ((_)()\\ )\\ | / ");
System.out.println(" /(_))_)\\ _ )\\(_()((_|(_) |/ ");
System.out.println("(_)) __(_)_\\(_) \\/ | __|( ");
System.out.println(" | (_ |/ _ \\ | |\\/| | _| )\\ ");
System.out.println(" \\___/_/ \\_\\|_| |_|___((_) ");
System.out.println(" By: RKGO");
System.out.print("\nStart Game? (y/n): ");
}
public static void startGame(Scanner sc, Random rand, Player player) {
String tempBuffer = "";
int numCards = 0;
int cost = 0;
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.printf("\n%d Coins Level %d Exp %d Username: %s\n\n",
player.getCoins(), player.getLevel(), player.getExp(), player.getUsername());
System.out.println(" [ X ] ____ [ ? ]");
System.out.println(" ( | /");
System.out.println(" ( )\\ ( ( ( | / ");
System.out.println(" )((_))\\ ( )\\))( ( | / ");
System.out.println(" ((_)_((_) )\\ ) ((_))\\ )\\ |/ ");
System.out.println(" | _ )(_) _(_/( (()(_)((_) ( ");
System.out.println(" | _ \\| || ' \\))/ _` |/ _ \\ )\\ ");
System.out.println(" |___/|_||_||_| \\__, |\\___/((_) ");
System.out.println(" |___/ \n\n");
System.out.println("[1] 1 Card [2] 2 Cards [3] 4 Cards [4] New Username");
System.out.println(" 10 Coins 20 Coins 40 Coins");
System.out.println(" Hard Normal Easy");
System.out.print("\nBingo: ");
tempBuffer = sc.nextLine();
if(tempBuffer.compareToIgnoreCase("X") == 0) return;
else if(tempBuffer.compareToIgnoreCase("?") == 0) {
howToPlay(); sc.nextLine(); return;
}
else if (!tempBuffer.matches("\\d+")) { //is not an integer
System.out.print("Invalid input.\nPress Enter to try again...");
sc.nextLine();
return;
}
numCards = Integer.parseInt(tempBuffer);
if (numCards <= 0 || numCards > 4) {
System.out.print("Invalid input.\nPress Enter to try again...");
sc.nextLine();
return;
}
switch (numCards) {
case 1: cost = 10; numCards = 1; break;
case 2: cost = 20; numCards = 2; break;
case 3: cost = 40; numCards = 4; break;
case 4:
System.out.print("New username: ");
player.setUsername(sc.nextLine());
return;
}
if (player.getCoins() < cost) {
System.out.print("Coins not enough.\nPress Enter to try again...");
sc.nextLine();
return;
}
player.deductCoins(cost);
BingoCard[] cards = new BingoCard[numCards];
for (int i = 0; i < numCards; i++) {
cards[i] = new BingoCard();
generateCard(cards[i], rand);
}
WinningPattern patterns = new WinningPattern();
Game game = new Game(cards, patterns, rand, sc);
int score = game.play();
player.reward(50, score); // 50 = EXP increase per game
}
public static void howToPlay() {
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("\n\n");
System.out.println(" ) ( ____");
System.out.println(" ( /( ) )\\ ) ( | /");
System.out.println(" )\\()) ( ( ( /( (()/( )\\ ) ( | / ");
System.out.println("((_\\ ( )\\))( )\\())( /(_)|(_| /( )\\ ) | / ");
System.out.println(" _((_) )\\((_)() (_))/ )\\ (_)) _ )(_)|()/( |/ ");
System.out.println("| || |((_)(()((_) | |_ ((_) | _ \\| ((_)_ )(_))( ");
System.out.println("| __ / _ \\ V V / | _/ _ \\ | _/| / _` | || |)\\ ");
System.out.println("|_||_\\___/\\_/\\_/ \\__\\___/ |_| |_\\__,_|\\_, ((_) ");
System.out.println(" |__/ ");
System.out.println("I. OBJECTIVE");
System.out.println(" - The goal is to match numbers on your Bingo card with the numbers drawn.");
System.out.println(" - Complete patterns such as rows, columns, diagonals, or corners for points.\n");
System.out.println("II. GAME SETUP");
System.out.println(" - Choose the number of Bingo cards to play with (1, 2, or 4).");
System.out.println(" - Each card costs coins (10 for 1 card, 20 for 2 cards, 40 for 4 cards).");
System.out.println(" - You start with 100 coins. Manage them wisely!\n");
System.out.println("III. GAMEPLAY");
System.out.println(" - Numbers between 1 and 75 are drawn randomly every 3 seconds.");
System.out.println(" - Each number corresponds to a letter on the card (B, I, N, G, O).");
System.out.println(" - Your card will automatically mark the drawn numbers.\n");
System.out.println("IV. WINNING PATTERNS");
System.out.println(" - Horizontal Rows: Complete a full row (10-14 points).");
System.out.println(" - Vertical Columns: Complete a full column (15-19 points).");
System.out.println(" - Diagonals: Complete a diagonal line (20-25 points).");
System.out.println(" - Four Corners: Mark all four corners of the card (30 points).\n");
System.out.println("V. REWARDS");
System.out.println(" - Earn 5 coins and 50 EXP for each game.");
System.out.println(" - Level up by gaining 100 EXP.\n");
System.out.println("VI. TIPS");
System.out.println(" - Enter 'X' anytime during the game to exit *before* purchasing a card.");
System.out.println(" - Once you purchase a card, you must play through the end of the drawing limit.");
System.out.println(" - Invalid inputs will be rejected, so enter valid options.\n");
System.out.print("Press Enter to return to the welcome screen...");
}
// Helper methods
private static void generateCard(BingoCard card, Random rand) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
card.card[i][j] = rand.nextInt(15) + 1 + (j * 15);
}
}
card.card[2][2] = -1;
}
public static void printBingoCards(BingoCard[] cards) {
System.out.println();
for (int z = 0; z < cards.length; z++) {
System.out.printf("Card %d:%11s", (z + 1), "");
}
System.out.println();
for (int z = 0; z < cards.length; z++) {
System.out.print(" B I N G O ");
}
System.out.println();
for (int i = 0; i < 5; i++) {
for (int k = 0; k < cards.length; k++) {
for (int j = 0; j < 5; j++) {
if ((cards[k].card[i][j] == -1) || (i == 2 && j == 2)) { // Free space
System.out.print(" X ");
} else {
System.out.printf("%2d ", cards[k].card[i][j]);
}
}
System.out.print(" ");
}
System.out.println();
}
System.out.println();
}
}