Package pong.client

Source Code of pong.client.ClientController

package pong.client;

import javax.swing.JFrame;
import pong.Pong;
import pong.client.model.ClientModel;
import pong.client.model.ClientModelInterface.State;
import pong.client.model.ClientModelInterface;
import pong.client.view.ClientView;
import pong.client.view.ClientViewInterface;
import pong.client.view.ClientViewListener;
import pong.common.Position;

/**
* This is the client controller, that manages the communication among view and the model.
*
* @author Lorenzo Gatto
*
*/
// only the EDT thread communicates with this class, so methods are not
// synchronized
public class ClientController implements ClientViewListener {

  private final ClientViewInterface view;
  private final Pong game;
  private final ClientModelInterface model;

  /**
   * The client controller constructor.
   *
   * @param window
   *            the frame where the game will be played
   * @param game
   *            the Pong object calling the constructor
   */
  public ClientController(final JFrame window, final Pong game) {
    this.model = new ClientModel(window);
    this.view = new ClientView(this, window);
    this.view.start();
    this.game = game;
  }

  @Override
  public void connect(final String hostName, final int port) {
    this.model.connect(hostName, port);
  }

  @Override
  public void disconnect() {
    this.model.disconnect();
  }

  @Override
  public void backToMainMenu() {
    this.view.stop();
    this.game.printMainMenu();
  }

  @Override
  public Position[] getPosition() {
    return this.model.getPositions();
  }

  @Override
  public State getState() {
    return this.model.getState();
  }

  @Override
  public Integer[] getRoundsWon() {
    return this.model.getRoundsWon();
  }

  @Override
  public int getPlayerIndex() {
    return this.model.getPlayerIndex();
  }

  @Override
  public Integer getRoundsNumber() {
    return this.model.getRoundsNumber();
  }
}
TOP

Related Classes of pong.client.ClientController

TOP
Copyright © 2018 www.massapi.com. 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.