The Java applet for the stone Scissors cloth for beginners Reference

Source: Internet
Author: User
Tags stub

Package Youxi;

public class Player {
private String name;
private double score;
Public Player (String name, double score) {
Super ();
THIS.name = name;
This.score = score;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
Public double Getscore () {
return score;
}
public void SetScore (double score) {
This.score = score;
}


Private String SetScore () {
TODO auto-generated Method Stub
return This.setscore ();
}


Private String SetName () {
TODO auto-generated Method Stub
return This.setname ();
}
}

Package Youxi;

Import Java.util.Scanner;


public class Game {

Private player player;
Public Game (player player) {
This.player=player;
}


public void Start () {
while (true) {
System.out.println ("Start Game");
Scanner sc=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please input scissors stone cloth or exit");
String S1=sc.next ();
if (S1.equals ("Exit")) {
Break
}
String[] arr=new string[]{"scissors", "stone", "cloth"};
int count= (int) (Math.random ());
String S2=arr[count];
int Flag=rule (S1,S2);
if (flag>0) {
System.out.println ("Robot" +arr[count]+ "~~~~~" +player.getname () + "won, plus very");
Player.setscore (Player.getscore () +10);

}
if (flag<0) {
System.out.println ("Robot" +arr[count]+ "~~~~~" +player.getname () + "lost, minus very");
Player.setscore (Player.getscore ()-10);

}
else if (flag==0) {
System.out.println ("Robot" +arr[count]+ "~~~~~" + "Tie");
}
System.out.println (Player.getname () + ":" +player.getscore ());
}

}

/**
* Rules of the game
* @return
*/

public int rule (String s1,string s2) {
if (s1.equals (S2))
{return 0;}
if (S1.equals ("scissors")) {
if (S2.equals ("stone")) {
return-1;

}
if (S2.equals ("cloth")) {
return 1;
}
}
if (S1.equals ("stone")) {
if (S2.equals ("cloth")) {
return-1;

}
if (S2.equals ("scissors")) {
return 1;
}
}
if (S1.equals ("cloth")) {
if (S2.equals ("scissors")) {
return-1;

}
if (S2.equals ("stone")) {
return 1;
}
}


return 0;
}
}

Package Youxi;

public class Test {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Player P=new player ("Chi Wei", 100);
Game G=new Game (p);
G.start ();

}

}

The Java applet for the stone Scissors cloth for beginners Reference

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.