zoukankan      html  css  js  c++  java
  • Java实现去火柴游戏

    package com.gh.p10;
    
    /**
     * Created by Lenovo on 2014/12/10.
     */
    
    import java.util.Random;
    import java.util.Scanner;
    
    /**
     * 取火柴游戏
     * 等待改进。。。。。
     */
    public class P10_6 {
        static int last,user,computer;
        static Scanner input=new Scanner(System.in);// 输入对象
        static void quhuochai(){
            Random r= new Random();//随机种子
            while (true){
                System.out.printf("--- 目前还有火柴%d根 ---
    ", last);
                System.out.printf("用户取火柴数量:");
                user=input.nextInt();
                if (user<1||user>=5||user>last){
                    System.out.printf("违规!取出的火柴数量有问题!重来。。。");
                    continue;
                }
                last=last-user;
                System.out.printf("用户取出%d根火柴
    ",user);
                if (last==0){
                    System.out.printf("Winner is Computer!!!");
                    break;
                }else{
                    if (last>5){
                        computer=r.nextInt(4)+1;
                    }else if (last<=1){
                        computer=1;
                    }else {
                        computer=last-1;
                    }
                    last=last-computer;
                    System.out.printf("电脑取出%d根火柴
    ",computer);
                    if (last==0){
                        System.out.printf("Winner is You!!!");
                        break;
                    }
                }
    
            }
        }
        public static void main(String[] args){
            System.out.printf("火柴数量:");
            last=input.nextInt();
            quhuochai();
        }
    
    }
  • 相关阅读:
    利用加载模块之外的地址绕过SafeSEH
    C++ 单实例运行
    添加程序以DLL函数
    HOOK地址还原
    利用未启用SafeSEH模块绕过SafeSEH
    SafeSEH基本概念+ 从堆区绕过SafeSEH学习
    替换.DATA的COOKIE突破GS
    虚函数绕过 GS保护 学习
    攻击虚函数学习
    虚函数学习
  • 原文地址:https://www.cnblogs.com/guhao123/p/4155298.html
Copyright © 2011-2022 走看看