Example #1
0
 public static void main(String[] args) {
   int screenWidth = WORLD_WIDTH * CELL_SIZE;
   int screenHeight = WORLD_HEIGHT * CELL_SIZE;
   Dimension screenSize = new Dimension(screenWidth, screenHeight);
   Game game = DesktopGameBuilder.build(screenSize);
   game.setScene(new SceneStart(game));
   game.start();
 }
Example #2
0
  public Window(int width, int height, String title, Game game) {
    JFrame frame = new JFrame(title);

    frame.setPreferredSize(new Dimension(width, height + 22));
    frame.setMaximumSize(new Dimension(width, height + 22));
    frame.setMinimumSize(new Dimension(width, height + 22));

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.add(game);
    frame.setVisible(true);
    game.start();
  }
Example #3
0
  public static void main(String[] args) {
    Game game = new Game();
    game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));

    JFrame frame = new JFrame("Tiles.Tile RPG");
    frame.setSize(WIDTH * SCALE, HEIGHT * SCALE);

    /** Important line to prevent memory leak! */
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.add(game);
    frame.setVisible(true);

    game.start();
  }
Example #4
0
  /** Run game server */
  public void run() {

    // Server socket
    try {
      this.listener = new ServerSocket(Integer.parseInt(this.config.getConfig("gamePort")));
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Listen for new connections
    try {
      while (true) {
        Game game = new Game();

        System.out.println("Waiting for players...");

        // Wait for red user
        game.addPlayer(game.new Player(listener.accept(), "red"));

        // Wait for blue user
        game.addPlayer(game.new Player(listener.accept(), "blue"));

        // Wait for yellow user
        game.addPlayer(game.new Player(listener.accept(), "yellow"));

        // Wait for green user
        game.addPlayer(game.new Player(listener.accept(), "green"));

        game.broadcast("STARTGAME");

        // Start game
        game.start();
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        listener.close();
      } catch (IOException e) {
        System.out.println("Error closing game server socket");
        e.printStackTrace();
      }
    }
  }
  void parseMessage(Element root) {
    /*
    	Deal with player chat messages, moves and game related messages.

    	If the message is chat: send on to all clients, they can parse the XML.
    	If it's a move:
    		Check game has started, and it's the players turn then:
    		Normal move: Get current pos of player piece
    					 Calculate new pos.
    					 Format XML - from, to, colour
    		Adaptive move:
    						Can player make adaptive move?
    						Validate move.
    						Format XML - from, to, id.
    	If it's game related:
    		Must be host telling server to start game:
    			Validate message is from host.
    			Start the game.
    */
    String type = root.getAttribute("type");
    if (type.equals("chat")) {
      game.tellAll(message);
    } else if (type.equals("game")) {
      // Start game or player move.
      Element start, finish, turn = null;
      start = (Element) root.getElementsByTagName("start").item(0);
      finish = (Element) root.getElementsByTagName("finish").item(0);
      turn = (Element) root.getElementsByTagName("turn").item(0);

      if (start != null) {
        // Game is starting, show the board.
        game.start(p);
      } else if (turn != null) {
        game.normalMove(p);
        // We will deal with adaptive moves here later.
      }
    }
  }
Example #6
0
 public void start() {
   game.start();
 }
Example #7
0
 /**
  * Peli ajetaan main-metodissa.
  *
  * @param args Käskyt ohjelmalle.
  */
 public static void main(String[] args) {
   Game game = new Game();
   game.start();
 }
Example #8
0
  public static void main(String[] args) {
    Game myGame = new Game("My Game", 640, 360);

    myGame.start();
  }
 public static void main(String[] args) throws IOException {
   Game game = new Game();
   game.start();
 }
Example #10
0
 /** @param args the command line arguments */
 public static void main(String[] args) {
   //       754,502
   Game game = new Game("titulo", 754, 502);
   game.start();
 }