-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (69 loc) · 2.68 KB
/
Main.java
File metadata and controls
80 lines (69 loc) · 2.68 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Main {
/**
* Use as a general-purpose user-defined exception for when something
* should not be expected but somehow happens anyway.
*/
public static class WhatTheHeckException extends RuntimeException {
public WhatTheHeckException(String message) {
super(message);
}
}
/**
* Initiates the game of Blackjack.
* <p>
* This program follows rules from the <a href="https://en.wikipedia.org/wiki/Blackjack">
* Wikipedia article on Blackjack</a>, especially those that are commonly
* practised.
* <p>
* This program allows a single player to play this game against a dealer.
* Multiple hands may be played at the same time.
*
* @param args some arguments that get ignored anyway
*/
public static void main(String[] args) {
// I have no idea how Blackjack works except that you want a 21
// So here's the Wikipedia article: https://en.wikipedia.org/wiki/Blackjack
// Ask player if they would like to read the rules
Scanner scanner = new Scanner(System.in);
String input;
System.out.print("Would you like to read the rules before playing? (y/N): ");
// Ignore invalid output and move on
if (scanner.hasNextLine()) {
input = scanner.nextLine();
if (input.equalsIgnoreCase("y")) {
// Show rules
System.out.println();
try (BufferedReader br = new BufferedReader(new FileReader("rules.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("\nNow that you know the rules, let's start the game!");
}
}
System.out.println();
// Create a GameDebugger instance
Blackjack.GameDebugger debugger = new Blackjack.GameDebugger();
boolean playAgain;
do {
Blackjack.Game game = new Blackjack.Game(debugger);
game.start();
System.out.print("Would you like to play again? (y/N): ");
// Ignore invalid output and move on
if (scanner.hasNextLine()) {
input = scanner.nextLine();
playAgain = input.equalsIgnoreCase("y");
} else {
playAgain = false;
}
System.out.println();
} while (playAgain);
}
}