Browse Source

Start of basic resource functionality and exception handling

master
Sven Slootweg 9 years ago
parent
commit
be2dce9a32
  1. 33
      core.js

33
core.js

@ -22,6 +22,39 @@ Function.prototype.inheritsFrom = function(parentObject)
/*Class*/ RadiumEngine = function()
{
this.version = "1.0";
var blah = "derp";
var /*Exception*/ Exception = this.Exception = function(message)
{
this.message = message;
}
var /*Exception*/ ResourceException = this.ResourceException = function(message, resource, action)
{
this.resource = resource;
this.message = message;
this.action = action;
}
ResourceException.inheritsFrom(Exception);
var /*Class*/ Player = this.Player = function()
{
this.credits = 0; /* Integer */
this.health = 1; /* Fraction */
this.resources = {}; /* Associative array -> Integer */
this.TakeResource = function(resource, amount)
{
if(this.resources[resource])
{
this.resources[resource] -= amount;
}
else
{
throw new ResourceException("This resource does not exist.", resource, "take");
}
}
}
var point_distance = this.point_distance = function(x1, y1, x2, y2)
{

Loading…
Cancel
Save