炉石传说 java实现
试题编号: 201609-3 《炉石传说:魔兽英雄传》(Hearthstone: Heroes of Warcraft,简称炉石传说)是暴雪娱乐开发的一款集换式卡牌游戏(如下图所示)。游戏在一个战斗棋盘上进行,由两名玩家轮流进行操作,本题所使用的炉石传说游戏的简化规则如下: * 玩家会控制一些角色,每个角色有自己的生命值和攻击力。当生命值小于等于 0 时,该角色死亡。角色分为英雄和随从。 输入格式 输入第一行是一个整数?n,表示操作的个数。接下来?n?行,每行描述一个操作,格式如下: 输出格式 输出共 5 行。 样例输入 8 样例输出 0 样例说明 按照样例输入从第 2 行开始逐行的解释如下: 评测用例规模与约定 * 操作的个数0 ≤?n?≤ 1000。 ? public class Dependent { int attack = -1; int health = -1; public Dependent(int attack,int health) { this.attack = attack; this.health = health; } public void beattacked(int attack) { this.health = this.health - attack; } public int gethealth() { return this.health; } public boolean bedestory() { if (this.health <= 0) { return true; } return false; } } ? role类: ? import java.util.ArrayList; import java.util.List; public class role { int helth = 30; List<Dependent> warland = new ArrayList<Dependent>(); static int num; public void beattacked(int num) { this.helth = this.helth - num; } public int gethealth() { return this.helth; } public boolean bedestory() { if (this.helth <= 0) { return true; } return false; } public List<Dependent> getwarland() { return this.warland; } public void init() { for (int i = 0; i < 8; i++) { warland.add(new Dependent(1000,1000)); } } public void printdependent() { int cout = 0; for (int i = 0; i < warland.size(); i++) { if (warland.get(i).health < 1000) { cout++; } } System.out.print(cout + " "); for (int i = 0; i < warland.size(); i++) { if (warland.get(i).health < 1000) { System.out.print(warland.get(i).health + "-" + i + "-" + warland.get(i).attack + " "); } } } } ? MAIN类: ? import java.util.Scanner; public class MAIN { static role orderRole = null; static role role1 = new role();// 先手 static role role2 = new role();// 后手 public static void main(String[] args) { // TODO Auto-generated method stub // 战场用LIST MAIN main = new MAIN(); Scanner scanner = new Scanner(System.in); System.out.println("Input num"); int num = scanner.nextInt(); String temp32323 = scanner.nextLine(); role1.num = 1; role1.init(); role2.num = 2; role2.init(); orderRole = role1; // System.out.println(orderRole.equals(role1)); for (int i = 0; i < num; i++) { String command = scanner.nextLine(); if (!command.equals("end")) { String[] dealStrings = command.split(" "); System.out.println("--------------"); for (int j = 0; j < dealStrings.length; j++) { System.out.println(dealStrings[j] + " " + dealStrings.length); } if (dealStrings[0].equals("summon")) { orderRole.warland.add(Integer.parseInt(dealStrings[1]),new Dependent(Integer.parseInt(dealStrings[2]),Integer.parseInt(dealStrings[3]))); role1.printdependent(); System.out.println("n"); System.out.println(orderRole.equals(role1) + " " + orderRole.equals(role2)); role2.printdependent(); System.out.println("n"); System.out.println(role1.warland); System.out.println(role2.warland); } if (dealStrings[0].equals("attack")) { role anotherrole = main.anotherrole(); if (anotherrole != null) { if (Integer.parseInt(dealStrings[2]) == 0) { anotherrole .beattacked(orderRole.warland.get(Integer.parseInt(dealStrings[1])).attack); if (anotherrole.bedestory()) { if (orderRole.num == 1) { System.out.println(1); System.exit(0); } if (orderRole.num == 2) { System.out.println(-1); System.exit(0); } } } else { anotherrole.warland.get(Integer.parseInt(dealStrings[2])) .beattacked(orderRole.warland.get(Integer.parseInt(dealStrings[1])).attack); orderRole.warland.get(Integer.parseInt(dealStrings[1])) .beattacked(anotherrole.warland.get(Integer.parseInt(dealStrings[2])).attack); if (orderRole.warland.get(Integer.parseInt(dealStrings[1])).bedestory()) { System.out.println("hey"); orderRole.warland.remove(Integer.parseInt(dealStrings[1])); // orderRole.warland.add(Integer.parseInt(dealStrings[1]),new Dependent(1000,// 1000)); } else { System.out.println( orderRole.warland.get(Integer.parseInt(dealStrings[1])).health + " healthhey"); } if (anotherrole.warland.get(Integer.parseInt(dealStrings[2])).bedestory()) { System.out.println("hey2"); anotherrole.warland.remove(Integer.parseInt(dealStrings[2])); // anotherrole.warland.add(Integer.parseInt(dealStrings[2]),// new Dependent(1000,1000)); } else { System.out.println(anotherrole.warland.get(Integer.parseInt(dealStrings[2])).health + " healthhey2"); } } } else { System.out.println("anotherrole is null"); System.exit(-1); } } } else { if (orderRole.equals(role1)) { orderRole = role2; System.out.println("change 1"); continue; } if (orderRole.equals(role2)) { orderRole = role1; System.out.println("change 2"); continue; } } } if (!role1.bedestory() && !role2.bedestory()) { System.out.println(0); } System.out.println(role1.helth); role1.printdependent(); System.out.println("n"); System.out.println(role2.helth); role2.printdependent(); System.out.println(role1.equals(role2)); } public role anotherrole() { if (orderRole.equals(role1)) { return role2; } if (orderRole.equals(role2)) { return role1; } return null; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |