示例#1
0
  /** The main loop. Call this to update the game state. */
  public void update() {
    if (getHeight() == 0 || getWidth() == 0) {
      mRedrawHandler.sleep(1000 / FPS);
      return;
    }

    if (!mInitialized) {
      initializePongView();
      mInitialized = true;
    }

    long now = System.currentTimeMillis();
    if (gameRunning() && mCurrentState != State.Stopped) {
      if (now - mLastFrame >= 1000 / FPS) {
        if (mNewRound) {
          nextRound();
          mNewRound = false;
        }
        doGameLogic();
      }
    }

    // We will take this much time off of the next update() call to normalize for
    // CPU time used updating the game state.

    if (mContinue) {
      long diff = System.currentTimeMillis() - now;
      mRedrawHandler.sleep(Math.max(0, (1000 / FPS) - diff));
    }
  }
  @Override
  public boolean onSingleTapUp(MotionEvent e) {

    if (myConnectFour != null) {
      //			Log.d("turn", "" + myConnectFour.getTurn());

      if (myConnectFour.getTurn()) {
        myConnectFour.update();
        if (myConnectFour.touch(e.getX(), e.getY())) {
          connect2.sendMsg("" + myConnectFour.getLastX());
          connect2.sendMsg("" + myConnectFour.getLastY());

          if (gameover = myConnectFour.getGameOver()) {
            if (myConnectFour.getWinner() == ConnectFourView.RED)
              myConnectFour.setText("Game Over: You win");
            else if (myConnectFour.getWinner() == ConnectFourView.GREEN)
              myConnectFour.setText("Game Over: You lose");
          }

          mRefreshHandler.sleep(50);
        }
      }
    }

    return true;
  }
  /**
   * Handles the basic update loop, checking to see if we are in the running state, determining if a
   * move should be made, updating the snake's location.
   */
  public void update() {
    if (mMode == RUNNING) {
      long now = System.currentTimeMillis();

      if (now - mLastMove > mMoveDelay) {
        clearTiles();
        updateWalls();
        updateSnake();
        updateApples();
        mLastMove = now;
      }
      mRedrawHandler.sleep(mMoveDelay);
    }
  }
示例#4
0
  // set up the lobby and start screen after logging in
  private void loggedIn() {
    // enables you to receive challenges
    connect.initServer();
    ready = false;
    ready2 = false;
    gameStart = false;
    mRefreshHandler.sleep(50);

    setActivity("In Lobby");

    setContentView(R.layout.loggedin);
    final TextView welcomeuser = (TextView) findViewById(R.id.welcomeuser);
    welcomeuser.setText("Welcome, " + netid + "!");

    GetLobbyViaPHP getlobby = new GetLobbyViaPHP();
    getlobby.execute(new String[] {getlobbyurl});

    final Button startgames = (Button) findViewById(R.id.startgames);
    startgames.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent myIntent = new Intent(HelloAndroid.this, Linker.class);
            myIntent.putExtra("netid", netid);
            HelloAndroid.this.startActivityForResult(myIntent, -1);
          }
        });

    final Button refreshlobby = (Button) findViewById(R.id.refreshlobby);
    refreshlobby.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            GetLobbyViaPHP getlobby = new GetLobbyViaPHP();
            getlobby.execute(new String[] {getlobbyurl});
          }
        });

    final Button logoutbtn = (Button) findViewById(R.id.logout);
    logoutbtn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {
            loggedOut();
          }
        });
  }
  public void updateUI() {
    // wait for a second Thread
    mRedrawHandler.sleep(1000);

    txtElectricityValue.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getElectricityValue()));
    txtChargingState.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getBatteryStatus()));
    txtTemperatur.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getTemperature()));

    if (initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[0]) {
      txtSchuetze1.setText("1");
    } else if (!(initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[0])) {
      txtSchuetze1.setText("0");
    }

    if (initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[1]) {
      txtSchuetze2.setText("1");
    } else if (!(initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[1])) {
      txtSchuetze2.setText("0");
    }

    if (initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[2]) {
      txtSchuetze3.setText("1");
    } else if (!(initialize.getDataHandler().getDisplay().getPositionOfSchuetze()[2])) {
      txtSchuetze3.setText("0");
    }

    txtCell1.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[0]));
    txtCell2.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[1]));
    txtCell3.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[2]));
    txtCell4.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[3]));
    txtCell5.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[4]));
    txtCell6.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[5]));
    txtCell7.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[6]));
    txtCell8.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[7]));
    txtCell9.setText(String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[8]));
    txtCell10.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[9]));
    txtCell11.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[10]));
    txtCell12.setText(
        String.valueOf(initialize.getDataHandler().getDisplay().getCellVoltages()[11]));
  }
  private void checkInput() {
    if (gameStart && !myConnectFour.getTurn() && !gameover) {
      String input = "";

      if (connect2 != null) {
        input = connect2.getMsg();
        if ((input != null) && !input.equals(" ")) {

          test(input);
          myConnectFour.setTurn(true);
          myConnectFour.setText("Your move.");
          if (gameover = myConnectFour.getGameOver()) {
            if (myConnectFour.getWinner() == ConnectFourView.RED)
              myConnectFour.setText("Game Over: You win");
            else if (myConnectFour.getWinner() == ConnectFourView.GREEN)
              myConnectFour.setText("Game Over: You lose");
          }
        }
      }
    }
    mRefreshHandler.sleep(50);
  }