java魔兽_魔兽世界终极版(c++)(java)

import java.util.*;

import java.io.*;

import java.math.*;

import java.util.HashMap;

class Weapon{

static int R;

int atk;

Weapon(int type, int _atk){

if(type == 0)atk = _atk / 5;

if(type == 1)atk = 100;

if(type == 2)atk = 3;

}

}

class SAM{

int atk;

int hp;

int id;

int loyalty;

int step;

String color;

String type;

double morale;

Weapon[] wea = new Weapon[3];

static HashMap HP = new HashMap();

static HashMap ATK = new HashMap();

SAM(String _color, int _id, String _type, int hhp){

color = _color;

id = _id;

type = _type;

step = 0;

morale = 0;

loyalty = 100;

hp = HP.get(type);

atk = ATK.get(type);

Weapon WA = new Weapon(id % 3, atk);

Weapon WB = new Weapon((id + 1) % 3, atk);

if(WA.atk == 0)WA = null;

if(WB.atk == 0)WB = null;

if(type == "dragon"){

wea[id % 3] = WA;

morale = (double)hhp / HP.get("dragon");

}

if(type == "ninja"){

wea[id % 3] = WA;

wea[(id + 1) % 3] = WB;

}

if(type == "iceman")wea[id % 3] = WA;

if(type == "lion")loyalty = hhp;

}

String S2str(){

return color + " " + type + " " + Integer.toString(id);

}

String attr(){

return "with " + Integer.toString(hp) + " elements and force " + Integer.toString(atk);

}

int usesword(boolean con){

Weapon x = wea[0];

if(x == null)return 0;

int res = x.atk;

if(con){

x.atk = (int)(x.atk * 0.8);

if(x.atk == 0)wea[0] = null;

}

return res;

}

int getatk(boolean defense){

if(defense)return atk / 2 + usesword(false);

else return atk + usesword(false);

}

}

class HEA{

static String[][] Sam_type = {

{"iceman", "lion", "wolf", "ninja", "dragon"},

{"lion", "dragon", "ninja", "iceman", "wolf"},

};

int hp;

int Stot;

int type;

int pos;

int rew;

String color;

HEA(){}

HEA(String _color, int _hp, int _pos){

color = _color;

hp = _hp;

pos = _pos;

if(color == "red")type = 0;

else type = 1;

Stot = 0;

}

void summon(){

String Stype = Sam_type[type][Stot % 5];

if(SAM.HP.get(Stype) <= hp){

hp -= SAM.HP.get(Stype);

Stot++;

SAM S = new SAM(color, Stot, Stype, hp);

Game.C[pos][type] = S;

System.out.printf("%03d:00 %s born\n", Game.t / 60, S.S2str());

if((S.type) == "dragon")

System.out.printf("Its morale is %.2f\n", S.morale);

if((S.type) == "lion")

System.out.printf("Its loyalty is %d\n", S.loyalty);

}

}

};

