自己製作的回答問題遊戲
用很簡單的東西來做出一些小遊戲
或者做出一些輔助程式,也是不錯的唷
以下使用了 CheckBox、Button、TextView、RatingBar
主程式為
package edu.fcu;
import org.w3c.dom.Text;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.widget.Button;
import java.awt.*;
import android.widget.RatingBar;
public class A123456Activity extends Activity {
/** Called when the activity is first created. */
protected String a,b,c;
protected float d=0;
protected TextView text1,text2;
protected CheckBox box1,box2,box3,box4;
protected Button but1;
protected RatingBar rat1;
protected int i=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1 = (TextView)A123456Activity.this.findViewById(R.id.textView1);
text2 = (TextView)A123456Activity.this.findViewById(R.id.textView2);
box1=(CheckBox)A123456Activity.this.findViewById(R.id.checkBox1);
box2=(CheckBox)A123456Activity.this.findViewById(R.id.checkBox2);
box3=(CheckBox)A123456Activity.this.findViewById(R.id.checkBox3);
box4=(CheckBox)A123456Activity.this.findViewById(R.id.checkBox4);
but1=(Button)A123456Activity.this.findViewById(R.id.button1);
rat1=(RatingBar)A123456Activity.this.findViewById(R.id.ratingBar1);
but1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
d=0;
a="好厲害!!你全對了~~按下確認答案進行下一題";
b="你確定?? 好像有問題喔";
if(i==0){
text1.setText("1+1=?");
box1.setText("2");
box2.setText("Two");
box3.setText("二");
box4.setText("11");
if (box1.isChecked()==true){
d=d+1;
}
if (box2.isChecked()==true){
d=d+1;
}
if (box3.isChecked()==true){
d=d+1;
}
if (box4.isChecked()==false){
d=d+2;
}
}
if (i==1){
text1.setText("這是不是一款問答遊戲?");
box1.setText("不是");
box2.setText("是");
box3.setText("一定是");
box4.setText("根本就是");
if (box1.isChecked()==false){
d=d+2;
}
if (box2.isChecked()==true){
d=d+1;
}
if (box3.isChecked()==true){
d=d+1;
}
if (box4.isChecked()==true){
d=d+1;
}
}
if(i==2){
text1.setText("這款0元大富翁好玩嗎?");
box1.setText("好玩");
box2.setText("難玩");
box3.setText("超好玩");
box4.setText("不錯玩");
if (box1.isChecked()==true){
d=d+1;
}
if (box2.isChecked()==false){
d=d+1;
}
if (box3.isChecked()==true){
d=d+2;
}
if (box4.isChecked()==true){
d=d+1;
}
}
if(i==3){
text1.setText("成績會有幾分");
box1.setText("100分");
box2.setText("滿分");
box3.setText("最高分");
box4.setText("夢醒時分?!");
if (box1.isChecked()==true){
d=d+1;
}
if (box2.isChecked()==true){
d=d+1;
}
if (box3.isChecked()==true){
d=d+1;
}
if (box4.isChecked()==false){
d=d+2;
}
}
if (d<5) {
text2.setText(b);
}
if (d>=5){
text2.setText(a);
i=i+1;
box1.setChecked(false);
box2.setChecked(false);
box3.setChecked(false);
box4.setChecked(false);
if (i>3)
i=0;
}
rat1.setRating(d);
}
});
}
}
--------------------------------------------------------------------------------------------
接下來是main的程式碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="1+1=?"
android:id="@+id/textView1">
</TextView>
<CheckBox
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/checkBox1"
android:text="2" >
</CheckBox>
<CheckBox android:text="二"
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<CheckBox android:text="Two"
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<CheckBox android:text="じゅういち"
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:text="確認答案">
</Button>
<TextView android:text="評語"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<RatingBar android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RatingBar>
</LinearLayout>
遊戲截圖
我試過了,
回覆刪除但是打不太開,
好想有一些變數沒有設定好,
請問要怎麼將原始碼無誤的使用在eclipse上呢?