Skip to content

Commit

Permalink
first initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Shavonne Cobb authored and Shavonne Cobb committed Oct 15, 2019
0 parents commit db52c39
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.imprioving</groupId>
<artifactId>battleship</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>

</project>
85 changes: 85 additions & 0 deletions src/main/java/BattleshipBust.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.net.SocketImpl;
import java.util.ArrayList;
import java.util.Scanner;

public class BattleshipBust {
private GameHelper helper = new GameHelper();
private ArrayList<SimpleBattleship> battleshipList = new ArrayList<>();
private int numOfGuesses = 0;

private void setUpGame() {
SimpleBattleship ship1 = new SimpleBattleship();
ship1.setName("Lucille");
SimpleBattleship ship2 = new SimpleBattleship();
ship2.setName("Drax");
SimpleBattleship ship3 = new SimpleBattleship();
ship3.setName("Lilith");
// SimpleBattleship ship4 = new SimpleBattleship();
// ship4.setName("Vincent");
battleshipList.add(ship1);
battleshipList.add(ship2);
battleshipList.add(ship3);
// battleshipList.add(ship4);

System.out.println("Your goal is to sink the three Ships.");
System.out.println("Lucille, Drax, Lilith");
System.out.println("Try to sink them all in the fewest number of guesses.");

for (SimpleBattleship lucilleToSet : battleshipList) {
ArrayList<String> newLocation = helper.placeBattleship(3);
ship1.setLocationCells(newLocation);
}
for (SimpleBattleship draxToSet : battleshipList) {
ArrayList<String> newLocation = helper.placeBattleship(3);
ship2.setLocationCells(newLocation);
}
for (SimpleBattleship lilithToSet : battleshipList) {
ArrayList<String> newLocation = helper.placeBattleship(3);
ship3.setLocationCells(newLocation);
}
// for (SimpleBattleship vincentToSet : battleshipList) {
// ArrayList<String> newLocation = helper.placeBattleship(3);
// ship4.setLocationCells(newLocation);
// }

}

public void startPlaying() {
while(!battleshipList.isEmpty()) {
String userGuess = helper.getUserInput("Enter a guess");
checkUserGuess(userGuess);
}
finishGame();
}

private void checkUserGuess(String userGuess) {
numOfGuesses++;
String result = "miss";
for (int x = 0; x < battleshipList.size(); x++) {
result = battleshipList.get(x).checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
battleshipList.remove(x);
break;
}
}
System.out.println(result);
}

private void finishGame() {
System.out.println("All Ships are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("Blah blach blach");
} else {
System.out.println("more blah");
}
}

public static void main(String[] args) {
BattleshipBust game = new BattleshipBust();
game.setUpGame();
game.startPlaying();
}
}
Loading

0 comments on commit db52c39

Please sign in to comment.