Skip to content

Instantly share code, notes, and snippets.

@pyrobot
Last active December 16, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrobot/5506398 to your computer and use it in GitHub Desktop.
Save pyrobot/5506398 to your computer and use it in GitHub Desktop.
coffeescript is awesome
class View
class @Pieces
@keys = ['floor', 'ceiling', 'side', 'front']
@floorPieces = document.getElementsByClassName('floor')[0].children
@ceilingPieces = document.getElementsByClassName('ceiling')[0].children
@sidePieces = document.getElementsByClassName('side')[0].children
@frontPieces = document.getElementsByClassName('front')[0].children
@allPieces = floor: @floorPieces, ceiling: @ceilingPieces, side: @sidePieces, front: @frontPieces
class @Utils
@hide = (e) -> e.style.display = 'none'
@show = (e) -> e.style.display = 'block'
@hideGroup = (pieces) -> View.Utils.hide piece for piece in pieces
@showGroup = (pieces) -> View.Utils.show piece for piece in pieces
@hideAll = -> View.Utils.hideGroup View.Pieces.allPieces[key] for key in View.Pieces.keys
@showAll = -> View.Utils.showGroup View.Pieces.allPieces[key] for key in View.Pieces.keys
class Room
constructor: (options) -> {@x, @y, @directionLinks, @boundary} = options
position: -> "#{@x}:#{@y}"
class Rooms
constructor: (@width, @height) ->
@length = (@width+1) * (@height+1)
for w in [0..@width]
for h in [0..@height]
directionLinks = north: h is 0, east: h is @width, south: h is @height, west: w is 0
boundary = if directionLinks.north or directionLinks.east or
directionLinks.south or directionLinks.west then true else false
options = x: w, y: h, directionLinks: directionLinks, boundary: boundary
room = new Room(options)
@[room.position()] = room
// Generated by CoffeeScript 1.3.3
var Room, Rooms, View;
View = (function() {
function View() {}
View.Pieces = (function() {
function Pieces() {}
Pieces.keys = ['floor', 'ceiling', 'side', 'front'];
Pieces.floorPieces = document.getElementsByClassName('floor')[0].children;
Pieces.ceilingPieces = document.getElementsByClassName('ceiling')[0].children;
Pieces.sidePieces = document.getElementsByClassName('side')[0].children;
Pieces.frontPieces = document.getElementsByClassName('front')[0].children;
Pieces.allPieces = {
floor: Pieces.floorPieces,
ceiling: Pieces.ceilingPieces,
side: Pieces.sidePieces,
front: Pieces.frontPieces
};
return Pieces;
})();
View.Utils = (function() {
function Utils() {}
Utils.hide = function(e) {
return e.style.display = 'none';
};
Utils.show = function(e) {
return e.style.display = 'block';
};
Utils.hideGroup = function(pieces) {
var piece, _i, _len, _results;
_results = [];
for (_i = 0, _len = pieces.length; _i < _len; _i++) {
piece = pieces[_i];
_results.push(View.Utils.hide(piece));
}
return _results;
};
Utils.showGroup = function(pieces) {
var piece, _i, _len, _results;
_results = [];
for (_i = 0, _len = pieces.length; _i < _len; _i++) {
piece = pieces[_i];
_results.push(View.Utils.show(piece));
}
return _results;
};
Utils.hideAll = function() {
var key, _i, _len, _ref, _results;
_ref = View.Pieces.keys;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
_results.push(View.Utils.hideGroup(View.Pieces.allPieces[key]));
}
return _results;
};
Utils.showAll = function() {
var key, _i, _len, _ref, _results;
_ref = View.Pieces.keys;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
_results.push(View.Utils.showGroup(View.Pieces.allPieces[key]));
}
return _results;
};
return Utils;
})();
return View;
}).call(this);
Room = (function() {
function Room(options) {
this.x = options.x, this.y = options.y, this.directionLinks = options.directionLinks, this.boundary = options.boundary;
}
Room.prototype.position = function() {
return "" + this.x + ":" + this.y;
};
return Room;
})();
Rooms = (function() {
function Rooms(width, height) {
var boundary, directionLinks, h, options, room, w, _i, _j, _ref, _ref1;
this.width = width;
this.height = height;
this.length = (this.width + 1) * (this.height + 1);
for (w = _i = 0, _ref = this.width; 0 <= _ref ? _i <= _ref : _i >= _ref; w = 0 <= _ref ? ++_i : --_i) {
for (h = _j = 0, _ref1 = this.height; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; h = 0 <= _ref1 ? ++_j : --_j) {
directionLinks = {
north: h === 0,
east: h === this.width,
south: h === this.height,
west: w === 0
};
boundary = directionLinks.north || directionLinks.east || directionLinks.south || directionLinks.west ? true : false;
options = {
x: w,
y: h,
directionLinks: directionLinks,
boundary: boundary
};
room = new Room(options);
this[room.position()] = room;
}
}
}
return Rooms;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment