Android Open Source - Airplanes Game






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.axnsan.airplanes.online;
//from w ww  .  ja v  a2s .  co  m
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import com.axnsan.airplanes.Airplanes;
import com.axnsan.airplanes.GameConfiguration;
import com.axnsan.airplanes.GameConfiguration.KillMode;
import com.axnsan.airplanes.util.ActionManager;
import com.axnsan.airplanes.util.StringManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class Game {
  public GameConfiguration config;
  
  public int gameID;
  public boolean joined = false;
  private int turnNumber;
  private int currentPlayers;
  @SuppressWarnings("unused") private int timeout;
  private boolean finished = false;
  
  public Game(int gameID, int timeout, int numPlayers, int gridSize, int numPlanes, boolean headshots,
      boolean reveal, int currentPlayers, int turn, boolean joined) {
    this.gameID = gameID;
    this.timeout = timeout;
    this.config = new GameConfiguration();
    this.config.numPlayers = numPlayers;
    this.config.gridSize = gridSize;
    this.config.numPlanes = numPlanes;
    this.config.killMode = (headshots)?KillMode.Headshot:KillMode.Full;
    this.config.revealDeadPlanes = reveal;
    this.currentPlayers = currentPlayers;
    this.turnNumber = turn;
    this.joined = joined;
    playerLabel = new Label(Integer.toString(currentPlayers) + "/" + Integer.toString(config.numPlayers), Airplanes.game.skin);
    turnLabel = new Label((turnNumber>=0)?Integer.toString(turnNumber):"-", Airplanes.game.skin);
    but = new TextButton(joined?">":"Join", Airplanes.game.skin);
  }
  
  private Label turnLabel, playerLabel;
  private TextButton but;
  public void addRowToTable(Table table, final ClientSocket socket, final SessionData session) {
    if (joined == false && (currentPlayers >= config.numPlayers || turnNumber >= 0))
      return;
    
    table.add(Integer.toString(gameID));
    table.add(config.revealDeadPlanes?"yes":"no");
    table.add(Integer.toString(config.gridSize));
    table.add(Integer.toString(config.numPlanes));
    playerLabel = new Label(Integer.toString(currentPlayers) + "/" + Integer.toString(config.numPlayers), Airplanes.game.skin);
    table.add(playerLabel);
    turnLabel = new Label((turnNumber>=0)?Integer.toString(turnNumber):"-", Airplanes.game.skin);
    table.add(turnLabel);
    but = new TextButton(joined?">":"Join", Airplanes.game.skin);
    but.addListener(new ClickListener() {
      @Override
        public void clicked(InputEvent event, float x, float y)
        {
        try {
          ActionManager.showProgressDialog(StringManager.getString("waiting_server"));
          synchronized (session) {
            if (joined == false && currentPlayers >= config.numPlayers) {
              ActionManager.dismissProgressDialog();
              return;
            }
            if (joined == true && currentPlayers >= config.numPlayers) {
              ActionManager.dismissProgressDialog();
              Airplanes.game.setScreen((Screen) (session.currentGame = new OnlineGameScreen(socket, session, gameID)));
              return;
            }
            socket.sendMessage(new GameJoinMessage(gameID, ""));
            ServerResponseMessage response = socket.responseQueue.poll(Airplanes.TIMEOUT, TimeUnit.SECONDS);
            if (response == null)
              throw new IOException("Request timed out");
            
            switch (response.responseCode) {
            case RESPONSE_CODE.BAD_GAME_ID:
              break;
            case RESPONSE_CODE.GAME_FULL:
              break;
            case RESPONSE_CODE.WRONG_GAME_PASSWORD:
              break;
            case RESPONSE_CODE.RESPONSE_OK:
              session.currentGame = new OnlineGameScreen(socket, session, gameID);
              joined = true;
              if (response.metadata.length() > 0) {
                String[] p = response.metadata.split("\\,");
                for (String s : p)
                  session.currentGame.addPlayer(s);
              }
              Airplanes.game.setScreen((Screen) session.currentGame);
            }
          }
        }
        catch (IOException | InterruptedException e) {
          ActionManager.dismissProgressDialog();
          ActionManager.showLongToast(StringManager.getString("connection_failed"));
          e.printStackTrace();
          Airplanes.game.back();
        }
        ActionManager.dismissProgressDialog();
        }
    });
    table.add(but).width(Gdx.graphics.getWidth()/9).height(Gdx.graphics.getHeight()/30 + 16).pad(2).padLeft(6);
    table.row();
  }

  public int getCurrentPlayers() {
    return currentPlayers;
  }

  public void setCurrentPlayers(int currentPlayers) {
    this.currentPlayers = currentPlayers;
    String tmp = Integer.toString(currentPlayers) + "/" + Integer.toString(config.numPlayers);
    playerLabel.setText(tmp);
  }
  
  public void addPlayer() {
    if (currentPlayers >= config.numPlayers)
      throw new RuntimeException("Adding player to full game");
    setCurrentPlayers(currentPlayers + 1);
  }
  
  public void removePlayer() {
    if (turnNumber <= 0)
      setCurrentPlayers(currentPlayers - 1);
  }
  
  public void join() {
    joined = true;
    but.setText(">");
  }
  
  public void leave() {
    joined = false;
    but.setText("Join");
  }

  public int getTurnNumber() { return turnNumber; }
  
  public void setTurn(int turn) { this.turnNumber = turn; }
  
  public boolean isFull() { return currentPlayers >= config.numPlayers; }
  
  public boolean isJoined() { return joined; }
  
  public void setFinished(boolean finished) { this.finished = finished; }
  
  public boolean isFinished() { return finished; }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java