Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Cli: BugFix related to chracter cards
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriele-caliandro committed Jul 1, 2022
1 parent 53ce220 commit ace3fb5
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ connected clients and multiple games.
* `4 players`: a 4 players' game can be played
* `Multiple games`: every game has an associated game code (e.g. `ABCD`). The player must supply one when trying to join
a game, and it is returned one after the creation of a new game. A list of available games to join is provided in UIs.
* `Player reconnections`: the server keep a heartbeat running with all clients (`PING` and `PONG` messages are used).
* `Player reconnections`: the server keeps a heartbeat running with all clients (`PING` and `PONG` messages are used).
Once the heartbeat fails, the client is marked as disconnected in the game lobby, and the game continues skipping
disconnected players. A player may also disconnect voluntarily from a game. Once it is reconnected, a copy of the game
state gets sent to that player.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/it/polimi/ingsw/eriantys/cli/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ final protected int getNumber() {
while (true) {
try {
line = getKeyboardInput();
return Integer.parseInt(line);
int number = Integer.parseInt(line);
return number;
} catch (NumberFormatException e) {
out.print("Must insert a number, insert again: ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
import it.polimi.ingsw.eriantys.controller.Controller;
import it.polimi.ingsw.eriantys.model.GameState;
import it.polimi.ingsw.eriantys.model.entities.character_cards.CharacterCard;
import it.polimi.ingsw.eriantys.model.entities.character_cards.CharacterCardEnum;
import it.polimi.ingsw.eriantys.model.entities.character_cards.ColorInputCards;
import it.polimi.ingsw.eriantys.model.entities.character_cards.IslandInputCards;

import java.beans.PropertyChangeEvent;
import java.util.List;

import static it.polimi.ingsw.eriantys.controller.EventType.INPUT_ENTERED;
import static it.polimi.ingsw.eriantys.model.enums.HouseColor.*;

public class MenuEffect extends MenuGame {
public MenuEffect() {
super();
addListeningEvents();
}

private void addListeningEvents() {
eventsToBeListening.forEach(eventType -> controller.addListener(this, eventType.tag));
}

private void removeListeningEvents() {
eventsToBeListening.forEach(eventType -> controller.removeListener(this, eventType.tag));
}

@Override
Expand Down Expand Up @@ -60,10 +71,10 @@ public MenuEnum show() {
waitForGreenLight();
out.println("Card activated. ", GREEN);
new CharacterCardsView(List.of(cc)).draw(out);
if (studentsLeftToMove() == 0)
if (studentsLeftToMove() == 0) {
removeListeningEvents();
return MenuEnum.MOVING;
else
return MenuEnum.PLACING;
}
}

// Print reasons why action is invalid
Expand Down Expand Up @@ -108,19 +119,29 @@ private boolean chooseCharacterCard() {
if (choice.equalsIgnoreCase("n"))
return false;

// Purchasable check
CharacterCardEnum chosenCard = ccs().get(ccIndex).getCardEnum();
boolean isUsed = game().getPlayingField().isCharacterCardUsed(chosenCard);
if (me().getCoins() < ccs().get(ccIndex).getCost(isUsed)) {
out.println("Not enough coins", RED);
return false;
}

// Send the action
if (controller.sender().sendChooseCharacterCard(ccIndex)) {
waitForGreenLight();
out.println("Card chosen.", GREEN);
return true;
}
out.println("Choose a valid card", RED);
out.println("Choose a valid card or not enough coins", RED);
}
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
super.propertyChange(evt);
if (evt.getPropertyName().equals(INPUT_ENTERED.tag))
inputGreenLight = true;
greenLight = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final protected void showViewOptions() {
.append("7 - Show turn orders").append(System.lineSeparator())
.append("8 - Show players");
if (rules().gameMode.equals(GameMode.EXPERT))
options.append("10 - CharacterCards");
options.append("\n10 - CharacterCards");
out.println(options);

// Optional closing row
Expand All @@ -159,22 +159,37 @@ final protected void handleViewOptions(String choice) {
if (rules().gameMode.equals(GameMode.EXPERT))
viewAll.addView(characterCardsView());
viewAll.draw(out);
return;
}

// View all islands
case "2" -> islandsView().draw(out);
case "2" -> {
islandsView().draw(out);
return;
}

// View all dashboards
case "3" -> dashboardsView().draw(out);
case "3" -> {
dashboardsView().draw(out);
return;
}

// View all character cards
case "4" -> cloudsView().draw(out);

case "4" -> {
cloudsView().draw(out);
return;
}
// View my assistant cards
case "5" -> new AssistantCardsView(me()).draw(out);
case "5" -> {
new AssistantCardsView(me()).draw(out);
return;
}

// View my dashboard
case "6" -> new DashboardView(me(), rules(), professorHolder()).draw(out);
case "6" -> {
new DashboardView(me(), rules(), professorHolder()).draw(out);
return;
}

// Show turn orders
case "7" -> {
Expand All @@ -190,15 +205,20 @@ final protected void handleViewOptions(String choice) {
.forEach(player -> out.print(player + " -> "));
}
out.println();
return;
}

case "8" -> playersView().draw(out);
case "8" -> {
playersView().draw(out);
return;
}

// View all character cards
case "10" -> {
if (rules().gameMode.equals(GameMode.EXPERT))
characterCardsView().draw(out);
}

default -> refreshMenu = false;
}
if (refreshMenu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public MenuEnum show() {
showOptions();
}

default -> {
}
default -> showOptions();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public MenuEnum show() {
out.println("Someone else already played this card.", RED);
showOptions();
}
default -> {
}
default -> showOptions();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public MenuEnum show() {
out.println("You're in the wrong phase.", RED);
showOptions();
}
default -> {
}
default -> showOptions();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public MenuEnum show() {
islandsView().draw(out);

// Take island index input
out.println("Choose an island: ");
out.print("Choose an island: ");
int islandIndex = getNumber() - 1; // Index correction

// Send actions
Expand All @@ -95,7 +95,9 @@ public MenuEnum show() {
waitForGreenLight();

// Advance game condition
return escapeCondition();
if(escapeCondition().equals(MenuEnum.EFFECT))
new MenuEffect().show();
return MenuEnum.MOVING;
}

// Move Students from entrance to dining
Expand All @@ -116,7 +118,10 @@ public MenuEnum show() {
waitForGreenLight();

// Advance game condition
return escapeCondition();
// Advance game condition
if(escapeCondition().equals(MenuEnum.EFFECT))
new MenuEffect().show();
return MenuEnum.MOVING;
}

// Choose a character card from those in playing field
Expand All @@ -127,9 +132,7 @@ public MenuEnum show() {
}
out.println("\nA card was already played", RED);
}

default -> {
}
default -> showOptions();
}
}
}
Expand All @@ -139,7 +142,7 @@ private MenuEnum escapeCondition() {
// Condition to continue the game
if (studentsLeftToMove() == 0) {
// Ask the player if he wants to play and effect before going on with the game
if (rules().gameMode.equals(GameMode.EXPERT) && !isCharacterCardUnplayed()) {
if (rules().gameMode.equals(GameMode.EXPERT) && isCharacterCardUnplayed()) {
out.println("\nDo you want to play a character card?");
out.println("1 - YES");
out.println("ANY_KEY - NO");
Expand Down

0 comments on commit ace3fb5

Please sign in to comment.