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
1 change: 1 addition & 0 deletions game/src/main/java/chon/group/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void running() {
}
/* ChonBota's Movements */
environment.getProtagonist().move(input);
environment.getProtagonist().sprint(input);
environment.checkBorders();
}
/* ChonBot's Automatic Movements */
Expand Down
47 changes: 47 additions & 0 deletions game/src/main/java/chon/group/game/core/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Agent extends Entity {

/** The agent's energy recovery factor */
private final double recoveryFactor;

/** The energy cost required for the agent to perform an action */
private double energyCost;

/**
* Constructor to initialize the agent properties.
Expand Down Expand Up @@ -69,6 +72,7 @@ public Agent(int posX, int posY, int height, int width, int speed, int health, S
this.energy = 1.0;
this.fullEnergy = 1.0;
this.recoveryFactor = 0.0002;
this.energyCost = 0.01;
}

/**
Expand Down Expand Up @@ -158,6 +162,24 @@ public double getRecoveryFactor() {
return recoveryFactor;
}

/**
* Gets the energy cost of performing an action.
*
* @return the energy cost
*/
public double getEnergyCost() {
return energyCost;
}

/**
* Sets the energy cost required to perform an action.
*
* @param energyCost the new energy cost
*/
public void setEnergyCost(double energyCost) {
this.energyCost = energyCost;
}

/**
* Consumes a specified amount of energy.
*
Expand Down Expand Up @@ -230,4 +252,29 @@ public Shot useWeapon() {
return null;
}

@Override
/**

Makes the agent sprint based on the movement commands provided, but only if there is enough energy in the energy bar.
@param movements a list of movement directions ("RIGHT", "LEFT", "UP",
"DOWN") and "SHIFT" to sprint
*/
public void sprint(List<String> movements) {
if (movements.contains("SHIFT") && this.energy >= this.energyCost) {
if (movements.contains("RIGHT")) {
setPosX(posX += speed * 2);
this.consumeEnergy(this.energyCost);
} else if (movements.contains("LEFT")) {
setPosX(posX -= speed * 2);
this.consumeEnergy(this.energyCost);
} else if (movements.contains("UP")) {
setPosY(posY -= speed * 2);
this.consumeEnergy(this.energyCost);
} else if (movements.contains("DOWN")) {
setPosY(posY += speed * 2);
this.consumeEnergy(this.energyCost);
}
}
}

}
19 changes: 19 additions & 0 deletions game/src/main/java/chon/group/game/core/agent/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,23 @@ public void takeDamage(int damage, List<Message> messages) {
}
}

/**

Makes the Entity sprint based on the movement commands provided.
@param movements a list of movement directions ("RIGHT", "LEFT", "UP",
"DOWN") and "SHIFT" to sprint
*/
public void sprint(List<String> movements) {
if (movements.contains("SHIFT")) {
if (movements.contains("RIGHT")) {
setPosX(posX += speed * 2);
} else if (movements.contains("LEFT")) {
setPosX(posX -= speed * 2);
} else if (movements.contains("UP")) {
setPosY(posY -= speed * 2);
} else if (movements.contains("DOWN")) {
setPosY(posY += speed * 2);
}
}
}
}