欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

先上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();//隨機數(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]);//放置隨機圖片
                        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="老虎機"
        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)老虎機小游戲代碼示例的文章就介紹到這了,更多相關(guān)Android老虎機小游戲內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android仿QQ列表左滑刪除操作

    Android仿QQ列表左滑刪除操作

    這篇文章主要為大家詳細介紹了Android仿QQ列表左滑刪除操作的實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android編程實現(xiàn)webview將網(wǎng)頁打包成apk的方法

    Android編程實現(xiàn)webview將網(wǎng)頁打包成apk的方法

    這篇文章主要介紹了Android編程實現(xiàn)webview將網(wǎng)頁打包成apk的方法,以打包HTML5為例分析了webview打包apk的相關(guān)方法、屬性與事件操作技巧,需要的朋友可以參考下
    2017-08-08
  • Kotlin中內(nèi)置函數(shù)的用法和區(qū)別總結(jié)

    Kotlin中內(nèi)置函數(shù)的用法和區(qū)別總結(jié)

    眾所周知相比Java, Kotlin提供了不少高級語法特性。對于一個Kotlin的初學(xué)者來說經(jīng)常會寫出一些不夠優(yōu)雅的代碼。下面這篇文章主要給大家介紹了關(guān)于Kotlin中內(nèi)置函數(shù)的用法和區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2018-06-06
  • Andriod 資源文件之存取操作

    Andriod 資源文件之存取操作

    這篇文章主要介紹了Andriod 資源文件之存取操作的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • Android RxJava創(chuàng)建操作符Timer的方法

    Android RxJava創(chuàng)建操作符Timer的方法

    這篇文章主要為大家詳細介紹了Android RxJava創(chuàng)建操作符Timer的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android Gridview布局出現(xiàn)滾動條或組件沖突解決方法

    Android Gridview布局出現(xiàn)滾動條或組件沖突解決方法

    這篇文章主要介紹了Android Gridview布局出現(xiàn)滾動條或組件沖突解決方法,GridView是一個在二維可滾動的網(wǎng)格中展示內(nèi)容的控件。網(wǎng)格中的內(nèi)容通過使用adapter自動插入到布局中
    2022-07-07
  • android socket聊天室功能實現(xiàn)

    android socket聊天室功能實現(xiàn)

    這篇文章主要為大家詳細介紹了android socket聊天室功能實現(xiàn)方法,不單純是聊天室,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android如何給按鈕添加點擊音效

    Android如何給按鈕添加點擊音效

    這篇文章主要為大家詳細介紹了Android如何給按鈕添加點擊音效,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android編程之殺毒的實現(xiàn)原理及具體實例

    Android編程之殺毒的實現(xiàn)原理及具體實例

    這篇文章主要介紹了Android編程之殺毒的實現(xiàn)原理及具體實例,結(jié)合實例形式分析了Android殺毒功能的原理與簡單實現(xiàn)技巧,需要的朋友可以參考下
    2015-12-12
  • Android Activity的生命周期與啟動模式全面解讀

    Android Activity的生命周期與啟動模式全面解讀

    雖然說我們天天都在使用Activity,但是你真的對Activity的生命機制完全了解了嗎?Activity的生命周期方法只有七個,但是其實那只是默認的情況。也就是說在其他情況下,Activity的生命周期可能不會是按照我們以前所知道的流程,這就要說到Activity的啟動模式
    2021-10-10

最新評論