Skip to content

Instantly share code, notes, and snippets.

@franksands
franksands / sample1.js
Last active December 9, 2015 00:24
sample1.js
var name = "Elsa";
var health = 50;
var magicPoints = 80;
var attack = "Axe";
print(name + " has " + health + " hit points");
var heroName = "Elsa";
var heroHealth = 50;
var heroMagicPoints = 80;
var heroAttack = "Axe";
var monsterName = "Goblin";
var monsterHealth = 20;
var monsterMagicPoints = 0;
var monsterAttack = "Dagger";
var monsterName = ["Goblin", "Dragon", "Orc"];
var monsterHealth = [20, 300, 40];
var monsterMagicPoints = [0, 200, 0];
var monsterAttack = ["Dagger", "Fireball", "Sword"];
print(monsterName[0] + " has " + monsterHealth[0] + " hit points");
function vanquishMonster(monsterIndex) {
remove(monsterName, monsterIndex);
remove(monsterHealth, monsterIndex);
remove(monsterMagicPoints, monsterIndex);
# Note there is no remove for monsterAttack
}
vanquishMonster(0);
monsterName = ["Dragon", "Goblin"]
monsterHealth = [300, 18]
monsterMagicPoints = [200, 0]
monsterAttack = ["Dagger", "Fireball", "Sword"]
monsters = [{"name":"Goblin", "health":20, "magicPoints":0, "attack":"Dagger"},
{"name":"Dragon", "health":300, "magicPoints":200, "attack":"Fireball"},
{"name":"Orc", "health":40, "magicPoints":0, "attack":"Sword"}]
public class LivingThing {
public String name;
public int health;
public int magicPoints;
public String attack;
public LivingThing(String name, int health, int magicPoints, String attack) {
this.name = name;
this.health = health;
this.magicPoints = magicPoints;
public class LivingThing {
public String name;
public int health;
public int magicPoints;
public String attack;
public int hunger;
public LivingThing(String name, int health, int magicPoints, String attack) {
this.name = name;
this.health = health;
hero = LivingThing("Elsa", 50, 80, "Axe");
hero.health -= 10; // Elsa takes 10 points of damage
if (hero.health < 0) {
print(hero.name + ' has died!')
}
hero = LivingThing("Elsa", 50, 80, "Axe");
hero.health -= 10 // Elsa takes 10 points of damage