Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
64ff16d
Project opened in IntelliJ
Sep 27, 2022
6c16505
Added classes according to the different types of weapons and Abstrac…
Sep 28, 2022
027d33d
README.md modified and Main added
Sep 30, 2022
04276b0
Main modified, Enemy toString added, WhiteMage toString fixed
Sep 30, 2022
2d3c19a
AbstractCharacter constructor protected -> public
Oct 1, 2022
5ce051c
Main: characters' setters and getters' tests added
Oct 2, 2022
3c8a31e
Weapons: equals and toString added
Oct 2, 2022
a168c02
Weapon -> AbstractWeapon; name, damage, weight made final protected
Oct 2, 2022
d2ee957
fix linter warnings in Main
Oct 2, 2022
946ae5e
Fixed all linter warnings
Oct 2, 2022
0818637
Weapon types interface deleted
Oct 2, 2022
322429d
Weapons' toString() fixed
Oct 2, 2022
84f5c55
Weapon interface created
Oct 3, 2022
29d88d6
Fixed usage of AbstractWeapon as type related problems
Oct 3, 2022
3ea3cfe
waitTurn() method fixed
Oct 3, 2022
d557177
addToQueue() added to interface and made public (to fix Main related …
Oct 3, 2022
58a0f12
constructor AbstractMage fixed related issues
Oct 3, 2022
03399da
Mage's ACCESSORS region changed to AbstractMage
Oct 3, 2022
a2f66e3
Fixed AbstractMage accesors
Oct 3, 2022
3ab873a
Fixed linted warnings
Oct 3, 2022
dae3e5f
Test package and test classes added
Nov 8, 2022
bd30cc4
Test classes for abstract classes added
Nov 8, 2022
4bc689d
Tests in Enemy added, fixed Enemy toString()
Nov 8, 2022
5fe07bb
Added AbstractCharacter's tests
Nov 8, 2022
1218426
Eng, knight, thief tests added
Nov 8, 2022
669ac02
All tests for mage added
Nov 9, 2022
bd79e26
Tests for weapons added, weapons' equals fixed
Nov 9, 2022
4743c5d
Tests for AbstractWeapon added
Nov 9, 2022
d319a1d
Double dispatch implemented for equip (all 25 methods added)
Nov 10, 2022
b7e4ed7
equip more tests added and equip method fixed
Nov 11, 2022
46a82f4
minimal error fixed uwu
Nov 11, 2022
5caeddd
equip fixed, equip's tests coverage 100%
Nov 11, 2022
db9821f
waitTurn() tests added
Nov 11, 2022
0a90e3c
main and timerExample classes deleted
Nov 11, 2022
9576e5f
one identantion error fixed
Nov 11, 2022
310f878
Controller package and class added
Dec 12, 2022
32e066a
listo
Dec 13, 2022
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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,40 @@ Broadly speaking for the combat the player has a group of characters to control
enemies controlled by the computer.

---
[comment]: <> (
The rest of the documentation is left for the users of this template to complete
What should the README contain?
1. All instructions that you'd need in order to run the program.
2. All the assumptions that I made.
3. Brief explanation of the functioning and logic of the program.
)
How to run the program?
-------
In "finalreality" package, you'll find an archive called "Main.java".
This archive will contain several functions that will instantiate the
classes on this program. Those include, the 5 types of playable characters (Engineer,
BlackMage, Knight, Thief and WhiteMage), an enemy and the several weapons. If you
run this Main, you will see in the output all the parameters printed according to
its method, that way you'll see a demonstration of the program.

**The rest of the documentation is left for the users of this template to complete**
In order to play the game Final Fantasy, you need to follow certain turns. Those turns will
be managed by a scheduler. To see the functioning of the scheduler, you can also
run the class "TimerExample".

This program only shows the model of the project, which shows the relations
between classes, but it doesn't implement any of the methods and the restrictions
related to which weapon can be equipped to which character are not considered,
with the purpose of showing the functionality of the program.

---
Functioning and logic of the program
-------
To develop this simplified clone of Final Fantasy's combat, the architectural pattern
Model-View-Controller was followed.

The model of the program contains all the necessary classes and entities, which work as
the basic structure of the project and its possible interactions. In this model, you'll
find that there's an interface GameCharacter, which is implemented by all the characters and also guides their behavior in the game. In addition, all the characters (including the enemies)
extends the abstract class AbstractCharacter.

The View and the Controller are yet to be developed.
37 changes: 0 additions & 37 deletions src/main/java/cl/uchile/dcc/TimerExample.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cl.uchile.dcc.finalreality.controller;

import cl.uchile.dcc.finalreality.model.character.GameCharacter;

/**
* The game controller.
*
* Class that makes the logic conexion between the view and the model. It manages
* the game and makes all the operations needed.
*/
public class GameController {
private GameCharacter player1;
private GameCharacter player2;




}




Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* "Final Reality" (c) by R8V and ~Your name~
* "Final Reality" (c) by R8V and Katia
* "Final Reality" is licensed under a
* Creative Commons Attribution 4.0 International License.
* You should have received a copy of the license along with this
Expand All @@ -12,7 +12,7 @@
* This error is used to represent an invalid stat value.
*
* @author <a href="https://github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public class InvalidStatValueException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* "Final Reality" (c) by R8V and ~Your name~
* "Final Reality" (c) by R8V and Katia
* "Final Reality" is licensed under a
* Creative Commons Attribution 4.0 International License.
* You should have received a copy of the license along with this
Expand All @@ -17,7 +17,7 @@
* instantiated.
*
* @author <a href="https://github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public final class Require {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
* An abstract class that holds the common behaviour of all the characters in the game.
*
* @author <a href="https://www.github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public abstract class AbstractCharacter implements GameCharacter {

private int currentHp;
protected int maxHp;
protected int defense;
protected int currentHp;
protected final int maxHp;
protected final int defense;
protected final BlockingQueue<GameCharacter> turnsQueue;
protected final String name;
private ScheduledExecutorService scheduledExecutor;
protected ScheduledExecutorService scheduledExecutor;

/**
* Creates a new character.
Expand All @@ -36,7 +36,7 @@ public abstract class AbstractCharacter implements GameCharacter {
* @param turnsQueue
* the queue with the characters waiting for their turn
*/
protected AbstractCharacter(@NotNull String name, int maxHp, int defense,
public AbstractCharacter(@NotNull String name, int maxHp, int defense,
@NotNull BlockingQueue<GameCharacter> turnsQueue) throws InvalidStatValueException {
Require.statValueAtLeast(1, maxHp, "Max HP");
Require.statValueAtLeast(0, defense, "Defense");
Expand All @@ -46,28 +46,9 @@ protected AbstractCharacter(@NotNull String name, int maxHp, int defense,
this.turnsQueue = turnsQueue;
this.name = name;
}

@Override
public void waitTurn() {
scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
if (this instanceof PlayerCharacter player) {
scheduledExecutor.schedule(
/* command = */ this::addToQueue,
/* delay = */ player.getEquippedWeapon().getWeight() / 10,
/* unit = */ TimeUnit.SECONDS);
} else {
var enemy = (Enemy) this;
scheduledExecutor.schedule(
/* command = */ this::addToQueue,
/* delay = */ enemy.getWeight() / 10,
/* unit = */ TimeUnit.SECONDS);
}
}

/**
* Adds this character to the turns queue.
*/
private void addToQueue() {
public void addToQueue() {
try {
turnsQueue.put(this);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
import cl.uchile.dcc.finalreality.exceptions.Require;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;

/**
* A class that holds all the information of a single enemy of the game.
* A class holds all the information of a single enemy of the game.
*
* @author <a href="https://www.github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public class Enemy extends AbstractCharacter {
protected final int damage;

private final int weight;
protected final int weight;

/**
* Creates a new enemy with a name, a weight and the queue with the characters ready to
* play.
*/
public Enemy(@NotNull final String name, final int weight, int maxHp, int defense,
@NotNull final BlockingQueue<GameCharacter> turnsQueue)
@NotNull final BlockingQueue<GameCharacter> turnsQueue, int damage)
throws InvalidStatValueException {
super(name, maxHp, defense, turnsQueue);
this.damage = damage;
Require.statValueAtLeast(1, weight, "Weight");
this.weight = weight;
}
Expand All @@ -45,13 +49,31 @@ public boolean equals(final Object o) {
}
return hashCode() == enemy.hashCode()
&& name.equals(enemy.name)
&& weight == enemy.weight
&& maxHp == enemy.maxHp
&& defense == enemy.defense;
&& weight == enemy.weight
&& maxHp == enemy.maxHp
&& damage == enemy.damage
&& defense == enemy.defense;
}

@Override
public int hashCode() {
return Objects.hash(Enemy.class, name, weight, maxHp, defense);
return Objects.hash(Enemy.class, name, weight, maxHp, defense, damage);
}

@Override
public String toString() {
return "Enemy{weight=%d, maxHp=%d, defense=%d, damage=%d, name='%s'}"
.formatted(weight, maxHp, defense, damage, name);


}

@Override
public void waitTurn() {
this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
this.scheduledExecutor.schedule(
/* command = */ this::addToQueue,
/* delay = */ this.getWeight() / 10,
/* unit = */ TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
* A character can be controlled by the player or by the CPU (an enemy).
*
* @author <a href="https://www.github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public interface GameCharacter {

/**
* Adds this character to the turns queue.
*/
public void addToQueue();

/**
* Sets a scheduled executor to make this character (thread) wait for {@code speed / 10}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* "Final Reality" (c) by R8V and ~Your name~
* "Final Reality" (c) by R8V and Katia
* "Final Reality" is licensed under a
* Creative Commons Attribution 4.0 International License.
* You should have received a copy of the license along with this
Expand All @@ -11,24 +11,27 @@
import cl.uchile.dcc.finalreality.exceptions.InvalidStatValueException;
import cl.uchile.dcc.finalreality.model.character.AbstractCharacter;
import cl.uchile.dcc.finalreality.model.character.GameCharacter;
import cl.uchile.dcc.finalreality.model.weapon.AbstractWeapon;
import cl.uchile.dcc.finalreality.model.weapon.Weapon;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;

/**
* A class that holds all the information of a player-controlled character in the game.
*
* <p>All player characters have a {@code name}, a maximum amount of <i>hit points</i>
* ({@code maxHp}), a {@code defense} value, a queue of {@link GameCharacter}s that are
* waiting for their turn ({@code turnsQueue}), and can equip a {@link Weapon}.
* waiting for their turn ({@code turnsQueue}), and can equip a {@link AbstractWeapon}.
*
* @author <a href="https://www.github.com/r8vnhill">R8V</a>
* @author ~Your name~
* @author Katia
*/
public abstract class AbstractPlayerCharacter extends AbstractCharacter implements
PlayerCharacter {

private Weapon equippedWeapon = null;
protected Weapon equippedWeapon = null;

/**
* Creates a new character.
Expand All @@ -48,14 +51,18 @@ protected AbstractPlayerCharacter(@NotNull final String name, final int maxHp,
throws InvalidStatValueException {
super(name, maxHp, defense, turnsQueue);
}

@Override
public void equip(Weapon weapon) {
this.equippedWeapon = weapon;
}


@Override
public Weapon getEquippedWeapon() {
return equippedWeapon;
}

@Override
public void waitTurn() {
this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
this.scheduledExecutor.schedule(
/* command = */ this::addToQueue,
/* delay = */ this.getEquippedWeapon().getWeight() / 10,
/* unit = */ TimeUnit.SECONDS);
}
}
Loading