1
0

player.js 856 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var Player = function() {
  2. this.inventory = {};
  3. this.ship = {};
  4. this.state = {};
  5. this.addItem = function(key, delta) {
  6. if (this.inventory[key] == null) {
  7. this.inventory[key] = delta;
  8. } else {
  9. this.inventory[key] += delta;
  10. }
  11. return this.inventory[key];
  12. };
  13. this.getItem = function(key) {
  14. return this.inventory[key];
  15. };
  16. this.getData = function(key) {
  17. return this.state[key];
  18. };
  19. this.setData = function(key, value) {
  20. this.state[key] = value;
  21. return this.state[key];
  22. };
  23. this.getShip = function(key) {
  24. return this.ship[key];
  25. }
  26. this.setShip = function(key, value) {
  27. this.ship[key] = value;
  28. return this.ship[key];
  29. };
  30. this.addShip = function(key, delta) {
  31. if (this.ship[key] == null) {
  32. this.ship[key] = delta;
  33. } else {
  34. this.ship[key] += delta;
  35. }
  36. return this.ship[key];
  37. };
  38. };
  39. var player = new Player();