-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
写得一塌糊涂的猜拳
- Loading branch information
Showing
7 changed files
with
255 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
app/src/main/java/com/example/helloandroid/Main7Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.example.helloandroid; | ||
|
||
import androidx.annotation.RequiresApi; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.RadioButton; | ||
import android.widget.RadioGroup; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import java.util.Random; | ||
|
||
public class Main7Activity extends AppCompatActivity { | ||
private Button button_finish_7; | ||
private RadioGroup radgroup; | ||
private RadioButton radbtn; | ||
private Button out; | ||
private Random random; | ||
private TextView wininfo; | ||
private TextView out_info; | ||
private String iii;//起名字真难 单选框信息 | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main7); | ||
|
||
Button out = (Button)findViewById(R.id.out_jdstb); | ||
final RadioGroup radgroup = (RadioGroup) findViewById(R.id.radgroup); | ||
|
||
out.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
for (int i = 0; i < radgroup.getChildCount(); i++) { | ||
RadioButton rd = (RadioButton) radgroup.getChildAt(i); | ||
if (rd.isChecked()) { | ||
iii = String.valueOf(rd.getText()); | ||
break; | ||
} | ||
} | ||
|
||
Random radom = new Random(); | ||
int radom_out = radom.nextInt(3); | ||
|
||
Log.i("radom_out", String.valueOf(radom_out));// 0石头1剪刀2布 | ||
Log.i("iii", String.valueOf(iii)); | ||
|
||
TextView out_info = (TextView)findViewById(R.id.out_info); | ||
if (radom_out==0){ // 0石头 | ||
out_info.setText("石头"); | ||
}else if(radom_out==1){ // 1剪刀 | ||
out_info.setText("剪刀"); | ||
}else if(radom_out==2){ // 2布 | ||
out_info.setText("布"); | ||
} | ||
|
||
TextView wininfo = (TextView)findViewById(R.id.wininfo); | ||
if (iii.equals("石头")){ | ||
wininfo.setText(iii); | ||
if(radom_out==0){ | ||
wininfo.setTextColor(Color.YELLOW); | ||
wininfo.setText("平手"); | ||
} | ||
if(radom_out==1) { | ||
wininfo.setTextColor(Color.GREEN); | ||
wininfo.setText("你赢了"); | ||
} | ||
if(radom_out==2) { | ||
wininfo.setTextColor(Color.RED); | ||
wininfo.setText("你输了"); | ||
} | ||
} | ||
|
||
if (iii.equals("剪刀")){ | ||
wininfo.setText(iii); | ||
if(radom_out==0){ | ||
wininfo.setTextColor(Color.RED); | ||
wininfo.setText("你输了"); | ||
} | ||
if(radom_out==1) { | ||
wininfo.setTextColor(Color.YELLOW); | ||
wininfo.setText("平手"); | ||
} | ||
if(radom_out==2) { | ||
wininfo.setTextColor(Color.GREEN); | ||
wininfo.setText("你赢了"); | ||
} | ||
} | ||
|
||
if (iii.equals("布")){ | ||
wininfo.setText(iii); | ||
if(radom_out==0){ | ||
wininfo.setTextColor(Color.GREEN); | ||
wininfo.setText("你赢了"); | ||
} | ||
if(radom_out==1) { | ||
wininfo.setTextColor(Color.RED); | ||
wininfo.setText("你输了"); | ||
} | ||
if(radom_out==2) { | ||
wininfo.setTextColor(Color.YELLOW); | ||
wininfo.setText("平手"); | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
}); | ||
|
||
button_finish_7 = (Button)findViewById(R.id.button_finish_7); | ||
button_finish_7.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
finish(); | ||
} | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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=".Main7Activity"> | ||
|
||
<TextView | ||
android:id="@+id/bottom" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
android:text="@string/moeyuuko" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
<RadioGroup | ||
android:id="@+id/radgroup" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.62"> | ||
|
||
<RadioButton | ||
android:id="@+id/radioButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:checked="true" | ||
android:text="石头" | ||
android:textSize="36sp" /> | ||
|
||
<RadioButton | ||
android:id="@+id/radioButton2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="剪刀" | ||
android:textSize="36sp" /> | ||
|
||
<RadioButton | ||
android:id="@+id/radioButton3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="布" | ||
android:textSize="36sp" /> | ||
|
||
</RadioGroup> | ||
|
||
<TextView | ||
android:id="@+id/out_info" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="---------" | ||
android:textSize="60sp" | ||
app:layout_constraintBottom_toTopOf="@+id/radgroup" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<Button | ||
android:id="@+id/out_jdstb" | ||
android:layout_width="200dp" | ||
android:layout_height="wrap_content" | ||
android:text="出" | ||
app:layout_constraintBottom_toTopOf="@+id/button_finish_7" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/radgroup" /> | ||
|
||
<TextView | ||
android:id="@+id/wininfo" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="-------" | ||
android:textSize="36sp" | ||
app:layout_constraintBottom_toTopOf="@+id/radgroup" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/out_info" /> | ||
|
||
<Button | ||
android:id="@+id/button_finish_7" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/back" | ||
app:layout_constraintBottom_toTopOf="@+id/bottom" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |