Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Battle.java
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions Game.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
46 changes: 46 additions & 0 deletions Human.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 3 additions & 0 deletions nonBattle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class nonBattle {

}
12 changes: 12 additions & 0 deletions work.txt
Original file line number Diff line number Diff line change
@@ -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