The most common scissors small game Android code implementation _android

Source: Internet
Author: User
Tags gettext visibility

This example for you to share the Android scissors games for your reference, the specific content as follows

Simple page jump and click event Implementation ...

--> Androidmanifest.xml

 <?xml version= "1.0" encoding= "Utf-8"?> <manifest "xmlns:android=" Schemas.android.com/apk/res/android "package=" Com.dragon.android.fight "android:versioncode=" 1 "android: 
  Versionname= "1.0" > <uses-sdk android:minsdkversion= "android:targetsdkversion="/> <application Android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@ Style/apptheme "> <activity android:name=" com.dragon.android.fight.MainActivity "android:label=" @string/app_ Name "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> <category Andro Id:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:

Name= "Com.dragon.android.fight.OtherActivity" > </activity> </application> </manifest> Androidmanifest 

--> Strings.xml

<?xml version= "1.0" encoding= "Utf-8"?> <resources> <string name= "App_name" >fight</string> & Lt;string name= "Hello_world" >hello world!</string> <string name= "Action_settings" >Settings</ string> <string name= "Player1" > Party a </string> <string name= "Player2" > Party b </string> <string Name= "Choose1" > Stone </string> <string name= "Choose2" > Scissors </string> <string name= "CHOOSE3" > Cloth </string> <string name= "Sure" > Out fist </string> <string name= "Again" > Another round of </string> </ resources>--> fragment_main.xml <relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height = "Match_parent" android:background= #ffffff "tools:context=" com.dragon.android.fight.mainactivity$ Placeholderfragment "> <textview android:id=" @+id/textview1 "android:layout_width="Wrap_content "android:layout_height=" Wrap_content "android:layout_alignparenttop=" true "Android:layout_ Centerhorizontal= "true" android:layout_margintop= "36DP" android:text= "@string/player1" android:textsize= "30SP"/&

 Gt <radiogroup android:id= "@+id/radiogroup1" android:layout_width= wrap_content "android:layout_height=" Wrap_ Content "Android:layout_centerhorizontal=" true "android:layout_centervertical=" true "> <radiobutton Androi D:id= "@+id/radio0" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" true "Android:text=" @string/choose1 "/> <radiobutton android:id=" @+id/radio1 "android:layout_width=" Wrap_con Tent "android:layout_height=" Wrap_content "android:text=" @string/choose2 "/> <radiobutton android:id=" @+ Id/radio2 "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" @string/choose3 "/> </RadioGroup> <button
  Android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout _alignleft= "@+id/radiogroup1" android:layout_below= "@+id/radiogroup1" android:layout_margintop= "14DP" Android: text= "@string/sure"/> <imageview android:id= "@+id/imageview1" android:layout_width= "120DP" Android:layout_h eight= "120DP" android:layout_above= "@+id/radiogroup1" android:layout_below= "@+id/textview1" Android:layout_

 Centerhorizontal= "true" android:src= "@drawable/b"/> </RelativeLayout>

--> Activity_other.xml

<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" 
 Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " android:background= "#ffffff" > <textview android:id= "@+id/textview1" android:layout_width= "Wrap_content" and
  roid:layout_height= "Wrap_content" android:layout_alignparenttop= "true" android:layout_centerhorizontal= "true" android:layout_margintop= "36DP" android:text= "@string/player2" android:textsize= "30sp"/> <radiogroup androi D:id= "@+id/radiogroup1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_ Centerhorizontal= "true" android:layout_centervertical= "true" > <radiobutton android:id= "@+id/radio0" Andr Oid:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:checked= "true" android:text= "@string /choose1 "/> <radiobutton Android: id= "@+id/radio1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "@string Choose2 "/> <radiobutton android:id= @+id/radio2" android:layout_width= "Wrap_content" Android:layout_hei
  ght= "Wrap_content" android:text= "@string/choose3"/> </RadioGroup> <button android:id= "@+id/button1" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignleft= "@+id/" RadioGroup1 "android:layout_below=" @+id/radiogroup1 "android:layout_margintop=" 14DP "android:text=" @string/sure " > <textview android:id= "@+id/textview2" android:layout_width= wrap_content "android:layout_height=" Wrap_cont
  Ent "android:layout_alignleft=" @+id/textview1 "android:layout_below=" @+id/button1 "android:visibility=" Invisible " android:layout_margintop= "14DP"/> <button android:id= "@+id/button2" android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" Android:layout_below= "@+id/textview2" android:layout_centerhorizontal= "true" android:visibility= "Invisible" Android: text= "@string/again"/> <imageview android:id= "@+id/imageview1" android:layout_width= "120DP" Android:layout_ height= "120DP" android:layout_above= "@+id/radiogroup1" android:layout_below= "@+id/textview1" Android:layout_

 Centerhorizontal= "true" android:src= "@drawable/a"/> </RelativeLayout>

