Skip to content

Commit

Permalink
Merge remote-tracking branch 'GitHub/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogatinov committed Jan 10, 2014
2 parents a51b47b + 594e824 commit 4bd4b26
Show file tree
Hide file tree
Showing 108 changed files with 3,482 additions and 0 deletions.
6 changes: 6 additions & 0 deletions battleships/.classpath
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>
18 changes: 18 additions & 0 deletions battleships/.project
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>
11 changes: 11 additions & 0 deletions battleships/.settings/org.eclipse.jdt.core.prefs
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
2 changes: 2 additions & 0 deletions battleships/.settings/org.eclipse.ltk.core.refactoring.prefs
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 added battleships/bin/Battleships/Agent.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 added battleships/bin/Battleships/GUI.class
Binary file not shown.
Binary file added battleships/bin/Battleships/GameState.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added battleships/bin/Battleships/Graphics/DrawGrid.class
Binary file not shown.
Binary file added battleships/bin/Battleships/Graphics/HitIcon.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added battleships/bin/Battleships/Graphics/MissIcon.class
Binary file not shown.
Binary file not shown.
Binary file added battleships/bin/Battleships/Graphics/Ship.class
Binary file not shown.
Binary file not shown.
Binary file added battleships/bin/Battleships/Grid.class
Binary file not shown.
Binary file added battleships/bin/Battleships/InfluenceMap.class
Binary file not shown.
Binary file not shown.
Binary file added battleships/bin/Battleships/Ships/Battleship.class
Binary file not shown.
Binary file added battleships/bin/Battleships/Ships/Destroyer.class
Binary file not shown.
Binary file added battleships/bin/Battleships/Ships/Minesweeper.class
Binary file not shown.
Binary file added battleships/bin/Battleships/Ships/Ship.class
Binary file not shown.
Binary file added battleships/bin/Battleships/Ships/Submarine.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 added battleships/bin/Enums/GridValue.class
Binary file not shown.
Binary file added battleships/bin/Enums/Orientation.class
Binary file not shown.
Binary file added battleships/bin/Enums/Position.class
Binary file not shown.
49 changes: 49 additions & 0 deletions battleships/src/Battleships/Adapters/AttackMousePressListener.java
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 battleships/src/Battleships/Adapters/HideButtonAction.java
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 battleships/src/Battleships/Adapters/HomeMousePressListener.java
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);
}

}
21 changes: 21 additions & 0 deletions battleships/src/Battleships/Adapters/NewButtonAction.java
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 battleships/src/Battleships/Adapters/QuitButtonAction.java
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 battleships/src/Battleships/Adapters/RotateButtonAction.java
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 battleships/src/Battleships/Adapters/ShowButtonAction.java
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();
}
}
85 changes: 85 additions & 0 deletions battleships/src/Battleships/Agent.java
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;
}
}
Loading

0 comments on commit 4bd4b26

Please sign in to comment.