Created
December 11, 2011 04:14
-
-
Save nthx/1458268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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