Finger-guessing game full of code

Tencent video Songguo An unfinished part of the finger-guessing game, providing the source code, if the problem can contact me. qq: 24766954

 

1. study human mora

2, eclipse how to create a good class to change the name of
a method of operation: first mouse clicks to modify the class or method name or field name,
shortcut keys ALT + SHIFT + R -> modified to target name -> Enter End

b Point class name (press F2 notebook can not ah)
Press the F2 function key.
above the keyboard - -
If you have tips, let you save and then renamed, the point is on the line.
3, the teacher's video code is incomplete, the following All the code is common four categories.

1)Person类
import java.util.Scanner;

Person1 class {public
String name;
int FEN;

Scanner the INPUT = new new Scanner (System.in);

public void setName () {
System.out.print ( "Please enter your name:");
name = input.next () ;
}


public int Chu () {
of System.out.print ( "Please punches: 1 2. scissors stone, cloth 3:.");
int = input.nextInt the Choose ();
Switch (the Choose) {
Case 1:
the System .out.println ( "you punch as: scissors");
BREAK;
Case 2:
System.out.println ( "you punch as: stones");
BREAK;
Case. 3:
System.out.println ( "you out boxing is: cloth ");
BREAK;
default:
System.out.println (" input error, set to default values as you punch: scissors ");
the Choose = 1;
BREAK;
}
return choose;
}
}


2)Computer类
import java.util.Scanner;

Computer class {public
String name;
int FEN;

Scanner Scanner new new INPUT = (the System.in);
public void the setName () {
of System.out.print ( "Please enter the role of each other: (1, 2 Altman, Monkey 3 , dinosaurs): ");
int = input.nextInt the Choose ();
Switch (the Choose) {
Case. 1:
name =" Altman ";
BREAK;
Case 2:
name =" Monkey ";
BREAK;
Case. 3:
name = "dinosaurs";
BREAK;
default:
System.out.println ( "input error, the default value: Sunguo An");
name = "Sunguo An";
BREAK;
}
}

public int Chu () {
int the Choose = ( int) (Math.random () *. 3);
Switch (the Choose) {
Case 0:
System.out.println (name + "Punches: scissors ");
BREAK;
. 1 Case:
System.out.println (name + "punches: Stone");
BREAK;
Case 2:
System.out.println (name + "punches: Cloth");
BREAK;

}
return the Choose +. 1;
}
}

3)Game类
import java.util.Scanner;

public class Game {
int pfen =0;
int cfen =0;
int g_cs =0;
public void guess (int p ,int c,String pname,String cname) {
if (p==c) { System.out.println("和了");
}

if ((p==1) & (c==2))
{
System.out.println(cname+" win");
cfen++;
}

if ((p==1) & (c==3))
{
System.out.println(pname+" win");
pfen++;
}
if ((p==2) & (c==1))
{
System.out.println(pname+" win");
pfen++;
}
if ((p==2) & (c==3))
{
System.out.println(cname+" win");
cfen++;
}
if ((p==3) & (c==1))
{
System.out.println (CNAME + "win");
CFEN ++;
}
IF ((P ==. 3) & (C == 2))
{
System.out.println (pname + "win");
PFEN ++;
}
}
public void Start () {
Scanner the INPUT = new new Scanner (System.in);
System.out.println ( "Welcome to the game of world ------------- --------- ---- ");
System.out.println (" ***************** ");
System.out.println (" mora **, ** start ") ;
System.out.println ( "********************************************************");
System.out.println ( "punches rules: 1. scissors 2. 3 stone, cloth") ;
Computer Computer Computer new new = ();
computer.setName ();

of Person1 Person of Person1 = new new ();
person.setName ();

System.out.println (+ PERSON.NAME "VS "+computer.name);
System.out.println("");


System.out.print("要开始吗?Y/N:");
String flag=input.next();
while ( flag.equals("Y")){
g_cs++;
int p= person.chu();
int c= computer.chu();
guess(p,c,person.name,computer.name);
System.out.println("");
System.out.println("");
System.out.print("要进行下一轮吗?Y/N:");
flag=input.next();

}
System.out.println("--------------------------------");
System.out.println(person.name+" VS "+computer.name);
System.out.println("对战次数 :"+g_cs );
System.out.println("");
System.out.println("姓名 得分 ");
System.out.println(person.name+" "+pfen);
System.out.println(computer.name+" "+cfen);




System.out.println("");
System.out.println("");

}
}

4) Test class

public class Test {
public static void main(String[] args){
Game game=new Game();
game.start();
}
}

Guess you like

Origin www.cnblogs.com/henryzkf2020/p/12153786.html