-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'GitHub/master'
- Loading branch information
Showing
108 changed files
with
3,482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>battleships</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>com.nwire.studio.tools.nwireNature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+721 Bytes
battleships/bin/Battleships/Factories/GridBehaviorSetterFactory.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+537 Bytes
battleships/bin/Battleships/exception/IncorrectOrientationParameterException.class
Binary file not shown.
Binary file added
BIN
+519 Bytes
battleships/bin/Battleships/exception/InitialPositionOccupiedException.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+510 Bytes
battleships/bin/Battleships/exception/PositionExceedsBoardException.class
Binary file not shown.
Binary file added
BIN
+498 Bytes
battleships/bin/Battleships/exception/PositionOccupiedException.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions
49
battleships/src/Battleships/Adapters/AttackMousePressListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import javax.swing.JTextField; | ||
|
||
import Battleships.GameState; | ||
import Battleships.Factories.ResolverFactory; | ||
import Battleships.Graphics.PlayerPanel; | ||
|
||
public class AttackMousePressListener extends MouseAdapter | ||
{ | ||
|
||
private PlayerPanel attackPanel; | ||
private GameState gameState; | ||
|
||
public AttackMousePressListener(PlayerPanel attackPanel, GameState gameState) | ||
{ | ||
this.attackPanel = attackPanel; | ||
this.gameState = gameState; | ||
} | ||
|
||
|
||
public void mousePressed(MouseEvent event) | ||
{ | ||
if(gameState.IsAcceptingPlayerInput()) | ||
{ | ||
int x = event.getX(); | ||
int y = event.getY(); | ||
|
||
int gridj= resolveAxisCoOrdinate(x); | ||
int gridi= resolveAxisCoOrdinate(y); | ||
|
||
Graphics attackPanelGraphics = attackPanel.getGraphics(); | ||
|
||
String acceptPlayerShotString = | ||
gameState.acceptPlayerShot(gridi,gridj, attackPanelGraphics); | ||
|
||
System.out.println(acceptPlayerShotString); | ||
System.out.println("Element corresponds to " + gridi + gridj); | ||
} | ||
} | ||
|
||
private int resolveAxisCoOrdinate(int x) { | ||
return ResolverFactory.AxisCoOrdinate(x); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
battleships/src/Battleships/Adapters/HideButtonAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import Battleships.GUI; | ||
|
||
public class HideButtonAction extends MouseAdapter { | ||
private GUI gui; | ||
|
||
public HideButtonAction(GUI gui2) | ||
{ | ||
|
||
gui=gui2; | ||
} | ||
|
||
public void mousePressed(MouseEvent event) | ||
{ | ||
gui.hideMap(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
battleships/src/Battleships/Adapters/HomeMousePressListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import Battleships.GUI; | ||
import Battleships.Factories.ResolverFactory; | ||
import Battleships.Ships.AircraftCarrier; | ||
import Enums.Position; | ||
|
||
public class HomeMousePressListener extends MouseAdapter { | ||
private GUI gui; | ||
private String currentShip; | ||
|
||
public HomeMousePressListener(GUI gui) | ||
{ | ||
this.gui = gui; | ||
this.currentShip = AircraftCarrier.class.getSimpleName(); | ||
} | ||
|
||
public void mousePressed(MouseEvent event) { | ||
int gridj= resolveAxisCoOrdinate(event.getX()); | ||
int gridi= resolveAxisCoOrdinate(event.getY()); | ||
|
||
boolean valid = gui.placeShip(currentShip, new Position(gridi, gridj, gui.orientation)); | ||
if(valid) | ||
currentShip = ResolverFactory.nextShip(currentShip); | ||
|
||
if(currentShip == null) | ||
gui.gameState.setPlayerShipsDeployed(); | ||
System.out.println("Element corresponds to " + gridi + gridj); | ||
|
||
if(gui.gameState.arePlayerShipsDeployed()) { | ||
gui.setOut("All Ships Deployed, Player's Turn! Click on the left grid to fire shots"); | ||
gui.setOut(gui.gameState.turnToString()); | ||
} | ||
} | ||
private int resolveAxisCoOrdinate(int x) { | ||
return ResolverFactory.AxisCoOrdinate(x); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import Battleships.GUI; | ||
|
||
public class NewButtonAction extends MouseAdapter { | ||
private GUI gui; | ||
|
||
public NewButtonAction(GUI gui2) | ||
{ | ||
|
||
gui=gui2; | ||
} | ||
|
||
public void mousePressed(MouseEvent event) | ||
{ | ||
gui.reset(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
battleships/src/Battleships/Adapters/QuitButtonAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
public class QuitButtonAction extends MouseAdapter { | ||
public QuitButtonAction() | ||
{} | ||
|
||
public void mouseClicked(MouseEvent event) | ||
{ | ||
System.exit(1); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
battleships/src/Battleships/Adapters/RotateButtonAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import Battleships.GUI; | ||
|
||
public class RotateButtonAction extends MouseAdapter { | ||
private GUI gui; | ||
|
||
public RotateButtonAction(GUI gui2) | ||
{ | ||
|
||
gui=gui2; | ||
} | ||
|
||
public void mousePressed(MouseEvent event) | ||
{ | ||
System.out.println("Orientation = " + gui.rotate().name()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
battleships/src/Battleships/Adapters/ShowButtonAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Battleships.Adapters; | ||
|
||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import Battleships.GUI; | ||
|
||
public class ShowButtonAction extends MouseAdapter { | ||
private GUI gui; | ||
|
||
public ShowButtonAction(GUI gui2) | ||
{ | ||
|
||
gui=gui2; | ||
} | ||
|
||
public void mousePressed(MouseEvent event) | ||
{ | ||
gui.showMap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package Battleships; | ||
import java.util.Random; | ||
|
||
import Battleships.Behaviors.ShooterBehavior; | ||
import Battleships.Factories.ShipFactory; | ||
import Battleships.Factories.ShotFactory; | ||
import Battleships.Ships.AircraftCarrier; | ||
import Battleships.Ships.Battleship; | ||
import Battleships.Ships.Destroyer; | ||
import Battleships.Ships.Minesweeper; | ||
import Battleships.Ships.Submarine; | ||
import Enums.Orientation; | ||
import Enums.Position; | ||
public class Agent | ||
{ | ||
private InfluenceMap m = null; | ||
private Grid grid = null; | ||
private int i=-1; | ||
private int j=-1; | ||
private ShooterBehavior shooterBehavior; | ||
|
||
public Agent() | ||
{ | ||
m = new InfluenceMap(); | ||
grid = new Grid(10,10); | ||
} | ||
|
||
public int getI() | ||
{ | ||
return i; | ||
} | ||
|
||
public int getJ() | ||
{ | ||
return j; | ||
} | ||
|
||
public InfluenceMap setSunk(int i, int j) | ||
{ | ||
m.sunk(i,j); | ||
return m; | ||
} | ||
|
||
public void nextShot(InfluenceMap m1, Grid Attackgrid) | ||
{ | ||
m = m1; | ||
grid = Attackgrid; | ||
shooterBehavior = ShotFactory.getShooterBehavior(m.getNumberOfHotspots()); | ||
shooterBehavior.nextShot(m, grid); | ||
i = shooterBehavior.i; | ||
j = shooterBehavior.j; | ||
} | ||
|
||
public Grid placeShips() | ||
{ | ||
while(!grid.areShipsPlaced()) | ||
{ | ||
Random random = new Random(); | ||
int x = random.nextInt(10); | ||
int y = random.nextInt(10); | ||
boolean orientation = random.nextBoolean(); | ||
Position position = new Position(x, y, orientation == true ? Orientation.Horizontal : Orientation.Vertical); | ||
if(!grid.isShipPlaced(AircraftCarrier.class.getSimpleName())) { | ||
grid.addShip(AircraftCarrier.class.getSimpleName(), position); | ||
} | ||
else if(!grid.isShipPlaced(Battleship.class.getSimpleName())) { | ||
grid.addShip(Battleship.class.getSimpleName(), position); | ||
} | ||
else if(!grid.isShipPlaced(Destroyer.class.getSimpleName())) { | ||
grid.addShip(Destroyer.class.getSimpleName(), position); | ||
} | ||
else if(!grid.isShipPlaced(Submarine.class.getSimpleName())) { | ||
grid.addShip(Submarine.class.getSimpleName(), position); | ||
} | ||
else if(!grid.isShipPlaced(Minesweeper.class.getName())) { | ||
grid.addShip(Minesweeper.class.getSimpleName(), position); | ||
} | ||
} | ||
|
||
System.out.println("agent grid"); | ||
System.out.println(grid.toString()); | ||
|
||
return grid; | ||
} | ||
} |
Oops, something went wrong.