JetBoypublic class JetBoy extends android.app.Activity implements View.OnClickListener
Fields Summary |
---|
private com.example.android.jetboy.JetBoyView.JetBoyThread | mJetBoyThreadA handle to the thread that's actually running the animation. | private JetBoyView | mJetBoyViewA handle to the View in which the game is running. | private android.widget.Button | mButton | private android.widget.Button | mButtonRetry | private android.widget.TextView | mTextView | private android.widget.TextView | mTimerView |
Methods Summary |
---|
public void | onClick(android.view.View v)Handles component interaction
// this is the first screen
if (mJetBoyThread.getGameState() == JetBoyThread.STATE_START) {
mButton.setText("PLAY!");
mTextView.setVisibility(View.VISIBLE);
mTextView.setText(R.string.helpText);
mJetBoyThread.setGameState(JetBoyThread.STATE_PLAY);
}
// we have entered game play, now we about to start running
else if (mJetBoyThread.getGameState() == JetBoyThread.STATE_PLAY) {
mButton.setVisibility(View.INVISIBLE);
mTextView.setVisibility(View.INVISIBLE);
mTimerView.setVisibility(View.VISIBLE);
mJetBoyThread.setGameState(JetBoyThread.STATE_RUNNING);
}
// this is a retry button
else if (mButtonRetry.equals(v)) {
mTextView.setText(R.string.helpText);
mButton.setText("PLAY!");
mButtonRetry.setVisibility(View.INVISIBLE);
// mButtonRestart.setVisibility(View.INVISIBLE);
mTextView.setVisibility(View.VISIBLE);
mButton.setText("PLAY!");
mButton.setVisibility(View.VISIBLE);
mJetBoyThread.setGameState(JetBoyThread.STATE_PLAY);
} else {
Log.d("JB VIEW", "unknown click " + v.getId());
Log.d("JB VIEW", "state is " + mJetBoyThread.mState);
}
| public void | onCreate(android.os.Bundle savedInstanceState)Required method from parent class
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get handles to the JetView from XML and the JET thread.
mJetBoyView = (JetBoyView)findViewById(R.id.JetBoyView);
mJetBoyThread = mJetBoyView.getThread();
// look up the happy shiny button
mButton = (Button)findViewById(R.id.Button01);
mButton.setOnClickListener(this);
mButtonRetry = (Button)findViewById(R.id.Button02);
mButtonRetry.setOnClickListener(this);
// set up handles for instruction text and game timer text
mTextView = (TextView)findViewById(R.id.text);
mTimerView = (TextView)findViewById(R.id.timer);
mJetBoyView.setTimerView(mTimerView);
mJetBoyView.SetButtonView(mButtonRetry);
mJetBoyView.SetTextView(mTextView);
| public boolean | onKeyDown(int keyCode, android.view.KeyEvent msg)Standard override to get key-press events.
if (keyCode == 4)
super.onKeyDown(keyCode, msg);
return mJetBoyThread.doKeyDown(keyCode, msg);
| public boolean | onKeyUp(int keyCode, android.view.KeyEvent msg)Standard override for key-up. We actually care about these, so we can
turn off the engine or stop rotating.
return mJetBoyThread.doKeyUp(keyCode, msg);
|
|