Skip to content
Snippets Groups Projects
Commit 1fe83f94 authored by Sondre Malerud's avatar Sondre Malerud :coffee:
Browse files

Updated javadoc

parent 08a49570
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import java.util.List;
/**
* Class used to communicate with Army class from GUI
*
* @author Sondre Malerud
*/
public class ArmyController {
......@@ -19,6 +20,7 @@ public class ArmyController {
/**
* Returns an instance of this army controller
*
* @return this army controller
*/
public static ArmyController getInstance() {
......@@ -27,6 +29,7 @@ public class ArmyController {
/**
* Creates an ally army with no units
*
* @param armyName is the name of the army
*/
public void createAllyArmy(String armyName) {
......@@ -35,6 +38,7 @@ public class ArmyController {
/**
* Creates an enemy army with no units
*
* @param armyName is the name of the army
*/
public void createEnemyArmy(String armyName) {
......@@ -43,6 +47,7 @@ public class ArmyController {
/**
* Gets the ally army
*
* @return Army, the ally army
*/
public Army getAllyArmy() {
......@@ -51,6 +56,7 @@ public class ArmyController {
/**
* Sets all units of the ally army. If the army contains units from beforehand, the method will remove all of these.
*
* @param units a List of units that should be put into the army
*/
public void setAllyUnits(List<Unit> units) {
......@@ -60,6 +66,7 @@ public class ArmyController {
/**
* Sets all units of the enemy army. If the army contains units from beforehand, the method will remove all of these.
*
* @param units a List of units that should be put into the army
*/
public void setEnemyUnits(List<Unit> units) {
......@@ -69,6 +76,7 @@ public class ArmyController {
/**
* Method that replaces the ally army in this controller
*
* @param army Army, is the updated army
* @return false if the army object is null, true otherwise
*/
......@@ -81,6 +89,7 @@ public class ArmyController {
/**
* Method that replaces the enemy army in this controller
*
* @param army Army, is the updated army
* @return false if the army object is null, true otherwise
*/
......@@ -93,6 +102,7 @@ public class ArmyController {
/**
* Gets the enemy army
*
* @return Army, the ally army
*/
public Army getEnemyArmy() {
......@@ -101,6 +111,7 @@ public class ArmyController {
/**
* Reads ally army from csv-file and assigns it to this.allyArmy
*
* @param path is the path to the csv-file.
* @throws IOException if the file cannot be read
*/
......@@ -110,6 +121,7 @@ public class ArmyController {
/**
* Reads enemy army from csv-file and assigns it to this.enemyArmy
*
* @param path is the path to the csv-file.
* @throws IOException if the file cannot be read
*/
......
......@@ -6,6 +6,7 @@ import javafx.beans.property.SimpleDoubleProperty;
/**
* Controller class to help with simulating a battle between to armies.
* The class stores the armies' total health and current health to help the GUI's health bars work properly
*
* @author Sondre Malerud
*/
public class SimulateController {
......@@ -20,6 +21,7 @@ public class SimulateController {
/**
* Returns an instance of this SimulateController
*
* @return an instance of this SimulateController
*/
public static SimulateController getInstance() {
......@@ -28,6 +30,7 @@ public class SimulateController {
/**
* Saves ally total health, which will be used to calculate health percentage
*
* @param allyTotalHealth int, is the total health of the ally army
*/
public void setAllyTotalHealth(int allyTotalHealth) {
......@@ -36,6 +39,7 @@ public class SimulateController {
/**
* Saves enemy total health, which will be used to calculate health percentage
*
* @param enemyTotalHealth int, is the total health of the enemy army
*/
public void setEnemyTotalHealth(int enemyTotalHealth) {
......@@ -44,6 +48,7 @@ public class SimulateController {
/**
* Gets current ally health
*
* @return the current health of the entire ally army
*/
public int getAllyHealth() {
......@@ -52,6 +57,7 @@ public class SimulateController {
/**
* Sets the allied army's current health
*
* @param allyHealth the number representing the entire army's current health
*/
public void setAllyHealth(int allyHealth) {
......@@ -60,6 +66,7 @@ public class SimulateController {
/**
* Gets current enemy health
*
* @return the current health of the entire ally army
*/
public int getEnemyHealth() {
......@@ -68,6 +75,7 @@ public class SimulateController {
/**
* Sets the enemy army's current health
*
* @param enemyHealth the number representing the entire army's current health
*/
public void setEnemyHealth(int enemyHealth) {
......
package no.ntnu.sondrmal.wargames.enums;
/**
* Different types of terrain that can be used
*
* @author Sondre Malerud
*/
public enum TerrainType {
HILL,
PLAINS,
......
package no.ntnu.sondrmal.wargames.enums;
/**
* Enum class with the 4 different unit types
* @version 0.0.1
* Different types of units that can be created
*
* @author Sondre Malerud
*/
public enum UnitType {
......
......@@ -10,6 +10,11 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Scanner;
/**
* File handling class. Will help saving and loading armies to csv files
*
* @author Sondre Malerud
*/
public class DataHandler {
......@@ -42,6 +47,16 @@ public class DataHandler {
}
}
/**
* Attempts to read a csv-file and convert it to an army.
* File must be on this format:
* First line: Name
* Following lines: UnitName,UnitType,Health
*
* @param path is the path to the csv file
* @return the army read from the csv file
* @throws IOException if the file cannot be read, does not exist, or is empty.
*/
public static Army readArmyFromFile(Path path) throws IOException {
File file = new File(String.valueOf(path));
......
......@@ -94,6 +94,11 @@ public class Army {
return true;
}
/**
* Removes all units from the army
*
* @return false if the army does not have any units, true otherwise.
*/
public boolean removeAllUnits() {
if (this.units.isEmpty()) return false;
this.units = new ArrayList<>();
......@@ -186,7 +191,6 @@ public class Army {
}
/**
*
* @return the total health of every unit in this army, 0 if the army is empty
*/
public int getTotalHealth() {
......
......@@ -9,6 +9,7 @@ import java.util.Random;
/**
* Class that simulates a battle between two armies.
* Uses java.util.Random to dictate which army attacks first
*
* @author Sondre Malerud
*/
public class Battle {
......@@ -18,6 +19,7 @@ public class Battle {
/**
* Constructor, taking in two armies that will battle against eachother
*
* @param armyOne Army, is the first army
* @param armyTwo Army, is the second army
*/
......@@ -29,6 +31,7 @@ public class Battle {
/**
* Constructor, taking in two armies that will battle against eachother as well as a terrain type
*
* @param armyOne Army, is the first army
* @param armyTwo Army, is the second army
*/
......@@ -40,6 +43,7 @@ public class Battle {
/**
* Method that simulates the battle between the two armies in a loop of attack-commands.
*
* @param slowedDown boolean, true if you want the simulation to take a 200ms pause between each new unit face-off.
* @return Army, the winner of the battle.
*/
......@@ -52,15 +56,13 @@ public class Battle {
Army secondAttacker;
if (startingAttacker == 1) {
secondAttacker = armies[0]; //if random = 0, this will give -1 which is the last element in the array (the other army)
}
else {
secondAttacker = armies[0];
} else {
secondAttacker = armies[1];
}
while (firstAttacker.hasUnits() && secondAttacker.hasUnits()) {
if (slowedDown) Thread.sleep(200);
System.out.println(firstAttacker.getAllUnits().size());
Unit unitOne = firstAttacker.getRandom();
Unit unitTwo = secondAttacker.getRandom();
......@@ -80,12 +82,16 @@ public class Battle {
if (firstAttacker.hasUnits()) {
return firstAttacker;
}
else {
} else {
return secondAttacker;
}
}
/**
* Simulates a single attack between to armies. Essentially works the same as the normal simulate-method, but without the continuous loop
*
* @return the winning army if one of the armies loses its final unit, null otherwise.
*/
public Army simulateSingleAttack() {
Army[] armies = {armyOne, armyTwo};
if (!armyOne.hasUnits()) return armyTwo;
......@@ -97,9 +103,8 @@ public class Battle {
Army secondAttacker;
if (startingAttacker == 1) {
secondAttacker = armies[0]; //if random = 0, this will give -1 which is the last element in the array (the other army)
}
else {
secondAttacker = armies[0];
} else {
secondAttacker = armies[1];
}
Unit unitOne = firstAttacker.getRandom();
......@@ -128,6 +133,7 @@ public class Battle {
/**
* Method that returns a text string of both armies
*
* @return String, both armies in readable format
*/
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment