|
|
1b8111 |
package com.icystar.findnumber;
|
|
|
1b8111 |
|
|
|
1b8111 |
import android.app.Activity;
|
|
|
1b8111 |
import android.app.AlertDialog;
|
|
|
1b8111 |
import android.content.DialogInterface;
|
|
|
1b8111 |
import android.content.DialogInterface.OnCancelListener;
|
|
|
1b8111 |
import android.content.DialogInterface.OnClickListener;
|
|
|
1b8111 |
import android.content.Intent;
|
|
|
1b8111 |
import android.os.Bundle;
|
|
|
1b8111 |
import android.text.InputType;
|
|
|
1b8111 |
import android.widget.EditText;
|
|
|
1b8111 |
import android.widget.TextView;
|
|
|
1b8111 |
|
|
|
1b8111 |
public class DoubleActivity extends Activity implements Game.Listener {
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
1b8111 |
super.onCreate(savedInstanceState);
|
|
|
1b8111 |
SoundPlayer.initSounds(getApplication());
|
|
|
1b8111 |
setContentView(R.layout.activity_double);
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
protected void onResume() {
|
|
|
1b8111 |
Game.games[0].setListener(this);
|
|
|
1b8111 |
Game.games[0].setNumberTextView( (TextView)findViewById(R.id.TextView1) );
|
|
|
1b8111 |
Game.games[0].setTimeTextView( (TextView)findViewById(R.id.TextView2) );
|
|
|
1b8111 |
Game.games[0].setPlayerNameTextView( (TextView)findViewById(R.id.TextView4) );
|
|
|
1b8111 |
Game.games[0].setNumbersView( (NumbersView)findViewById(R.id.NumbersView1) );
|
|
|
1b8111 |
Game.games[0].setLockView( findViewById(R.id.frameLock) );
|
|
|
1b8111 |
|
|
|
1b8111 |
Game.games[1].setListener(this);
|
|
|
1b8111 |
Game.games[1].setNumberTextView( (TextView)findViewById(R.id.TextView3) );
|
|
|
1b8111 |
Game.games[1].setTimeTextView(null);
|
|
|
1b8111 |
Game.games[1].setPlayerNameTextView( (TextView)findViewById(R.id.TextView5) );
|
|
|
1b8111 |
Game.games[1].setNumbersView( (NumbersView)findViewById(R.id.NumbersView2) );
|
|
|
1b8111 |
Game.games[1].setLockView(null);
|
|
|
1b8111 |
|
|
|
1b8111 |
((NumbersView)findViewById(R.id.NumbersView1)).setGameIndex(0);
|
|
|
1b8111 |
((NumbersView)findViewById(R.id.NumbersView2)).setGameIndex(1);
|
|
|
1b8111 |
|
|
|
1b8111 |
for(Game g : Game.games) g.setPaused(false);
|
|
|
1b8111 |
|
|
|
1b8111 |
super.onResume();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
protected void onPause() {
|
|
|
1b8111 |
for(Game g : Game.games) g.setPaused(true);
|
|
|
1b8111 |
|
|
|
1b8111 |
Game.saveState(getApplication());
|
|
|
1b8111 |
|
|
|
1b8111 |
((NumbersView)findViewById(R.id.NumbersView1)).setGameIndex(-1);
|
|
|
1b8111 |
((NumbersView)findViewById(R.id.NumbersView2)).setGameIndex(-1);
|
|
|
1b8111 |
|
|
|
1b8111 |
Game.games[0].setListener(null);
|
|
|
1b8111 |
Game.games[0].setNumberTextView(null);
|
|
|
1b8111 |
Game.games[0].setTimeTextView(null);
|
|
|
1b8111 |
Game.games[0].setPlayerNameTextView(null);
|
|
|
1b8111 |
Game.games[0].setNumbersView(null);
|
|
|
1b8111 |
Game.games[0].setLockView(null);
|
|
|
1b8111 |
|
|
|
1b8111 |
Game.games[1].setListener(null);
|
|
|
1b8111 |
Game.games[1].setNumberTextView(null);
|
|
|
1b8111 |
Game.games[1].setTimeTextView(null);
|
|
|
1b8111 |
Game.games[1].setPlayerNameTextView(null);
|
|
|
1b8111 |
Game.games[1].setNumbersView(null);
|
|
|
1b8111 |
Game.games[1].setLockView(null);
|
|
|
1b8111 |
|
|
|
1b8111 |
super.onPause();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onWin(Game game, float time) {
|
|
|
1b8111 |
for(Game g : Game.games) if (game != g) g.lose();
|
|
|
1b8111 |
|
|
|
1b8111 |
SoundPlayer.playSound(R.raw.sound_win);
|
|
|
1b8111 |
|
|
|
1b8111 |
final int count = game.getCount();
|
|
|
1b8111 |
final int secs = Math.round(time);
|
|
|
1b8111 |
final int gameIndex = game == Game.games[0] ? 0 : 1;
|
|
|
1b8111 |
final int rank = ScoreboardActivity.isRecord(count, secs);
|
|
|
1b8111 |
final Activity activity = this;
|
|
|
1b8111 |
final String defaultPlayerName = getString(gameIndex == 0 ? R.string.defaultPlayer1Name : R.string.defaultPlayer2Name);
|
|
|
1b8111 |
|
|
|
1b8111 |
if (rank > 0) {
|
|
|
1b8111 |
String name = Game.getPlayerName(gameIndex + 1);
|
|
|
1b8111 |
if (name.length() == 0) name = defaultPlayerName;
|
|
|
1b8111 |
ScoreboardActivity.addNewRecord(count, secs, name);
|
|
|
1b8111 |
Game.saveState(getApplication());
|
|
|
1b8111 |
|
|
|
1b8111 |
final EditText edit = new EditText(this);
|
|
|
1b8111 |
edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
|
|
|
1b8111 |
edit.setText(name);
|
|
|
1b8111 |
|
|
|
1b8111 |
final Intent intent = new Intent(activity, ScoreboardActivity.class);
|
|
|
1b8111 |
intent.putExtra("count", count);
|
|
|
1b8111 |
intent.putExtra("rank", rank);
|
|
|
1b8111 |
|
|
|
1b8111 |
new AlertDialog.Builder(this)
|
|
|
1b8111 |
.setTitle(R.string.dialogDoubleRecordTitle)
|
|
|
1b8111 |
.setIcon(R.drawable.ic_dialog_win)
|
|
|
1b8111 |
.setMessage(getString(R.string.dialogDoubleRecordMessage, defaultPlayerName, rank, count, secs))
|
|
|
1b8111 |
.setView(edit)
|
|
|
1b8111 |
.setPositiveButton(R.string.dialogSubmit, new OnClickListener() {
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
1b8111 |
String name = edit.getText().toString();
|
|
|
1b8111 |
ScoreboardActivity.updateRecord(count, secs, name);
|
|
|
1b8111 |
Game.setPlayerName(gameIndex + 1, name);
|
|
|
1b8111 |
Game.saveState(getApplication());
|
|
|
1b8111 |
startActivity(intent);
|
|
|
1b8111 |
activity.finish();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
})
|
|
|
1b8111 |
.setOnCancelListener(new OnCancelListener() {
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onCancel(DialogInterface dialog) {
|
|
|
1b8111 |
String name = edit.getText().toString();
|
|
|
1b8111 |
ScoreboardActivity.updateRecord(count, secs, name);
|
|
|
1b8111 |
Game.setPlayerName(gameIndex + 1, name);
|
|
|
1b8111 |
Game.saveState(getApplication());
|
|
|
1b8111 |
startActivity(intent);
|
|
|
1b8111 |
activity.finish();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
})
|
|
|
1b8111 |
.show();
|
|
|
1b8111 |
} else {
|
|
|
1b8111 |
new AlertDialog.Builder(this)
|
|
|
1b8111 |
.setTitle(R.string.dialogDoubleWinTitle)
|
|
|
1b8111 |
.setIcon(R.drawable.ic_dialog_win)
|
|
|
1b8111 |
.setMessage(getString(R.string.dialogDoubleWinMessage, defaultPlayerName))
|
|
|
1b8111 |
.setPositiveButton(R.string.dialogOk, new OnClickListener() {
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onClick(DialogInterface dialog, int which) { activity.finish(); }
|
|
|
1b8111 |
})
|
|
|
1b8111 |
.setOnCancelListener(new OnCancelListener() {
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onCancel(DialogInterface dialog) { activity.finish(); }
|
|
|
1b8111 |
})
|
|
|
1b8111 |
.show();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onTouchNumber(Game game, int touchedNumber, int maxNumber, boolean win) {
|
|
|
1b8111 |
if (!win) {
|
|
|
1b8111 |
if (game == Game.games[0]) SoundPlayer.playSound(R.raw.sound_player1_clicked);
|
|
|
1b8111 |
if (game == Game.games[1]) SoundPlayer.playSound(R.raw.sound_player2_clicked);
|
|
|
1b8111 |
}
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public void onLock(Game game) {
|
|
|
1b8111 |
SoundPlayer.playSound(R.raw.sound_lock);
|
|
|
1b8111 |
}
|
|
|
1b8111 |
}
|