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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<javafx.version>16</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
Expand All @@ -32,4 +32,4 @@
<version>${javafx.version}</version>
</dependency>
</dependencies>
</project>
</project>
17 changes: 16 additions & 1 deletion src/main/java/lol/client/ai/RandomAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ public Turn championSelect() {

public Turn turn() {
Turn turn = new Turn();
// Try to attack the Nexus first.
// First check if a champion needs to be revived.
arena.teamOf(teamID).forEachChampion((champion, id) -> {
if (!champion.isAlive()){
turn.registerAction(new Revive(teamID, id, (int) (Math.random()*9), (int) (Math.random()*9)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be automatic on the server side, and the champion should spawn next to its nexus.
Also, because it is done on the client side, the client can choose to spawn just next to the opponent nexus.
Why do we need a revive action? Doesn't a Spawn action would be enough? (It would also allows to reuse most of the mechanics of a spawn action).

}
});
// Try to attack ennemies next.
arena.teamOf(teamID).forEachChampion((champion, id) ->
battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
public void visitChampion(Champion otherChampion) {
if(arena.teamOf(1-teamID).belongsToTeam(otherChampion)) {
turn.registerAction(new Attack(teamID, id, otherChampion.x(), otherChampion.y()));
}
}
}));
// Try to attack the Nexus next.
arena.teamOf(teamID).forEachChampion((champion, id) ->
battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
public void visitNexus(Nexus nexus) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/lol/game/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public void visitSpawn(int teamID, int championID, int x, int y) {
}
}

public void visitRevive(int teamID, int championID, int x, int y) {
if(phase == Phase.GAME) {
if(!championsWhoActed.contains(championID)) {
if(teams.get(teamID).reviveChampion(championID, x, y)) {
championsWhoActed.add(championID);
}
}
else {
System.out.println("Team " + teamID + " tried to move a champion outside a GAME phase.");
}
}
}

public void visitMove(int teamID, int championID, int x, int y) {
if(phase == Phase.GAME) {
if(!championsWhoActed.contains(championID)) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/lol/game/Battlefield.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public boolean allNexusAlive() {
return true;
}

public void removeChampion(Destructible d, int x, int y) {
if (d instanceof Champion && !d.isAlive()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could generalize to removeDestructible since anything destructible (including nexus) should be remove when it's dead. That would also remove the need for an instanceof.

battlefield[y][x] = Optional.empty();
}
}

// We can place something at (x, y) if:
// * The ground tile at (x, y) is walkable.
// * No other destructible is present at (x, y).
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/lol/game/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Champion extends Destructible {
private int rangeOfAttack;
private int damages;
private int speed;
private int deathTimer = 0;

private Champion(String name, int hp, int rangeOfAttack, int damages, int speed) {
super(hp);
Expand Down Expand Up @@ -62,6 +63,18 @@ public boolean attack(Destructible d) {
return false;
}

public void increaseTimer() {
deathTimer = deathTimer + 1;
}

public boolean reachedTimer() {
return deathTimer==3;
}

public void resetTimer() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to override revive and reset the timer there?

deathTimer = 0;
}

@Override public String toString() {
return name();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/lol/game/Destructible.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public boolean isAlive() {
return currentHP > 0;
}

public void revive() {
currentHP = initialHP;
}

public void reviveAt(int x, int y) {
currentHP = initialHP;
place(x, y);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/lol/game/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void forEachChampion(BiConsumer<Champion, Integer> f) {
}
}

public boolean belongsToTeam(Champion champion) {
return champions.contains(champion);
}

public boolean spawnChampion(int championID, int x, int y) {
Champion champion = champions.get(championID);
boolean placed = battlefield.placeAt(champion, x, y);
Expand All @@ -40,6 +44,28 @@ public boolean spawnChampion(int championID, int x, int y) {
return placed;
}

public void removeChampion(Destructible d ,int x ,int y) {
battlefield.removeChampion(d, x, y);
}

public boolean reviveChampion(int championID ,int x ,int y) {
Champion champion = champions.get(championID);
boolean revived = false;
if(champion.reachedTimer()) {
revived = battlefield.placeAt(champion, x, y);
champion.revive();
champion.resetTimer();
}
else {
champion.increaseTimer();
revived = true;
}
if(!revived && logInvalidMove) {
System.out.println("Invalid respawn position of champion " + champion.name());
}
return revived;
}

public boolean moveChampion(int championID, int x, int y) {
Champion champion = champions.get(championID);
boolean moved = false;
Expand All @@ -58,6 +84,7 @@ public boolean championAttack(int championID, int x, int y) {
battlefield.visit(x, y, new TileVisitor(){
@Override public void visitDestructible(Destructible d) {
attacked[0] = champion.attack(d);
removeChampion(d, x ,y);
}
});
if(!attacked[0]) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/lol/game/action/ActionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public interface ActionVisitor {
public void visitSpawn(int teamID, int championID, int x, int y);
public void visitRevive(int teamID,int championID, int x, int y);
public void visitMove(int teamID, int championID, int x, int y);
public void visitAttack(int teamID, int championID, int x, int y);
public void visitChampionSelect(int teamID, String championName);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/lol/game/action/Revive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lol.game.action;

import lol.game.*;
import java.io.Serializable;

public class Revive extends ChampionAction implements Serializable {

public Revive(int teamID, int championID, int x, int y) {
super(teamID, championID, x, y);
}

public void accept(ActionVisitor visitor) {
visitor.visitRevive(teamID, championID, x, y);
}
}