mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 15:45:20 +01:00
Add high score system with persistent storage using SharedPreferences and Gson
This commit is contained in:
parent
8dc1d433ea
commit
b068de76f5
17 changed files with 480 additions and 168 deletions
9
app/src/main/res/drawable/edit_text_background.xml
Normal file
9
app/src/main/res/drawable/edit_text_background.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#33FFFFFF" />
|
||||
<corners android:radius="8dp" />
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="@color/white" />
|
||||
</shape>
|
|
@ -190,6 +190,16 @@
|
|||
android:text="@string/restart"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/highScoresButton"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@color/transparent"
|
||||
android:text="@string/high_scores"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/levelSelectorContainer"
|
||||
|
|
52
app/src/main/res/layout/high_score_entry.xml
Normal file
52
app/src/main/res/layout/high_score_entry.xml
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/black"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_high_score"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:fontFamily="monospace"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scoreText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp"
|
||||
android:fontFamily="monospace"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nameInput"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/edit_text_background"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="center"
|
||||
android:inputType="text"
|
||||
android:maxLength="10"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveButton"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent"
|
||||
android:text="@string/save"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"/>
|
||||
|
||||
</LinearLayout>
|
38
app/src/main/res/layout/high_scores.xml
Normal file
38
app/src/main/res/layout/high_scores.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/black"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/high_scores"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:fontFamily="monospace"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/highScoresList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/backButton"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/transparent"
|
||||
android:text="@string/back"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"/>
|
||||
|
||||
</LinearLayout>
|
37
app/src/main/res/layout/item_high_score.xml
Normal file
37
app/src/main/res/layout/item_high_score.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rankText"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="start"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nameText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"
|
||||
android:layout_marginStart="16dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scoreText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="monospace"
|
||||
android:layout_marginStart="16dp"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -16,4 +16,8 @@
|
|||
<string name="sound_on">Sound: On</string>
|
||||
<string name="sound_off">Sound: Off</string>
|
||||
<string name="toggle_music">Toggle music</string>
|
||||
<string name="high_scores">High Scores</string>
|
||||
<string name="new_high_score">New High Score!</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="back">Back</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue