public class Player {
Scanner sc = new Scanner(System.in);
int randomShanghai;
String name;
int hp;
String hero;
String num;
int win;
public void lvbuattack(){
boolean flag = true;
while (flag){
System.out.println("真人发动攻击:");
System.out.print("请输入你的英雄;A:吕布 B:貂蝉:");
name = sc.next();
if (name.equals("A")){
flag = false;
System.out.print("请输入你的招式:A:方天画戟 B:贪狼之杖 C:魔神降临");
num = sc.next();
if (num.equals("A")){
randomShanghai = (int)(Math.random()*30);
hp += 5;
hp += randomShanghai;
System.out.println("你发出【方天画戟】招式,对AI英雄造成了"+hp+"点伤害!");
}else if (num.equals("B")){
randomShanghai = (int)(Math.random()*30);
hp += 10;
hp += randomShanghai;
System.out.println("你发出【贪狼之杖】招式,对AI英雄造成了"+hp+"点伤害!");
}else if (num.equals("C")){
randomShanghai = (int)(Math.random()*30);
hp += 15;
hp += randomShanghai;
System.out.println("你发出【魔神降临】招式,对AI英雄造成了"+hp+"点伤害!");
}else {
hp += 0;
System.out.println("你未发出技能");
}
}else if (name.equals("B")){
flag = false;
System.out.print("请输入你的招式:A:飞落红雨 B:飘雨花印 C:绽放风华");
num = sc.next();
if (num.equals("A")){
randomShanghai = (int)(Math.random()*30);
hp += 5;
hp += randomShanghai;
System.out.println("你发出【飞落红雨】招式,对AI英雄造成了"+hp+"点伤害!");
}else if (num.equals("B")){
randomShanghai = (int)(Math.random()*30);
hp += 10;
hp += randomShanghai;
System.out.println("你发出【飘雨花印】招式,对AI英雄造成了"+hp+"点伤害!");
}else if (num.equals("C")){
randomShanghai = (int)(Math.random()*30);
hp += 15;
hp += randomShanghai;
System.out.println("你发出【绽放风华】招式,对AI英雄造成了"+hp+"点伤害!");
}else {
hp += 0;
System.out.println("你未发出技能");
}
}else {
System.out.print("请输入你的英雄;A:吕布 B:貂蝉:");
name = sc.next();
}
}
}
}
public class computer {
Scanner sc = new Scanner(System.in);
int randomShanghai;
String name;
int hp;
String hero;
String skil;
int randomskil;
int win;
public void aiAttack(){
boolean flag = true;
while (flag) {
System.out.println("AI发动攻击:");
System.out.print("请输入你的英雄;A:赵云 B:诸葛亮");
name = sc.next();
if (name.equals("A")) {
flag = false;
randomskil = (int)(Math.random()*3);
System.out.println(randomskil);
if (randomskil == 0) {
randomShanghai = (int) (Math.random() * 30);
hp += 5;
hp += randomShanghai;
System.out.println("AI英雄发出了【惊云之龙】招式对你造成了" + hp + "点伤害!");
} else if (randomskil == 1) {
randomShanghai = (int) (Math.random() * 30);
hp += 10;
hp += randomShanghai;
System.out.println("AI英雄发出了【破晓之龙】招式对你造成了" + hp + "点伤害!");
} else if (randomskil == 2) {
randomShanghai = (int) (Math.random() * 30);
hp += 15;
hp += randomShanghai;
System.out.println("AI英雄发出了【飞天之龙】招式对你造成了" + hp + "点伤害!");
} else {
}
} else if (name.equals("B")) {
flag = false;
randomskil = (int)(Math.random()*4);
System.out.println(randomskil);
if (randomskil == 0) {
randomShanghai = (int) (Math.random() * 30);
hp += 5;
hp += randomShanghai;
System.out.println("AI英雄发出了【东风逆袭】招式对你造成了" + hp + "点伤害!");
} else if (randomskil == 1) {
randomShanghai = (int) (Math.random() * 30);
hp += 10;
hp += randomShanghai;
System.out.println("AI英雄发出了【时空穿越】招式对你造成了" + hp + "点伤害!");
} else if (randomskil == 2) {
randomShanghai = (int) (Math.random() * 30);
hp += 15;
hp += randomShanghai;
System.out.println("AI英雄发出了【元气之弹】招式对你造成了" + hp + "点伤害!");
} else {
}
} else {
System.out.print("请输入你的英雄;A:吕布 B:貂蝉");
name = sc.next();
}
}
}
}
public class Game {
Scanner sc = new Scanner(System.in);
Player zhenren = new Player();
computer AI = new computer();
int player ;
int Computer;
int playerCount;
int computerCount;
String jushu = "y";
int ju = 0;
public void initial(){
start();
}
public void start(){
while (jushu.equals("y")){
player = 100;
Computer = 100;
ju++;
for (int i = 1; i <=3 ; i++) {
zhenren.hp = 0;
AI.hp = 0;
System.out.println("------欢迎来到1V1人机对战游戏------");
System.out.println("*******************************");
System.out.println("********* 游戏开始 **********");
System.out.println("*********【真人 VS AI】**********");
System.out.println("*******************************");
System.out.println("-----------【第"+i+"回合】-----------");
zhenren.lvbuattack();
AI.aiAttack();
player -= zhenren.hp;
Computer -= AI.hp;
System.out.println("真人剩余血量:"+Computer);
System.out.println("AI余血量:"+player);
if (player<Computer){
System.out.println("第【"+i+"】回合真人胜");
playerCount++;
}else {
System.out.println("第【"+i+"】回合AI胜");
computerCount++;
}
System.out.println("********************************");
}
if (playerCount>computerCount){
System.out.println("真人本局胜出");
}else {
System.out.println("AI本局胜出");
}
System.out.println("请选择是否进入下一局(y/n)");
jushu = sc.next();
}
System.out.println("********************************");
System.out.println("\t共进行"+ju+"局游戏");
System.out.println("真人获胜回合数:"+playerCount);
System.out.println("AI获胜回合数:"+computerCount);
if (playerCount>computerCount){
System.out.println("\t结果:真人胜出");
}else if (playerCount <computerCount){
System.out.println("\t结果:AI胜出");
}else {
System.out.println("平局");
}
System.out.println("********************************");
}
}
public class GameTest {
public static void main(String[] args) {
//初始化
Game youxi = new Game();
youxi.initial();
}
}