games/rogue/rogue.js

66 lines
878 B
JavaScript

export default class Rogue {
constructor() {
this.message = ""
this.end = false
this.init_level()
this.x = 5
this.y = 5
}
apply_commad = function(command)
{
this.message = ""
let nx = this.x
let ny = this.y
switch (command)
{
case "q":
this.end_game()
break
case "h":
nx--
break
case "j":
ny++
break
case "k":
ny--
break
case "l":
nx++
break
}
if (this.level[nx][ny] == ".") {
this.x = nx
this.y = ny
}
}
end_game = function()
{
this.message = "good bye"
this.end = true
}
init_level = function()
{
const size = 20
this.level = []
for (let y = 0; y < size; y++) {
let cols = []
for (let x = 0; x < size; x++) {
let tile = '.'
if (x == 0 || y == 0 || x == size - 1 || y == size - 1) {
tile = '#'
}
cols.push(tile)
}
this.level.push(cols)
}
}
}