Merge remote-tracking branch 'origin/master'

# Conflicts:
#	.idea/vcs.xml
This commit is contained in:
blzimme000 2022-03-07 07:16:57 -06:00
commit 45f89a0d07
2 changed files with 52 additions and 21 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="" vcs="Git" />
</component> </component>
</project> </project>

View file

@ -13,7 +13,7 @@ public class Board{
public String toString(){ public String toString(){
String toReturn = ""; String toReturn = "";
for (int i = 0; i < squares[0].length; i++){ for (int i = 0; i < 10; i++){
for (int c = 0; c < 10; c++){ // C++ :) for (int c = 0; c < 10; c++){ // C++ :)
toReturn += squares[i][c] + " "; toReturn += squares[i][c] + " ";
} }
@ -23,42 +23,73 @@ public class Board{
} }
public boolean addShip(int row, int col, int len, boolean horizontal){ public boolean addShip(int row, int col, int len, boolean horizontal){
if (len > 9 || len < 0 || row > 9 || row < 0 || col > 9 || col < 0)return false; if (len > 10 || len < 0 || row > 9 || row < 0 || col > 9 || col < 0)return false;
if (horizontal){ if (horizontal){
if (col + len > 9){ if (col + len > 10){
return false;
}
for (int i = 0; i < squares[0].length; i++){
for (int c = 0; c < 10; c++){ // C++ :)
if (c == row && i >= col && i <= col + len){
if (squares[c][i].equals("x") || squares[c][i].equals("b"))return false;
squares[c][i] = "b";
}
}
}
} else {
if (row + len > 10){
return false; return false;
} }
for (int i = 0; i < squares[0].length; i++){ for (int i = 0; i < squares[0].length; i++){
for (int c = 0; c < 10; c++){ // C++ :) for (int c = 0; c < 10; c++){ // C++ :)
if (i == col && c >= row && c <= row + len){ if (i == col && c >= row && c <= row + len){
squares[i][c] = "b"; if (squares[c][i].equals("x") || squares[c][i].equals("b"))return false;
} squares[c][i] = "b";
}
}
} else {
if (row + len > 9){
return false;
}
for (int i = 0; i < squares[0].length; i++){
for (int c = 0; c < 10; c++){ // C++ :)
if (c == row && i >= col && i <= row + col){
squares[i][c] = "b";
} }
} }
} }
} }
}
public boolean foundShip(int len){
return true; return true;
} }
public boolean foundShip(int len){
for (String[] square : squares) {
int bInColumn = 0;
for (int c = 0; c < squares[0].length; c++) {
if (square[c].equals("b")) bInColumn++;
if (bInColumn == len && !(square[c + 1].equals("b"))) return true;
}
}
for (int i = 0; i < squares[0].length; i++){
int bInColumn = 0;
for (String[] square : squares) {
if (square[i].equals("b")) bInColumn++;// May need to switch this c and i, not sure
if (bInColumn == len && !(square[i + 1].equals("b"))) return true;
}
}
return false;
}
public int shoot(int row, int col){ public int shoot(int row, int col){
if (row > 9 || row < 0 || col > 9 || col < 0)return -1;
if (squares[row][col].equals("-")){
squares[row][col] = "m";
return 0;
}
if (squares[row][col].equals("x") || squares[row][col].equals("m"))return 2;
if (squares[row][col].equals("b")){
squares[row][col] = "x";
return 1;
}
return 0; return 0;
} }
public boolean gameOver(){ public boolean gameOver(){
return false; for (String[] arr : squares){
for (String e : arr){
if (e.equals("b"))return false;
}
}
return true;
} }
} }