Skip to content

Commit

Permalink
Aflevering 3 final
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus authored and Magnus committed Nov 25, 2014
1 parent 900b389 commit 8544fe6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 58 deletions.
1 change: 0 additions & 1 deletion src/hotciv/factories/DeltaCivFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import hotciv.variants.AlphaCivUnitAction;
import hotciv.variants.AlphaCivWinCondition;
import hotciv.variants.DeltaCivWorldLayout;
import hotciv.framework.common.Worlds;

public class DeltaCivFactory implements CivFactory {

Expand Down
26 changes: 26 additions & 0 deletions src/hotciv/framework/common/Worlds.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package hotciv.framework.common;

import hotciv.common.TileImpl;

import java.util.HashMap;
import java.util.Map;

public class Worlds {

public static Map<Position, Tile> defineWorld(String[] layout) {
// Conversion...
Map<Position,Tile> theWorld = new HashMap<Position,Tile>();
String line;
for ( int r = 0; r < GameConstants.WORLDSIZE; r++ ) {
line = layout[r];
for ( int c = 0; c < GameConstants.WORLDSIZE; c++ ) {
char tileChar = line.charAt(c);
String type = "error";
if ( tileChar == '.' ) { type = GameConstants.OCEANS; }
if ( tileChar == 'o' ) { type = GameConstants.PLAINS; }
if ( tileChar == 'M' ) { type = GameConstants.MOUNTAINS; }
if ( tileChar == 'f' ) { type = GameConstants.FOREST; }
if ( tileChar == 'h' ) { type = GameConstants.HILLS; }
Position p = new Position(r,c);
theWorld.put( p, new TileImpl(type));
}
}
return theWorld;
}

// DeltaCiv
public static final String[] WORLD_DELTA = new String[] {
Expand Down
3 changes: 0 additions & 3 deletions src/hotciv/framework/strategy/WorldLayoutStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hotciv.framework.common.Tile;

import java.util.HashMap;
import java.util.Map;

public interface WorldLayoutStrategy {

Expand All @@ -20,6 +19,4 @@ public interface WorldLayoutStrategy {
* @return the tile at position p.
*/
public Tile getTileAt(Position p);

public Map<Position,Tile> defineWorld(String[] layout);
}
29 changes: 6 additions & 23 deletions src/hotciv/variants/AlphaCivWorldLayout.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
package hotciv.variants;

import hotciv.common.CityImpl;
import hotciv.common.TileImpl;
import hotciv.framework.common.GameConstants;
import hotciv.framework.common.Player;
import hotciv.framework.common.Position;
import hotciv.framework.common.Tile;
import hotciv.framework.common.Worlds;
import hotciv.framework.strategy.WorldLayoutStrategy;

import java.util.HashMap;
import java.util.Map;

public class AlphaCivWorldLayout implements WorldLayoutStrategy {

private Map<Position,Tile> world;

public AlphaCivWorldLayout(String[] layout){
world = defineWorld(layout);
world = Worlds.defineWorld(layout);
}

public void putCities(HashMap<Position, CityImpl> cities) {
cities.put(new Position(1,1), new CityImpl(Player.RED));
cities.put(new Position(4,1), new CityImpl(Player.BLUE));
}

public Tile getTileAt(Position p) {
Tile t = null;
if(p.getRow()==0 && p.getColumn()==1){
t= new TileImpl(GameConstants.OCEANS);
}else if(p.getRow()==1 && p.getColumn()==0){
t = new TileImpl(GameConstants.HILLS);
}else if(p.getRow()==2 && p.getColumn()==2 ){
t = new TileImpl(GameConstants.MOUNTAINS);
}else{
t = new TileImpl(GameConstants.PLAINS);
}
return t;
}

@Override
public Map<Position, Tile> defineWorld(String[] layout) {
// TODO Auto-generated method stub
return null;
return world.get(p);
}
}
28 changes: 2 additions & 26 deletions src/hotciv/variants/DeltaCivWorldLayout.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package hotciv.variants;

import hotciv.common.CityImpl;
import hotciv.common.TileImpl;
import hotciv.framework.common.GameConstants;
import hotciv.framework.common.Player;
import hotciv.framework.common.Position;
import hotciv.framework.common.Tile;
import hotciv.framework.common.Worlds;
import hotciv.framework.strategy.WorldLayoutStrategy;

import java.util.HashMap;
Expand All @@ -16,7 +15,7 @@ public class DeltaCivWorldLayout implements WorldLayoutStrategy {
private Map<Position,Tile> world;

public DeltaCivWorldLayout(String[] layout) {
world = defineWorld(layout);
world = Worlds.defineWorld(layout);
}

public void putCities(HashMap<Position, CityImpl> cities) {
Expand All @@ -25,27 +24,4 @@ public void putCities(HashMap<Position, CityImpl> cities) {
}

public Tile getTileAt( Position p ) { return world.get(p); }

/** Define the world as the DeltaCiv layout */
public Map<Position,Tile> defineWorld(String[] layout) {

// Conversion...
Map<Position,Tile> theWorld = new HashMap<Position,Tile>();
String line;
for ( int r = 0; r < GameConstants.WORLDSIZE; r++ ) {
line = layout[r];
for ( int c = 0; c < GameConstants.WORLDSIZE; c++ ) {
char tileChar = line.charAt(c);
String type = "error";
if ( tileChar == '.' ) { type = GameConstants.OCEANS; }
if ( tileChar == 'o' ) { type = GameConstants.PLAINS; }
if ( tileChar == 'M' ) { type = GameConstants.MOUNTAINS; }
if ( tileChar == 'f' ) { type = GameConstants.FOREST; }
if ( tileChar == 'h' ) { type = GameConstants.HILLS; }
Position p = new Position(r,c);
theWorld.put( p, new TileImpl(type));
}
}
return theWorld;
}
}
5 changes: 0 additions & 5 deletions test/hotciv/civs/TestAlphaCiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ public void ShouldNotBeAbleToMoveOnOcean(){
public void ShouldNotBeAbleToMoveOnMountains(){
assertFalse("you cannot move on mountains", game.moveUnit(new Position(2,0), new Position(2, 2)));
}

@Test
public void ToShouldbeInsideWorld(){
assertFalse("To should be inside world", game.moveUnit(new Position(2,0), new Position(17, 5)));
}

@Test
public void ShouldBeValidMove(){
Expand Down

0 comments on commit 8544fe6

Please sign in to comment.