-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard backup1.txt
More file actions
201 lines (154 loc) · 5.89 KB
/
Copy pathboard backup1.txt
File metadata and controls
201 lines (154 loc) · 5.89 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
public class Board {
private int nrows;
private int ncols;
private Cell[][] boardP1;
private Cell[][] boardP2;
private Boat[] boatArrayP1;
private Boat[] boatArrayP2;
private int turnCountP1;
private int turnCountP2;
private int turnCountTotal;
private int boatsRemainingP1;
private int boatsRemainingP2;
private int powerPointsRemainingP1;
private int powerPointsRemainingP2;
public Board(char difficulty, char mode){
this.turnCountP1 = 0;
this.turnCountP2 = 0;
this.turnCountTotal = 0;
mode = Character.toUpperCase(mode);
if (mode == 'S') // Single player. P1 variables only.
{
difficulty = Character.toUpperCase(difficulty);
switch(difficulty){
case 'I': // Intermediate. 6x6 board
this.boatsRemainingP1 = 3;
this.ncols = 6;
this.nrows = 6;
this.powerPointsRemainingP1 = 3;
break;
case 'A': // Advanced. 9x9 board
this.boatsRemainingP1 = 5;
this.ncols = 9;
this.nrows = 9;
this.powerPointsRemainingP1 = 5;
break;
default: // Default to Beginner ('B')
this.boatsRemainingP1 = 1;
this.ncols = 3;
this.nrows = 3;
this.powerPointsRemainingP1 = 1;
break;
}
// Set up new board.
boardP1 = new Cell[this.nrows][this.ncols];
// Set up the boats
this.boardP1 = placeBoats(this.ncols, this.nrows);
}
else{
// Two players. P1 and P2 variables used. AI might be implemented.
if (mode == 'T') {
switch(difficulty){
case 'B': // Beginner
break;
case 'I': // Intermediate
break;
case 'A':
break;
default: // Default to beginner
break;
}
}
else{
System.out.println("ERROR: invalid input for singleplayer/multiplayer mode.");
}
}
}
public Cell[][] placeBoats(int rows, int cols){
int intNumBoats = 0;
int randX;
int randY;
// Always Assume the 2D array always has the same number of columns as rows.
Cell[][] cellBoard = new Cell[rows][cols]; // 2D cell array to be returned.
//int intLeftSideX = 0;
int intRightSideX = cols-1;
//int intTopSideY = 0;
int intBottomSideY = rows-1;
/*int[] PossOrients = new int[4];
// PossOrients is an array of integers (1 or 0) that indicate whether the orientation represented by that index is available for use by a boat.
// A value of 1 means that orientation is available. A value of 0 indicates the orientation is not available.
// The indexes of PossOrients go clockwise around a standard circular compass, starting at North:
// PossOrients[0] = North
// PossOrients[1] = East
// PossOrients[2] = South
// PossOrients[3] = West
for (int a = 0; a < PossOrients.length; a++){
PossOrients[a] = 1;
}
*/
boolean NorthPoss = true;
/*
NORTH:
^ front
|
|
| tail
*/
boolean SouthPoss = true;
/*
SOUTH:
| tail
|
|
v front
*/
boolean EastPoss = true;
// EAST: --->
boolean WestPoss = true;
// WEST: <---
boolean bPositionFound = false;
if (rows == 3){
// If it's a 3x3 grid, then there is one ships: One 2-cell Destroyer.
// Since we are only making one ship here, we don't need to check for overlapping ships.
intNumBoats = 1;
while (bPositionFound == false){
randX = getRandomNumber(0, intRightSideX);
randY = getRandomNumber(0, intBottomSideY);
// If the destroyer's x-position is on the left side of the grid, its orientation can't be east or else its tail would be off the board.
// Likewise, if the destroyer' x-position is on the right side of the grid, it's orientation can't be west.
// If the destroyer's y-position is on the top side of the grid, its orientation can't be south or else its tail would be off the board.
// Likewise, if the destroyer' y-position is on the bottom side of the grid, it's orientation can't be north.
if(randX == 0){ // check if the boat is on the left side.4
}
}
}
else{
if (rows == 6){
// If it's a 6x6 grid, then there are three ships: One 2-cell Destroyer, one 3-cell Cruiser, and one 4-cell Battleship.
intNumBoats = 3;
}
else{
if (rows == 9){
intNumBoats = 5;
// One 2-cell Destroyer. two 3-cell Cruisers, one 4-cell Battleship and one 5-cell Carrier.
}
else{
System.out.println("ERROR: Invalid input for board size in placeBoats.");
}
}
}
}
public int getRandomNumber(int min, int max) {
return (int)((Math.random() * (max - min)) + min);
}
public Boolean fire(int x, int y, int targetPlayer){
}
public String display(char player, boolean bShipsHidden){
}
public String print(String strPassword){
}
public String missile(int x, int y, int targetPlayer){
}
public String submarine(int x, int y, int targetPlayer){
}
}