-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
123 lines (116 loc) · 8.19 KB
/
Menu.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
117
118
119
120
121
122
123
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import Helper.ConsoleHelper;
/**
* Represents the game launcher
*/
public class Menu {
private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/**
* Ask user to select a menu option
*
* @return int
*/
public int selectOption() {
String input = "";
do {
System.out.print(" What do you wish to do? ");
try {
input = in.readLine();
} catch (java.io.IOException e) {
System.out.println("An error occured : " + e);
}
} while (!Pattern.matches("[0123]", input));
return Integer.valueOf(input);
}
/**
* Show main menu
*
* @return void
*/
public void showMenu() {
ConsoleHelper.eraseConsole();
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(" __..._____--==/___]_|__|_____________________________[___\\==--____,------' .7");
System.out.println("| BB-61/");
System.out.println(" \\_________________________________________________________________________|");
System.out.println();
System.out.println("╔════════════════════════════════════════════════════════════════════════╗");
System.out.println("║ Welcome to BattleShip ║");
System.out.println("╚════════════════════════════════════════════════════════════════════════╝");
System.out.println();
System.out.println(" ╔════════════════╗ ╔══════════════════════╗ ╔═════════════╗");
System.out.println(" ║ 1. Start a game ║ ║ 2. Rules of the game ║ ║ 3. Know more ║");
System.out.println(" ╚════════════════╝ ╚══════════════════════╝ ╚═════════════╝");
System.out.println();
}
/**
* Show game rules
*
* @return void
*/
public void showRules() {
ConsoleHelper.eraseConsole();
System.out.println();
System.out.println("╔══════════════════════════════════════════════════════════════════════════════╗");
System.out.println("║ Naval Battle : Rules ║");
System.out.println("╚══════════════════════════════════════════════════════════════════════════════╝");
System.out.println();
System.out.println(" You will face an opponent in a fierce naval battle with your fleet of warships.");
System.out.println();
System.out.println(" Both will have a fleet consisting of "+ Config.getNbBoats() + " battleships :");
for (int i = 0; i < Config.getBoatsConfig().length; i++) {
String plural = Integer.valueOf(Config.getBoatsConfig()[i][2]) > 1 ? "s" : "";
System.out.println(" - 1 " + Config.getBoatsConfig()[i][1] + " (" + Config.getBoatsConfig()[i][2] + " case" + plural + ")");
}
System.out.println();
System.out.println(" Your objective is simple: destroy your opponent's fleet as quickly as possible, before the latter destroys yours.");
System.out.println(" However, your adversary is using a latest-generation camouflage technique that makes it impossible for his ships to be detected on your radar.");
System.out.println(" So you have to be strategic to avoid wasting torpedoes and missiles!");
System.out.println(" You have 100 torpedoes and missiles that you can fire towards your opponent.");
System.out.println();
System.out.println(" Prepare your strategy and play as a maritime fleet captain now!");
System.out.println();
System.out.println(" ╔══════════════════════╗ ╔════════════════╗ ╔══════════════════════╗ ╔═════════════╗");
System.out.println(" ║ 0. Return to menu ║ ║ 1. Start a game ║ ║ 2. Rules of the game ║ ║ 3. Know more ║");
System.out.println(" ╚══════════════════════╝ ╚════════════════╝ ╚══════════════════════╝ ╚═════════════╝");
System.out.println();
System.out.println();
}
/**
* About this game
*
* @return void
*/
public void showAbout() {
ConsoleHelper.eraseConsole();
System.out.println();
System.out.println("╔═══════════════════════════════════════════════════════╗");
System.out.println("║ About This Game ║");
System.out.println("╚═══════════════════════════════════════════════════════╝");
System.out.println();
System.out.println(" This game is an improved version of my previous Battleship game.");
System.out.println();
System.out.println(" --------------- How to play? ---------------");
System.out.println();
System.out.println(" To play the game, run the main functino of 'Main' class");
System.out.println(" The game is played entirely on console.");
System.out.println(" It is possible to modify the number of boats of each player as well as their properties by editing the configuration file ");
System.out.println();
System.out.println(" ╔══════════════════════╗ ╔════════════════╗ ╔══════════════════════╗ ╔═════════════╗");
System.out.println(" ║ 0. Return to menu ║ ║ 1. Start a game ║ ║ 2. Rules of the game ║ ║ 3. Know more ║");
System.out.println(" ╚══════════════════════╝ ╚════════════════╝ ╚══════════════════════╝ ╚═════════════╝");
System.out.println();
}
}