Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize slot Machine Mini Game by Android

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to realize slot machine Mini Game by Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Go to the MainActivity.java code first. I use a timer here. I wanted to use java threads, but I don't know how to use Android yet, and the application will flicker.

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 (); / / Random number int b, c, d; Handler handler= new Handler (); Runnable runnable=new Runnable () {@ Override public void run () {/ / TODO Auto-generated method stub / / what to do b = a.nextInt (3); c = a.nextInt (3) D = a.nextInt (3); TP1.setImageResource (IMG [b]); / / place random pictures 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 () {/ / start button listening event @ Override public void onClick (View view) {handler.postDelayed (runnable, 20) / / timer start}}); BTN_FINISH.setOnClickListener (new View.OnClickListener () {/ / end button listening event @ Override public void onClick (View view) {handler.removeCallbacks (runnable)) / / timer ends if (img [b] = = img [c] & & img [b] = = img [d] & img [c] = = img [d]) {if (IMG [b] = = img [0]) {RESULT.setText ("Congratulations on your character explosion, winning the first prize: three pea shooters") } else if (IMG [b] = = img [1]) {RESULT.setText ("Congratulations on your character explosion, winning the special prize: three corn pitchers");} else if (IMG [b] = = img [2]) {RESULT.setText ("Congratulations on the smoke from your ancestral grave and your diamond gift bag") }} else if (img [b] = = img [c]) {if (IMG [b] = = img [0]) {RESULT.setText ("Congratulations, second prize: two pea shooters") } if (IMG [b] = = img [1]) {RESULT.setText ("Congratulations, winning the second prize: 2 corn pitchers") } if (IMG [b] = = img [2]) {RESULT.setText ("Congratulations, second prize: two diamonds!") ;} else if (img [b] = = img [d]) {if (img [b] = = img [0]) {RESULT.setText ("Congratulations, second prize: two pea shooters") } if (img [b] = = img [1]) {RESULT.setText ("Congratulations, second prize: 2 corn pitchers") } if (img [b] = = img [2]) {RESULT.setText ("Congratulations, winning the second prize: two diamonds!") ;} else if (img [c] = = img [d]) {if (img [c] = = img [0]) {RESULT.setText ("Congratulations, second prize: two pea shooters") } if (img [c] = = img [1]) {RESULT.setText ("Congratulations, second prize: 2 corn pitchers") } if (img [c] = = img [2]) {RESULT.setText ("Congratulations, second prize: two diamonds!") ;}} else {RESULT.setText ("too bad luck! let's put a coin and do it again.") );} 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);}}

Place the layout in activity_main.xml.

The effect is as follows

End result: the video is too big

Attach a few pictures, click the start picture to switch constantly, and click the end button to judge the result.

This is the end of the introduction of "how to implement slot machine Mini Game with Android". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report