class Game{

static boolean[] arr = new boolean[25];

static int t, M, N, R, K, T;

int[] chp = new int[25];

int[] flag = new int[25];

int[] lastwin = new int[25];

int[] win = new int[25];

HEA H[] = new HEA[2];

static SAM[][] C = new SAM[25][2];

int offen(int x){

if(flag[x] != -1)return flag[x];

if(x % 2 == 0)return 1;

else return 0;

}

void reset(int cas){

System.out.printf("Case %d:\n", cas);

t = 0;

for(int i = 0; i <= N + 1; i++){

C[i][0] = C[i][1] = null;

flag[i] = lastwin[i] = -1;

chp[i] = 0;

}

}

void escape(){

for(int i = 0; i <= N + 1; i++)

for(int j = 0; j < 2; j++)

if(C[i][j] != null && C[i][j].loyalty <= 0 && i != H[j ^ 1].pos){

System.out.printf("%03d:05 %s ran away\n", t / 60, C[i][j].S2str());

C[i][j] = null;

}

}

void move(){

boolean end = false;

int[] d = {-1, 1};

SAM[][] tmp = new SAM[25][2];

for(int i = 0; i <= N + 1; i++)

for(int j = 0; j < 2; j++){

int u = i + d[j];

if(i == H[j ^ 1].pos)tmp[i][j] = C[i][j];

if(u >= 0 && u <= N + 1 && C[u][j] != null){

SAM S = C[u][j];

S.step++;

if(S.step % 2 == 0 && S.type == "iceman"){

S.atk += 20; S.hp = Math.max(1, S.hp - 9);

}

tmp[i][j] = S;

if(i == H[j ^ 1].pos){

System.out.printf("%03d:10 %s reached %s headquarter %s\n", t / 60, S.S2str(), H[j ^ 1].color, S.attr());

if(C[i][j] != null){

System.out.printf("%03d:10 %s headquarter was taken\n", t / 60, H[j ^ 1].color);

end = true;

}

}

else System.out.printf("%03d:10 %s marched to city %d %s\n", t / 60, S.S2str(), i, S.attr());

}

}

for(int i = 0; i <= N + 1; i++)

for(int j = 0; j < 2; j++)

C[i][j] = tmp[i][j];

if(end)t = -1;

}

void gethp(){

for(int i = 1; i <= N ; i++)

for(int j = 0; j < 2; j++)

if(C[i][j] != null && C[i][j ^ 1] == null){

H[j].hp += chp[i];

System.out.printf("%03d:30 %s earned %d elements for his headquarter\n", t / 60, C[i][j].S2str(), chp[i]);

chp[i] = 0;

}

}

void shoot(){

for(int i = 1; i <= N; i++)arr[i] = false;

for(int i = 0; i <= N + 1; i++)

for(int j = 0; j < 2; j++){

SAM u = C[i][j], v = null;

int p;

if(j == 0)p = i + 1;

else p = i - 1;

if(p >= 0 && p <= N + 1)v = C[p][j ^ 1];

if(u == null || v == null || u.wea[2] == null)continue;

v.hp -= R;

u.wea[2].atk--;

if(u.wea[2].atk == 0)u.wea[2] = null;

if(v.hp > 0)System.out.printf("%03d:35 %s shot\n", t / 60, u.S2str());

else{

System.out.printf("%03d:35 %s shot and killed %s\n", t / 60, u.S2str(), v.S2str());

arr[p] = true;

}

}

}

void usebomb(){

for(int i = 1; i <= N; i++){

int p = offen(i);

SAM u = C[i][p], v = C[i][p ^ 1];

if(u == null || v == null || arr[i] == true)continue;

if(v.wea[1] != null && u.getatk(false) >= v.hp){

System.out.printf("%03d:38 %s used a bomb and killed %s\n", t / 60, v.S2str(), u.S2str());

C[i][p] = C[i][p ^ 1] = null;

}

else if(u.wea[1] != null && u.getatk(false) < v.hp && v.getatk(true) >= u.hp && v.type != "ninja"){

System.out.printf("%03d:38 %s used a bomb and killed %s\n", t / 60, u.S2str(), v.S2str());

C[i][p] = C[i][p ^ 1] = null;

}

}

}

void fight(int pos, int p, boolean defense){

SAM u = C[pos][p], v = C[pos][p ^ 1];

int tmp = Math.max(0, v.hp);

if(u.hp > 0 && v.hp > 0)

if(!defense || u.type != "ninja"){

v.hp -= u.getatk(defense);

u.usesword(true);

if(defense)

System.out.printf("%03d:40 %s fought back against %s in city %d\n", t / 60, u.S2str(), v.S2str(), pos);

else System.out.printf("%03d:40 %s attacked %s in city %d %s\n", t / 60, u.S2str(), v.S2str(), pos, u.attr());

}

if(v.hp <= 0 && u.hp > 0){

if(!arr[pos])

System.out.printf("%03d:40 %s was killed in city %d\n", t / 60, v.S2str(), pos);

win[pos] = p;

if(v.type == "lion")u.hp += tmp;

if(u.type == "wolf")

for(int i = 0; i < 3; i++)

if(u.wea[i] == null)u.wea[i] = v.wea[i];

}

}

void war(){

for(int i = 1; i <= N; i++)win[i] = -1;

H[0].rew = H[0].hp / 8;

H[1].rew = H[1].hp / 8;

for(int i = 1; i <= N; i++)

if(C[i][0] != null && C[i][1] != null){

int p = offen(i);

fight(i, p, false);

fight(i, p ^ 1, true);

if(C[i][p].morale > 0.8 && C[i][p].hp > 0)

System.out.printf("%03d:40 %s yelled in city %d\n", t / 60, C[i][p].S2str(), i);

if(win[i] != -1){

int w = win[i];

System.out.printf("%03d:40 %s earned %d elements for his headquarter\n", t / 60, C[i][w].S2str(), chp[i]);

H[w].hp += chp[i]; chp[i] = 0;

if(lastwin[i] == w && flag[i] != w){

flag[i] = w;

System.out.printf("%03d:40 %s flag raised in city %d\n", t / 60, H[w].color, i);

}

lastwin[i] = w;

}

for(int j = 0; j < 2; j++)

if(C[i][j].type == "dragon"){

if(j == win[i])C[i][j].morale += 0.2;

else C[i][j].morale -= 0.2;

}

if(C[i][0].hp > 0 && C[i][1].hp > 0){

for(int j = 0; j < 2; j++)

if(C[i][j].type == "lion")C[i][j].loyalty -= K;

lastwin[i] = -1;

}

}

for(int i = 1; i <= N; i++)

for(int j = 0; j < 2; j++)

if(C[i][j] != null && C[i][j].hp <= 0)C[i][j] = null;

for(int i = N; i > 0 && H[0].rew > 0; i--)

if(win[i] == 0){

H[0].hp -= 8; H[0].rew--;

C[i][0].hp += 8;

}

for(int i = 1; i <= N && H[1].rew > 0; i++)

if(win[i] == 1){

H[1].hp -= 8; H[1].rew--;

C[i][1].hp += 8;

}

}

void print15(SAM S){

System.out.printf("%03d:55 %s has ", t / 60, S.S2str());

if(S.wea[2] != null){

System.out.printf("arrow(%d)", S.wea[2].atk);

if(S.wea[1] != null || S.wea[0] != null)System.out.printf(",");

else System.out.printf("\n");

}

if(S.wea[1] != null){

System.out.printf("bomb");

if(S.wea[0] != null)System.out.printf(",");

else System.out.printf("\n");

}

if(S.wea[0] != null)System.out.printf("sword(%d)\n", S.wea[0].atk);

if(S.wea[0] == null && S.wea[1] == null && S.wea[2] == null)System.out.println("no weapon");

}

void turn(){

int M = t % 60;

if(M == 0){

H[0].summon();

H[1].summon();

}

if(M == 5)escape();

if(M == 10)move();

if(t == -1)return;

if(M == 20)for(int i = 1; i <= N; i++)chp[i] += 10;

if(M == 30)gethp();

if(M == 35)shoot();

if(M == 38)usebomb();

if(M == 40)war();

if(M == 50)

for(int i = 0; i < 2; i++)

System.out.printf("%03d:50 %d elements in %s headquarter\n", t / 60, H[i].hp, H[i].color);

if(M == 55){

for(int i = 0; i <= N + 1; i++)

if(C[i][0] != null)print15(C[i][0]);

for(int i = 0; i <= N + 1; i++)

if(C[i][1] != null)print15(C[i][1]);

}

t++;

}

void run(boolean debug){

Scanner sc = new Scanner(System.in);

int tot = sc.nextInt();

for(int cas = 1; cas <= tot; cas++){

M = sc.nextInt(); N = sc.nextInt(); R = sc.nextInt(); K = sc.nextInt(); T = sc.nextInt();

reset(cas);

H[0] = new HEA("red", M, 0);

H[1] = new HEA("blue", M, N + 1);

String tmp[] = {"dragon","ninja","iceman","lion","wolf"};

for(int i = 0; i < 5; i++)

SAM.HP.put(tmp[i], sc.nextInt());

for(int i = 0; i < 5; i++)

SAM.ATK.put(tmp[i], sc.nextInt());

while(t <= T && t != -1)turn();

}

}

}

public class Main{

public static void main(String[] args){

Game game = new Game();

game.run(true);

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值