예제 #1
0
 private void sendState() {
   if (asHost) {
     networkProvider.sendMessage(
         new GameStateMessage(localPlayer, "gameState", modelFacade.getGameState()));
   } else {
     networkProvider.sendMessage(
         new GameStateMessage(localPlayer, "gameState", modelFacade.getGameState()));
   }
 }
예제 #2
0
 public void doMove(PawnView p) {
   if (modelFacade.isFinished() == false) {
     if (em.get(modelFacade.getPlayerColor(modelFacade.getCurrentPlayerName())) == p.getColor()) {
       modelFacade.doMove(p.getPawnNumber());
       drawState();
     }
   }
   checkIfYourTurn();
   sendState();
 }
예제 #3
0
  private void drawState() {
    if (modelFacade.isFinished() == false) {
      String currentPlayerName = modelFacade.getCurrentPlayerName();
      gameView.setCurrentPlayer(
          currentPlayerName + " " + em.get(modelFacade.getPlayerColor(currentPlayerName)));

      gameView.clearBoard();

      gameView.drawDice(modelFacade.getDice());

      for (String player : modelFacade.getAllPlayers()) {
        drawPlayerPawns(player);
      }

      if (modelFacade.noMove()) {
        gameView.showPassButton();
      } else {
        gameView.hidePassButton();
      }
    }
    if (modelFacade.winner()) {
      String player = modelFacade.getWinnerName();
      gameView.drawWinnerPrompt(player);
      gameView.showStartButton();
    }
  }
예제 #4
0
 private void checkIfYourTurn() {
   if (modelFacade.getCurrentPlayerName().equals(localPlayer)) {
     gameView.setUnlocked(true);
     gameView.setStatus("It's your turn.");
   } else {
     gameView.setUnlocked(false);
     gameView.setStatus("Wait for your turn.");
   }
 }
예제 #5
0
  private void drawPlayerPawns(String player) {
    PawnSet ps = modelFacade.getPlayerPawnSet(player);
    Iterator<IPawn<Integer>> psi = ps.createIterator();
    psi.first();
    while (!psi.isDone()) {
      IPawn<Integer> currentPawn = psi.currentItem();
      Colors playerColor = modelFacade.getPlayerColor(player);
      Integer currentElementNumber = ((PawnSetIterator) psi).getCurrentElementNumber();
      PawnColor translatedViewColor = em.get(playerColor);

      PawnView p =
          new PawnView(
              new PawnRelative(currentPawn, playerColor),
              currentElementNumber,
              translatedViewColor);

      gameView.drawPawn(p);
      psi.next();
    }
  }
예제 #6
0
  @Override
  public void onStartGame() {
    //////////////////////////////////////////////
    // onGameJoin("MyMyselfAndI");
    // onGameJoin("MyMyselfAndI2");
    //////////////////////////////////////////////

    modelFacade.startRound();
    gameView.hideStartButton();

    drawState();
  }
예제 #7
0
 public void doPass() {
   modelFacade.doPass();
   drawState();
   checkIfYourTurn();
   sendState();
 }
예제 #8
0
 public void onGameLeave(String player) {
   modelFacade.removePlayer(player);
   gameView.removePlayer(player);
   networkProvider.sendMessage(new StringMessage(localPlayer, "iQuit", localPlayer));
 }
예제 #9
0
  public void onGameJoin(String player) {
    modelFacade.addPlayer(player);
    gameView.addPlayer(player);

    drawPlayerPawns(player);
  }