Skip to content

Instantly share code, notes, and snippets.

@nthx
Created December 11, 2011 04:14
Show Gist options
  • Save nthx/1458268 to your computer and use it in GitHub Desktop.
Save nthx/1458268 to your computer and use it in GitHub Desktop.
player = new Player()
player.assignGun (new Ak47())
console.log player.myGun().toStr()
class Player
constructor: (@name, @lives, @gun) ->
@guns = []
@currentGun = null
assignGun: (gun) =>
@guns.push gun
@currentGun = gun
myGun: =>
@currentGun
class Gun
constructor: (@name, @magazineCapacity, @accuracy, @power) ->
@ammo = @magazineCapacity
shoot: =>
@ammo -= 1
toStr: =>
"I am #{@name} gun, and have mag capacity of #{@magazineCapacity} and currently still holding #{@ammo} bullets"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment