java编程-小游戏

package day02;

import java.util.Scanner;

public class HomeWork1 {
	public static void main(String[] args) {
		int heroDam = 500;
		int bossDam = 1000;
		int heroHp = 20000;
		int bossHp = 100000;
		
		int dis = 100;
		
		Scanner sc = new Scanner(System.in);
		
		while(dis>15) {
			System.out.println("当前距离boss的距离"+dis);
			System.out.println("请输入你要前进的距离");
			int move =sc.nextInt();
			if(move>15) {
				System.out.println("步子太大,走不了");
				continue;
			}else if(move<0) {
				System.out.println("输入的值有误,请重新输入");
				continue;
			}else {
				dis = dis -move;
			}
		}
		System.out.println("已经发现boss,是否战斗?");
		
		String judgement = sc.next();
		
		while(true) {
			switch(judgement) {
			case "N":
				System.out.println("胆小鬼,去死吧");
				break;
			case "Y":
				System.out.println("boss的血量是"+bossHp);
				System.out.println("hero的血量是"+heroHp);
				
				int random = (int)(Math.random()*1000);
				if(random<100) {
					heroHp = heroHp + 500;
				}
				if(random<10) {
					heroDam = heroDam*3;
				}
				if(random==1) {
					bossHp = bossHp+1000000;
				}			
				
				bossHp = bossHp-heroDam;				
				heroHp = heroHp-bossDam;
					
			}
			if(bossHp<=0 & heroHp>0) {
				System.out.println("英雄赢了");
				break;
			}
			if(bossHp>0 & heroHp<=0) {
				System.out.println("boss赢了");
				break;
			}
			if(bossHp<=0 & heroHp<=0) {
				System.out.println("同归于尽了");
				break;
			}				
		}		
	}
}

 

你可能感兴趣的:(java编程-小游戏)