-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextView.java
More file actions
152 lines (137 loc) · 7.45 KB
/
TextView.java
File metadata and controls
152 lines (137 loc) · 7.45 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
import java.util.Scanner;
/**
@author John Henry Cooper
@version 15.0.2
Provides a text based interface to players of the game
has:
-5 member feilds: fromRow, fromColumn, toRow, toColumn, and action
that represents aspects of the game and board
-getters for all member feilds
*/
public class TextView {
protected int fromRow, fromColumn, toRow, toColumn;
protected char action;
public char getAction() {
return action;
}
public int getFromColumn() {
return fromColumn;
}
public int getFromRow() {
return fromRow;
}
public int getToColumn() {
return toColumn;
}
public int getToRow() {
return toRow;
}
/**
* Asks the user to enter an integer repeatedly until their entry falls between min and max
* @param min minimum
* @param max maximum
* @param scr a scanner
* @return the first valid value the user enters
*/
public static int getValidInt( int min, int max, Scanner scr){
boolean flag=true;
int intValue = max + 1;
System.out.println("Enter an integer between " + min + " and " + max + ":");
while(flag){
if (scr.hasNextInt()){
intValue = scr.nextInt();
if (intValue>=min && intValue<=max) {
flag = false;
}
else {
System.out.println("Invalid Entry. Please enter an integer between " + min + " and " + max + ":" );
}
}
else {
System.out.println("Invalid Entry. Please enter an integer between " + min + " and " + max + ":" );
scr.next();
}
}
return intValue;
}
/**
* Prompts the user to enter a valid action type (A for Attack,M for Move,R for Recruit, T for ThrowSpear, or S for Spawn)
* @param scr the scanner that gets the user input
* @return nextAction returns character A,M,R,T, or S once the user inputs one of these values
*/
public static char getUsersNextActionType(Scanner scr){
char nextAction = 'F';
boolean flag = true;
System.out.println("Type A to attack, M to move, R to recruit, T to Throw Spear, or S to spawn");// New Action Modification
while (flag){
char userInput = scr.next().charAt(0);
userInput = Character.toUpperCase(userInput);
if (!(Character.isDigit(userInput))) {
if (userInput == 'A' || userInput == 'M' || userInput == 'R' || userInput == 'T' || userInput == 'S') {// New Action Modification
nextAction = userInput;
flag = false;
}
else {
System.out.println("Invalid input. Please type A, M, R, or S");
}
}
}
return nextAction;
}
/**
* Gets the action selected by the player who is next
* @param game
* @ return the next players action that was selected
*/
public void getNextPlayersAction(GameS22 game){
Scanner scr = new Scanner(System.in);
this.action = getUsersNextActionType(scr);
System.out.println("Enter the row index of the desired piece:");
this.fromRow = getValidInt(0,game.board.getNumRows()-1,scr);
System.out.println("Enter the column index of the desired piece:");
this.fromColumn = getValidInt(0,game.board.getNumColumns()-1,scr);
System.out.println("Enter the row index of the desired destination:");
this.toRow = getValidInt(0,game.board.getNumRows()-1,scr);
System.out.println("Enter the column index of the desired destination:");
this.toColumn = getValidInt(0,game.board.getNumColumns()-1,scr);
}
/**
prints the game to the screen
*/
public void updateView(Game game){
System.out.println(game);
}
/**
* prints the game over message to the screem
* @param game a game object
*/
public void printEndOfGameMessage(Game game){
System.out.println(
"┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"███▀▀▀██┼███▀▀▀███┼███▀█▄█▀███┼██▀▀▀\n" +
"██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼█┼┼┼██┼██┼┼┼\n" +
"██┼┼┼▄▄▄┼██▄▄▄▄▄██┼██┼┼┼▀┼┼┼██┼██▀▀▀\n" +
"██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██┼┼┼\n" +
"███▄▄▄██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██▄▄▄\n" +
"┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"███▀▀▀███┼▀███┼┼██▀┼██▀▀▀┼██▀▀▀▀██▄┼\n" +
"██┼┼┼┼┼██┼┼┼██┼┼██┼┼██┼┼┼┼██┼┼┼┼┼██┼\n" +
"██┼┼┼┼┼██┼┼┼██┼┼██┼┼██▀▀▀┼██▄▄▄▄▄▀▀┼\n" +
"██┼┼┼┼┼██┼┼┼██┼┼█▀┼┼██┼┼┼┼██┼┼┼┼┼██┼\n" +
"███▄▄▄███┼┼┼─▀█▀┼┼─┼██▄▄▄┼██┼┼┼┼┼██▄\n" +
"┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼██┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼██┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼████▄┼┼┼▄▄▄▄▄▄▄┼┼┼▄████┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼▀▀█▄█████████▄█▀▀┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼█████████████┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼██▀▀▀███▀▀▀██┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼██┼┼┼███┼┼┼██┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼█████▀▄▀█████┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼┼███████████┼┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼▄▄▄██┼┼█▀█▀█┼┼██▄▄▄┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼▀▀██┼┼┼┼┼┼┼┼┼┼┼██▀▀┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼▀▀┼┼┼┼┼┼┼┼┼┼┼▀▀┼┼┼┼┼┼┼┼┼┼┼\n" +
"┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n" +
"WINNING TEAM: " + game.getWinner().getTeamColor());
}
}