Java = Javascript

main
mike 2023-03-02 12:39:49 -05:00
parent 84271b265b
commit af4788969a
10 changed files with 163 additions and 16 deletions

View File

@ -7,7 +7,7 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
GameEngine engine = new GameEngine(); GameEngine engine = new GameEngine();
engine.printMap(); engine.printState();
engine.run(); engine.run();
} }

View File

@ -1,9 +1,7 @@
package ca.cosc3p91.a2.game; package ca.cosc3p91.a2.game;
import ca.cosc3p91.a2.gameobjects.Building; import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a2.gameobjects.VillageStage; import ca.cosc3p91.a2.player.*;
import ca.cosc3p91.a2.gameobjects.Village_Hall;
import ca.cosc3p91.a2.player.Player;
public class GameEngine implements Runnable { public class GameEngine implements Runnable {
@ -22,11 +20,17 @@ public class GameEngine implements Runnable {
map = new Map(new Village_Hall(1,vInitialStage),30); map = new Map(new Village_Hall(1,vInitialStage),30);
} }
public void printMap() { public void printState() {
System.out.println("~ Current Map State ~\n\n"); // Print toPrint = new Print("~ Current Village Buildings ~",2);
System.out.println("In Map:\n"); System.out.println("In Map:\n");
System.out.println("\t~ Current Village Buildings ~\n");
for (Building b : map.contains) { for (Building b : map.contains) {
System.out.println("|> "+b.getClass().getSimpleName()+" lvl: "+b.getLevel()+" health: "+b.getHealth()); System.out.println("\t|> "+b.getClass().getSimpleName()+" lvl: "+b.getLevel()+" health: "+b.getHealth());
}
System.out.println("\n\t~ Current Village Inhabitants ~\n\n");
for (Inhabitant i : map.inhabitants) {
System.out.println("\t|> "+i.getClass().getSimpleName()+" lvl: "+i.getLevel());
} }
} }

View File

@ -33,7 +33,7 @@ public class Map {
} }
public void build(Village_Hall hall, Tile t, Building b) { public void build(Tile t, Building b) {
contains.add(b); contains.add(b);
} }

View File

@ -1,4 +1,28 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Archer extends Infantry { public class Archer extends Infantry {
public Archer() {
super(90, 2, 10);
}
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return super.getLevel();
}
@Override
public int setLevel(int level) {
return super.setLevel(level);
}
} }

View File

@ -1,4 +1,28 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Catapult extends Infantry { public class Catapult extends Infantry {
public Catapult() {
super(80, 12, 12);
}
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return super.getLevel();
}
@Override
public int setLevel(int level) {
return super.setLevel(level);
}
} }

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public abstract class Infantry { public abstract class Infantry implements Inhabitant {
private int health; private int health;
@ -8,16 +8,36 @@ public abstract class Infantry {
private int range; private int range;
public Infantry(int hitPoints, int damage, int range) {
this.health = hitPoints;
this.damage = damage;
this.range = range;
}
public void attack(Building b) { public void attack(Building b) {
} }
public void getHealth() { public int getHealth() {
return health;
} }
public void getDamage() { public int getDamage() {
return damage;
} }
public void getRange() { public int getRange() {
return range;
} }
public void setHealth(int health) {
this.health = health;
}
public void setDamage(int damage) {
this.damage = damage;
}
public void setRange(int range) {
this.range = range;
}
} }

View File

@ -1,14 +1,19 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
import ca.cosc3p91.a2.game.Map; import ca.cosc3p91.a2.game.Map;
public interface Inhabitant { public interface Inhabitant {
Map map = null; Map map = null;
Building building = null; Building building = null;
int lvl = 1;
void move(Tile t); void move(Tile t);
void getPosition(); void getPosition();
default int getLevel() {
return lvl;
}
default int setLevel(int level) {
return lvl;
}
} }

View File

@ -1,4 +1,28 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Knight extends Infantry { public class Knight extends Infantry {
public Knight() {
super(150, 6, 6);
}
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return super.getLevel();
}
@Override
public int setLevel(int level) {
return super.setLevel(level);
}
} }

View File

@ -1,4 +1,28 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Soldier extends Infantry { public class Soldier extends Infantry {
public Soldier() {
super(100, 4, 4);
}
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return super.getLevel();
}
@Override
public int setLevel(int level) {
return super.setLevel(level);
}
} }

View File

@ -1,11 +1,33 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Worker { public class Worker implements Inhabitant {
private boolean currentlyBuilding; private boolean currentlyBuilding;
public void set_IsBuilding(boolean state) {
currentlyBuilding = state;
}
public boolean isCurrentlyBuilding() { public boolean isCurrentlyBuilding() {
return currentlyBuilding; return currentlyBuilding;
} }
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return Inhabitant.super.getLevel();
}
@Override
public int setLevel(int level) {
return Inhabitant.super.setLevel(level);
}
} }