Skip to content

Instantly share code, notes, and snippets.

@christiansmith
Created October 21, 2013 14:00
Show Gist options
  • Save christiansmith/7084333 to your computer and use it in GitHub Desktop.
Save christiansmith/7084333 to your computer and use it in GitHub Desktop.
sip = 1
slurp = 2
gulp = 3
class EarlyRiser
constructor: (@config) ->
@caffeinated = false
@cupsRequired = @config.cupsRequired
@cupsConsumed =
@cupLevel = 0
console.log "I need #{@cupsRequired} cups of coffee to get started"
getCoffee: =>
@cupLevel = 10
if @cupsConsumed is 0
console.log "The first cup is always the best"
else
console.log "This is cup number #{@cupsConsumed}"
drinkCoffee: (amount) =>
@getCoffee() unless @cupLevel > 0
if amount is gulp and @cupLevel > 5
console.log "Be careful, this coffee is hot!"
@cupLevel -= amount
if @cupLevel > 0
console.log "#{@cupLevel} sips remaining in this cup"
@drinkCoffee(Math.floor(Math.random()*4))
else if @cupsConsumed < @cupsRequired
console.log "The cup is 0% full. Time to get another cup"
@cupsConsumed += 1
@drinkCoffee(Math.floor(Math.random()*4))
else
@caffeinated = true
console.log "#{Math.floor @cupsConsumed} cups of coffee consumed"
console.log "Ready to write some code"
me = new EarlyRiser cupsRequired: 3
me.drinkCoffee(sip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment