@@ -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,39 +1,130 @@
package com.vengeful.sloths.Models.Entity;

import com.vengeful.sloths.Models.ActionCommandFactory.ActionCommandFactory;
import com.vengeful.sloths.Models.ActionCommandFactory.AvatarActionCommandFactory;
import com.vengeful.sloths.Models.Inventory.Equipped;
import com.vengeful.sloths.Models.Inventory.Inventory;
import com.vengeful.sloths.Models.InventoryItems.InventoryItem;
import com.vengeful.sloths.Models.InventoryItems.EquippableItems.*;
import com.vengeful.sloths.Utility.Coord;
import com.vengeful.sloths.Models.Stats.EntityStats;
import com.vengeful.sloths.View.AreaView.Direction;

/**
* Created by zach on 1/30/16.
*/
public class Avatar extends Entity {

public Avatar() {
super();
private Inventory inventory;
private Equipped equipped;
private ActionCommandFactory commandFactory;

public Avatar(String name, String occupationString, EntityStats entityStats, ActionCommandFactory commandFactory) {
super(name, occupationString, entityStats);
this.inventory = new Inventory();
this.equipped = new Equipped();
this.commandFactory = commandFactory;
}

public void move(Direction dir) {
Coord dst = this.getLocation();
switch (dir) {
case N:
dst.setY(dst.getY() - 1);
break;
case E:
dst.setX(dst.getX() + 1);
break;
case S:
dst.setY(dst.getY() + 1);
break;
case W:
dst.setX(dst.getX() - 1);
break;
case NE:
dst.setY(dst.getY() - 1);
dst.setX(dst.getX() + 1);
break;
case NW:
dst.setY(dst.getY() - 1);
dst.setX(dst.getX() - 1);
break;
case SE:
dst.setY(dst.getY() + 1);
dst.setX(dst.getX() + 1);
break;
case SW:
dst.setY(dst.getY() + 1);
dst.setX(dst.getX() - 1);
break;
default:
break;
}

this.commandFactory.createMovementCommand(dst, this);
}

public boolean equip(int itemIndex) {
return false;

try {
InventoryItem i = this.inventory.getItem(itemIndex);
if(i instanceof Hat){
this.equipped.setHat((Hat)i);
}else if(i instanceof Sword){
this.equipped.setSword((Sword)i);
}

this.inventory.removeItem(i);

} catch(Exception e){
System.out.println(e);
return false;
}

return true;
}

public boolean unequip(int itemIndex) {
return false;
public boolean unequip(InventoryItem item) {
if(item instanceof Hat){
this.equipped.setHat(null);
}else if(item instanceof Sword){
this.equipped.setSword(null);
}else
return false;

this.inventory.addItem(item);
return true;
}

public boolean drop(int itemIndex) {
//Get Tile from map
//Try to drop on tile
//Need to create Takeable item
return false;
}

public void levelUp() {

// Let occupation know level is increased, then levelUp occ and base stats
occupation.levelUp(entityStats);
}

public void gainXP(int xp) {
entityStats.updateXP(xp);

if(entityStats.getXP() >= entityStats.getRequiredLevelXP()){
this.levelUp();
}
}

public void gainHealth(int health) {

entityStats.setCurrentHealth(health);
}

public void takeDamage(int damage) {
entityStats.setCurrentHealth(-damage);

if(entityStats.getCurrentHealth() <= 0)
this.die();

}

@@ -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 loc;

public 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 getLoc() {
return loc;
public Coord getLocation() {
return location;
}

public void setLoc(Coord coord) {
loc = coord;
public void setLocation(Coord coord) {
location = coord;
}




}
@@ -1,30 +1,34 @@
package com.vengeful.sloths.Models.Inventory;

import com.vengeful.sloths.Models.InventoryItems.EquippableItems;
import com.vengeful.sloths.Models.InventoryItems.InventoryItem;

import java.util.ArrayList;
import com.vengeful.sloths.Models.InventoryItems.EquippableItems.*;

/**
* Created by qianwen on 1/30/16.
*/
public class Equipped {
private ArrayList<EquippableItems> equipped;

private Hat hat = null;
private Sword sword = null;

public Equipped(){
equipped = new ArrayList<EquippableItems>();

}

public Hat getHat(){
return this.hat;
}

public InventoryItem getItem(int itemIndex){
return equipped.get(itemIndex);
public void setHat(Hat h){
this.hat = h;
}

public boolean addItem(EquippableItems item){
return equipped.add(item);
public Sword getSword(){
return this.sword;
}

public boolean removeItem(EquippableItems item){
return equipped.remove(item);
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);
}

}

This file was deleted.

@@ -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
}

}

This file was deleted.

@@ -5,7 +5,7 @@
*/
public abstract class InventoryItem {

public InventoryItem(){
public InventoryItem() {

}

This file was deleted.

@@ -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
}
@@ -2,8 +2,10 @@

import com.vengeful.sloths.Models.Entity.Entity;
import com.vengeful.sloths.Models.Map.MapItems.MapItem;
import com.vengeful.sloths.Models.Map.Terrains.Grass;
import com.vengeful.sloths.Models.Map.Terrains.Terrain;

import java.util.ArrayList;
import java.util.List;

/**
@@ -13,12 +15,28 @@ public class Tile {

private Entity entity;
private boolean canBeMovedOn;
private List<MapItem> mapItems;
private List<AreaEffect> areaEffect;
private List<Decal> decals;
private ArrayList<MapItem> mapItems;
private ArrayList<AreaEffect> areaEffect;
private ArrayList<Decal> decals;
private Terrain terrain;


public Tile(){
canBeMovedOn = true;
mapItems = new ArrayList<MapItem>();
areaEffect = new ArrayList<AreaEffect>();
decals = new ArrayList<Decal>();
terrain = new Grass();
}

public Tile(Terrain terrain){
canBeMovedOn = true;
mapItems = new ArrayList<MapItem>();
areaEffect = new ArrayList<AreaEffect>();
decals = new ArrayList<Decal>();
this.terrain = terrain;
}

public void execute(){

}
@@ -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,6 +1,6 @@
package com.vengeful.sloths.Models.Occupation;

import com.vengeful.sloths.Models.Stats.BaseStats;
import com.vengeful.sloths.Models.Stats.EntityStats;

/**
* Created by zach on 1/30/16.
@@ -11,9 +11,10 @@ public Occupation() {

}

public BaseStats levelUp() {
public abstract void init(EntityStats entityStats);

return new BaseStats();
public void levelUp(EntityStats eStats) {
eStats.levelUp();
}

}
@@ -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() {
super();

}

@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() {
super();

}

@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() {
super();

}

@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);
}
}
@@ -6,6 +6,15 @@
public class BaseStats extends Stats {

public BaseStats() {

super();
}

public void setStats(int str, int agil, int intel, int hardi, int move){
this.strength = str;
this.agility = agil;
this.intellect = intel;
this.hardiness = hardi;
this.movement = move;
}
}
@@ -1,25 +1,125 @@
package com.vengeful.sloths.Models.Stats;

import com.vengeful.sloths.Models.Entity.Entity;

/**
* 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;
}
}
@@ -11,8 +11,19 @@ public abstract class Stats {
protected int movement;

public Stats() {

this.strength = 5;
this.agility = 5;
this.intellect = 5;
this.hardiness = 5;
this.movement = 1;
}

public void increaseStats(int strength, int agility, int intellect, int hardiness, int movement) {
this.strength += strength;
this.agility += agility;
this.intellect += intellect;
this.hardiness += hardiness;
this.movement += 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 {
UP, LEFT, DOWN, RIGHT
N, E, S, W, NE, NW, SE, SW
}
@@ -75,17 +75,18 @@ void paintComponent(Graphics2D g) {
}

public void alertDirectionChange(Direction d) {
System.out.println("New direction " + d);
switch (d) {
case UP:
case N:
currentImage = entityUp;
break;
case LEFT:
case W:
currentImage = entityLeft;
break;
case DOWN:
case S:
currentImage = entityDown;
break;
case RIGHT:
case E:
currentImage = entityRight;
break;
}
@@ -14,6 +14,7 @@ public void clear() {
}
public void addMapViewObject(ViewObject vo) {
//We can sort on iterator because it will be called less
System.out.println("Adding " + vo.getClass() + " to mapviewmanager");
voList.add(vo);
}
public Iterator<ViewObject> iterator() {
@@ -27,6 +28,7 @@ public int compare(ViewObject left, ViewObject right) {
return viewObjectClassToHeightIndex(left) - viewObjectClassToHeightIndex(right);
}
});

return voList.iterator();
}
}
@@ -56,6 +56,7 @@ public void run() {
if (count%25 == 0 && count < 125) eo.alertMove(1,ay++,1000);

//End of actual code


long delta = System.currentTimeMillis() - lastTime;
if (delta < 50) {
@@ -66,12 +67,14 @@ public void run() {
}

}
System.out.println(count++);
count++;
// System.out.println(count++);
}
}
public void start() {
new Thread(this).start();
}

public static void main(String[] args) {


@@ -11,17 +11,36 @@
public class InventoryItemViewObject extends JComponent{
protected int x;
protected int y;
private final Image itemImage;
private Image itemImage;
private final int imageHeight = 18; //increment the y positions by height + 2
private final int imageWidth = 18;
private final int horizontalOffset = imageWidth + 100;
private String itemName;
//private Item item; //the connected Item object

public InventoryItemViewObject(int x, int y, String image) {
//public InventoryItemViewObject(Item item, int x, int y, String image) { //this will be the constructor so can pass in actual items
public InventoryItemViewObject(String itemName, int x, int y, String image) {
this.x = x;
this.y = y;

//this.itemName = item.itemName; //get the name directly from the connected item object
this.itemName = itemName; //this will be removed and replaced with the above line, to get the name directly from the connected Item object
ImageIcon itemIcon = new ImageIcon(image);
itemImage = itemIcon.getImage();
}

public InventoryItemViewObject(String itemName, int x, int y) {
this.x = x;
this.y = y;
//this.itemName = item.itemName; //get the name directly from the connected item object
this.itemName = itemName; //this will be removed and replaced with the above line, to get the name directly from the connected Item object
ImageIcon itemIcon = new ImageIcon("resources/"+itemName+".jpg");
itemImage = itemIcon.getImage();
}


public void paintComponent(Graphics2D g) {
g.drawImage(itemImage, x,y, this);
//g.drawImage(itemImage, x,y, this);
g.drawImage(itemImage,x,y,imageWidth,imageHeight,this);
g.drawString(itemName, x+horizontalOffset, y + imageHeight); //want to draw the item image and then its name on the same line. Drawing of name is offset by the width of the image.
}
}
@@ -10,15 +10,20 @@
*/
public class ListInventoryView extends InventoryView {

private int VIEW_HEIGHT = 250;
private int VIEW_WIDTH = 250;
private int VIEW_HEIGHT = 450;
private int VIEW_WIDTH = 450;
public ListInventoryViewObjectManager manager;

//InventoryItemViewObject testItem = new InventoryItemViewObject("Blue Partyhat", 5, 5, "resources/bluePhat.jpg");
InventoryItemViewObject testItem = new InventoryItemViewObject("GodSword", 5, 5);
InventoryItemViewObject testItem2 = new InventoryItemViewObject("Blue Partyhat", 5, 25);

public ListInventoryView() {
public ListInventoryView() {

manager = new ListInventoryViewObjectManager();

setBackground(Color.WHITE);
setPreferredSize(new Dimension(VIEW_WIDTH, VIEW_HEIGHT));

}

@@ -37,11 +42,16 @@ public void paintComponent(Graphics g) {

Graphics2D g2d = (Graphics2D) g;

Iterator<InventoryItemViewObject> iter = manager.iterator();
while (iter.hasNext()) {
InventoryItemViewObject current = iter.next();
current.paintComponent(g2d);
}
testItem.paintComponent(g2d);
testItem2.paintComponent(g2d);

// Iterator<InventoryItemViewObject> iter = manager.iterator();
// while (iter.hasNext()) {
// InventoryItemViewObject current = iter.next();
// current.paintComponent(g2d);
// }

Toolkit.getDefaultToolkit().sync(); //purpose?
}

}
@@ -14,23 +14,12 @@ public ListInventoryViewObjectManager() {
itemList = new ArrayList<InventoryItemViewObject>();
}

public void addInventoryItemViewObject(InventoryItemViewObject item) {
public void addInventoryItemViewObject(InventoryItemViewObject itemView) {
//We can sort on iterator because it will be called less
itemList.add(item);
itemList.add(itemView);
}


public Iterator<InventoryItemViewObject> iterator() {
// itemList.sort(new Comparator<InventoryItemViewObject>() {
// private int viewObjectClassToHeightIndex(InventoryItemViewObject vo) {
// if (vo.getClass() == EntityMapViewObject.class) return 100;
// else if (vo.getClass() == TerrainMapViewObject.class) return 0;
// else return 1000;
// }
// public int compare(InventoryItemViewObject left, InventoryItemViewObject right) {
// return viewObjectClassToHeightIndex(left) - viewObjectClassToHeightIndex(right);
// }
// });
return itemList.iterator();
}

@@ -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();



}
}