--> mainactivity

Package com.dragon.android.fight;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ImageView;
Import Android.widget.RadioButton;

Import Android.widget.RadioGroup;
 public class Mainactivity extends activity {//Set a static variable to close the activity public static mainactivity instance = NULL;
 Private Radiogroup RadioGroup1;
 Private Button button1;

 Private ImageView ImageView1;
 @Override protected void OnCreate (Bundle savedinstancestate) {//Represents the current Activity instance = this;
 Super.oncreate (savedinstancestate);
 Setcontentview (R.layout.fragment_main);
 RadioGroup1 = (radiogroup) Findviewbyid (r.id.radiogroup1);
 Set picture transparency//ImageView1 = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);
 Imageview1.getbackground (). Setalpha (100);
 Button1 = (Button) Findviewbyid (R.id.button1);
 Button1.setonclicklistener (New Mybuttonlistener ()); } class MyBUttonlistener implements Onclicklistener {@Override public void OnClick (View v) {//Get the selected RadioButton RadioButton
  RadioButton = (RadioButton) Findviewbyid (radioGroup1. Getcheckedradiobuttonid ());
  String Radiotext = Radiobutton.gettext (). toString ();
  Intent Intent = new Intent ();
  Intent.putextra ("Checked", radiotext);
  Intent.setclass (Mainactivity.this, Otheractivity.class);
 StartActivity (Intent);
 }
 }
}

--> otheractivity

Package com.dragon.android.fight;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.RadioButton;
Import Android.widget.RadioGroup;

Import Android.widget.TextView;
 public class Otheractivity extends activity {private Radiogroup radioGroup1;
 Private Button button1;
 Private TextView textView2;
 Private RadioButton RadioButton;

 Private Button button2;
 @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
 Setcontentview (R.layout.activity_other);
 RadioGroup1 = (radiogroup) Findviewbyid (r.id.radiogroup1);
 Button1 = (Button) Findviewbyid (R.id.button1);
 TextView2 = (TextView) Findviewbyid (R.ID.TEXTVIEW2);
 Button2 = (Button) Findviewbyid (R.id.button2);
 Button1.setonclicklistener (New Mybuttonlistener ());
 Button2.setonclicklistener (New MyButtonListener1 ()); } class MybuttonlisteNER implements Onclicklistener {@Override public void OnClick (View v) {RadioButton = (RadioButton) Findviewbyid (rad
  IoGroup1. Getcheckedradiobuttonid ());
  String ButtonText = Radiobutton.gettext (). toString ();
  Intent Intent = Getintent ();
  String checked = Intent.getstringextra ("checked");
  Set View to Visible textview2.setvisibility (view.visible);
  Button2.setvisibility (view.visible);
  String msg = "A out:" + checked + "\ n" + "B out:" + ButtonText + "\ n";
  if (buttontext.equals (checked)) {Textview2.settext (msg + "Draw");
  if (Buttontext.equals ("stone")) {if (Checked.equals ("scissors")) {Textview2.settext (msg + "Party B wins");
  else if (checked.equals ("cloth")) {Textview2.settext (msg + "party A WINS");
  } if (Buttontext.equals ("scissors")) {if (Checked.equals ("cloth")) {Textview2.settext (msg + "Party B wins");
  else if (Checked.equals ("stone")) {Textview2.settext (msg + "party A WINS");
  } if (Buttontext.equals ("cloth")) {if (Checked.equals ("stone")) {Textview2.settext (msg + "Party B wins"); } else if (Checked.equals ("scissors")) {Textview2.settext (msg + "party A WINS"); Class MyButtonListener1 implements Onclicklistener {@Override public void OnClick (View arg0) {Intent
  Intent = new Intent ();
  Intent.setclass (Otheractivity.this, Mainactivity.class);
  Finish ();
  Closes the specified activity MainActivity.instance.finish ();
 StartActivity (Intent);
 }
 }
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.