import java.util.List; import java.util.ArrayList; public class Main { public static void main(String[] args) { //put the battle in testing so that it is print to log } } class Fight { // do your magic here! List<Fighter> fighters = new ArrayList<Fighter>(); public void introduceYourself(String name, int strength, int health) { System.out.println("Hi, my name is " + name + " (Strength: " + strength + ", Health: " + health + ")"); fighters.add(new Fighter(name,strength,health)); } public void startFight(){ System.out.println("\n** The battle begins! **\n"); while(fighters.size()>1){ for(int i=0;i<fighters.size();i++){ int randomTarget = (int)(Math.random()*fighters.size()); //gets a random targets position in the list to attack while(randomTarget == i) randomTarget = (int)(Math.random()*fighters.size()); //if the target is yourself, find a new target fighters.get(i).attack(fighters.get(randomTarget)); if(fighters.get(randomTarget).isDead()){ fighters.remove(randomTarget); //remove target from fighters list if they are dead } } } System.out.println("\n" + fighters.get(0).getName() + " is the CHAMPIOOOONNNNN!!!"); } } class Fighter { private String name; private int strength; private int health; public Fighter(String name, int strength, int health){ this.name = name; this.strength = strength; this.health = health; } public boolean isDead(){ return health <= 0; } public void attack(Fighter target){ int randomDamage = (int) ((Math.random() * strength)/2)+(strength/2); target.health -= randomDamage; System.out.println(target.name + " was attacked by " + name + " for "+ randomDamage + " damage! " + ((target.health > 0) ? "("+target.name+"'s health left " + target.health +")" : target.name.toUpperCase() + " HAS DIED!\n")); } public String getName(){ return name; } }
- import java.util.List;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
Fight fight = new Fight();// do your magic here!System.out.println("Hello world!");fight.introduceYourself("Mateusz");- //put the battle in testing so that it is print to log
- }
- }
- class Fight {
- // do your magic here!
static void introduceYourself(String name) {System.out.println("Hi, my name is " + name);- List<Fighter> fighters = new ArrayList<Fighter>();
- public void introduceYourself(String name, int strength, int health) {
- System.out.println("Hi, my name is " + name + " (Strength: " + strength + ", Health: " + health + ")");
- fighters.add(new Fighter(name,strength,health));
- }
- public void startFight(){
- System.out.println("\n** The battle begins! **\n");
- while(fighters.size()>1){
- for(int i=0;i<fighters.size();i++){
- int randomTarget = (int)(Math.random()*fighters.size()); //gets a random targets position in the list to attack
- while(randomTarget == i) randomTarget = (int)(Math.random()*fighters.size()); //if the target is yourself, find a new target
- fighters.get(i).attack(fighters.get(randomTarget));
- if(fighters.get(randomTarget).isDead()){
- fighters.remove(randomTarget); //remove target from fighters list if they are dead
- }
- }
- }
- System.out.println("\n" + fighters.get(0).getName() + " is the CHAMPIOOOONNNNN!!!");
- }
- }
- class Fighter {
- private String name;
- private int strength;
- private int health;
- public Fighter(String name, int strength, int health){
- this.name = name;
- this.strength = strength;
- this.health = health;
- }
- public boolean isDead(){
- return health <= 0;
- }
- public void attack(Fighter target){
- int randomDamage = (int) ((Math.random() * strength)/2)+(strength/2);
- target.health -= randomDamage;
- System.out.println(target.name + " was attacked by " + name + " for "+ randomDamage + " damage! " + ((target.health > 0) ? "("+target.name+"'s health left " + target.health +")" : target.name.toUpperCase() + " HAS DIED!\n"));
- }
- public String getName(){
- return name;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class Fight_1 { @Test public void arena_1() { Fight fight = new Fight(); // do your magic here! fight.introduceYourself("Mateusz",10,100); fight.introduceYourself("Your Mom",5,75); fight.introduceYourself("Pickle Rick",20,110); fight.startFight(); } @Test public void arena_2(){ Fight fight = new Fight(); fight.introduceYourself("Matimateoki",10,50); fight.introduceYourself("Your Mom6969",10,50); fight.startFight(); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own testsclass ExampleTest {- class Fight_1 {
- @Test
void testSomething() {// assertEquals("expected", "actual");- public void arena_1() {
- Fight fight = new Fight();
- // do your magic here!
- fight.introduceYourself("Mateusz",10,100);
- fight.introduceYourself("Your Mom",5,75);
- fight.introduceYourself("Pickle Rick",20,110);
- fight.startFight();
- }
- @Test
- public void arena_2(){
- Fight fight = new Fight();
- fight.introduceYourself("Matimateoki",10,50);
- fight.introduceYourself("Your Mom6969",10,50);
- fight.startFight();
- }
- }