Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active October 7, 2019 15:00
Show Gist options
  • Save ndugger/d128b0f631d7e0201293d1465f4875ef to your computer and use it in GitHub Desktop.
Save ndugger/d128b0f631d7e0201293d1465f4875ef to your computer and use it in GitHub Desktop.
Language Comparison: DungeonMaster -> TypeScript
use master dice.
use master game.
use goblin.
define d12 as dice, set to result of new dice (sides: 12).
define mob as goblin, set to result of new goblin (hp: 10, mp: 5).
roll d12.
if result of d12 roll < 6:
heal mob (points: 5).
if result of d12 roll = 6:
hurt mob (points: 5).
if result of d12 roll > 6:
kill mob.
if mob health = 0:
end game.
use game.
use math.
define dice as blueprint (use number as sides) of game'item, set to:
define roll as action (use number as times, share number), set to:
define value as number, set to 0.
repeat times:
set value to value + do math'round (do math'random (0, sides)).
share value.
share roll.
share dice.
import Game from 'game';
import Math from 'math';
class Dice extends Game.Item {
private sides: number;
public constructor(sides: number) {
this.sides = sides;
}
public roll(times: number): number {
let value = 0;
for (let i = 0; i < times; ++i) {
value += Math.round(Math.random() * sides);
}
return value;
}
}
export default Dice;
use master npc.
define goblin as blueprint of npc:
define health as number.
define magic as number.
define new as action (define hp as number, define mp as number):
set health to hp.
set magic to mp.
define hurt as action (define points as number):
set health to health - points.
if health < 0:
kill.
define kill as action:
set hp to 0.
define heal as action (define points as number):
set health to health + points.
share goblin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment