-
Notifications
You must be signed in to change notification settings - Fork 1
/
SeaBattle.java
97 lines (92 loc) · 8.8 KB
/
SeaBattle.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
package seaBattle;
import seaBattle.configuration.Configuration;
import seaBattle.modes.GameMode;
import seaBattle.modes.types.Multiplayer;
import seaBattle.modes.types.Single;
import seaBattle.players.types.UI;
import java.util.InputMismatchException;
/**
* The Java realisation of the game Battleship.
*
* <p>Game going through players in the room. The room may
* contains 2 or more players. If the room includes more
* then 2 players than game going through cyclic. Example:
* We have room with 3 players: A, B, C.
* Games looks so:
* 1. A attacks B
* 2. B attacks C
* 3. C attacks A
* ... again in the same way
* When one of them won't have alive boats he'll lose
* and skipped. Player before them will attack next
* player. Game continues while all players almost one
* will lose.
*
* <p>This game provides two types of player: PC and UI.
* You can choose every player whom it can be.
*
* <p>You can play via the internet. And you can secure
* your room with password. In web mode you can chat
* with all competitors. Just type "chat <message>"
* when coordinates for attack was requested. And in any
* mode you can make your computer play for you, for
* that you should call yourself "PC".
*
* @author T1MON
* @version 1.0
*/
public class SeaBattle {
public static void main(String[] args) {
try {
// Meeting
System.out.println("\n" +
"█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████\n" +
"█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░████░░░░░░░░░░░░░░███░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█\n" +
"█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░████░░▄▀▄▀▄▀▄▀▄▀░░███░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\n" +
"█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░████░░▄▀░░░░░░▄▀░░███░░▄▀░░░░░░▄▀░░█░░░░░░▄▀░░░░░░█░░░░░░▄▀░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█\n" +
"█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░████░░▄▀░░██░░▄▀░░███░░▄▀░░██░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████████\n" +
"█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░████░░▄▀░░░░░░▄▀░░░░█░░▄▀░░░░░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░░░░░░░░░█\n" +
"█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░████░░▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\n" +
"█░░░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░████░░▄▀░░░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░░░░░░░░░█\n" +
"█████████░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░████░░▄▀░░████░░▄▀░░█░░▄▀░░██░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████████\n" +
"█░░░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀░░████░░▄▀░░░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\n" +
"█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░████░░▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\n" +
"█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██░░░░░░████░░░░░░░░░░░░░░░░█░░░░░░██░░░░░░█████░░░░░░█████████░░░░░░█████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\n" +
"█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████");
System.out.println("\n\n Hello, my Dear Friend! Let's play in SEA BATTLE ヽ(*⌒▽⌒*)ノ\n\n" +
">>> How I can call You? (ಠ_ಠ)");
String userName = UI.input.playerName();
UI.print.line();
System.out.println(" Nice to meet You, " + userName + "! (*^‿^*)");
UI.print.line();
// Mode choosing
System.out.println("Please choose mode for game: \n" +
" 0 - Single (Fight with local players)\n" +
" 1 - Multiplayer (Play with gamers around the world)\n" +
">>> Make your choice ヽ(o^―^o)ノ");
int gameMode = UI.input.variant(2, "Game mode");
GameMode game = switch (gameMode) {
case 0 -> new Single();
case 1 -> new Multiplayer();
default -> throw new IllegalStateException("Unknown game mode " + gameMode);
};
// Running
game.play(userName);
// Ended
System.out.println("Is it time to say good bye? (>﹏<)");
try { UI.input.command(); }
catch (InputMismatchException e) { throw new UI.input.CommandException.Exit(); }
// Catches commands from user
} catch (UI.input.CommandException e) {
String[] name = e.getClass().getCanonicalName().split("\\.");
switch (name[name.length - 1]) {
case "Exit" -> System.exit(69);
case "Reset" -> {
UI.print.space();
main(null);
}
default -> e.printStackTrace();
}
}
}
}