diff --git a/Battle.java b/Battle.java new file mode 100644 index 00000000..68599425 --- /dev/null +++ b/Battle.java @@ -0,0 +1,56 @@ +public class Battle { + + public Game game; + boolean end; + + Battle(Game g){ + this.game = g; + this.end = false; + } + + public void battle(){ + System.out.println("Your battle with the enemy has started."); + do{ + //enemy attacks character + game.enemy.kick(game.character); + + //checks to see if character has lost battle + if (game.character.health == 0) { + System.out.println("Sorry you lost the battle."); + this.end = true; + } + else if (game.enemy.health == 0 && game.character.health != 0){ + System.out.println("Congrats you won the battle!"); + this.end = true; + } + + System.out.println("Do you wish to attack the enemy or to see the status of your troops?"); + String order = game.sc.nextLine().toLowerCase(); + if (order.equals("attack")){ + //choose random number between range + int x = game.getRandomNumber(1, 2); + //based on random number, character chooses an attack + if (x == 1){ + game.character.kick(game.enemy); + } else { + game.character.shoot(game.enemy); + } + } else { + System.out.println("The captain has ordered the troop to retreat"); + System.out.println(game.character); + } + + } while (end != true); + } + + + public static void main(String[] args) { + Game game = new Game(); + Battle battle = new Battle(game); + battle.battle(); + } +} + +//NOTES TO US +// Need to fix how battle ends. Character can't keep playing after health = 0 +// Make sure check status works diff --git a/Game.java b/Game.java new file mode 100644 index 00000000..a7477bd3 --- /dev/null +++ b/Game.java @@ -0,0 +1,43 @@ +import java.util.Scanner; +import java.util.Random; + +public class Game { + public Human enemy; + public Human character; + public Scanner sc; + public boolean gameEnd; + + public Game(){ + this.enemy = new Human("enemy", 10, 5, 0, true); + this.character = new Human("human", 10, 5, 5, false); + this.sc = new Scanner(System.in); + this.gameEnd = false; + } + + //getRandomNumber within range + public int getRandomNumber(int min, int max){ + Random random = new Random(); + return random.nextInt(max - min) + min; + } + + //overloaded getRandomNumber without range + public int getRandomNumber(){ + Random random = new Random(); + return random.nextInt(); + } + + //game method + public void gameMethod(){ + System.out.println("Your game has started."); + if (character.name == "insert whatever ending condition we want for the game here") + gameEnd = true; + System.out.println("Your game has ended."); + //return + } + +public static void main(String[] args) { + Game game = new Game(); + game.gameMethod(); + +} +} diff --git a/Human.java b/Human.java new file mode 100644 index 00000000..9989f667 --- /dev/null +++ b/Human.java @@ -0,0 +1,46 @@ +public class Human{ + +//attributes +public String name; +public int health; +public int experience; +public int alliance; +public boolean isEnemy; + +//constructor +public Human(String name, int health, int experience, int alliance, boolean isEnemy){ + this.name = name; + this.health = health; + this.experience = experience; + this.alliance = alliance; + this.isEnemy = isEnemy; +} + +//methods +public void kick(Human h){ + //-5 points to enemy + System.out.println(h.name + " has suffered a kick"); + int damage = 5; + h.health -= damage; +} + +public void shoot(Human h){ + // -10 points to enemy + System.out.println(h.name + "is down with a grave injury"); + int damage = 10; + h.health -= damage; +} + +public String toString(){ + return "Name: " + name + + "\nHealth: " + health + + "\nExperience: " + experience + + "\nAlliance: " + alliance + + "\nisEnemy: " + isEnemy; +} + +public static void main(String[] args) { + Human h = new Human("enemy", 10, 5, 0, true); + System.out.println(h); +} +} \ No newline at end of file diff --git a/nonBattle.java b/nonBattle.java new file mode 100644 index 00000000..e2da64db --- /dev/null +++ b/nonBattle.java @@ -0,0 +1,3 @@ +public class nonBattle { + +} diff --git a/work.txt b/work.txt new file mode 100644 index 00000000..22b0ac1b --- /dev/null +++ b/work.txt @@ -0,0 +1,12 @@ +Work Meeting #1: 4/16/23 +Accomplished: basic structure of game and classes +To-Do: +- Need to fix how battle ends. Character can't keep playing after health = 0 +- Create human class and let enemy and character inherit from there. + +FP Workshop #1: 4/18 +Accomplished: figuring out structure of classes +To-Do: +- seperate battle and game class +- battle & non-battle classes +