項目名
Name
Package name
Save location
Language
Minumum API level
This project will support instant apps
Use android.* artifacts
設定
number_RPSapp
com.number.rpsapp
自身の作業ディレクトリ
Kotlin
API 23: Android 6.0 (Marshmallow)
unchecked
checked (default)
各 ImageButton (rock: グー, paper: パー, scissors: チョキ) がタップされたときの処理をつぎに示す。
計算で求めること。(AND 条件と IF のネストで実装しない)
ImageButton および ImageView にセットする画像ファイルはここからダウンロードして、Resources の drawable に格納してください
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:text="@string/rps_label" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintBottom_toTopOf="@+id/btnPaper" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" /> <ImageButton android:id="@+id/btnRock" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/btnPaper" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/rock" android:contentDescription="@string/rock_button" /> <ImageButton android:id="@+id/btnPaper" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/btnScissors" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/btnRock" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/paper" android:contentDescription="@string/paper_button"/> <ImageButton android:id="@+id/btnScissors" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/btnPaper" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/scissors" android:contentDescription="@string/scissors_button" /> <Button android:id="@+id/btnRate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="@string/rate_button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout><?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ResultActivity"> <ImageView android:id="@+id/imgPlayer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/your_hand_description" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/imgCpu" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/rock" /> <ImageView android:id="@+id/imgCpu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/cpu_hand_description" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/imgPlayer" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/rock" /> <TextView android:id="@+id/txtResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintBottom_toTopOf="@+id/imgPlayer" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" tools:text="You WIN!" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="@string/you_label" app:layout_constraintEnd_toEndOf="@+id/imgPlayer" app:layout_constraintStart_toStartOf="@+id/imgPlayer" app:layout_constraintTop_toBottomOf="@+id/imgPlayer" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="@string/cpu_label" app:layout_constraintEnd_toEndOf="@+id/imgCpu" app:layout_constraintStart_toStartOf="@+id/imgCpu" app:layout_constraintTop_toBottomOf="@+id/imgCpu" /> <Button android:id="@+id/btnRate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="@string/rate_button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> <Button android:id="@+id/btnRematch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="@string/rematch_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView3" /></androidx.constraintlayout.widget.ConstraintLayout><?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".WinRateActivity"> <TextView android:id="@+id/txtWinRate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintBottom_toTopOf="@+id/txtLoseRate" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" tools:text="Win: 100.0%" /> <TextView android:id="@+id/txtLoseRate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="Lose: 100.0%" /> <TextView android:id="@+id/txtDrawRate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtLoseRate" tools:text="Draw: 100.0%" /> <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:layout_marginBottom="16dp" android:text="@string/rate_label" app:layout_constraintBottom_toTopOf="@+id/txtWinRate" app:layout_constraintEnd_toStartOf="@+id/txtWinRate" /> <Button android:id="@+id/btnRematch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="@string/rematch_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtDrawRate" /></androidx.constraintlayout.widget.ConstraintLayout><resources> <string name="app_name">RPSapp</string> <string name="rps_label">Rock-Paper-Scissors…</string> <string name="rock_button">rock</string> <string name="scissors_button">scissors</string> <string name="paper_button">paper</string> <string name="your_hand_description">your hand</string> <string name="cpu_hand_description">cpu hand</string> <string name="you_label">YOU</string> <string name="cpu_label">CPU</string> <string name="win_message">You WIN!</string> <string name="lose_message">You LOSE…</string> <string name="rate_label">Rate:</string> <string name="rate_button">rate</string> <string name="win_rate">Win: %1.2f%%</string> <string name="lose_rate">Lose: %1.2f%%</string> <string name="draw_rate">Draw: %1.2f%%</string> <string name="rematch_button">rematch</string></resources>皇帝: 基本、勝つ(ただし奴隷に負ける)奴隷: 基本、負ける(ただし皇帝に勝つ)