close

package Practice;

import java.util.Scanner;

public class HomeWork {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int player;

        int w = 0;
        int l = 0;
        int s = 0;
        while (1 < 2 || 2 < 3 || 3 < 1) {
            int cpu = (int) (Math.random() * 3) + 1;
            System.out.println("猜拳遊戲");
            System.out.println("1.剪刀");
            System.out.println("2.石頭");
            System.out.println("3.布");
            System.out.println("4.不玩了");
            System.out.println("---------------");
            player = sc.nextInt();

            if (player > 4 || player < 1) {
                System.out.println("輸入錯誤了!");
                System.out.println("-----------------");
                continue;

            }

            if (player == 4) {
                System.out.println("Game over");
                System.out.println("比賽" + (w + l + s) + "次");
                System.out.println("你贏了" + w + "次");
                System.out.println("你輸了" + l + "次");
                break;
            }

            System.out.println("---------------");
            System.out.println("Player = " + player);
            System.out.println("Computer = " + cpu);
            System.out.println("---------------");

            if (player < cpu) {

                System.out.println("你輸了");
                System.out.println("---------------");
                l++;
                continue;
            } else if (player > cpu) {

                System.out.println("你贏了");
                System.out.println("---------------");
                w++;
                continue;

            }
            if (player == cpu) {
                System.out.println("平手");
                System.out.println("---------------");
                s++;

            }
        }

    }

}

arrow
arrow
    文章標籤
    程式語言 HomeWork 猜拳
    全站熱搜

    蛋餅Brook 發表在 痞客邦 留言(0) 人氣()