Package org.gojul.fourinaline.model

Examples of org.gojul.fourinaline.model.GameModel


  private synchronized void updateMainPanel(final GameModel newGameModel)
  {
    // This method is synchronized since it may be called by the client
    // thread or by the GUI.
   
    GameModel gameModel = newGameModel;
   
    if (newGameModel == null)
    {
      try
      {
        gameModel = gameClient.getGameModelImmediately();
      }
      catch (RemoteException e)
      {
        e.printStackTrace();
        gameModel = gameClient.getGameModel();
      }
    }
   
    if (gameModel == null)
    { 
      mainPanel.removeAll();
   
      JLabel label = new JLabel(GUIMessages.NO_GAME_RUNNING_MESSAGE.toString());
      label.setHorizontalAlignment(JLabel.CENTER);
      label.setVerticalAlignment(JLabel.CENTER);
      label.setOpaque(true);
      label.setBackground(Color.BLUE);
      label.setForeground(Color.WHITE);
     
      gameModelDrawPanel = null;
   
      mainPanel.add(label, BorderLayout.CENTER);
     
      statusLabel.setText(GUIMessages.NO_GAME_RUNNING_MESSAGE.toString());     
     
      localGameModel = null;
    }
    else
    {
      if (localGameModel == null)
      {
        initFulfilledMainPanel(gameModel);
      }
     
      boolean bUpdatedGame = !gameModel.equals(localGameModel);
     
      localGameModel = new GameModel(gameModel);
     
      gameModelDrawPanel.updateModel(localGameModel);
     
      PlayerMark mark = localGameModel.getCurrentPlayer();
     
View Full Code Here


      {
        // We work on a local copy of the game model in order to avoid
        // some side effects due to the speed of some games.
        // In some cases the panel would not even notify that something
        // has happened.
        GameModel model = gameClient.getGameModel();
        final GameModel localModel = model != null ? new GameModel(model): null;
       
        SwingUtilities.invokeLater(new Runnable()
        {
          /**
           * @see java.lang.Runnable#run()
View Full Code Here

          {
            disconnectionFromServer();
            return;
          }
         
          GameModel model = gameClient.getGameModel();
         
         
          // Updates the actions if necessary.
          if (model == null || !model.getGameStatus().equals(GameStatus.CONTINUE_STATUS))
          {
            // Well... no risk of redundant enabling
            // with the gameFinished() listener since
            // there's no thread concurrency at this stage.
            // Thus in some conditions the new game action
            // must be enabled while no game has been started
            // nor is running. In these cases the gameFinished()
            // event will never be thrown.
            newGameAction.setEnabled(isGameOwner);
            endGameAction.setEnabled(false);
          }
          // Prevents the user from ending a game when it is not up to it to play.
          // Avoids some very tricky unsolvable multithread conflicts, without being
          // surprising for the users.
          else if (model != null && model.getGameStatus().equals(GameStatus.CONTINUE_STATUS))
          {
            newGameAction.setEnabled(false);       
            endGameAction.setEnabled(isGameOwner && model.getCurrentPlayer().equals(gameClient.getPlayer().getPlayerMark()));
          }
        }
      });
    }
   
View Full Code Here

      PlayerMark currentPlayerMark = null;
     
      try
      {
        commandResult = mainFrame.gameClient.newGame();
        GameModel currentModel = mainFrame.gameClient.getGameModelImmediately();
       
        // Avoids some possible multithread issues in which a
        // user may have ended a game that has just started now.
        if (currentModel != null)
          currentPlayerMark = currentModel.getCurrentPlayer();
      }
      catch (Throwable t)
      {
        t.printStackTrace();
        commandResult = false;
View Full Code Here

TOP

Related Classes of org.gojul.fourinaline.model.GameModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.