Ejemplo n.º 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));
    }
  }
Ejemplo n.º 2
0
 public void showDashBorder(boolean show) {
   mPreShowDashBorder = mShowDashBorder;
   mShowDashBorder = show;
   if (mShowDashBorder) {
     if (getParent() instanceof ViewGroup) {
       getParent().bringChildToFront(this);
     }
     mRefreshHandler.sendEmptyMessage(MSG_DRAW);
   } else {
     mRefreshHandler.sendEmptyMessage(MSG_ERASE);
   }
 }
Ejemplo n.º 3
0
  @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;
  }
Ejemplo n.º 4
0
 /**
  * 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) {
     clearTiles();
     updateBackground();
     mRedrawHandler.update();
   }
 }
Ejemplo n.º 5
0
 @Override
 public void onNewDataReceived(Display display) {
   trace("Daten f�r Batterie Info empfangen");
   mRedrawHandler.post(
       new Runnable() {
         public void run() {
           Message message = new Message();
           mRedrawHandler.handleMessage(message);
         }
       });
 }
Ejemplo n.º 6
0
  @Override
  protected void execute(ExecutionEvent event, SortedSet<IEntity> resources) {
    if (resources.size() == 0) {
      return;
    }

    if (!CommonIDEParameters.isRolesEnabled()) {
      // assume trial instance, hence disable this function
      MessageDialog.openInformation(null, PASTE_ERROR, PASTE_FUNCTION_IS_DISABLED_IN_THIS_INSTANCE);
      return;
    }

    IRepository repository = RepositoryFacade.getInstance().getRepository();

    String targetReposiotryPath = resources.first().getPath().toString();

    Clipboard clipboard = Clipboard.getInstance();

    String command = clipboard.getCommand();

    Throwable throwable = null;
    if (CUT.equals(command) || COPY.equals(command)) {

      for (Object name : clipboard) {
        IEntity resource = (IEntity) name;
        String sourceRepositoryPath = resource.getPath().toString();
        try {
          byte[] data = repository.exportZip(sourceRepositoryPath, true);
          repository.importZip(data, targetReposiotryPath);
        } catch (IOException e) {
          if (throwable == null) {
            throwable = e;
          }
        }
        if (CUT.equals(command)) {
          try {
            resource.delete();
          } catch (IOException e) {
            if (throwable == null) {
              throwable = e;
            }
          }
        }
      }
    }

    if (throwable != null) {
      MessageDialog.openWarning(null, PASTE_ERROR, SOME_OR_ALL_OF_THE_FILES_COULD_NOT_BE_PASTED);
    }

    RefreshHandler.refreshActivePart(event);
  }
Ejemplo n.º 7
0
  /**
   * 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);
    }
  }
Ejemplo n.º 8
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();
          }
        });
  }
Ejemplo n.º 9
0
  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]));
  }
Ejemplo n.º 10
0
  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);
  }