Android-Android poker guess games

Source: Internet
Author: User

This game is a simple guess game. The point 1 is the correct point java code: package com. mrzhu. test01__project; import java. util. random; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. imageView; import android. widget. textView; public class Main extends Activity {private ImageView imav1; private ImageView imav2; private ImageV Iew imav3; private Button reset; // restart the private TextView content Button; // display the result private int [] arr; // array between 0 and 2, used for shuffling/** Called when the activity is first created. * // @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); // obtain the control imav1 = (ImageView) findViewById (R. id. imv1); imav2 = (ImageView) findViewById (R. id. imv2); imav3 = (ImageView) f IndViewById (R. id. imv3); reset = (Button) findViewById (R. id. reset); content = (TextView) findViewById (R. id. content); // set the reset listener for the restart button. setOnClickListener (new resetOnClickListener ();} // determines which card is clicked and returns the public void click (View v) {if (v. getId () = imav1.getId () {imav1Click ();} else if (v. getId () = imav2.getId () {imav2onClick ();} else if (v. getId () = imav3.getId () {imav3onClick () ;}// click the first card to respond Public void imav1Click () {retu (); if (arr [0] = 0) content. setText ("Congratulations, you guessed it! "); Else content. setText (" oh, I guess it's wrong! "); Imav2.setAlpha (100); imav3.setAlpha (100); imav2.setClickable (false); imav3.setClickable (false);} // click the public void imav2onClick () event in the second card response () {retu (); if (arr [1] = 0) content. setText ("Congratulations, you guessed it! "); Else content. setText (" oh, I guess it's wrong! "); Imav1.setAlpha (100); imav3.setAlpha (100); imav1.setClickable (false); imav3.setClickable (false);} // click the public void imav3onClick () event responded by the third card () {retu (); if (arr [2] = 0) content. setText ("Congratulations, you guessed it! "); Else content. setText (" oh, I guess it's wrong! "); Imav1.setAlpha (100); imav2.setAlpha (100); imav1.setClickable (false); imav2.setClickable (false );} // restart the button event public class resetOnClickListener implements OnClickListener {public void onClick (View v) {imav1.setImageResource (R. drawable. p04); imav2.setImageResource (R. drawable. p04); imav3.setImageResource (R. drawable. p04); imav1.setAlpha (255); imav2.setAlpha (255); imav3.setAlpha (255); content. setTe Xt ("Guess"); imav1.setClickable (true); imav2.setClickable (true); imav3.setClickable (true) ;}// method called during flop, generate Random numbers that are not repeated and add them to the array. Set the private void retu () {random Random = new Random (); arr = new int [3]; for (int I = 0; I <3; ++ I) {int index = random. nextInt (3); if (arr [index]! = 0) I --; else arr [index] = I;} imav1.setImageResource (R. drawable. p01 + arr [0]); imav2.setImageResource (R. drawable. p01 + arr [1]); imav3.setImageResource (R. drawable. p01 + arr [2]) ;}} main. xml code: <? 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_width = "fill_parent" android: layout_height = "wrap_content" android: id = "@ + id/content" android: textSize = "20px" android: text = "Guess"/> <LinearLayout android: orientation = "horizontal" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <ImageView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@ drawable/p04" android: id = "@ + id/imv1" android: onClick = "click"/> <ImageView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@ drawable/p04" android: id = "@ + id/imv2" android: onClick = "click"/> <ImageView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@ drawable/p04" android: id = "@ + id/imv3" android: onClick = "click"/> </LinearLayout> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "restart" android: id = "@ + id/reset"/> </LinearLayout>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.