///|
#derive(Eq, Debug)
pub(all) enum Tile {
Floor
Wall
Door
LockedDoor
Key
Start
Goal
Corridor
Water
Empty
}
///|
pub fn Tile::to_char(self : Tile) -> Char {
match self {
Floor => '.'
Wall => '#'
Door => '+'
LockedDoor => 'L'
Key => 'K'
Start => 'S'
Goal => 'G'
Corridor => ','
Water => '~'
Empty => ' '
}
}
///|
#derive(Eq, Compare, Debug)
pub(all) struct Point {
x : Int32
y : Int32
}
///|
#derive(Eq, Debug)
pub(all) struct Rect {
x : Int32
y : Int32
w : Int32
h : Int32
}
///|
pub fn Rect::center(self : Rect) -> Point {
{ x: self.x + self.w / 2, y: self.y + self.h / 2, }
}
///|
pub fn Rect::contains(self : Rect, p : Point) -> Bool {
p.x >= self.x &&
p.x < self.x + self.w &&
p.y >= self.y &&
p.y < self.y + self.h
}
///|
pub fn Rect::intersects(self : Rect, other : Rect) -> Bool {
self.x < other.x + other.w &&
self.x + self.w > other.x &&
self.y < other.y + other.h &&
self.y + self.h > other.y
}
///|
#derive(Debug)
pub(all) struct Room {
rect : Rect
id : Int32
}
///|
#derive(Debug)
pub(all) struct Edge {
from : Int32
to : Int32
}
///|
#derive(Eq, Debug)
pub(all) enum NodeKind {
StartNode
GoalNode
RoomNode
KeyNode
LockNode
}
///|
#derive(Debug)
pub(all) struct GraphNode {
id : Int32
kind : NodeKind
children : Array[Int32]
}
///|
pub impl Show for Tile with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for Point with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for Rect with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for Room with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for Edge with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for NodeKind with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}
///|
pub impl Show for GraphNode with fn output(self, logger) {
logger.write_string(@debug.to_string(self))
}