Skip to content

Commit

Permalink
Merge pull request #130 from UQcsse3200/Team-3-maps-main
Browse files Browse the repository at this point in the history
Team 3 maps main
  • Loading branch information
Moksh-Mehta7 authored Sep 10, 2023
2 parents ad3e412 + 5beb7c0 commit fa8df71
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 2 deletions.
Binary file modified source/core/assets/images/ingamebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/terrain_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
});
}
}

0 comments on commit fa8df71

Please sign in to comment.