Skip to content

Commit

Permalink
REQ: user can type a password -> unlock scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
pe-pan committed Dec 2, 2016
1 parent 7f0f4ee commit 26f676f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 21 additions & 0 deletions mobile/src/main/java/com/mz800/flappy/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class OptionsActivity extends FlappyActivity {
private static final int MAX_PLAYER_NAME_LEN = 64;

private EditText playerNameView;
private EditText passwordView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -26,6 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_options);
playerNameView = (EditText) findViewById(R.id.playerName);
playerNameView.setText(retrievePlayerName());
passwordView = (EditText) findViewById(R.id.password);
}

public void saveOptions(View view) {
Expand All @@ -39,6 +41,25 @@ public void saveOptions(View view) {
Toast.makeText(this, "Cheating " + (Main.cheating ? "ON" : "OFF"), Toast.LENGTH_LONG).show();
//todo remove the code above from the production!
}

String password = passwordView.getText().toString();
if (password.length() > 0) {
int i = Scene.checkPass(password);
if (i < 0) {
Toast.makeText(this, R.string.incorrect_password, Toast.LENGTH_LONG).show();
} else {
int openScene = retrieveOpenScenes();
if (openScene < (i + 1) * 5) {
openScene = (i + 1) * 5;
if (openScene >= Constants.NUM_SCENES)
openScene = Constants.NUM_SCENES - 1; // do not open scene #201 (there is no such!)
storeOpenScene(openScene);
Toast.makeText(this, getString(R.string.open_scene, openScene + 1), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, getString(R.string.scene_already_open, openScene + 1), Toast.LENGTH_LONG).show();
}
}
}
closeOptions(view);
}

Expand Down
18 changes: 18 additions & 0 deletions mobile/src/main/res/layout/activity_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@
android:singleLine="true" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/scene_password" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:singleLine="true" />
</LinearLayout>

<View
android:layout_width="0dp"
android:layout_height="0dp"
Expand Down
6 changes: 5 additions & 1 deletion mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
<string name="main_menu">Main Menu</string>
<string name="play_flappy">Play Flappy</string>
<string name="resume_intro">Resume Intro</string>
<string name="show_options">Give Name</string>
<string name="show_options">Show Options</string>
<string name="exit_flappy">Exit Flappy</string>
<string name="notThisSceneYet">Not this scene yet!</string>
<string name="scores">Scores</string>
<string name="play">Play</string>
<string name="hint">Hint</string>
<string name="ok">OK</string>
<string name="will_show_hints">Will show hints to finish this scene. Not implemented yet.</string>
<string name="scene_password">Scene key:</string>
<string name="open_scene">Opening scenes #1-#%d</string>
<string name="scene_already_open">Scenes #1-#%d already open</string>
<string name="incorrect_password">Incorrect password!</string>
</resources>

0 comments on commit 26f676f

Please sign in to comment.