/*
 * 定义用户类
 * 
 *
 */
package game.dingming_liu;import java.util.*;public class showFist { Scanner input = new Scanner(System.in); String name1 = "刘备"; String name2 = "孙权"; String name3 = "曹操"; String score1 = "剪刀"; String score2 = "石头"; String score3 = "布"; public void show() { String answer1 = "y";
System.out.print("1:刘备 2:孙权 3:曹操 (请选择角色)"); int choice = input.nextInt();
System.out.println("是否开始?(y/n)");
answer1 = input.next(); do {
System.out.println("1:剪刀 2:石头 3:布 (请输入对应数字)");
switch (choice) {
case 1:
System.out.println(name1);
break; case 2:
System.out.println(name2);
break;
case 3:
System.out.println(name3);
return; }
System.out.print("请出拳:"); int change = input.nextInt();
switch (change) {
case 1:
System.out.println(score1);
break;
case 2:
System.out.println(score2);
break;
case 3:
System.out.println(score3); return;
}


System.out.println("是否继续?(y/n)");
answer1 = input.next();
} while (!answer1.equals("y")); System.out.println("程序结束!");

}}/*
 * 定义计算机类
 */
package game.dingming_liu;
import game.dingming_liu.showFist;
import java.util.*;
public class computer {
String compname = "电脑出拳:";

showFist answer2 = new showFist();
Scanner input = new Scanner(System.in);

String answer1 ="n";

int Score;

public void showcomp() {
//随机产生1、2、3

Score = (int)(Math.random()*3);
int score = (int) (Math.random() * 3);
do{
if (score == 1) { System.out.println(compname + "剪刀");
} else if (score == 2) {
System.out.println(compname + "石头");
} else if (score ==3){
System.out.println(compname + "布");
}
System.out.println("是否继续?(y/n)");
answer1= input.next();
//answer2.show();
//System.out.println("*********进行下一轮比赛*********");
}while (answer1.equals("y"));
System.out.println("程序结束!");

}
}/*
 * 定义游戏类
 */
package game.dingming_liu;
import game.dingming_liu.showFist;
import game.dingming_liu.computer;
/*定义游戏的属性*/
public class game {



showFist com = new showFist();
computer score = new computer();

int count;
int win;
int lost;
int ping;
String person;
String computer;
String answer = "n";
/* 定义游戏的方法*/
public int calcResult(){
//do{
if(com.score1.equals("1")){
if(score.Score == 1){
System.out.println("电脑猜的拳是:剪刀");
System.out.println("您猜的拳是:剪刀");
System.out.println("结果:打成平手,下次再和你一分高下!");
count++;
ping++;
}
else if(score.Score==2){
System.out.println("电脑猜的拳是:石头");
System.out.println("您猜的拳是:剪刀");
System.out.println("结果:呵呵,笨笨,下次加油啊!");
count++;
lost++;
}else if(score.Score == 3){
System.out.println("电脑猜的拳是:布");
System.out.println("您猜的拳是:剪刀");
System.out.println("结果:恭喜恭喜!");
count++;
win++;
}

}
if(com.score1.equals("2")){
if(score.Score==1){
System.out.println("电脑猜的拳是:剪刀");
System.out.println("您猜的拳是:石头 ");
System.out.println("结果:恭喜恭喜!");
count++;
win++;
}else if(score.Score == 2){
System.out.println("电脑猜的拳是:石头");
System.out.println("您猜的拳是:石头 ");
System.out.println("结果:打成平手,下次再和你一分高下!");
count++;
ping++;
}else if(score.Score == 3){
System.out.println("电脑猜的拳是:布");
System.out.println("您猜的拳是:石头");
System.out.println("结果:呵呵,笨笨,下次加油啊!");
lost++;
count++;

}
}
if(com.score1.equals("3")){
if(score.Score == 1){
System.out.println("电脑猜的拳是:剪刀");
System.out.println("您猜的拳是:布    ");
System.out.println("结果:呵呵,笨笨,下次加油啊!");
lost++;
count++;
}else if(score.Score == 2){
System.out.println("电脑猜的拳是:石头");
System.out.println("您猜的拳是:布    ");
System.out.println("结果:恭喜恭喜!");
win++;
count++;
}else if(score.Score == 3){
System.out.println("电脑猜的拳是:布");
System.out.println("您猜的拳是:布    ");
System.out.println("结果:打成平手,下次再和你一分高下!");
ping++;
count++;
}
}
return (count++) + (lost++) + (ping++);
}//while(answer.equals("n"));
//System.out.println();

public void showResult(){
calcResult();
}
}/*
*定义游戏类的方法:开始游戏
*
*
*/
package game.dingming_liu;//import java.util.*;
//import game.dingming_liu.showFist;
//import game.dingming_liu.computer;public class Gamebegin { /**
 * @param args
 */ public void showgamebegin() {
System.out.println("----------欢 迎 进 入 游 戏 世 界----------");
System.out.println("\t****************\t");
System.out.println("\t**猜 拳 开 始**\t");
System.out.println("\t****************\t"); }
}/*
*编写程序入口,并测试
*
*
*/
package game.dingming_liu;
import java.util.*;
import game.dingming_liu.showFist;
import game.dingming_liu.computer;public class Testgame { /**
 * 
 * @param args
 * 
 * 
 * 
 */


public static void main(String[] args) {
// TODO 自动生成方法存根
showFist new1 = new showFist();
computer new2 = new computer();
Gamebegin new3 = new Gamebegin();
game new4 = new game();
//System.out.println(showgamebegin());
new3.showgamebegin();
new1.show();
new2.showcomp();
new4.showResult(); }}
/*要求:效果如下
*        ***************欢迎进入游戏世界*************
*        ************   猜  拳  开  始   ************
*        ********************************************
* 出拳规则: 1:剪刀  2:石头 3 :布
*请选择角色1.曹操 2:孙权 3:曹操
*
*要开始吗?(y/n)  y
*请出拳:1:剪刀  2:石头 3 :布
*你出拳:剪刀
*电脑出拳:剪刀
*结果 :和局,真衰!嘿嘿,等着瞧吧!
*
*是否开始下一轮(y/n) n
*-------------------------------------------------------------
*刘备  VS  匿名
*对战次数 : 1
*结局:打成平手,下次再和你一分高下!
*-------------------------------------------------------------
*/