@@ -67,6 +67,14 @@ public GameImpl() { //Constructor for GameImpl
6767 for (int j = 0 ; j < WORLDSIZE ; j ++)
6868 world [i ][j ] = new TileImpl ();
6969
70+ for (int i = 0 ; i < WORLDSIZE ; i ++)
71+ for (int j = 0 ; j < WORLDSIZE ; j ++)
72+ units [i ][j ] = null ;
73+
74+ for (int i = 0 ; i < WORLDSIZE ; i ++)
75+ for (int j = 0 ; j < WORLDSIZE ; j ++)
76+ cities [i ][j ] = null ;
77+
7078 //set the special tiles
7179 world [1 ][0 ].setTerrain (OCEANS );
7280 world [0 ][1 ].setTerrain (HILLS );
@@ -83,27 +91,30 @@ public GameImpl() { //Constructor for GameImpl
8391 Position posArcher = new Position (0 ,2 );
8492 Position posSettler = new Position (3 , 4 );
8593 Position posLegion = new Position (2 ,3 );
86- setUnitAt (posArcher , ARCHER , Player .RED );
87- setUnitAt (posSettler , SETTLER , Player .RED );
88- setUnitAt (posLegion , LEGION , Player .BLUE );
94+ createUnitAt (posArcher , ARCHER , Player .RED );
95+ createUnitAt (posSettler , SETTLER , Player .RED );
96+ createUnitAt (posLegion , LEGION , Player .BLUE );
8997
9098
9199 this .year = -4000 ;
92-
93100 }
94101
95102
96103 public Tile getTileAt ( Position p ) {
97104 return world [p .getColumn ()][p .getRow ()];
98105 }
106+
99107 public Unit getUnitAt ( Position p ) {
100108 return this .units [p .getColumn ()][p .getRow ()];
101109 }
102110
103111 //This will be changed later to account for the conditions needed to buy and place units -MAP
104- public boolean setUnitAt ( Position p , String unitType , Player owner ) {
105- this .units [p .getColumn ()][p .getRow ()] = new UnitImpl (unitType , owner );
106- return true ;
112+ public boolean createUnitAt ( Position p , String unitType , Player owner ) {
113+ if (this .units [p .getColumn ()][p .getRow ()] != null ) {
114+ return false ;
115+ }
116+ this .units [p .getColumn ()][p .getRow ()] = new UnitImpl (unitType , owner );
117+ return true ;
107118 }
108119
109120 public City getCityAt ( Position p ) {
@@ -133,7 +144,7 @@ public int getAge() {
133144 }
134145
135146 public boolean moveUnit ( Position from , Position to ) {
136- if (units [from .getColumn ()][from .getRow ()] != null ) {
147+ if (units [from .getColumn ()][from .getRow ()] != null && units [ to . getColumn ()][ to . getRow ()] == null ) {
137148 units [to .getColumn ()][to .getRow ()] = units [from .getColumn ()][from .getRow ()];
138149 units [from .getColumn ()][from .getRow ()] = null ;
139150 return true ;
@@ -172,9 +183,13 @@ public void performUnitActionAt( Position p ) {
172183
173184
174185 //----------------- True / False Queries ---------------------//
186+
175187 public boolean isPlayerInGame (Player player ) {
176188 return Players .contains (player );
177189 }
178190
179191
192+
193+
194+
180195}
0 commit comments