Created
May 29, 2016 14:16
-
-
Save marciojrtorres/a1a95b416b08ac708b7e7f879f816d6c to your computer and use it in GitHub Desktop.
Simulação de batalha para a atividade Name Of The Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simulando batalha | |
Arma[] armas = new Arma[]{martelo, arco, poMagico}; | |
Escudo[] escudos = new Escudo[]{escudoFerro, escudoMagico, escudoMagico}; | |
int personagensVivos = personagens.length; | |
Personagem vencedor = null; | |
while (personagensVivos > 1) { | |
Personagem p1 = personagens[(int)(Math.random() * personagens.length)]; | |
Personagem p2 = p1; | |
while (p1 == p2) p2 = personagens[(int)(Math.random() * personagens.length)]; | |
p1.ataca(p2); | |
if (Math.random() < 0.5) p1.largaArma(); | |
if (Math.random() < 0.5) p2.largaArma(); | |
if (Math.random() < 0.5) p1.pegaArma(armas[(int)(Math.random() * armas.length)]); | |
if (Math.random() < 0.5) p2.pegaArma(armas[(int)(Math.random() * armas.length)]); | |
if (Math.random() < 0.5) p1.largaEscudo(); | |
if (Math.random() < 0.5) p2.largaEscudo(); | |
if (Math.random() < 0.5) p1.pegaEscudo(escudos[(int)(Math.random() * escudos.length)]); | |
if (Math.random() < 0.5) p2.pegaEscudo(escudos[(int)(Math.random() * escudos.length)]); | |
personagensVivos = 0; | |
for (Personagem p : personagens) if (p.estaVivo()) { | |
vencedor = p; | |
personagensVivos++; | |
} | |
} | |
System.out.println(vencedor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment