最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)老虎機(jī)小游戲代碼示例

 更新時間:2021年12月15日 15:18:12   作者:z2955  
大家好,本篇文章主要講的是Android實現(xiàn)老虎機(jī)小游戲代碼示例,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽

用?Android studio軟件寫的一個老虎機(jī)小游戲

先上MainActivity.java 的代碼。這里我用得定時器,本想用java線程,奈何安卓還不太會,應(yīng)用會閃退。

package com.example.myapplication;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
 
import java.util.Random;
 
 
 
 
 
public class MainActivity extends AppCompatActivity {
    private ImageView TP1, TP2, TP3;
    private Button BTN_START, BTN_FINISH;
    private TextView RESULT;
    private int[] img = {R.drawable.z1, R.drawable.z2, R.drawable.z3};
  
    Random a = new Random();//隨機(jī)數(shù)
    int b, c, d;
 
 
 
 
 
    Handler handler= new Handler();
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            //要做的事情
 
                        b = a.nextInt(3);
                        c = a.nextInt(3);
                        d = a.nextInt(3);
 
                        TP1.setImageResource(img[b]);//放置隨機(jī)圖片
                        TP2.setImageResource(img[c]);
                        TP3.setImageResource(img[d]);
 
                       handler.postDelayed(this, 20);
        }
    };
 
 
 
 
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        show();
 
 
 
 
 
 
 
        BTN_START.setOnClickListener(new View.OnClickListener() { //開始按鈕監(jiān)聽事件
            @Override
            public void onClick(View view) {
 
                handler.postDelayed(runnable, 20);//定時器啟動
 
            }
        });
 
 
 
        BTN_FINISH.setOnClickListener(new View.OnClickListener() { //結(jié)束按鈕監(jiān)聽事件
            @Override
            public void onClick(View view) {
 
                handler.removeCallbacks(runnable);//定時器結(jié)束
 
                if (img[b] == img[c] && img[b] == img[d] && img[c] == img[d] ) {
                    if(img[b]==img[0]){
                    RESULT.setText("恭喜您人品大爆發(fā),獲得一等獎:三株豌豆射手");}
                    else if(img[b]==img[1]){
                        RESULT.setText("恭喜您人品大爆發(fā),獲得特等獎:三株玉米投手");
                    }else if(img[b]==img[2]){
                        RESULT.setText("恭喜您祖墳冒青煙,獲得鉆石大禮包");
                    }
                } else
                    if (img[b] == img[c]) {
                        if(img[b]==img[0]){
                            RESULT.setText("恭喜您,獲得二等獎:兩頭豌豆射手");
                        }
                        if(img[b]==img[1]){
                            RESULT.setText("恭喜您,獲得二等獎:2株玉米投手");
                        }
                        if(img[b]==img[2]){
                            RESULT.setText("恭喜您,獲得二等獎:兩顆鉆啊!");
                        }
 
 
 
                }
                    else
                    if (img[b] == img[d]) {
                        if (img[b] == img[0]) {
                            RESULT.setText("恭喜您,獲得二等獎:兩頭豌豆射手");
                        }
                        if (img[b] == img[1]) {
                            RESULT.setText("恭喜您,獲得二等獎:2株玉米投手");
                        }
                        if (img[b] == img[2]) {
                            RESULT.setText("恭喜您,獲得二等獎:兩顆鉆?。?);
                        }
 
                    }
                        else
                        if (img[c] == img[d]) {
                            if (img[c] == img[0]) {
                                RESULT.setText("恭喜您,獲得二等獎:兩頭豌豆射手");
                            }
                            if (img[c] == img[1]) {
                                RESULT.setText("恭喜您,獲得二等獎:2株玉米投手");
                            }
                            if (img[c] == img[2]) {
                                RESULT.setText("恭喜您,獲得二等獎:兩顆鉆??!");
                            }
 
                        }
 
 
                    else {
                    RESULT.setText("手氣也太差了吧!投幣再來一次吧。");
                }
 
 
            }
        });
 
 
    }
 
    private void show() {
        TP1 = findViewById(R.id.tp1);
        TP2 = findViewById(R.id.tp2);
        TP3 = findViewById(R.id.tp3);
 
        BTN_START = findViewById(R.id.btn_start);
        BTN_FINISH = findViewById(R.id.btn_finish);
 
        RESULT = findViewById(R.id.result);
 
    }
 
 
 
 
 
}
 
 
 
 

在activity_main.xml 放置布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical"
    android:background="@drawable/bj"
    tools:context=".MainActivity">
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="老虎機(jī)"
        android:textSize="50dp"
        android:layout_gravity="center"
        android:textColor="#00ff00"
        android:layout_marginTop="8dp"
        ></TextView>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:paddingTop="40dp"
        >
        <ImageView
            android:id="@+id/tp1"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:src="@drawable/z1"
            android:layout_marginLeft="10dp"
 
 
           ></ImageView>
        <ImageView
            android:id="@+id/tp2"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:src="@drawable/z3"
            android:layout_marginLeft="15dp"
 
           ></ImageView>
        <ImageView
            android:id="@+id/tp3"
            android:layout_marginLeft="15dp"
 
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:src="@drawable/z2"
 
            ></ImageView>
 
 
    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:layout_gravity="center"
        android:paddingTop="40dp"
        >
        <Button
            android:id="@+id/btn_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
 
            android:text="開始"
            android:textSize="40dp"
 
 
            ></Button>
        <Button
            android:id="@+id/btn_finish"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:text="結(jié)束"
            android:textSize="40dp"
 
           ></Button>
 
 
    </TableRow>
    <TextView
        android:id="@+id/result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dp"
        android:text="抽獎結(jié)果:"
        android:textColor="@color/white"
        android:textSize="30dp"
        ></TextView>
 
</LinearLayout>

圖片資源我就不給了,效果如下圖

最后效果:視頻太大

附上幾張圖,點擊開始圖片不斷切換,點擊結(jié)束按紐判斷結(jié)果。

?到此這篇關(guān)于Android實現(xiàn)老虎機(jī)小游戲代碼示例的文章就介紹到這了,更多相關(guān)Android老虎機(jī)小游戲內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

高密市| 宜兴市| 琼结县| 布尔津县| 马公市| 营口市| 屯留县| 万荣县| 尖扎县| 环江| 溧水县| 土默特左旗| 潢川县| 南汇区| 富裕县| 大丰市| 磐石市| 黄龙县| 腾冲县| 榆中县| 蓝田县| 仪陇县| 泸溪县| 平山县| 徐闻县| 界首市| 彩票| 潜江市| 洛浦县| 古田县| 玉门市| 武穴市| 碌曲县| 高青县| 兴海县| 海宁市| 安西县| 繁峙县| 繁昌县| 紫阳县| 富阳市|