diff --git a/source/core/assets/images/ingamebg.png b/source/core/assets/images/ingamebg.png index 0fbc1c543..2301477d4 100644 Binary files a/source/core/assets/images/ingamebg.png and b/source/core/assets/images/ingamebg.png differ diff --git a/source/core/assets/images/terrain_use.png b/source/core/assets/images/terrain_use.png index 59ddab66d..698343323 100644 Binary files a/source/core/assets/images/terrain_use.png and b/source/core/assets/images/terrain_use.png differ diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index a3bde2263..2ccb749db 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -45,7 +45,9 @@ public class ForestGameArea extends GameArea { private static final int NUM_WEAPON_TOWERS = 3; - private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 0); + + private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(1, 4); + // Temporary spawn point for testing private static final float WALL_WIDTH = 0.1f; diff --git a/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java b/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java index 991a3589d..794878666 100644 --- a/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java +++ b/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java @@ -152,6 +152,111 @@ private void fillInvisibleTiles(TiledMapTileLayer layer, GridPoint2 mapSize) { } } +//tile class + public static class Tile { + private int row; + private int col; + private Object object; + + public Tile(int row, int col) { + this.row = row; + this.col = col; + this.object = null; // Initially, no object is placed on the tile + } + + public void setObject(Object object) { + this.object = object; + } + + public Object getObject() { + return object; + } + + public String getLogCoordinates() { + return "(" + row + ", " + col + ")"; + } + } + +// grid class +public static class Grid { + private Tile[][] tiles; + + public Grid(int numRows, int numCols) { + tiles = new Tile[numRows][numCols]; + + for (int row = 0; row < numRows; row++) { + for (int col = 0; col < numCols; col++) { + tiles[row][col] = new Tile(row,col); + } + } + } + + public void placeObject(int row, int col, Object object) { + if (isValidCoordinate(row, col)) { + tiles[row][col].setObject(object); + } else { + System.out.println("Invalid coordinates."); + } + } + + public Object getObject(int row, int col) { + if (isValidCoordinate(row, col)) { + return tiles[row][col].getObject(); + } else { + System.out.println("Invalid coordinates."); + return null; + } + } + + public String getLogCoordinates(int row, int col) { + if (isValidCoordinate(row, col)) { + return tiles[row][col].getLogCoordinates(); + } else { + return "Invalid coordinates."; + } + } + + private boolean isValidCoordinate(int row, int col) { + return row >= 0 && row < tiles.length && col >= 0 && col < tiles[0].length; + } + + public void placeEntity(int row, int col, Object existingEntity) { + } + + public Object getEntity(int row, int col) { + return null; + } +} + +// Array class 1+2 +public class Array { + public static void main(String[] args) { + int numRows = 8; + int numCols = 20; + + Grid grid = new Grid(numRows, numCols); + + // Place an existing entity in a specific tile + int row = 3; + int col = 5; + // Replace 'Object' with the type of existing entity you want to place + Object existingEntity = new YourExistingEntity(); + + grid.placeEntity(row, col, existingEntity); + + // Get the entity from a tile + Object entity = grid.getEntity(row, col); + System.out.println("Entity at " + grid.getLogCoordinates(row, col) + ": " + entity); + } + + private static class YourExistingEntity { + } +} + + + + + private static void fillTiles(TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile) { BitmapFont font = new BitmapFont(); TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); diff --git a/source/core/src/main/com/csse3200/game/utils/math/GridPoint2Utils.java b/source/core/src/main/com/csse3200/game/utils/math/GridPoint2Utils.java index af3b20287..332e029af 100644 --- a/source/core/src/main/com/csse3200/game/utils/math/GridPoint2Utils.java +++ b/source/core/src/main/com/csse3200/game/utils/math/GridPoint2Utils.java @@ -6,9 +6,14 @@ * Contains additional utility constants and functions for common GridPoint2 operations. */ public class GridPoint2Utils { - public static final GridPoint2 ZERO = new GridPoint2(0, 4); + public static final GridPoint2 ZERO = new GridPoint2(0, 0); + private GridPoint2Utils() { throw new IllegalStateException("Instantiating static util class"); } + + public static GridPoint2Utils createInstance() { + return new GridPoint2Utils(); + } } diff --git a/source/core/src/test/com/csse3200/game/utils/math/GridPoint2UtilsTest.java b/source/core/src/test/com/csse3200/game/utils/math/GridPoint2UtilsTest.java new file mode 100644 index 000000000..354b7dfe9 --- /dev/null +++ b/source/core/src/test/com/csse3200/game/utils/math/GridPoint2UtilsTest.java @@ -0,0 +1,30 @@ +package com.csse3200.game.utils.math; + +import com.badlogic.gdx.math.GridPoint2; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class GridPoint2UtilsTest { + + /** + * testZero() ensures that GridPoint2Utils.ZERO constant is (0, 0). + * GridPoint2Utils.ZERO is a constant representing the point (0, 0). + */ + @Test + public void testZero() { + GridPoint2 zero = GridPoint2Utils.ZERO; + assertEquals(0, zero.x); + assertEquals(0, zero.y); + } + + /** + * testInstantiation() checks if private constructor of GridPoint2Utils throws an exception + * while creating an instance. + */ + @Test + public void testInstantiation() { + assertThrows(IllegalStateException.class, () -> { + GridPoint2Utils.createInstance(); + }); + } +} \ No newline at end of file