Skip to content

Instantly share code, notes, and snippets.

start: ->
@loop()
@gameLoop = setInterval @loop, 100
loop: =>
switch @state
when Game.STATES.WAITING, Game.STATES.RESTARTING
@checkIfGameStarts()
when Game.STATES.COUNTDOWN
@countdown()
buffer = ->
buf = new Buffer(arguments.length ? 0)
buf.writeUInt8(arguments[index], index) for index in [0...arguments.length]
buf
module.exports = buffer
buffer = ->
buf = new Buffer(arguments.length ? 0)
for index in [0...arguments.length]
buf.writeUInt8(arguments[index], index)
buf
beer = buffer(0xF0, 0x9F, 0x8D, 0xBA)
process.stdout.write beer
console.log '\ndone!'
x = 3
y = 5
blankRowSpaces = (y-1) * process.stdout.columns
blankColSpaces = (x-1)
rows = ('' for i in [1..blankRowSpaces]).join(' ')
cols = ('' for i in [1..blankColSpaces]).join(' ')
process.write rows
process.write cols
process.stdin.on 'data', (data)->
console.log "data = #{data}"
process.stdin.setRawMode true
process.stdin.resume()
process.stdin.on 'data', @onData
createGame = (attributes, server)->
game = new Game(attributes)
game.addListener 'game', server.onGameChange
game.addListener 'stopped', server.onGameStopped
game.start()
game
class Server
constructor: (attributes={})->
@gameFactory = attributes.createGame ? createGame
class ClientGameSocket
constructor: (@socket, @game, @cycle)->
@socket.on 'movement', @onMovement
@socket.on 'disconnect', @onLeave
@socket.on 'leave', @onLeave
@socket.join @game.name
@socket.emit 'cycle', @cycle
onGameChange: (game)=>
@io.sockets.in(game.name).emit 'game', game.toJSON()
{
"name": "vimtronner",
"version": "0.0.9",
"description": "A multi-player Vim trainer.",
"main": "lib/vimtronner.js",
...,
"dependencies": {
"socket.io": "",
"socket.io-client": "",
"commander": "",