Skip to content

Commit

Permalink
Continuo test partita
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaMalnati committed Feb 21, 2024
1 parent 69fe07c commit 4dcf7f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public enum PlayerColor {
}

public Territory getTerritoryByName(String name) {
try {
return GameRepository.getInstance().getTerritory(userName, gameId, name);
} catch (GameException | DatabaseConnectionException | UserException e) {
LOGGER.error(e.getMessage());
for (Territory t : territories) {
if (t.getName().equals(name))
return t;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ public class BattleState extends GameState{
public void onActionPlayer(AttackRequest attackRequest) throws GameException, DatabaseConnectionException, UserException {

game.getCurrentTurn().setNumAttDice(attackRequest.getRequestAttackBody().getNumAttDice());
game.getCurrentTurn().setAttackerTerritory(
attackRequest.getPlayer().getTerritoryByName(attackRequest.getRequestAttackBody().getAttackerTerritory().getNameTerritory()));

game.getCurrentTurn().setDefenderTerritory(

game.findPlayerByUsername(attackRequest.getRequestAttackBody().getDefenderTerritory().getUsername()).getTerritoryByName(
attackRequest.getRequestAttackBody().getDefenderTerritory().getNameTerritory()));

game.getCurrentTurn().setAttackerTerritory(attackRequest.getPlayer()
.getTerritoryByName(attackRequest.getRequestAttackBody().getAttackerTerritory().getNameTerritory()));

game.getCurrentTurn().setDefenderTerritory(game.findPlayerByUsername(attackRequest.getRequestAttackBody().getDefenderTerritory()
.getUsername()).getTerritoryByName(attackRequest.getRequestAttackBody().getDefenderTerritory().getNameTerritory()));


GameRepository.getInstance().updateNumAttackDice(game.getCurrentTurn(), game.getCurrentTurn().getNumAttDice());

GameRepository.getInstance().updateAttackerTerritory(game.getCurrentTurn(), game.getCurrentTurn().getAttackerTerritory());

GameRepository.getInstance().updateDefenderTerritory(game.getCurrentTurn(), game.getCurrentTurn().getDefenderTerritory());
}

@Override
public void onActionPlayer(DefenceRequest defenceRequest) throws GameException, DatabaseConnectionException, UserException {
System.out.println("DEFENCE REQUEST -------------------------------------------");
game.getCurrentTurn().setNumDefDice(defenceRequest.getDefenderRequestBody().getNumDefDice());
GameRepository.getInstance().updateNumDefenseDice(game.getCurrentTurn(), game.getCurrentTurn().getNumDefDice());
game.getCurrentTurn().attack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

import com.mvcguru.risiko.maven.eclipse.actions.AttackRequest;
import com.mvcguru.risiko.maven.eclipse.actions.ComboRequest;
import com.mvcguru.risiko.maven.eclipse.actions.DefenceRequest;
import com.mvcguru.risiko.maven.eclipse.actions.GameEntry;
import com.mvcguru.risiko.maven.eclipse.actions.GameExit;
import com.mvcguru.risiko.maven.eclipse.actions.TerritorySetup;
import com.mvcguru.risiko.maven.eclipse.actions.TurnSetUp;
import com.mvcguru.risiko.maven.eclipse.controller.body_request.AttackRequestBody;
import com.mvcguru.risiko.maven.eclipse.controller.body_request.BattleBody;
import com.mvcguru.risiko.maven.eclipse.controller.body_request.ComboRequestBody;
import com.mvcguru.risiko.maven.eclipse.controller.body_request.DefenceRequestBody;
import com.mvcguru.risiko.maven.eclipse.controller.body_request.SetUpBody;
import com.mvcguru.risiko.maven.eclipse.exception.DatabaseConnectionException;
import com.mvcguru.risiko.maven.eclipse.exception.FullGameException;
Expand Down Expand Up @@ -207,6 +209,11 @@ void totalGameLogic() throws IOException, GameException, DatabaseConnectionExcep
assertEquals(game.getCurrentTurn().getDefenderTerritory().getName(), "Argentina");
assertEquals(game.getCurrentTurn().getNumAttDice(), 1);

DefenceRequestBody defenceRequestBody = DefenceRequestBody.builder().username(player2.getUserName()).numDefDice(1).build();

DefenceRequest defenceRequest = DefenceRequest.builder().defenderRequestBody(defenceRequestBody).build();

game.getState().onActionPlayer(defenceRequest);

}

Expand Down

0 comments on commit 4dcf7f0

Please sign in to comment.