≈佐

—— 有恒则成。

统计

最新评论

第一次写的,石头剪子布游戏,不懂怎么优化算法等部份。

 

 1import java.util.*;
 2import java.lang.*;
 3class Gameing
 4{
 5 //String yzfy=new String("yzfy");
 6 //String wtt=new String("wtthappy");
 7boolean Ends=true;
 8
 9 void GameStart()
10 {
11   System.out.println("\n输入相应的英文代表石头剪子布");
12   System.out.println("石头 stone | 剪子 scissors | 布 cloth");
13   System.out.println();
14 }

15  
16 void GamePKInput()
17 {
18  do{
19   Scanner in=new Scanner(System.in);
20   String PK=in.nextLine();
21   PK=PK.toLowerCase();
22   Ends=PK.equalsIgnoreCase("end");
23   
24   if(Ends==false)
25   {
26
27    String[] PKWords=PK.split("[ ,]");
28    
29    
30    if(PKWords[0].equalsIgnoreCase("stone")||PKWords[0].equalsIgnoreCase("scissors")||PKWords[0].equalsIgnoreCase("cloth"))
31    {
32     if(PKWords[1].equalsIgnoreCase("stone")||PKWords[1].equalsIgnoreCase("scissors")||PKWords[1].equalsIgnoreCase("cloth"))
33     {
34      String yzfy=PKWords[0];
35      String wtt=PKWords[1];
36      GamePK(yzfy,wtt);
37     }

38     else
39     {
40      System.out.println("\n输入错误,请重新输入!\n");
41     }

42      
43    }

44    else
45    {
46     System.out.println("\n输入错误,请重新输入!\n");
47     
48    }

49   }

50   else
51   {
52    System.out.println("Game over!");
53   }

54  }
while(Ends==false);
55   
56   
57 }

58 
59 void GamePK(String yzfy,String wtt)
60 {
61  if(yzfy.equalsIgnoreCase("stone")&&wtt.equalsIgnoreCase("stone"))
62   System.out.println("平手。");
63  if(yzfy.equalsIgnoreCase("stone")&&wtt.equalsIgnoreCase("scissors"))
64   System.out.println("这一局是 yzfy 赢");
65  if(yzfy.equalsIgnoreCase("stone")&&wtt.equalsIgnoreCase("cloth"))
66   System.out.println("这一局是 wtt 赢");
67  
68  if(yzfy.equalsIgnoreCase("scissors")&&wtt.equalsIgnoreCase("scissors"))
69   System.out.println("平手。");
70  if(yzfy.equalsIgnoreCase("scissors")&&wtt.equalsIgnoreCase("stone"))
71   System.out.println("这一局是 yzfy 赢");
72  if(yzfy.equalsIgnoreCase("scissors")&&wtt.equalsIgnoreCase("cloth"))
73   System.out.println("这一局是 wtt 赢");
74
75  if(yzfy.equalsIgnoreCase("cloth")&&wtt.equalsIgnoreCase("cloth"))
76   System.out.println("平手。");
77  if(yzfy.equalsIgnoreCase("cloth")&&wtt.equalsIgnoreCase("stone"))
78   System.out.println("这一局是 wtt 赢");
79  if(yzfy.equalsIgnoreCase("cloth")&&wtt.equalsIgnoreCase("scissors"))
80   System.out.println("这一局是 yzfy 赢");
81
82 
83
84 }

85}

86public class SSCGame
87{
88 public static void main(String[] args)
89 {
90  Gameing pk=new Gameing();
91  pk.GameStart();
92  pk.GamePKInput();
93  //System.out.println(pk.GamePK());
94 }

95}

96

posted on 2008-03-17 18:55 ≈佐 阅读(379) 评论(0)  编辑  收藏 所属分类: J2SE 知识