Task 5 fixed with the shapes
Signed-off-by: Immanuel Alvaro Bhirawa <u7280427@anu.edu.au>
This commit is contained in:
parent
c633c8188f
commit
187e66b5e7
@ -1,5 +1,7 @@
|
||||
package comp1110.ass2;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
@ -199,12 +201,136 @@ public class BlueLagoon {
|
||||
* Importantly, players can now only play on the sea if it is
|
||||
* adjacent to a piece they already own.
|
||||
*
|
||||
* @param stateString a string representing a game state
|
||||
* @param moveString a string representing the current player's move
|
||||
// * @param stateString a string representing a game state
|
||||
// * @param moveString a string representing the current player's move
|
||||
* @return true if the current player can make the move and false otherwise
|
||||
*
|
||||
* * move = pieceType, " ", coordinate
|
||||
* *
|
||||
* * pieceType = "S" | "T"
|
||||
* *
|
||||
* * currentStateStatement = "c ", playerId, " ", phase, ";"
|
||||
* *
|
||||
* * phase = "E" | "S"
|
||||
* *
|
||||
* *
|
||||
* * c 0 E; S 2,3
|
||||
*/
|
||||
public static boolean isMoveValid(String stateString, String moveString){
|
||||
return false; // FIXME Task 7
|
||||
public static void main(String[] args) {
|
||||
isMoveValid("a 13 2; c 0 E; i 6 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 1,4 2,0 2,1; i 6 0,5 0,6 0,7 1,6 1,7 1,8 2,6 2,7 2,8 3,7 3,8; i 6 7,12 8,11 9,11 9,12 10,10 10,11 11,10 11,11 11,12 12,10 12,11; i 8 0,9 0,10 0,11 1,10 1,11 1,12 2,10 2,11 3,10 3,11 3,12 4,10 4,11 5,11 5,12; i 8 4,0 5,0 5,1 6,0 6,1 7,0 7,1 7,2 8,0 8,1 8,2 9,0 9,1 9,2; i 8 10,3 10,4 11,0 11,1 11,2 11,3 11,4 11,5 12,0 12,1 12,2 12,3 12,4 12,5; i 10 3,3 3,4 3,5 4,2 4,3 4,4 4,5 5,3 5,4 5,5 5,6 6,3 6,4 6,5 6,6 7,4 7,5 7,6 8,4 8,5; i 10 5,8 5,9 6,8 6,9 7,8 7,9 7,10 8,7 8,8 8,9 9,7 9,8 9,9 10,6 10,7 10,8 11,7 11,8 12,7 12,8; s 0,0 0,5 0,9 1,4 1,8 1,12 2,1 3,5 3,7 3,10 3,12 4,0 4,2 5,9 5,11 6,3 6,6 7,0 7,8 7,12 8,2 8,5 9,0 9,9 10,3 10,6 10,10 11,0 11,5 12,2 12,8 12,11; r C B W P S; p 0 0 0 0 0 0 0 S T; p 1 0 0 0 0 0 0 S T;", "S 2,3" );
|
||||
}
|
||||
public static boolean isMoveValid(String stateString, String moveString) {
|
||||
if (!isStateStringWellFormed(stateString)) return false;
|
||||
if (moveString == "") return false; // checking if the players have any pieces left to move
|
||||
|
||||
String[] parts = stateString.split("; ?");
|
||||
for (String part : parts) {
|
||||
String[] parseSplit = part.split(" ");
|
||||
String stateCases = parseSplit[0];
|
||||
|
||||
// Collect the island coordinates into 1 single array first
|
||||
// Then use .contains for each resource pos and island pos
|
||||
// to check whether that pos is unoccupied or not
|
||||
|
||||
ArrayList<String> coordsContainer = new ArrayList<>();
|
||||
switch (stateCases) {
|
||||
case "i":
|
||||
for (int i = 2; i < parseSplit.length; i++) {
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
}
|
||||
break;
|
||||
case "c":
|
||||
String currentPhase = parseSplit[2];
|
||||
switch (currentPhase) {
|
||||
case "E":
|
||||
|
||||
break;
|
||||
case "S":
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "r":
|
||||
for (int i = 1; i < parseSplit.length; i++) {
|
||||
switch (parseSplit[i]) {
|
||||
case "C":
|
||||
i++; // To Skip the "C" itself and go to the numbers in the string
|
||||
while (!parseSplit[i].equals("B")) {
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
i++; // To continue the iteration for the while loops
|
||||
}
|
||||
i--; // So that i does not go straight to the coords after the letters instead
|
||||
// i stop at the letter "B"
|
||||
break;
|
||||
|
||||
// Generating Resource: Bamboo Tiles
|
||||
case "B":
|
||||
i++; // To Skip the "B" itself and go to the numbers in the string
|
||||
while (!parseSplit[i].equals("W")) {
|
||||
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
i++; // To continue the iteration for the while loops
|
||||
}
|
||||
i--; // So that i does not go straight to the coords after the letters instead
|
||||
// i stop at the letter "W"
|
||||
break;
|
||||
|
||||
// Generating Resource: Water tiles
|
||||
case "W":
|
||||
i++; // To Skip the "W" itself and go to the numbers in the string
|
||||
while (!parseSplit[i].equals("P")) {
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
i++; // To continue the iteration for the while loops
|
||||
}
|
||||
i--; // So that i does not go straight to the coords after the letters instead
|
||||
// i stop at the letter "P"
|
||||
break;
|
||||
|
||||
// Generating Resource: Precious Stone tiles
|
||||
case "P":
|
||||
i++; // To Skip the "P" itself and go to the numbers in the string
|
||||
while (!parseSplit[i].equals("S")) {
|
||||
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
i++; // To continue the iteration for the while loops
|
||||
}
|
||||
i--; // So that i does not go straight to the coords after the letters instead
|
||||
// i stop at the letter "S"
|
||||
break;
|
||||
|
||||
// Generating Resource: Statuettes tiles
|
||||
case "S":
|
||||
i++; // To Skip the "P" itself and go to the numbers in the string
|
||||
while (i < parseSplit.length) {
|
||||
|
||||
String coords = parseSplit[i];
|
||||
coordsContainer.add(coords);
|
||||
System.out.println(coords);
|
||||
System.out.println(coordsContainer);
|
||||
i++; // To continue the iteration for the while loops
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,7 +210,7 @@ public class Viewer extends Application {
|
||||
// Generating the Stone Tiles from the Stone Statement
|
||||
case "s":
|
||||
for(int i = 1; i < parseSplit.length; i++){
|
||||
addTileToBoard(viewerGrid, tileSize, parseSplit[i], Color.GRAY);
|
||||
addStoneTileToBoard(viewerGrid, tileSize, parseSplit[i], Color.GRAY);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -318,7 +318,7 @@ public class Viewer extends Application {
|
||||
String[] coords = parseSplit[i].split(",");
|
||||
|
||||
// Tile generator
|
||||
addTileToBoard(viewerGrid, tileSize, parseSplit[i], Color.PINK);
|
||||
addStoneTileToBoard(viewerGrid, tileSize, parseSplit[i], Color.PINK);
|
||||
|
||||
// Label generator
|
||||
addSmallLabelToTile(viewerGrid, tileSize, parseSplit[i], Color.BLACK, "Settlers");
|
||||
@ -339,7 +339,7 @@ public class Viewer extends Application {
|
||||
String[] coords = parseSplit[i].split(",");
|
||||
|
||||
// Tile generator
|
||||
addTileToBoard(viewerGrid, tileSize, parseSplit[i], Color. LIGHTGOLDENRODYELLOW);
|
||||
addStoneTileToBoard(viewerGrid, tileSize, parseSplit[i], Color. LIGHTGOLDENRODYELLOW);
|
||||
|
||||
// Label generator
|
||||
addSmallLabelToTile(viewerGrid, tileSize, parseSplit[i], Color.BLACK, "Village");
|
||||
@ -388,7 +388,7 @@ public class Viewer extends Application {
|
||||
}
|
||||
|
||||
// Generating the small tiles such as resources, stones, etc
|
||||
void addTileToBoard(GridPane board, int tileSize, String coordString, Color color) {
|
||||
void addStoneTileToBoard(GridPane board, int tileSize, String coordString, Color color) {
|
||||
int tileSize2 = tileSize;
|
||||
tileSize2 -= 15;
|
||||
|
||||
@ -407,6 +407,25 @@ public class Viewer extends Application {
|
||||
board.add(hex, Integer.parseInt(coords[1]), Integer.parseInt(coords[0]));
|
||||
}
|
||||
|
||||
void addTileToBoard(GridPane board, int tileSize, String coordString, Color color) {
|
||||
int tileSize2 = tileSize;
|
||||
tileSize2 -= 25;
|
||||
|
||||
// If the string empty, stop the function
|
||||
if (coordString.equals("")) return;
|
||||
String[] coords = coordString.split(",");
|
||||
Hexagon hex = new Hexagon(tileSize2, color);
|
||||
|
||||
// if the row is even, translate the tile to the right by tileSize/2
|
||||
if (Integer.parseInt(coords[0]) % 2 == 0) hex.setTranslateX(tileSize/2);
|
||||
// Translate the whole tile's Y axis downwards so they connect and there's no gap
|
||||
hex.setTranslateY(Integer.parseInt(coords[0]) * -0.25 * tileSize);
|
||||
|
||||
// Translate the tile so they look center
|
||||
hex.setTranslateX(12 + hex.getTranslateX());
|
||||
board.add(hex, Integer.parseInt(coords[1]), Integer.parseInt(coords[0]));
|
||||
}
|
||||
|
||||
// Adding labels to the resources tiles and stones tiles
|
||||
void addLabelToTile(GridPane board, int tileSize, String coordString, Color color, String labelName){
|
||||
// If the string empty, stop the function
|
||||
@ -421,7 +440,7 @@ public class Viewer extends Application {
|
||||
newLabel.setTranslateY(Integer.parseInt(coords[0]) * -0.25 * tileSize);
|
||||
|
||||
// Making the label center
|
||||
newLabel.setTranslateX(20 + newLabel.getTranslateX());
|
||||
newLabel.setTranslateX(19.5 + newLabel.getTranslateX());
|
||||
board.add(newLabel, Integer.parseInt(coords[1]), Integer.parseInt(coords[0]));
|
||||
}
|
||||
|
||||
@ -439,7 +458,7 @@ public class Viewer extends Application {
|
||||
newLabel.setTranslateY(Integer.parseInt(coords[0]) * -0.25 * tileSize);
|
||||
|
||||
// Making the label center
|
||||
newLabel.setTranslateX(9 + newLabel.getTranslateX());
|
||||
newLabel.setTranslateX(11 + newLabel.getTranslateX());
|
||||
board.add(newLabel, Integer.parseInt(coords[1]), Integer.parseInt(coords[0]));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user