| @@ -0,0 +1,107 @@ | ||
| package com.vengeful.sloths.Controller; | ||
|
|
||
| import com.vengeful.sloths.Controller.ControllerStates.AvatarState; | ||
| import com.vengeful.sloths.Controller.ControllerStates.InventoryState; | ||
| import com.vengeful.sloths.Controller.ControllerStates.MainControllerState; | ||
| import com.vengeful.sloths.Controller.ControllerStates.MenuState; | ||
| import com.vengeful.sloths.Models.Entity.Avatar; | ||
| import com.vengeful.sloths.Models.TimeModel.TimeController; | ||
|
|
||
| import java.awt.event.KeyEvent; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class MainController { | ||
|
|
||
| private Avatar player; | ||
| private MainControllerState state; | ||
| private InputHandler inputHandler; | ||
| private Screen screen; | ||
|
|
||
| private AvatarState avatarState; | ||
| private InventoryState inventoryState; | ||
| private MenuState menuState; | ||
|
|
||
| public MainController(Avatar player){ | ||
|
|
||
| this.player = player; | ||
|
|
||
| avatarState = new AvatarState(this); | ||
| inventoryState = new InventoryState(this); | ||
| menuState = new MenuState(this); | ||
|
|
||
| inputHandler = new InputHandler(this); | ||
|
|
||
| Screen screen = new Screen(); | ||
| screen.setVisible(true); | ||
| screen.addKeyListener(inputHandler); | ||
| screen.start(); | ||
| this.state = avatarState; | ||
| } | ||
|
|
||
| public boolean dispatchKey(int key){ | ||
| System.out.println(state.getClass()); | ||
| switch(key){ | ||
| case KeyEvent.VK_I : | ||
| state.handleIKey(); | ||
| break; | ||
| case KeyEvent.VK_E : | ||
| state.handleEKey(); | ||
| break; | ||
| case KeyEvent.VK_ESCAPE : | ||
| state.handleESCKey(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD1 : | ||
| state.handle1Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD2 : | ||
| state.handle2Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD3 : | ||
| state.handle3Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD4 : | ||
| state.handle4Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD5 : | ||
| state.handle5Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD6 : | ||
| state.handle6Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD7 : | ||
| state.handle7Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD8 : | ||
| state.handle8Key(); | ||
| break; | ||
| case KeyEvent.VK_NUMPAD9 : | ||
| state.handle9Key(); | ||
| break; | ||
|
|
||
| default: System.out.println("key not supported (WTF ARE U EVEN DOIN U SCRUB???)"); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public void setAvatarState(){ | ||
| this.state = this.avatarState; | ||
| } | ||
|
|
||
| public void setInventoryState(){ | ||
| this.state = this.inventoryState; | ||
| } | ||
|
|
||
| public void setMenuState(){ | ||
| this.state = menuState; | ||
| } | ||
|
|
||
| public Avatar getAvatar(){ | ||
| return this.player; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| @@ -0,0 +1,79 @@ | ||
| package com.vengeful.sloths.Controller; | ||
|
|
||
|
|
||
| import javax.swing.JFrame; | ||
| import com.vengeful.sloths.View.AreaView.AreaView; | ||
| import com.vengeful.sloths.View.AreaView.Direction; | ||
| import com.vengeful.sloths.View.AreaView.EntityObserver; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
|
|
||
|
|
||
| public class Screen extends JFrame implements Runnable{ | ||
|
|
||
| public Screen() { | ||
| av = new AreaView(); | ||
| initUI(); | ||
| } | ||
|
|
||
| private AreaView av; | ||
|
|
||
| private void initUI() { | ||
|
|
||
| add(av); | ||
|
|
||
| setTitle("A game"); | ||
| setResizable(false); | ||
| pack(); | ||
| setLocationRelativeTo(null); | ||
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| } | ||
|
|
||
| public void run() { | ||
| int count = 0; | ||
|
|
||
| while(true) { | ||
| long lastTime = System.currentTimeMillis(); | ||
|
|
||
| //Actual Code goes here | ||
|
|
||
| av.repaint(); | ||
| EntityObserver eo = (EntityObserver)av.getPlayer(); | ||
|
|
||
| if ( count%20 == 4 ) { | ||
| eo.alertDirectionChange(Direction.E); | ||
| } else if ( count%20 == 8) { | ||
| eo.alertDirectionChange(Direction.N); | ||
| } else if ( count%20 == 12) { | ||
| eo.alertDirectionChange(Direction.W); | ||
| } else if ( count%20 == 16) { | ||
| eo.alertDirectionChange(Direction.S); | ||
| } | ||
|
|
||
| //End of actual code | ||
|
|
||
| long delta = System.currentTimeMillis() - lastTime; | ||
| if (delta < 250) { | ||
| try { | ||
| Thread.sleep((250 - delta)); | ||
| } catch (Exception e) { | ||
| //dont care | ||
| } | ||
|
|
||
| } | ||
| System.out.println(count++); | ||
| } | ||
| } | ||
| public void start() { | ||
| new Thread(this).start(); | ||
| } | ||
| // public static void main(String[] args) { | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // } | ||
| } |
| @@ -1,8 +1,27 @@ | ||
| package com.vengeful.sloths; | ||
|
|
||
| import com.vengeful.sloths.Controller.MainController; | ||
| import com.vengeful.sloths.Models.ActionCommandFactory.ActionCommandFactory; | ||
| import com.vengeful.sloths.Models.ActionCommandFactory.AvatarActionCommandFactory; | ||
| import com.vengeful.sloths.Models.Entity.Avatar; | ||
| import com.vengeful.sloths.Models.Stats.EntityStats; | ||
| import com.vengeful.sloths.Models.Map.Map; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("hello world TEST"); | ||
|
|
||
| //make map factory and make a level to test with to create the map | ||
| Map map = new Map(); | ||
|
|
||
| ActionCommandFactory avatarActionCommandFactory = new AvatarActionCommandFactory(map); | ||
|
|
||
| Avatar avatar = new Avatar("SlothMan", "Smasher", new EntityStats(), avatarActionCommandFactory); | ||
|
|
||
|
|
||
|
|
||
| MainController controller = new MainController(avatar); | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,23 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
| import com.vengeful.sloths.Utility.Coord; | ||
| import com.vengeful.sloths.Models.Entity.Entity; | ||
| import com.vengeful.sloths.Models.Map.Map; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public abstract class ActionCommandFactory { | ||
|
|
||
| Map map; | ||
|
|
||
| // movement command | ||
| // drop command | ||
|
|
||
| public ActionCommandFactory(Map map) { | ||
| this.map = map; | ||
| } | ||
|
|
||
| public abstract MovementCommand createMovementCommand(Coord dst, Entity entity); | ||
| public abstract DropCommand createDropCommand(); | ||
| } |
| @@ -0,0 +1,27 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
|
|
||
| import com.vengeful.sloths.Models.Entity.Entity; | ||
| import com.vengeful.sloths.Utility.Coord; | ||
| import com.vengeful.sloths.Models.Map.Map; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class AvatarActionCommandFactory extends ActionCommandFactory { | ||
|
|
||
| public AvatarActionCommandFactory(Map map) { | ||
| super(map); | ||
| } | ||
| @Override | ||
| public MovementCommand createMovementCommand(Coord dst, Entity avatar) { | ||
| MovementCommand mc = new AvatarMovementCommand(map, dst, avatar); | ||
|
|
||
| return mc; | ||
| } | ||
|
|
||
| @Override | ||
| public DropCommand createDropCommand() { | ||
| return null; | ||
| } | ||
| } |
| @@ -0,0 +1,29 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
| import com.vengeful.sloths.Models.Entity.Entity; | ||
| import com.vengeful.sloths.Models.Map.Map; | ||
| import com.vengeful.sloths.Utility.Coord; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class AvatarMovementCommand extends MovementCommand { | ||
|
|
||
| public AvatarMovementCommand(Map map, Coord dst, Entity avatar) { | ||
| super(map, dst, avatar); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| if (dst.getX() < 0 || | ||
| dst.getY() < 0) { | ||
| // @TODO: OR IF GREATER THAN MAX COORDS | ||
| System.out.println("ERROR: Attempted to move out of bounds"); | ||
| return; | ||
| } | ||
|
|
||
| // Tile t = map.getTile() | ||
| // can Tile t take an entity? | ||
| // Move calling entity onto the tile | ||
| } | ||
| } |
| @@ -0,0 +1,7 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class DropCommand { | ||
| } |
| @@ -0,0 +1,25 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
| import com.vengeful.sloths.Models.Map.Map; | ||
| import com.vengeful.sloths.Utility.Coord; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public abstract class EntityCommandFactory extends ActionCommandFactory { | ||
|
|
||
| public EntityCommandFactory(Map map) { | ||
| super(map); | ||
| } | ||
|
|
||
|
|
||
| public MovementCommand createMovementCommand(Coord dst) { | ||
| // @TODO: Not implemented in this iteration | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public DropCommand createDropCommand() { | ||
| return null; | ||
| } | ||
| } |
| @@ -0,0 +1,25 @@ | ||
| package com.vengeful.sloths.Models.ActionCommandFactory; | ||
|
|
||
| import com.vengeful.sloths.Models.Map.Map; | ||
| import com.vengeful.sloths.Models.Entity.Entity; | ||
| import com.vengeful.sloths.Utility.Coord; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public abstract class MovementCommand { | ||
|
|
||
| Map map; | ||
| Coord dst; | ||
| Entity entity; | ||
|
|
||
| public MovementCommand(Map map, Coord dst, Entity ent) { | ||
| this.map = map; | ||
| this.dst = dst; | ||
| this.entity = ent; | ||
|
|
||
| this.execute(); | ||
| } | ||
|
|
||
| public abstract void execute(); | ||
| } |
| @@ -1,24 +1,59 @@ | ||
| package com.vengeful.sloths.Models.Entity; | ||
|
|
||
| import com.vengeful.sloths.Models.Occupation.Occupation; | ||
| import com.vengeful.sloths.Models.Occupation.Smasher; | ||
| import com.vengeful.sloths.Models.Occupation.Sneak; | ||
| import com.vengeful.sloths.Models.Occupation.Summoner; | ||
| import com.vengeful.sloths.Models.Stats.EntityStats; | ||
| import com.vengeful.sloths.Utility.Coord; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public abstract class Entity { | ||
|
|
||
| private Coord location; | ||
|
|
||
| protected String name; | ||
| protected Occupation occupation; | ||
| protected EntityStats entityStats; | ||
|
|
||
|
|
||
| public Entity(String name, String occupationString, EntityStats entityStats) { | ||
| this.name = name; | ||
|
|
||
| this.entityStats = entityStats; | ||
|
|
||
| // @TODO: NOT ALL ENTITIES SHOULD TO SPAWN AT 2,2! | ||
| this.location = new Coord(2,2); | ||
|
|
||
| switch (occupationString) { | ||
| case "Smasher": | ||
| this.occupation = new Smasher(); | ||
| break; | ||
| case "Sneak": | ||
| this.occupation = new Sneak(); | ||
| break; | ||
| case "Summoner": | ||
| this.occupation = new Summoner(); | ||
| break; | ||
| default: | ||
| this.occupation = new Smasher(); | ||
| } | ||
|
|
||
| this.occupation.init(entityStats); | ||
|
|
||
| } | ||
|
|
||
| public Coord getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| public void setLocation(Coord coord) { | ||
| location = coord; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
| @@ -1,30 +1,34 @@ | ||
| package com.vengeful.sloths.Models.Inventory; | ||
|
|
||
|
|
||
| import com.vengeful.sloths.Models.InventoryItems.EquippableItems.*; | ||
|
|
||
| /** | ||
| * Created by qianwen on 1/30/16. | ||
| */ | ||
| public class Equipped { | ||
|
|
||
| private Hat hat = null; | ||
| private Sword sword = null; | ||
|
|
||
| public Equipped(){ | ||
|
|
||
| } | ||
|
|
||
| public Hat getHat(){ | ||
| return this.hat; | ||
| } | ||
|
|
||
| public void setHat(Hat h){ | ||
| this.hat = h; | ||
| } | ||
|
|
||
| public Sword getSword(){ | ||
| return this.sword; | ||
| } | ||
|
|
||
| public void setSword(Sword s){ | ||
| this.sword = s; | ||
| } | ||
|
|
||
| } |
| @@ -25,4 +25,5 @@ public boolean addItem(InventoryItem item){ | ||
| public boolean removeItem(InventoryItem item){ | ||
| return inventory.remove(item); | ||
| } | ||
|
|
||
| } | ||
| @@ -0,0 +1,16 @@ | ||
| package com.vengeful.sloths.Models.InventoryItems.EquippableItems; | ||
|
|
||
| import com.vengeful.sloths.Models.InventoryItems.InventoryItem; | ||
| import com.vengeful.sloths.Models.Stats.BaseStats; | ||
|
|
||
| /** | ||
| * Created by qianwen on 1/30/16. | ||
| */ | ||
| public abstract class EquippableItems extends InventoryItem { | ||
| protected BaseStats baseStats; | ||
|
|
||
| public EquippableItems(BaseStats b){ | ||
| super(); | ||
| this.baseStats = b; | ||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| package com.vengeful.sloths.Models.InventoryItems.EquippableItems; | ||
|
|
||
| import com.vengeful.sloths.Models.InventoryItems.EquippableItems.EquippableItems; | ||
| import com.vengeful.sloths.Models.Stats.BaseStats; | ||
|
|
||
| /** | ||
| * Created by qianwen on 1/30/16. | ||
| */ | ||
| public class Hat extends EquippableItems { | ||
|
|
||
| public Hat(BaseStats b){ | ||
| super(b); | ||
|
|
||
| //Set BaseStats | ||
| b.setStats(0, 0, 0, 10, 0); //Once equipped, increase avatar stats by these factors | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,18 @@ | ||
| package com.vengeful.sloths.Models.InventoryItems.EquippableItems; | ||
|
|
||
| import com.vengeful.sloths.Models.InventoryItems.EquippableItems.EquippableItems; | ||
| import com.vengeful.sloths.Models.Stats.BaseStats; | ||
|
|
||
| /** | ||
| * Created by qianwen on 1/30/16. | ||
| */ | ||
| public class Sword extends EquippableItems { | ||
|
|
||
| public Sword(BaseStats b){ | ||
| super(b); | ||
| //Set BaseStats | ||
|
|
||
| b.setStats(10, 0, 0, 0, 0); //Once equipped, increase avatar stats by these factors | ||
| } | ||
|
|
||
| } |
| @@ -5,7 +5,7 @@ | ||
| */ | ||
| public abstract class InventoryItem { | ||
|
|
||
| public InventoryItem() { | ||
|
|
||
| } | ||
|
|
||
| @@ -13,5 +13,4 @@ public Tile getTile(Coord coord){ | ||
| Tile tile = tiles[coord.getX()][coord.getY()]; | ||
| return tile; | ||
| } | ||
| } | ||
| @@ -6,6 +6,7 @@ | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class InteractableItem extends MapItem { | ||
|
|
||
| public void interact(Entity entity){ | ||
| //maybe alert user he cannot move here | ||
| } | ||
| @@ -6,6 +6,7 @@ | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class TakeableItem extends MapItem { | ||
|
|
||
| public void interact(Entity entity){ | ||
| //maybe alert user he cannot move here | ||
| } | ||
| @@ -0,0 +1,24 @@ | ||
| package com.vengeful.sloths.Models; | ||
|
|
||
| import com.vengeful.sloths.Models.TimeModel.TimeController; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class ModelEngine implements Runnable { | ||
|
|
||
| private TimeController timeController; | ||
|
|
||
| public ModelEngine(){ | ||
| timeController = new TimeController(); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| while(true) { | ||
| timeController.tick(); | ||
|
|
||
| } | ||
| } | ||
| } |
| @@ -1,11 +1,25 @@ | ||
| package com.vengeful.sloths.Models.Occupation; | ||
|
|
||
| import com.vengeful.sloths.Models.Stats.EntityStats; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class Smasher extends Occupation { | ||
|
|
||
| public Smasher() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void init(EntityStats entityStats) { | ||
| entityStats.increaseStats(10, 0, 0, 0, 0); | ||
| } | ||
|
|
||
| @Override | ||
| public void levelUp(EntityStats eStats) { | ||
| super.levelUp(eStats); | ||
|
|
||
| eStats.increaseStats(2, 1, 1, 1, 0); | ||
| } | ||
| } |
| @@ -1,11 +1,25 @@ | ||
| package com.vengeful.sloths.Models.Occupation; | ||
|
|
||
| import com.vengeful.sloths.Models.Stats.EntityStats; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class Sneak extends Occupation { | ||
|
|
||
| public Sneak() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void init(EntityStats entityStats) { | ||
| entityStats.increaseStats(0, 10, 0, 0, 0); | ||
| } | ||
|
|
||
| @Override | ||
| public void levelUp(EntityStats eStats) { | ||
| super.levelUp(eStats); | ||
|
|
||
| eStats.increaseStats(1, 2, 1, 1, 0); | ||
| } | ||
| } |
| @@ -1,11 +1,25 @@ | ||
| package com.vengeful.sloths.Models.Occupation; | ||
|
|
||
| import com.vengeful.sloths.Models.Stats.EntityStats; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class Summoner extends Occupation { | ||
|
|
||
| public Summoner() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void init(EntityStats entityStats) { | ||
| entityStats.increaseStats(0, 0, 10, 0, 0); | ||
| } | ||
|
|
||
| @Override | ||
| public void levelUp(EntityStats eStats) { | ||
| super.levelUp(eStats); | ||
|
|
||
| eStats.increaseStats(1, 1, 2, 1, 0); | ||
| } | ||
| } |
| @@ -1,25 +1,125 @@ | ||
| package com.vengeful.sloths.Models.Stats; | ||
|
|
||
| /** | ||
| * Created by zach on 1/30/16. | ||
| */ | ||
| public class EntityStats extends Stats { | ||
|
|
||
| // Base stats: | ||
| // int strength; | ||
| // int agility; | ||
| // int intellect; | ||
| // int hardiness; | ||
| // int movement; | ||
|
|
||
| protected int livesLeft; | ||
| protected int experience; | ||
| protected int level; | ||
| // HP stat | ||
| protected int life; | ||
| protected int mana; | ||
| protected int offensiveRating; | ||
| protected int defensiveRating; | ||
| protected int armorRating; | ||
|
|
||
| protected int[] requiredLevelXP = {0, 10, 20, 40, 80, 160, 320, 640, 1280, 2560}; | ||
| protected int currentHealth; | ||
|
|
||
|
|
||
| public EntityStats() { | ||
| super(); | ||
|
|
||
| // Set defaults | ||
| this.experience = 1; | ||
| this.level = 1; | ||
| this.livesLeft = 1; | ||
| this.life = 10; | ||
|
|
||
| this.currentHealth = life; | ||
|
|
||
| updateStats(); | ||
| } | ||
|
|
||
| private void updateStats() { | ||
| //livesLeft | ||
| //experience | ||
|
|
||
| life = calculateLife(); | ||
| mana = calculateMana(); | ||
| offensiveRating = calculateOffensiveRating(); | ||
| defensiveRating = calculateDefensiveRating(); | ||
| armorRating = calculateArmorRating(); | ||
|
|
||
| } | ||
|
|
||
| private int calculateLife() { | ||
| double factor = hardiness / 50.0; | ||
| double levelFactor = level / 50.0; | ||
| return life + ((int)(life * factor)) + ((int)(life * levelFactor)); | ||
| } | ||
|
|
||
| private int calculateMana() { | ||
| double factor = intellect / 50.0; | ||
| double levelFactor = level / 50.0; | ||
| return mana + ((int)(mana * factor)) + ((int)(mana * levelFactor)); | ||
| } | ||
|
|
||
| private int calculateOffensiveRating() { | ||
| double factor = strength / 50.0; | ||
| double levelFactor = level / 50.0; | ||
| // FACTOR IN EQUIPPED ARMOR! | ||
| return offensiveRating + ((int)(offensiveRating * factor)) + ((int)(offensiveRating * levelFactor)); | ||
| } | ||
|
|
||
| private int calculateDefensiveRating() { | ||
| double factor = agility / 50.0; | ||
| double levelFactor = level / 50.0; | ||
| return defensiveRating + ((int)(defensiveRating * factor)) + ((int)(defensiveRating * levelFactor)); | ||
| } | ||
|
|
||
| private int calculateArmorRating() { | ||
| double factor = hardiness / 50.0; | ||
| double levelFactor = level / 50.0; | ||
| // FACTOR IN EQUIPPED ARMOR! | ||
| return armorRating + ((int)(armorRating * factor)) + ((int)(armorRating * levelFactor)); | ||
| } | ||
|
|
||
| public void levelUp() { | ||
| level++; | ||
| } | ||
|
|
||
| public void increaseStats(int strength, int agility, int intellect, int hardiness, int movement) { | ||
| super.increaseStats(strength, agility, intellect, hardiness, movement); | ||
|
|
||
| updateStats(); | ||
| } | ||
|
|
||
| public void updateXP(int xp){ | ||
| this.experience += xp; | ||
| } | ||
|
|
||
| public int getXP(){ | ||
| return this.experience; | ||
| } | ||
|
|
||
| public int getRequiredLevelXP(){ | ||
| return requiredLevelXP[this.level]; | ||
| } | ||
|
|
||
| public void setCurrentHealth(int health){ | ||
| this.currentHealth += health; | ||
|
|
||
| if(this.currentHealth > life) | ||
| this.currentHealth = life; | ||
| } | ||
|
|
||
| public int getCurrentHealth(){ | ||
| return this.currentHealth; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public String toString() { | ||
| return this.strength + " " + this.agility + " " + this.intellect + " " + this.hardiness + " " + this.movement; | ||
| } | ||
| } |
| @@ -0,0 +1,9 @@ | ||
| package com.vengeful.sloths.Models.TimeModel; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public interface Alertable { | ||
| public void execute(); | ||
|
|
||
| } |
| @@ -0,0 +1,27 @@ | ||
| package com.vengeful.sloths.Models.TimeModel; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class TimeController { | ||
|
|
||
| private TimeModel timeModel = new TimeModel(); | ||
|
|
||
| public void tick(){ | ||
| Long startTime = System.currentTimeMillis(); | ||
| //do shit | ||
|
|
||
| timeModel.tick(); | ||
|
|
||
| //delay to get 30 ticks per seconds | ||
| Long deltaTime = System.currentTimeMillis() - startTime; | ||
| deltaTime = 33L - deltaTime; | ||
| if(deltaTime < 0L)deltaTime = 0L; | ||
|
|
||
| try { | ||
| Thread.sleep(deltaTime); | ||
| }catch(InterruptedException e){ | ||
| //suck 1000 dicks | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| package com.vengeful.sloths.Models.TimeModel; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class TimeModel { | ||
|
|
||
| private ArrayList<TimedObject> alertables; | ||
|
|
||
| public TimeModel(){ | ||
| alertables = new ArrayList<TimedObject>(); | ||
| } | ||
| //decremenets timedobjects and calls alterables execute when ticks == 0 | ||
| public void tick(){ | ||
| for (TimedObject timedObject : alertables){ | ||
| if(timedObject.decrement()){ | ||
| timedObject.execute(); | ||
| alertables.remove(timedObject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void registerAlertable(Alertable alertable, int ticks){ | ||
| alertables.add(new TimedObject(alertable, ticks)); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,27 @@ | ||
| package com.vengeful.sloths.Models.TimeModel; | ||
|
|
||
| /** | ||
| * Created by John on 1/30/2016. | ||
| */ | ||
| public class TimedObject { | ||
|
|
||
| private Alertable alertable; | ||
| private int ticks; | ||
|
|
||
| public TimedObject(Alertable alertable, int ticks){ | ||
| this.ticks = ticks; | ||
| this.alertable = alertable; | ||
| } | ||
|
|
||
| //boolean true if ticks = 0 and its time to execute/remove from list | ||
| //this is called from time model | ||
| public boolean decrement(){ | ||
| --ticks; | ||
| return (ticks == 0); | ||
| } | ||
|
|
||
| public void execute(){ | ||
| alertable.execute(); | ||
| } | ||
|
|
||
| } |
| @@ -1,5 +1,5 @@ | ||
| package com.vengeful.sloths.Utility; | ||
|
|
||
| public enum Direction { | ||
| N, E, S, W, NE, NW, SE, SW | ||
| } |
| @@ -0,0 +1,78 @@ | ||
| package com.vengeful.sloths.View.InventoryView; | ||
|
|
||
| import com.vengeful.sloths.View.AreaView.AreaView; | ||
| import com.vengeful.sloths.View.AreaView.Direction; | ||
| import com.vengeful.sloths.View.AreaView.EntityObserver; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| public class driver extends JFrame implements Runnable{ | ||
|
|
||
| public driver() { | ||
| av = new AreaView(); | ||
| initUI(); | ||
| } | ||
|
|
||
| private AreaView av; | ||
|
|
||
| private void initUI() { | ||
|
|
||
| add(av); | ||
|
|
||
| setTitle("A game"); | ||
| setResizable(false); | ||
| pack(); | ||
| setLocationRelativeTo(null); | ||
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| } | ||
|
|
||
| public void run() { | ||
| int count = 0; | ||
|
|
||
| while(true) { | ||
| long lastTime = System.currentTimeMillis(); | ||
|
|
||
| //Actual Code goes here | ||
|
|
||
| av.repaint(); | ||
| EntityObserver eo = (EntityObserver)av.getPlayer(); | ||
|
|
||
| if ( count%20 == 4 ) { | ||
| eo.alertDirectionChange(Direction.E); | ||
| } else if ( count%20 == 8) { | ||
| eo.alertDirectionChange(Direction.N); | ||
| } else if ( count%20 == 12) { | ||
| eo.alertDirectionChange(Direction.W); | ||
| } else if ( count%20 == 16) { | ||
| eo.alertDirectionChange(Direction.S); | ||
| } | ||
|
|
||
| //End of actual code | ||
|
|
||
| long delta = System.currentTimeMillis() - lastTime; | ||
| if (delta < 250) { | ||
| try { | ||
| Thread.sleep((250 - delta)); | ||
| } catch (Exception e) { | ||
| //dont care | ||
| } | ||
|
|
||
| } | ||
| System.out.println(count++); | ||
| } | ||
| } | ||
| public void start() { | ||
| new Thread(this).start(); | ||
| } | ||
| public static void main(String[] args) { | ||
|
|
||
|
|
||
| driver ex = new driver(); | ||
| ex.setVisible(true); | ||
|
|
||
| ex.start(); | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } |