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
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/lol/.DS_Store
Binary file not shown.
33 changes: 17 additions & 16 deletions src/main/java/lol/client/ai/RandomAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,38 @@ public RandomAI(Arena arena, Battlefield battlefield) {
public Turn championSelect() {
Turn turn = new Turn();
String championName;
//TODO Champion diversity
switch(teamID) {
case Nexus.BLUE: championName = "Warrior"; break;
case Nexus.RED: championName = "Archer"; break;
case Nexus.RED: championName = "Scientist"; break;
default: throw new RuntimeException("Unknown team color.");
}
turn.registerAction(new ChampionSelect(teamID, championName));
turn.registerAction(new ChampionSelect(teamID, "Warrior"));
turn.registerAction(new ChampionSelect(teamID, "Archer"));
turn.registerAction(new ChampionSelect(teamID, "Scientist"));
return turn;
}

public Turn turn() {
Turn turn = new Turn();
// Try to attack the Nexus first.
arena.teamOf(teamID).forEachChampion((champion, id) ->
battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
public void visitNexus(Nexus nexus) {
if(nexus.teamOfNexus() != teamID) {
turn.registerAction(new Attack(teamID, id, nexus.x(), nexus.y()));
}
}
}));
battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
public void visitNexus(Nexus nexus) {
if(nexus.teamOfNexus() != teamID) {
turn.registerAction(new Attack(teamID, id, nexus.x(), nexus.y()));
}
}
}));
// Add a move action in case we could not attack the Nexus.
arena.teamOf(teamID).forEachChampion((champion, id) ->
battlefield.visitAdjacent(champion.x(), champion.y(), champion.walkSpeed(), new TileVisitor(){
public void visitGrass(int x, int y) {
if(random.nextInt() % 3 == 0) {
turn.registerAction(new Move(teamID, id, x, y));
}
}
}));
battlefield.visitAdjacent(champion.x(), champion.y(), champion.walkSpeed(), new TileVisitor(){
public void visitGrass(int x, int y) {
if(random.nextInt() % 3 == 0) {
turn.registerAction(new Move(teamID, id, x, y));
}
}
}));
return turn;
}
}
6 changes: 5 additions & 1 deletion src/main/java/lol/game/ASCIIBattlefieldBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

// Initialize the battlefield with the given textual battlefield.
// The textual battlefield is an ASCII representation:
// - '~' is a grass tile (groundASCIIMap).
// - ',' is a grass tile (groundASCIIMap).
// - '~' is a water tile (groundASCIIMap).
// - '-' is a path tile (groundASCIIMap).
// - '*' is a rock tile (groundASCIIMap).
// - 'B' is a blue Nexus tile (destructibleASCIIMap).
// - 'R' is a red Nexus tile (destructibleASCIIMap).
// - '.' indicates no destructible is present there (destructibleASCIIMap).

