001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2011 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.action; 021 022import java.awt.Point; 023import java.io.File; 024import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModel; 025import net.sf.gridarta.model.archetype.DuplicateArchetypeException; 026import net.sf.gridarta.model.archetype.TestArchetype; 027import net.sf.gridarta.model.gameobject.TestGameObject; 028import net.sf.gridarta.model.maparchobject.TestMapArchObject; 029import net.sf.gridarta.model.mapcontrol.MapControl; 030import net.sf.gridarta.model.mapcontrol.TestMapControlCreator; 031import net.sf.gridarta.model.mapmodel.CannotInsertGameObjectException; 032import net.sf.gridarta.model.mapmodel.MapModel; 033import net.sf.gridarta.model.mapmodel.MapSquare; 034import net.sf.gridarta.model.mapmodel.TestMapModelHelper; 035import net.sf.gridarta.utils.Size2D; 036import org.junit.Assert; 037import org.junit.Test; 038 039/** 040 * Regression tests for {@link AbstractMoveSquareAction} implementations. 041 * @author Andreas Kirschbaum 042 */ 043public class SelectedSquareActionsTest { 044 045 /** 046 * The first map file. 047 */ 048 private static final File MAP_FILE1 = new File("a"); 049 050 /** 051 * The first map name. 052 */ 053 private static final String MAP_NAME1 = "name1"; 054 055 /** 056 * Checks that {@link MoveSquareTopAction} does work for single-square game 057 * objects. 058 * @throws CannotInsertGameObjectException if the test fails 059 * @throws DuplicateArchetypeException if the test fails 060 */ 061 @Test 062 public void testDoMoveSquareTopSingle() throws CannotInsertGameObjectException, DuplicateArchetypeException { 063 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 064 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 065 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 066 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 067 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareTopAction = new MoveSquareTopAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 068 069 final Point point = new Point(0, 0); 070 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 071 mapModel.beginTransaction("TEST"); 072 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 073 final TestGameObject ob2 = mapModelHelper.insertFloor(mapModel, point); 074 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 075 076 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 077 078 // empty selection => nothing to move 079 Assert.assertFalse(moveSquareTopAction.doAction(false)); 080 Assert.assertFalse(moveSquareTopAction.doAction(true)); 081 082 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 083 selectedSquareModel.setSelectedGameObject(ob2); 084 085 // [ob2, ob1] => ob2 can move 086 Assert.assertTrue(moveSquareTopAction.doAction(false)); 087 Assert.assertTrue(moveSquareTopAction.doAction(true)); 088 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 089 090 // [ob1, ob2] => ob2 cannot move 091 Assert.assertFalse(moveSquareTopAction.doAction(false)); 092 Assert.assertFalse(moveSquareTopAction.doAction(true)); 093 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 094 } 095 096 /** 097 * Checks that {@link MoveSquareTopAction} does work for multi-square game 098 * objects. 099 * @throws CannotInsertGameObjectException if the test fails 100 * @throws DuplicateArchetypeException if the test fails 101 */ 102 @Test 103 public void testDoMoveSquareTopMulti() throws CannotInsertGameObjectException, DuplicateArchetypeException { 104 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 105 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 106 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 107 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 108 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareTopAction = new MoveSquareTopAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 109 110 final Point pointHead = new Point(0, 0); 111 final Point pointTail = new Point(1, 0); 112 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 113 mapModel.beginTransaction("TEST"); 114 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); 115 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); 116 final TestGameObject ob1Head = mapModelHelper.insertFloor(mapModel, pointHead); 117 final TestGameObject ob1Tail = mapModelHelper.insertFloor(mapModel, pointTail); 118 final TestGameObject ob2Head = mapModelHelper.insertMob21(mapModel, pointHead); 119 final TestGameObject ob2Tail = ob2Head.getMultiNext(); 120 121 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 122 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 123 124 // empty selection => nothing to move 125 Assert.assertFalse(moveSquareTopAction.doAction(false)); 126 Assert.assertFalse(moveSquareTopAction.doAction(true)); 127 128 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 129 selectedSquareModel.setSelectedGameObject(ob1Head); 130 131 // [ob1, ob2] => ob1 can move 132 Assert.assertTrue(moveSquareTopAction.doAction(false)); 133 Assert.assertTrue(moveSquareTopAction.doAction(true)); 134 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 135 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 136 137 // [ob2, ob1] => ob1 cannot move 138 Assert.assertFalse(moveSquareTopAction.doAction(false)); 139 Assert.assertFalse(moveSquareTopAction.doAction(true)); 140 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 141 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 142 143 selectedSquareModel.setSelectedMapSquare(mapSquareTail, null); 144 selectedSquareModel.setSelectedGameObject(ob1Tail); 145 146 // [ob1, ob2] => ob1 can move // XXX: this probably should be changed: moving tail parts is not sensible 147 Assert.assertTrue(moveSquareTopAction.doAction(false)); 148 Assert.assertTrue(moveSquareTopAction.doAction(true)); 149 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 150 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 151 152 // [ob2, ob1] => ob1 cannot move 153 Assert.assertFalse(moveSquareTopAction.doAction(false)); 154 Assert.assertFalse(moveSquareTopAction.doAction(true)); 155 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 156 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 157 } 158 159 /** 160 * Checks that {@link MoveSquareUpAction} does work for single-square game 161 * objects. 162 * @throws CannotInsertGameObjectException if the test fails 163 * @throws DuplicateArchetypeException if the test fails 164 */ 165 @Test 166 public void testDoMoveSquareUpSingle() throws CannotInsertGameObjectException, DuplicateArchetypeException { 167 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 168 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 169 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 170 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 171 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareUpAction = new MoveSquareUpAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 172 173 final Point point = new Point(0, 0); 174 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 175 mapModel.beginTransaction("TEST"); 176 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 177 final TestGameObject ob2 = mapModelHelper.insertFloor(mapModel, point); 178 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 179 180 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 181 182 // empty selection => nothing to move 183 Assert.assertFalse(moveSquareUpAction.doAction(false)); 184 Assert.assertFalse(moveSquareUpAction.doAction(true)); 185 186 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 187 selectedSquareModel.setSelectedGameObject(ob2); 188 189 // [ob2, ob1] => ob2 can move 190 Assert.assertTrue(moveSquareUpAction.doAction(false)); 191 Assert.assertTrue(moveSquareUpAction.doAction(true)); 192 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 193 194 // [ob1, ob2] => ob2 cannot move 195 Assert.assertFalse(moveSquareUpAction.doAction(false)); 196 Assert.assertFalse(moveSquareUpAction.doAction(true)); 197 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 198 } 199 200 /** 201 * Checks that {@link MoveSquareUpAction} does work for multi-square game 202 * objects. 203 * @throws CannotInsertGameObjectException if the test fails 204 * @throws DuplicateArchetypeException if the test fails 205 */ 206 @Test 207 public void testDoMoveSquareUpMulti() throws CannotInsertGameObjectException, DuplicateArchetypeException { 208 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 209 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 210 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 211 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 212 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareUpAction = new MoveSquareUpAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 213 214 final Point pointHead = new Point(0, 0); 215 final Point pointTail = new Point(1, 0); 216 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 217 mapModel.beginTransaction("TEST"); 218 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); 219 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); 220 final TestGameObject ob2Head = mapModelHelper.insertFloor(mapModel, pointHead); 221 final TestGameObject ob2Tail = mapModelHelper.insertFloor(mapModel, pointTail); 222 final TestGameObject ob1Head = mapModelHelper.insertMob21(mapModel, pointHead); 223 final TestGameObject ob1Tail = ob1Head.getMultiNext(); 224 225 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 226 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 227 228 // empty selection => nothing to move 229 Assert.assertFalse(moveSquareUpAction.doAction(false)); 230 Assert.assertFalse(moveSquareUpAction.doAction(true)); 231 232 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 233 selectedSquareModel.setSelectedGameObject(ob2Head); 234 235 // [ob2, ob1] => ob2 can move 236 Assert.assertTrue(moveSquareUpAction.doAction(false)); 237 Assert.assertTrue(moveSquareUpAction.doAction(true)); 238 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 239 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 240 241 // [ob1, ob2] => ob2 cannot move 242 Assert.assertFalse(moveSquareUpAction.doAction(false)); 243 Assert.assertFalse(moveSquareUpAction.doAction(true)); 244 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 245 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 246 247 selectedSquareModel.setSelectedMapSquare(mapSquareTail, null); 248 selectedSquareModel.setSelectedGameObject(ob2Tail); 249 250 // [ob2, ob1] => ob2 can move // XXX: this probably should be changed: moving tail parts is not sensible 251 Assert.assertTrue(moveSquareUpAction.doAction(false)); 252 Assert.assertTrue(moveSquareUpAction.doAction(true)); 253 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 254 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 255 256 // [ob1, ob2] => ob2 cannot move 257 Assert.assertFalse(moveSquareUpAction.doAction(false)); 258 Assert.assertFalse(moveSquareUpAction.doAction(true)); 259 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 260 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 261 } 262 263 /** 264 * Checks that {@link MoveSquareDownAction} does work for single-square game 265 * objects. 266 * @throws CannotInsertGameObjectException if the test fails 267 * @throws DuplicateArchetypeException if the test fails 268 */ 269 @Test 270 public void testDoMoveSquareDownSingle() throws CannotInsertGameObjectException, DuplicateArchetypeException { 271 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 272 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 273 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 274 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 275 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareDownAction = new MoveSquareDownAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 276 277 final Point point = new Point(0, 0); 278 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 279 mapModel.beginTransaction("TEST"); 280 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 281 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 282 final TestGameObject ob2 = mapModelHelper.insertFloor(mapModel, point); 283 284 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 285 286 // empty selection => nothing to move 287 Assert.assertFalse(moveSquareDownAction.doAction(false)); 288 Assert.assertFalse(moveSquareDownAction.doAction(true)); 289 290 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 291 selectedSquareModel.setSelectedGameObject(ob2); 292 293 // [ob1, ob2] => ob2 can move 294 Assert.assertTrue(moveSquareDownAction.doAction(false)); 295 Assert.assertTrue(moveSquareDownAction.doAction(true)); 296 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 297 298 // [ob2, ob1] => ob2 cannot move 299 Assert.assertFalse(moveSquareDownAction.doAction(false)); 300 Assert.assertFalse(moveSquareDownAction.doAction(true)); 301 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 302 } 303 304 /** 305 * Checks that {@link MoveSquareDownAction} does work for multi-square game 306 * objects. 307 * @throws CannotInsertGameObjectException if the test fails 308 * @throws DuplicateArchetypeException if the test fails 309 */ 310 @Test 311 public void testDoMoveSquareDownMulti() throws CannotInsertGameObjectException, DuplicateArchetypeException { 312 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 313 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 314 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 315 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 316 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareDownAction = new MoveSquareDownAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 317 318 final Point pointHead = new Point(0, 0); 319 final Point pointTail = new Point(1, 0); 320 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 321 mapModel.beginTransaction("TEST"); 322 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); 323 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); 324 final TestGameObject ob1Head = mapModelHelper.insertMob21(mapModel, pointHead); 325 final TestGameObject ob1Tail = ob1Head.getMultiNext(); 326 final TestGameObject ob2Head = mapModelHelper.insertFloor(mapModel, pointHead); 327 final TestGameObject ob2Tail = mapModelHelper.insertFloor(mapModel, pointTail); 328 329 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 330 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 331 332 // empty selection => nothing to move 333 Assert.assertFalse(moveSquareDownAction.doAction(false)); 334 Assert.assertFalse(moveSquareDownAction.doAction(true)); 335 336 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 337 selectedSquareModel.setSelectedGameObject(ob2Head); 338 339 // [ob2, ob1] => ob2 can move 340 Assert.assertTrue(moveSquareDownAction.doAction(false)); 341 Assert.assertTrue(moveSquareDownAction.doAction(true)); 342 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 343 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 344 345 // [ob1, ob2] => ob2 cannot move 346 Assert.assertFalse(moveSquareDownAction.doAction(false)); 347 Assert.assertFalse(moveSquareDownAction.doAction(true)); 348 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 349 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 350 351 selectedSquareModel.setSelectedMapSquare(mapSquareTail, null); 352 selectedSquareModel.setSelectedGameObject(ob2Tail); 353 354 // [ob2, ob1] => ob2 can move // XXX: this probably should be changed: moving tail parts is not sensible 355 Assert.assertTrue(moveSquareDownAction.doAction(false)); 356 Assert.assertTrue(moveSquareDownAction.doAction(true)); 357 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 358 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 359 360 // [ob1, ob2] => ob2 cannot move 361 Assert.assertFalse(moveSquareDownAction.doAction(false)); 362 Assert.assertFalse(moveSquareDownAction.doAction(true)); 363 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 364 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 365 } 366 367 /** 368 * Checks that {@link MoveSquareBottomAction} does work for single-square 369 * game objects. 370 * @throws CannotInsertGameObjectException if the test fails 371 * @throws DuplicateArchetypeException if the test fails 372 */ 373 @Test 374 public void testDoMoveSquareBottomSingle() throws CannotInsertGameObjectException, DuplicateArchetypeException { 375 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 376 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 377 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 378 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 379 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareBottomAction = new MoveSquareBottomAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 380 381 final Point point = new Point(0, 0); 382 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 383 mapModel.beginTransaction("TEST"); 384 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 385 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 386 final TestGameObject ob2 = mapModelHelper.insertFloor(mapModel, point); 387 388 TestMapModelHelper.checkContents(mapSquare, ob1, ob2); 389 390 // empty selection => nothing to move 391 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 392 Assert.assertFalse(moveSquareBottomAction.doAction(true)); 393 394 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 395 selectedSquareModel.setSelectedGameObject(ob2); 396 397 // [ob1, ob2] => ob2 can move 398 Assert.assertTrue(moveSquareBottomAction.doAction(false)); 399 Assert.assertTrue(moveSquareBottomAction.doAction(true)); 400 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 401 402 // [ob2, ob1] => ob2 cannot move 403 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 404 Assert.assertFalse(moveSquareBottomAction.doAction(true)); 405 TestMapModelHelper.checkContents(mapSquare, ob2, ob1); 406 } 407 408 /** 409 * Checks that {@link MoveSquareBottomAction} does work for multi-square 410 * game objects. 411 * @throws CannotInsertGameObjectException if the test fails 412 * @throws DuplicateArchetypeException if the test fails 413 */ 414 @Test 415 public void testDoMoveSquareBottomMulti() throws CannotInsertGameObjectException, DuplicateArchetypeException { 416 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 417 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 418 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 419 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 420 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareBottomAction = new MoveSquareBottomAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 421 422 final Point pointHead = new Point(0, 0); 423 final Point pointTail = new Point(1, 0); 424 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 425 mapModel.beginTransaction("TEST"); 426 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); 427 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); 428 final TestGameObject ob1Head = mapModelHelper.insertMob21(mapModel, pointHead); 429 final TestGameObject ob1Tail = ob1Head.getMultiNext(); 430 final TestGameObject ob2Head = mapModelHelper.insertFloor(mapModel, pointHead); 431 final TestGameObject ob2Tail = mapModelHelper.insertFloor(mapModel, pointTail); 432 433 TestMapModelHelper.checkContents(mapSquareHead, ob1Head, ob2Head); 434 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 435 436 // empty selection => nothing to move 437 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 438 Assert.assertFalse(moveSquareBottomAction.doAction(true)); 439 440 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 441 selectedSquareModel.setSelectedGameObject(ob2Head); 442 443 // [ob2, ob1] => ob2 can move 444 Assert.assertTrue(moveSquareBottomAction.doAction(false)); 445 Assert.assertTrue(moveSquareBottomAction.doAction(true)); 446 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 447 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 448 449 // [ob1, ob2] => ob2 cannot move 450 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 451 Assert.assertFalse(moveSquareBottomAction.doAction(true)); 452 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 453 TestMapModelHelper.checkContents(mapSquareTail, ob1Tail, ob2Tail); 454 455 selectedSquareModel.setSelectedMapSquare(mapSquareTail, null); 456 selectedSquareModel.setSelectedGameObject(ob2Tail); 457 458 // [ob2, ob1] => ob2 can move // XXX: this probably should be changed: moving tail parts is not sensible 459 Assert.assertTrue(moveSquareBottomAction.doAction(false)); 460 Assert.assertTrue(moveSquareBottomAction.doAction(true)); 461 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 462 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 463 464 // [ob1, ob2] => ob2 cannot move 465 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 466 Assert.assertFalse(moveSquareBottomAction.doAction(true)); 467 TestMapModelHelper.checkContents(mapSquareHead, ob2Head, ob1Head); 468 TestMapModelHelper.checkContents(mapSquareTail, ob2Tail, ob1Tail); 469 } 470 471 /** 472 * Checks that {@link MoveSquareEnvAction} does work for single-square game 473 * objects. 474 * @throws CannotInsertGameObjectException if the test fails 475 * @throws DuplicateArchetypeException if the test fails 476 */ 477 @Test 478 public void testDoMoveSquareEnvSingle1() throws CannotInsertGameObjectException, DuplicateArchetypeException { 479 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 480 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 481 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 482 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 483 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 484 485 final Point point = new Point(0, 0); 486 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 487 mapModel.beginTransaction("TEST"); 488 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 489 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 490 491 TestMapModelHelper.checkContents(mapSquare, ob1); 492 493 // empty selection => nothing to move 494 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 495 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 496 497 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 498 selectedSquareModel.setSelectedGameObject(ob1); 499 500 // [ob1] => ob1 cannot move 501 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 502 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 503 TestMapModelHelper.checkContents(mapSquare, ob1); 504 } 505 506 /** 507 * Checks that {@link MoveSquareEnvAction} does work for single-square game 508 * objects. 509 * @throws CannotInsertGameObjectException if the test fails 510 * @throws DuplicateArchetypeException if the test fails 511 */ 512 @Test 513 public void testDoMoveSquareEnvSingle2() throws CannotInsertGameObjectException, DuplicateArchetypeException { 514 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 515 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 516 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 517 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 518 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 519 520 final Point point = new Point(0, 0); 521 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 522 mapModel.beginTransaction("TEST"); 523 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 524 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 525 final TestGameObject ob2 = mapModelHelper.insertExit(mapModel, point); 526 final TestGameObject ob3 = mapModelHelper.insertExit(mapModel, point); 527 final TestGameObject ob4 = mapModelHelper.insertExit(ob2); 528 529 TestMapModelHelper.checkContents(mapSquare, ob1, ob2, ob3); 530 TestMapModelHelper.checkContents(ob2, ob4); 531 532 // empty selection => nothing to move 533 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 534 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 535 536 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 537 selectedSquareModel.setSelectedGameObject(ob4); 538 539 // ob4 can move 540 Assert.assertTrue(moveSquareEnvAction.doAction(false)); 541 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 542 TestMapModelHelper.checkContents(mapSquare, ob1, ob4, ob2, ob3); 543 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 544 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 545 546 // ob4 cannot move 547 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 548 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 549 TestMapModelHelper.checkContents(mapSquare, ob1, ob4, ob2, ob3); 550 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 551 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 552 } 553 554 /** 555 * Checks that {@link MoveSquareEnvAction} does work for single-square game 556 * objects. 557 * @throws CannotInsertGameObjectException if the test fails 558 * @throws DuplicateArchetypeException if the test fails 559 */ 560 @Test 561 public void testDoMoveSquareEnvSingle3() throws CannotInsertGameObjectException, DuplicateArchetypeException { 562 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 563 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 564 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 565 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 566 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 567 568 final Point point = new Point(0, 0); 569 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 570 mapModel.beginTransaction("TEST"); 571 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 572 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 573 final TestGameObject ob2 = mapModelHelper.insertExit(ob1); 574 final TestGameObject ob3 = mapModelHelper.insertExit(ob2); 575 final TestGameObject ob4 = mapModelHelper.insertExit(ob2); 576 final TestGameObject ob5 = mapModelHelper.insertExit(ob2); 577 578 TestMapModelHelper.checkContents(mapSquare, ob1); 579 TestMapModelHelper.checkContents(ob1, ob2); 580 TestMapModelHelper.checkContents(ob2, ob3, ob4, ob5); 581 582 // empty selection => nothing to move 583 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 584 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 585 586 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 587 selectedSquareModel.setSelectedGameObject(ob4); 588 589 // ob4 can move 590 Assert.assertTrue(moveSquareEnvAction.doAction(false)); 591 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 592 TestMapModelHelper.checkContents(mapSquare, ob1); 593 TestMapModelHelper.checkContents(ob1, ob4, ob2); 594 TestMapModelHelper.checkContents(ob2, ob3, ob5); 595 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 596 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 597 598 // ob4 can move 599 Assert.assertTrue(moveSquareEnvAction.doAction(false)); 600 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 601 TestMapModelHelper.checkContents(mapSquare, ob4, ob1); 602 TestMapModelHelper.checkContents(ob1, ob2); 603 TestMapModelHelper.checkContents(ob2, ob3, ob5); 604 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 605 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 606 607 // ob4 cannot move 608 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 609 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 610 TestMapModelHelper.checkContents(mapSquare, ob4, ob1); 611 TestMapModelHelper.checkContents(ob1, ob2); 612 TestMapModelHelper.checkContents(ob2, ob3, ob5); 613 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 614 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 615 } 616 617 /** 618 * Checks that {@link MoveSquareEnvAction} does work for multi-square game 619 * objects. 620 * @throws CannotInsertGameObjectException if the test fails 621 * @throws DuplicateArchetypeException if the test fails 622 */ 623 @Test 624 public void testDoMoveSquareEnvMulti3() throws CannotInsertGameObjectException, DuplicateArchetypeException { 625 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 626 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 627 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 628 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 629 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 630 631 final Point point = new Point(0, 0); 632 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 633 mapModel.beginTransaction("TEST"); 634 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); 635 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(new Point(1, 0)); 636 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 637 final TestGameObject ob2 = mapModelHelper.insertExit(ob1); 638 final TestGameObject ob3 = mapModelHelper.insertExit(ob2); 639 final TestGameObject ob4Head = mapModelHelper.insertMob21(ob2); 640 final TestGameObject ob5 = mapModelHelper.insertExit(ob2); 641 642 TestMapModelHelper.checkContents(mapSquareHead, ob1); 643 TestMapModelHelper.checkContents(ob1, ob2); 644 TestMapModelHelper.checkContents(ob2, ob3, ob4Head, ob5); 645 TestMapModelHelper.checkContents(mapSquareTail); 646 647 // empty selection => nothing to move 648 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 649 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 650 651 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 652 selectedSquareModel.setSelectedGameObject(ob4Head); 653 654 // ob4Head can move 655 Assert.assertTrue(moveSquareEnvAction.doAction(false)); 656 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 657 TestMapModelHelper.checkContents(mapSquareHead, ob1); 658 TestMapModelHelper.checkContents(ob1, ob4Head, ob2); 659 final TestGameObject ob4Tail1 = ob4Head.getMultiNext(); 660 Assert.assertNull(ob4Tail1); 661 TestMapModelHelper.checkContents(ob2, ob3, ob5); 662 TestMapModelHelper.checkContents(mapSquareTail); 663 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 664 Assert.assertEquals(ob4Head, selectedSquareModel.getSelectedGameObject()); 665 666 // ob4Head can move 667 Assert.assertTrue(moveSquareEnvAction.doAction(false)); 668 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 669 TestMapModelHelper.checkContents(mapSquareHead, ob4Head, ob1); 670 TestMapModelHelper.checkContents(ob1, ob2); 671 TestMapModelHelper.checkContents(ob2, ob3, ob5); 672 final TestGameObject ob4Tail2 = ob4Head.getMultiNext(); 673 Assert.assertNotNull(ob4Tail2); 674 TestMapModelHelper.checkContents(mapSquareTail, ob4Tail2); 675 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 676 Assert.assertEquals(ob4Head, selectedSquareModel.getSelectedGameObject()); 677 678 // ob4Head cannot move 679 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 680 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 681 TestMapModelHelper.checkContents(mapSquareHead, ob4Head, ob1); 682 TestMapModelHelper.checkContents(ob1, ob2); 683 TestMapModelHelper.checkContents(ob2, ob3, ob5); 684 Assert.assertEquals(ob4Tail2, ob4Head.getMultiNext()); 685 TestMapModelHelper.checkContents(mapSquareTail, ob4Tail2); 686 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 687 Assert.assertEquals(ob4Head, selectedSquareModel.getSelectedGameObject()); 688 } 689 690 /** 691 * Checks that {@link MoveSquareEnvAction} does work for multi-square game 692 * objects. 693 * @throws CannotInsertGameObjectException if the test fails 694 * @throws DuplicateArchetypeException if the test fails 695 */ 696 @Test 697 public void testDoMoveSquareEnvMulti4() throws CannotInsertGameObjectException, DuplicateArchetypeException { 698 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 699 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 700 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 701 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 702 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 703 704 final Point point = new Point(0, 0); 705 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 706 mapModel.beginTransaction("TEST"); 707 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); 708 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 709 final TestGameObject ob2Head = mapModelHelper.insertMob21(ob1); 710 711 TestMapModelHelper.checkContents(mapSquareHead, ob1); 712 TestMapModelHelper.checkContents(ob1, ob2Head); 713 714 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 715 selectedSquareModel.setSelectedGameObject(ob2Head); 716 717 // ob2Head cannot move: would not fit into map 718 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 719 Assert.assertFalse(moveSquareEnvAction.doAction(true)); 720 TestMapModelHelper.checkContents(mapSquareHead, ob1); 721 TestMapModelHelper.checkContents(ob1, ob2Head); 722 Assert.assertNull(ob2Head.getMultiNext()); 723 } 724 725 /** 726 * Checks that {@link MoveSquareInvAction} does work for single-square game 727 * objects. 728 * @throws CannotInsertGameObjectException if the test fails 729 * @throws DuplicateArchetypeException if the test fails 730 */ 731 @Test 732 public void testDoMoveSquareInvSingle1() throws CannotInsertGameObjectException, DuplicateArchetypeException { 733 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 734 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 735 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(1, 1)); 736 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 737 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareInvAction = new MoveSquareInvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 738 739 final Point point = new Point(0, 0); 740 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 741 mapModel.beginTransaction("TEST"); 742 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); 743 final TestGameObject ob4 = mapModelHelper.insertExit(mapModel, point); 744 final TestGameObject ob3 = mapModelHelper.insertExit(mapModel, point); 745 final TestGameObject ob2 = mapModelHelper.insertExit(mapModel, point); 746 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 747 748 TestMapModelHelper.checkContents(mapSquare, ob4, ob3, ob2, ob1); 749 750 // empty selection => nothing to move 751 Assert.assertFalse(moveSquareInvAction.doAction(false)); 752 Assert.assertFalse(moveSquareInvAction.doAction(true)); 753 754 // select ob3 755 selectedSquareModel.setSelectedMapSquare(mapSquare, null); 756 selectedSquareModel.setSelectedGameObject(ob3); 757 758 // ob3 can move 759 Assert.assertTrue(moveSquareInvAction.doAction(false)); 760 Assert.assertTrue(moveSquareInvAction.doAction(true)); 761 TestMapModelHelper.checkContents(mapSquare, ob4, ob2, ob1); 762 TestMapModelHelper.checkContents(ob2, ob3); 763 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 764 Assert.assertEquals(ob3, selectedSquareModel.getSelectedGameObject()); 765 766 // ob3 cannot move 767 Assert.assertFalse(moveSquareInvAction.doAction(false)); 768 Assert.assertFalse(moveSquareInvAction.doAction(true)); 769 TestMapModelHelper.checkContents(mapSquare, ob4, ob2, ob1); 770 TestMapModelHelper.checkContents(ob2, ob3); 771 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 772 Assert.assertEquals(ob3, selectedSquareModel.getSelectedGameObject()); 773 774 // select ob2 775 selectedSquareModel.setSelectedGameObject(ob2); 776 777 // ob2 can move 778 Assert.assertTrue(moveSquareInvAction.doAction(false)); 779 Assert.assertTrue(moveSquareInvAction.doAction(true)); 780 TestMapModelHelper.checkContents(mapSquare, ob4, ob1); 781 TestMapModelHelper.checkContents(ob1, ob2); 782 TestMapModelHelper.checkContents(ob2, ob3); 783 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 784 Assert.assertEquals(ob2, selectedSquareModel.getSelectedGameObject()); 785 786 // ob2 cannot move 787 Assert.assertFalse(moveSquareInvAction.doAction(false)); 788 Assert.assertFalse(moveSquareInvAction.doAction(true)); 789 TestMapModelHelper.checkContents(mapSquare, ob4, ob1); 790 TestMapModelHelper.checkContents(ob1, ob2); 791 TestMapModelHelper.checkContents(ob2, ob3); 792 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 793 Assert.assertEquals(ob2, selectedSquareModel.getSelectedGameObject()); 794 795 // select ob4 796 selectedSquareModel.setSelectedGameObject(ob4); 797 798 // ob4 can move 799 Assert.assertTrue(moveSquareInvAction.doAction(false)); 800 Assert.assertTrue(moveSquareInvAction.doAction(true)); 801 TestMapModelHelper.checkContents(mapSquare, ob1); 802 TestMapModelHelper.checkContents(ob1, ob4, ob2); 803 TestMapModelHelper.checkContents(ob2, ob3); 804 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 805 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 806 807 // ob4 can move 808 Assert.assertTrue(moveSquareInvAction.doAction(false)); 809 Assert.assertTrue(moveSquareInvAction.doAction(true)); 810 TestMapModelHelper.checkContents(mapSquare, ob1); 811 TestMapModelHelper.checkContents(ob1, ob2); 812 TestMapModelHelper.checkContents(ob2, ob4, ob3); 813 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 814 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 815 816 // ob4 can move 817 Assert.assertTrue(moveSquareInvAction.doAction(false)); 818 Assert.assertTrue(moveSquareInvAction.doAction(true)); 819 TestMapModelHelper.checkContents(mapSquare, ob1); 820 TestMapModelHelper.checkContents(ob1, ob2); 821 TestMapModelHelper.checkContents(ob2, ob3); 822 TestMapModelHelper.checkContents(ob3, ob4); 823 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 824 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 825 826 // ob4 cannot move 827 Assert.assertFalse(moveSquareInvAction.doAction(false)); 828 Assert.assertFalse(moveSquareInvAction.doAction(true)); 829 TestMapModelHelper.checkContents(mapSquare, ob1); 830 TestMapModelHelper.checkContents(ob1, ob2); 831 TestMapModelHelper.checkContents(ob2, ob3); 832 TestMapModelHelper.checkContents(ob3, ob4); 833 Assert.assertEquals(mapSquare, selectedSquareModel.getSelectedMapSquare()); 834 Assert.assertEquals(ob4, selectedSquareModel.getSelectedGameObject()); 835 } 836 837 /** 838 * Checks that {@link MoveSquareInvAction} does work for multi-square game 839 * objects. 840 * @throws CannotInsertGameObjectException if the test fails 841 * @throws DuplicateArchetypeException if the test fails 842 */ 843 @Test 844 public void testDoMoveSquareInvMulti1() throws CannotInsertGameObjectException, DuplicateArchetypeException { 845 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 846 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 847 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 848 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 849 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareInvAction = new MoveSquareInvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 850 851 final Point point = new Point(0, 0); 852 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 853 mapModel.beginTransaction("TEST"); 854 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); 855 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(new Point(1, 0)); 856 final TestGameObject ob3Head = mapModelHelper.insertMob21(mapModel, point); 857 final TestGameObject ob1 = mapModelHelper.insertExit(mapModel, point); 858 final TestGameObject ob2 = mapModelHelper.insertExit(ob1); 859 860 final TestGameObject ob3Tail = ob3Head.getMultiNext(); 861 Assert.assertNotNull(ob3Tail); 862 TestMapModelHelper.checkContents(mapSquareHead, ob3Head, ob1); 863 TestMapModelHelper.checkContents(mapSquareTail, ob3Tail); 864 TestMapModelHelper.checkContents(ob1, ob2); 865 866 // empty selection => nothing to move 867 Assert.assertFalse(moveSquareInvAction.doAction(false)); 868 Assert.assertFalse(moveSquareInvAction.doAction(true)); 869 870 // select ob3Head 871 selectedSquareModel.setSelectedMapSquare(mapSquareHead, null); 872 selectedSquareModel.setSelectedGameObject(ob3Head); 873 874 // ob3Head can move; ob3Tail is removed 875 Assert.assertTrue(moveSquareInvAction.doAction(false)); 876 Assert.assertTrue(moveSquareInvAction.doAction(true)); 877 TestMapModelHelper.checkContents(mapSquareHead, ob1); 878 TestMapModelHelper.checkContents(mapSquareTail); 879 TestMapModelHelper.checkContents(ob1, ob3Head, ob2); 880 Assert.assertNull(ob3Head.getMultiNext()); 881 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 882 Assert.assertEquals(ob3Head, selectedSquareModel.getSelectedGameObject()); 883 884 // ob3Head can move 885 Assert.assertTrue(moveSquareInvAction.doAction(false)); 886 Assert.assertTrue(moveSquareInvAction.doAction(true)); 887 TestMapModelHelper.checkContents(mapSquareHead, ob1); 888 TestMapModelHelper.checkContents(mapSquareTail); 889 TestMapModelHelper.checkContents(ob1, ob2); 890 TestMapModelHelper.checkContents(ob2, ob3Head); 891 Assert.assertNull(ob3Head.getMultiNext()); 892 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 893 Assert.assertEquals(ob3Head, selectedSquareModel.getSelectedGameObject()); 894 895 // ob3Head cannot move 896 Assert.assertFalse(moveSquareInvAction.doAction(false)); 897 Assert.assertFalse(moveSquareInvAction.doAction(true)); 898 TestMapModelHelper.checkContents(mapSquareHead, ob1); 899 TestMapModelHelper.checkContents(mapSquareTail); 900 TestMapModelHelper.checkContents(ob1, ob2); 901 TestMapModelHelper.checkContents(ob2, ob3Head); 902 Assert.assertNull(ob3Head.getMultiNext()); 903 Assert.assertEquals(mapSquareHead, selectedSquareModel.getSelectedMapSquare()); 904 Assert.assertEquals(ob3Head, selectedSquareModel.getSelectedGameObject()); 905 } 906 907 /** 908 * Checks that {@link MoveSquareInvAction} always inserts into the 909 * head-part. 910 * @throws CannotInsertGameObjectException if the test fails 911 * @throws DuplicateArchetypeException if the test fails 912 */ 913 @Test 914 public void testDoMoveSquareInvIntoHead1() throws CannotInsertGameObjectException, DuplicateArchetypeException { 915 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 916 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 917 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(3, 1)); 918 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 919 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareInvAction = new MoveSquareInvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 920 921 final Point point0 = new Point(0, 0); 922 final Point point1 = new Point(1, 0); 923 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 924 mapModel.beginTransaction("TEST"); 925 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare0 = mapModel.getMapSquare(point0); 926 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare1 = mapModel.getMapSquare(point1); 927 final TestGameObject ob2 = mapModelHelper.insertMob21(mapModel, point1); 928 final TestGameObject ob1 = mapModelHelper.insertMob21(mapModel, point0); 929 930 TestMapModelHelper.checkMapContents(mapModel, "mob21|mob21,mob21b|mob21b"); 931 932 // select ob2 933 selectedSquareModel.setSelectedMapSquare(mapSquare1, null); 934 selectedSquareModel.setSelectedGameObject(ob2); 935 936 // move ob2 into ob1 937 Assert.assertTrue(moveSquareInvAction.doAction(true)); 938 939 TestMapModelHelper.checkMapContents(mapModel, "mob21|mob21b|"); 940 TestMapModelHelper.checkContents(mapSquare0, ob1); 941 final TestGameObject ob1Tail = ob1.getMultiNext(); 942 Assert.assertNotNull(ob1Tail); 943 TestMapModelHelper.checkContents(mapSquare1, ob1Tail); 944 TestMapModelHelper.checkContents(ob1, ob2); 945 } 946 947 /** 948 * Checks that tail parts cannot be moved. 949 * @throws CannotInsertGameObjectException if the test fails 950 * @throws DuplicateArchetypeException if the test fails 951 */ 952 @Test 953 public void testMoveTailPart() throws CannotInsertGameObjectException, DuplicateArchetypeException { 954 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 955 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 956 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(2, 1)); 957 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 958 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareTopAction = new MoveSquareTopAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 959 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareUpAction = new MoveSquareUpAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 960 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareDownAction = new MoveSquareDownAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 961 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareBottomAction = new MoveSquareBottomAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 962 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareInvAction = new MoveSquareInvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 963 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 964 965 final Point pointHead = new Point(0, 0); 966 final Point pointTail = new Point(1, 0); 967 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 968 mapModel.beginTransaction("TEST"); 969 final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); 970 mapModelHelper.insertExit(mapModel, pointHead); 971 mapModelHelper.insertExit(mapModel, pointTail); 972 final TestGameObject ob2Head = mapModelHelper.insertMob21(mapModel, pointHead); 973 mapModelHelper.insertExit(mapModel, pointHead); 974 mapModelHelper.insertExit(mapModel, pointTail); 975 976 TestMapModelHelper.checkMapContents(mapModel, "exit,mob21,exit|exit,mob21b,exit"); 977 978 // select ob2Tail 979 selectedSquareModel.setSelectedMapSquare(mapSquareTail, null); 980 selectedSquareModel.setSelectedGameObject(ob2Head.getMultiNext()); 981 982 // ob2Tail cannot move 983 Assert.assertFalse(moveSquareTopAction.doAction(false)); 984 Assert.assertFalse(moveSquareUpAction.doAction(false)); 985 Assert.assertFalse(moveSquareDownAction.doAction(false)); 986 Assert.assertFalse(moveSquareBottomAction.doAction(false)); 987 Assert.assertFalse(moveSquareInvAction.doAction(false)); 988 Assert.assertFalse(moveSquareEnvAction.doAction(false)); 989 } 990 991 /** 992 * Checks that {@link MoveSquareEnvAction} inserts into selected map 993 * square. 994 * @throws CannotInsertGameObjectException if the test fails 995 * @throws DuplicateArchetypeException if the test fails 996 */ 997 @Test 998 public void testMoveEnvIntoSelectedMapSquare() throws CannotInsertGameObjectException, DuplicateArchetypeException { 999 final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); 1000 final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator(); 1001 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(3, 1)); 1002 final SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareModel = new SelectedSquareModel<TestGameObject, TestMapArchObject, TestArchetype>(); 1003 final AbstractMoveSquareAction<TestGameObject, TestMapArchObject, TestArchetype> moveSquareEnvAction = new MoveSquareEnvAction<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel, null); 1004 1005 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); 1006 mapModel.beginTransaction("TEST"); 1007 final TestGameObject ob1 = mapModelHelper.insertMob21(mapModel, new Point(0, 0)); 1008 final TestGameObject ob2 = mapModelHelper.insertMob21(ob1); 1009 1010 TestMapModelHelper.checkMapContents(mapModel, "mob21|mob21b|"); 1011 1012 // select ob2 in (1,0) 1013 selectedSquareModel.setSelectedMapSquare(mapModel.getMapSquare(new Point(1, 0)), null); 1014 selectedSquareModel.setSelectedGameObject(ob2); 1015 1016 // move ob2 into (1,0) 1017 Assert.assertTrue(moveSquareEnvAction.doAction(true)); 1018 1019 TestMapModelHelper.checkMapContents(mapModel, "mob21|mob21,mob21b|mob21b"); 1020 } 1021 1022}