-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
104 lines (96 loc) · 3.36 KB
/
Client.java
File metadata and controls
104 lines (96 loc) · 3.36 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
/**
* Violet Monserate
* 10/11/2023
* CSE 123
* Section 0 Creative Project: Abstract Strategy Game
* TA: Hawa
*/
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Manages the Tapatan game played between 2 players, displaying and inputting data from terminal.
*/
public class Client
{
/**
* The main function that runs our game of Tapatan.
*
* @param args arguments that are put in during runtime, not used
*/
public static void main(String... args)
{
AbstractStrategyGame tapatan = new Tapatan();
Scanner scanner = new Scanner(System.in);
printMessage(tapatan.instructions());
while (!tapatan.isGameOver())
{
System.out.println(tapatan);
String color = tapatan.getNextPlayer() == 0 ? "BLACK" : "WHITE";
printMessage("It is now " + color + "'s turn");
System.out.println();
tapatan.makeMove(scanner);
}
System.out.println(tapatan);
if (tapatan.getWinner() == -1)
{
printMessage("There is no winner due to 3 move repetition! Oh well");
}
else
{
String color = tapatan.getWinner() == 0 ? "BLACK" : "WHITE";
printMessage(color + " has won... congrats, I guess... fr tho, thanks for playing! <3");
}
scanner.close();
}
/**
* Prints out the message in a fancy border, with wraparound if neccessary. (I need it!
* The default just looks so bad on the screen with the board state printed out)
*
* @param message the message of any length that we want to print to terminal.
*/
public static void printMessage(String message)
{
int lineLength = 37; // Includes the box lines
int margin = 2; // Minimum white space amount + side of box, per side
System.out.println("┌───────────────────────────────────┐");
List<String> lines = new ArrayList<>();
String[] words = message.split(" ");
String currentLine = "";
for (String word : words)
{
String sectionOfLine = word + " ";
if (currentLine.length() + sectionOfLine.length() <= lineLength - (2 * margin))
{
currentLine += sectionOfLine;
}
else
{
lines.add(currentLine.substring(0, currentLine.length() - 1)); // Removes end space
currentLine = sectionOfLine;
}
}
if (currentLine != "")
{
lines.add(currentLine);
}
for (String line : lines)
{
String entireLine = "│";
int leftWhitespace = (lineLength - line.length()) / 2;
for (int i = 1; i < leftWhitespace; i++)
{
entireLine += " ";
}
entireLine += line;
int rightWhitespace = lineLength - leftWhitespace - line.length();
for (int i = 1; i < rightWhitespace; i++)
{
entireLine += " ";
}
entireLine += "│";
System.out.println(entireLine);
}
System.out.println("└───────────────────────────────────┘");
}
}