Add high score system with persistent storage using SharedPreferences and Gson

This commit is contained in:
cmclark00 2025-03-27 00:27:44 -04:00
parent 8dc1d433ea
commit b068de76f5
17 changed files with 480 additions and 168 deletions

View file

@ -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"

View 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>

View 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>

View 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>