tests improvements
This commit is contained in:
@@ -202,33 +202,6 @@ public class DeckGridAppFX extends Application {
|
||||
|
||||
}
|
||||
|
||||
private void pickTopCardAction(Player player, GameBoard board, int cardid){
|
||||
Card card = board.getTopRow().stream()
|
||||
.filter(CharacterCard.class::isInstance)
|
||||
.map(CharacterCard.class::cast)
|
||||
.filter(c -> c.getCardId() == cardid)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (card != null) {
|
||||
board.getTopRow().remove(card);
|
||||
CharacterCard charCard = (CharacterCard)card;
|
||||
player.addCharacterToTribe((CharacterCard) card);
|
||||
}
|
||||
}
|
||||
|
||||
private void pickBottomCardAction(Player player, GameBoard board, int cardid){
|
||||
Card card = board.getBottomRow().stream()
|
||||
.filter(CharacterCard.class::isInstance)
|
||||
.map(CharacterCard.class::cast)
|
||||
.filter(c -> c.getCardId() == cardid)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (card != null) {
|
||||
board.getBottomRow().remove(card);
|
||||
player.addCharacterToTribe((CharacterCard) card);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawBottomRow(HBox row, Game game) {
|
||||
@@ -271,9 +244,6 @@ public class DeckGridAppFX extends Application {
|
||||
}
|
||||
}
|
||||
private void drawTopMenu(HBox row, Game game) {
|
||||
//topMenu = new HBox(15, btnChooseOffering, btnAction, btnTop, btnBottom, btnMsg);
|
||||
//topMenu.setAlignment(Pos.CENTER);
|
||||
//topMenu.setPadding(new Insets(10));
|
||||
|
||||
Label stateLabel = new Label("Game State = " + game.getState() );
|
||||
stateLabel.setFont(Font.font("System", FontWeight.BOLD, 16));
|
||||
@@ -281,9 +251,6 @@ public class DeckGridAppFX extends Application {
|
||||
row.getChildren().add(stateLabel);
|
||||
row.getChildren().add(btnRefresh);
|
||||
row.getChildren().add(btnMsg);
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void drawTopRow(HBox row, Game game) {
|
||||
for (Card c : game.getGameBoard().getTopRow()) {
|
||||
@@ -310,8 +277,6 @@ public class DeckGridAppFX extends Application {
|
||||
cardImage.setOnMouseClicked(event -> {
|
||||
logger.info("Card clicked");
|
||||
Player p = game.getCurrentPlayer();
|
||||
//pickTopCardAction(p, game.getGameBoard(), c.getCardId());
|
||||
//game.resolveCardAction(p, true, c.getCardId());
|
||||
|
||||
ActionResult result = game.resolveCardAction(p, true, c.getCardId());
|
||||
if (!result.isSuccess()) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import server.cards.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
|
||||
/**
|
||||
@@ -357,6 +357,14 @@ public class GameBoard {
|
||||
return events;
|
||||
}
|
||||
|
||||
public int getOfferingIdxFromLetter(char letter) {
|
||||
List<OfferingTile> tiles = getOfferingTiles();
|
||||
|
||||
return IntStream.range(0, tiles.size())
|
||||
.filter(i -> tiles.get(i).getLetter() == letter)
|
||||
.findFirst()
|
||||
.orElse(-1);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helpers
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package server.utils;
|
||||
|
||||
import server.GameBoard;
|
||||
import server.OfferingTile;
|
||||
import server.Player;
|
||||
import server.TurnTile;
|
||||
@@ -31,17 +32,39 @@ public class GameUtils {
|
||||
sb.append("[TURN ORDER]\n");
|
||||
for (int i = 0; i < t.getPositions().length; i++) {
|
||||
Player p = t.getPositions()[i];
|
||||
|
||||
sb.append(" ").append(i + 1).append(". ")
|
||||
.append(p.toString()+ "\n");
|
||||
.append((p!=null? p.toString():"")+ "\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String formatOffTile(OfferingTile o) {
|
||||
|
||||
|
||||
return null;
|
||||
private void pickBottomCardAction(Player player, GameBoard board, int cardid){
|
||||
Card card = board.getBottomRow().stream()
|
||||
.filter(CharacterCard.class::isInstance)
|
||||
.map(CharacterCard.class::cast)
|
||||
.filter(c -> c.getCardId() == cardid)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (card != null) {
|
||||
board.getBottomRow().remove(card);
|
||||
player.addCharacterToTribe((CharacterCard) card);
|
||||
}
|
||||
}
|
||||
|
||||
private void pickTopCardAction(Player player, GameBoard board, int cardid){
|
||||
Card card = board.getTopRow().stream()
|
||||
.filter(CharacterCard.class::isInstance)
|
||||
.map(CharacterCard.class::cast)
|
||||
.filter(c -> c.getCardId() == cardid)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (card != null) {
|
||||
board.getTopRow().remove(card);
|
||||
CharacterCard charCard = (CharacterCard)card;
|
||||
player.addCharacterToTribe((CharacterCard) card);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package server.automaton;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import server.Player;
|
||||
import server.TotemColor;
|
||||
import server.*;
|
||||
import server.cards.BuildingCard;
|
||||
import server.cards.Card;
|
||||
import server.cards.CharacterCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -11,18 +14,25 @@ import static server.utils.GameUtils.formatTurnTile;
|
||||
|
||||
class GameTest {
|
||||
|
||||
@Test
|
||||
void newGame() {
|
||||
private Game game;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(){
|
||||
List<Player> players = new ArrayList<>();
|
||||
players.add(new Player("Yellow", TotemColor.YELLOW));
|
||||
players.add(new Player("Blue", TotemColor.BLUE));
|
||||
players.add(new Player("Purple", TotemColor.PURPLE));
|
||||
players.add(new Player("Red", TotemColor.RED));
|
||||
players.add(new Player("Green", TotemColor.GREEN));
|
||||
//players.add(new Player("Green", TotemColor.GREEN));
|
||||
//players.add(new Player("Purple", TotemColor.PURPLE));
|
||||
|
||||
Game game = new Game(players);
|
||||
|
||||
game = new Game(players);
|
||||
game.newGame(getClass().getResourceAsStream("/files/cards.csv"));
|
||||
System.out.println("Current Player " +game.getCurrentPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
void newGame() {
|
||||
System.out.println("Round " + game.getRound());
|
||||
System.out.println("Game State " + game.getState());
|
||||
|
||||
@@ -31,14 +41,63 @@ class GameTest {
|
||||
|
||||
System.out.println("______ Top _________ \n" + game.getGameBoard().getTopRow());
|
||||
System.out.println("______ Bottom _________ \n" + game.getGameBoard().getBottomRow());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void placeTotem() {
|
||||
int i=0;System.out.println(game.getGameBoard().getTurnTile().getReturnedCount());
|
||||
System.out.println(game.getGameBoard().getTurnTile().getPositions().length);
|
||||
for(Player p : game.getGameBoard().getTurnTile().getPositions()){
|
||||
Player current = game.getCurrentPlayer();
|
||||
System.out.println((i++)+" " +current);
|
||||
|
||||
OfferingTile ot =game.getGameBoard().getOfferingTiles().stream().filter(o->o.isEmpty()).findFirst().orElse(null);
|
||||
int idx =game.getGameBoard().getOfferingIdxFromLetter(ot.getLetter());
|
||||
boolean ok =game.placeTotem(current, idx);
|
||||
System.out.println("-- Turn Tile --\n" +formatTurnTile( game.getGameBoard().getTurnTile()));
|
||||
System.out.println("---- Offering Tiles ----\n" + game.getGameBoard().getOfferingTiles());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveCardAction() {
|
||||
placeTotem();
|
||||
|
||||
System.out.println(game.getState());
|
||||
game.getGameBoard()
|
||||
.getOfferingTiles()
|
||||
.stream()
|
||||
.filter(o -> !o.isEmpty())
|
||||
.forEach(
|
||||
o -> {
|
||||
Player p = o.getOccupant();
|
||||
if (o.getActions().size()==3){
|
||||
System.out.println("AZIONE FOOD ");
|
||||
|
||||
} else {
|
||||
for (Symbol act : o.getActions()){
|
||||
if (Symbol.UP.equals(act)){
|
||||
Card ctop = game.getGameBoard().getTopRow().stream().filter(s -> s instanceof CharacterCard || s instanceof BuildingCard).findFirst().orElse(null);
|
||||
ActionResult result = game.resolveCardAction(p, true, ctop.getCardId());
|
||||
System.out.println(result);
|
||||
}
|
||||
if (Symbol.DOWN.equals(act)){
|
||||
Card cdown = game.getGameBoard().getBottomRow().stream().filter(s -> s instanceof CharacterCard || s instanceof BuildingCard).findFirst().orElse(null);
|
||||
ActionResult result = game.resolveCardAction(p, false, cdown.getCardId());
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user