A Simple Simulator

Raise a warrior that's drifted in from the mainland somewhere. It must learn to survive and gather skills to eventually leave the island through various means. Be that sorcery or building a boat, etc.

by Sam Fereday

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/javascript-state-machine/2.0.0/state-machine.min.js"></script>
<span data-bind="text: entity.hunger"></span>
<button data-bind="click: entity.eat">Eat</button>

CSS

body {
  text-align: center;
}

span {
  display: block;
  text-align: center;
}

JavaScript

// Loop stuff
var gameloop = (function() {
  'use strict';
  var reqAnimFrame = window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    function(callback) {
      window.setTimeout(callback, 1000 / 60);
    };

  return function(callback) {
    var lastUpdate = +new Date();
    (function loop() {
      callback(((+new Date()) - lastUpdate) / 1000);
      reqAnimFrame(loop);
      lastUpdate = +new Date();
    }());
  };
}());

// Concrete states the character can be in
const States = {
  Content: 'content',
  Hungry: 'hungry',
  Full: 'full'
}

// https://github.com/jakesgordon/javascript-state-machine
MyFSM = function() { // my constructor function
  this.startup();
};

MyFSM.prototype = {

  onpanic: function(event, from, to) {
    alert('panic');
  },
  onclear: function(event, from, to) {
    alert('all is clear');
  },

  // my other prototype methods

};

StateMachine.create({
  target: MyFSM.prototype,
  events: [{
    name: 'startup',
    from: 'none',
    to: States.Content
  }, {
    name: States.Hungry,
    from: States.Content,
    to: States.Hungry
  }, {
    name: States.Full,
    from: States.Hungry,
    to: States.Content
  }]
});

// A model that holds an action currently running (state machine stuff)
let Action = function() {

}

// The meat of the entity
let Warrior = function() {

	let self = this;

  // Our current mood
  this.mood = ko.observable(States.Content);

  // Needed to live
  this.hunger = ko.observable(0);
  this.thirst = ko.observable(0);
  this.tiredness = ko.observable(0);

  // Whether they like it or not
  this.overallHealth = ko.observable(100);
  this.age = ko.observable(0);
  this.hygiene = ko.observable(100);
  this.bathroom = ko.observable(0);

  // Skillsets
  this.purpose = ko.observable(0);
  this.craftsmanship = ko.observable(0);
  this.sorcery = ko.observable(0);
  this.fishing = ko.observable(0);
  this.archery = ko.observable(0);
  this.combat =...