猜拳游戏

 1 import java.util.Scanner;
 2 
 3 public class caiquan {
 4     public static void main(String[] args) {
 5         Scanner sc = new Scanner(System.in);
 6         for (;;) {
 7             int person = 0;
 8             for (;;) {
 9                 System.out.println("请输入你的选择(1--石头 2--剪刀 3--布)");
10                 person =sc.nextInt();
11                 if (person == 1) {
12                     System.out.println("你的选择是:石头");
13                     break;
14                 } else if (person == 2) {
15                     System.out.println("你的选择是:剪刀");
16                     break;
17                 } else if (person == 3) {
18                     System.out.println("你的选择是:布");
19                     break;
20                 } else {
21                     System.out.println("你的选择无效");
22                     continue;
23                 }
24             }
25 
26             int marchine;
27             for (;;) {
28                 System.out.println("电脑输入的选择(1--石头 2--剪刀 3--布)");
29                 marchine = (int) (Math.random() * 4);
30                 if (marchine == 1) {
31                     System.out.println("电脑的选择是:石头");
32                     break;
33                 } else if (marchine == 2) {
34                     System.out.println("电脑的选择是:剪刀");
35                     break;
36                 } else if (marchine == 3) {
37                     System.out.println("电脑的选择是:布");
38                     break;
39                 } else {
40                     System.out.println("电脑的选择无效");
41                     continue;
42                 }
43             }
44 
45             if (person == 1 && marchine == 1 || person == 2 && marchine == 2
46                     || person == 3 && marchine == 3) {
47                 System.out.println("平局!");
48             } else if (person == 1 && marchine == 2 || person == 2
49                     && marchine == 3 || person == 3 && marchine == 1) {
50                 System.out.println("你赢了!");
51             } else if (person == 1 && marchine == 3 || person == 2
52                     && marchine == 1 || person == 3 && marchine == 2) {
53                 System.out.println("很遗憾,你输了!");
54             }
55 
56             boolean bool = false;
57             for (;;) {
58                 System.out.print("是否继续下一局(Y/N):");
59                 String b = sc.next();
60                 if (b.equals("Y")) {
61                     bool = true;
62                     break;
63                 } else if (b.equals("N")) {
64                     bool = false;
65                     break;
66                 } else {
67                     continue;
68                 }
69             }
70             if (bool == true) {
71                 
72             } else {
73                 break;
74             }
75             System.out.println("\n"); 
76         }
77     }
78 }

 

posted @ 2016-09-13 10:25  奋斗的少年WH  阅读(183)  评论(0编辑  收藏  举报