public class ASCIIBattlefieldBuilder {
private Battlefield battlefield;
private char[][] groundASCIIMap;
Expand Down Expand Up @@ -57,6 +60,7 @@ private void initDestructibleTile(char destructibleASCII, int x, int y) {
assert placed : errorMsg;
break;
case '.': break;
case ',': break;
default:
throw new RuntimeException("No destructible object with the representation `" + destructibleASCII + "`.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lol/game/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void visitChampionSelect(int teamID, String championName) {
}
else {
System.out.println("Champion selection action outside of the champion selection phase (teamID = "
+ teamID + ", championName = " + championName + ".");
+ teamID + ", championName = " + championName + ".");
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/lol/game/Battlefield.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@
public class Battlefield {
public enum GroundTile {
GRASS,
ROCK;
ROCK,
WATER,
PATH;

public static GroundTile fromASCII(char c) {
switch(c) {
case '~': return GroundTile.GRASS;
case ',': return GroundTile.GRASS;
case '*': return GroundTile.ROCK;
case '~': return GroundTile.WATER;
case '-': return GroundTile.PATH;
default: throw new RuntimeException("No ground tile with the representation `" + c + "`.");
}
}

public static boolean walkable(GroundTile groundTile) {
switch(groundTile) {
case GRASS: return true;
case WATER: return true;
case PATH: return true;
case ROCK: return false;
default: throw new RuntimeException("Missing GroundTile case in walkable.");
}
}

public static char stringOf(GroundTile groundTile) {
switch(groundTile) {
case GRASS: return '~';
case GRASS: return ',';
case ROCK: return '*';
case WATER: return '~';
case PATH: return '-';
default: throw new RuntimeException("Missing GroundTile case in stringOf.");
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/lol/game/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public static Champion makeWarrior() {
return new Champion("Warrior", 15, 1, 3, 2);
}

public static Champion makeScientist() { return new Champion("Scientist", 3, 2, 15, 2);}

public static Champion make(String name) {
switch(name) {
case "Archer": return makeArcher();
case "Warrior": return makeWarrior();
case "Scientist" : return makeScientist();
default: throw new RuntimeException("The champion " + name + " does not exist.");
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/lol/game/TileVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
public interface TileVisitor {
default void visitGrass(int x, int y) {}
default void visitRock(int x, int y) {}
default void visitPath(int x, int y) {}
default void visitWater(int x, int y) {}

default void visitGround(Battlefield.GroundTile groundTile, int x, int y) {
switch(groundTile) {
case GRASS: visitGrass(x, y); break;
case ROCK: visitRock(x, y); break;
case PATH: visitPath(x, y); break;
case WATER: visitWater(x, y); break;
default: throw new RuntimeException("Missing GroundTile case in visitGround.");
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/lol/ui/BattlefieldView.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ public void update() {
ImageView groundView(Battlefield.GroundTile tile) {
switch(tile) {
case GRASS: return sprites.grass();
case WATER: return sprites.water();
case ROCK: return sprites.rock();
case PATH: return sprites.path();
default: throw new UnsupportedOperationException(
"Displaying ground tile `" + tile.name() + "` is not yet supported.");
"Displaying ground tile `" + tile.name() + "` is not yet supported.");
}
}

ImageView championView(Champion champion) {
String name = champion.name();
if(name.equals("Archer")) { return sprites.archer(); }
else if (name.equals("Warrior")) { return sprites.warrior(); }
else if (name.equals("Scientist")) { return sprites.scientist();}
else {
throw new UnsupportedOperationException(
"Displaying Champion tile `" + name + "` is not yet supported.");
"Displaying Champion tile `" + name + "` is not yet supported.");
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/lol/ui/Sprites.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

public class Sprites {
private Image grassImage;
private Image waterImage;
private Image pathImage;
private Image archerImage;
private Image warriorImage;
private Image scientistImage;
private Image blueNexusImage;
private Image redNexusImage;

public Sprites() {

grassImage = new Image("sprites/grass-tile.png");
waterImage = new Image("sprites/water-tile.png");
pathImage = new Image("sprites/path-tile.png");
archerImage = new Image("sprites/archer.png");
warriorImage = new Image("sprites/warrior.png");
scientistImage = new Image("sprites/scientist.png");
blueNexusImage = new Image("sprites/blue-nexus.png");
redNexusImage = new Image("sprites/red-nexus.png");
}
Expand All @@ -28,6 +35,18 @@ public ImageView grass() {
return makeView(grassImage);
}

public ImageView water() {
return makeView(waterImage);
}

public ImageView path() {
return makeView(pathImage);
}

public ImageView rock() {
return makeView(pathImage);
}

public ImageView archer() {
return makeView(archerImage);
}
Expand All @@ -36,6 +55,8 @@ public ImageView warrior() {
return makeView(warriorImage);
}

public ImageView scientist() {return makeView(scientistImage);}

public ImageView blueNexus() {
return makeView(blueNexusImage);
}
Expand Down
Binary file added src/main/resources/.DS_Store
Binary file not shown.
21 changes: 11 additions & 10 deletions src/main/resources/maps/ground.map
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
~~~~~~~~~~
,,,,,,,---
,---------
,-~,,,,---
,-,~,,-,-,
,-,,~-,,-,
,-,,-~,,-,
,-,-,,~,-,
---,,,,~-,
---------,
---,,,,,,,

Binary file added src/main/resources/sprites/.DS_Store
Binary file not shown.
Binary file added src/main/resources/sprites/path-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/sprites/scientist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/sprites/water-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions target/classes/maps/destructible.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
..........
........R.
..........
..........
..........
..........
..........
..........
.B........
..........
11 changes: 11 additions & 0 deletions target/classes/maps/ground.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
,,,,,,,---
,---------
,-~,,,,---
,-,~,,-,-,
,-,,~-,,-,
,-,,-~,,-,
,-,-,,~,-,
---,,,,~-,
---------,
---,,,,,,,

Binary file added target/classes/sprites/archer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/blue-nexus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/grass-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/path-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/red-nexus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/river-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/warrior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/classes/sprites/water-tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
lol/client/ai/RandomAI$2.class
lol/game/Arena.class
lol/game/action/ChampionSelect.class
lol/client/Client.class
lol/client/ai/AIBase.class
lol/game/Champion.class
lol/game/TileVisitor.class
lol/game/Battlefield$2.class
lol/game/Arena$Phase.class
lol/game/action/Spawn.class
lol/ui/Sprites.class
lol/game/Team$1.class
lol/game/action/Turn.class
lol/ui/BattlefieldView.class
lol/common/ServerInfo.class
lol/game/action/ActionVisitor.class
lol/game/action/ChampionAction.class
lol/game/action/Attack.class
lol/server/Server.class
lol/game/ASCIIBattlefieldBuilder.class
lol/game/Battlefield$1.class
lol/game/Team.class
lol/game/action/Action.class
lol/client/ai/RandomAI$1.class
lol/game/Battlefield.class
lol/ui/BattlefieldView$1.class
lol/server/LOL2D.class
lol/game/Team$2.class
lol/client/ai/RandomAI.class
lol/game/Battlefield$GroundTile.class
lol/game/Nexus.class
lol/game/Arena$ApplyAction.class
lol/game/TileVisitor$1.class
lol/common/BadProtocolException.class
lol/server/Player.class
lol/game/action/Move.class
lol/game/Destructible.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/common/ServerInfo.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/ChampionAction.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/client/ai/RandomAI.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Team.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Battlefield.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/ChampionSelect.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/Action.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/ui/BattlefieldView.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/client/ai/AIBase.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/Move.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/server/Player.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/common/BadProtocolException.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/ActionVisitor.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/Turn.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/client/Client.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/TileVisitor.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/server/Server.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Arena.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Destructible.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/ui/Sprites.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Champion.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/Spawn.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/action/Attack.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/ASCIIBattlefieldBuilder.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/server/LOL2D.java
/Users/daniel/git/BICS-S2.21/lol2d/src/main/java/lol/game/Nexus.java