Permalink
Browse files

Merge branch 'master' of github.com:outworlder/Elite.js

Conflicts:
	public/scripts/analytics.js
	src/analytics.coffee
  • Loading branch information...
2 parents 458bc6c + 43c0d04 commit 4158fd8cb20b2b6b86e3839d5133c01bec064aad @outworlder committed Mar 21, 2012
Showing with 102 additions and 1 deletion.
  1. +1 −1 Procfile
  2. +2 −0 boot.js
  3. +61 −0 spec/commander_spec.coffee
  4. +38 −0 src/commander.coffee
  5. 0 {src → }/web.coffee
View
@@ -1 +1 @@
-web: node web.js
+web: node boot.js
View
@@ -0,0 +1,2 @@
+require('coffee-script');
+require('./web.coffee')
View
@@ -0,0 +1,61 @@
+Commander = require('../src/commander').Commander
+
+describe 'Commander', ->
+ beforeEach ->
+ @commander = new Commander()
+
+ describe "Initial state", ->
+ it "Should initialize a commander" ,->
+ expect(@commander).toBeDefined()
+
+ it "The initial commander name must be 'Jameson'", ->
+ expect(@commander.name).toEqual "Jameson"
+
+ it "The initial legal status must be 'Clean", ->
+ expect(@commander.legal_status).toEqual 'Clean'
+
+ it "The commander must start with 100.0 credits", ->
+ expect(@commander.credits).toEqual 100.0
+
+ it "New GalCop pilot licenses are issued only at 'Lave'", ->
+ expect(@commander.current_system).toEqual 'Lave'
+
+ it "A fresh pilot should have 0 kills", ->
+ expect(@commander.kills).toEqual 0
+
+ it "Commanders start out as 'Harmless'", ->
+ expect(@commander.elite_rating).toEqual "Harmless"
+
+ describe "Elite Rating", ->
+ it "Should award the rating 'Mostly Harmless' after 8 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..7]
+ expect(@commander.elite_rating).toEqual "Mostly Harmless"
+
+ it "Should award the rating 'Poor' after 16 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..15]
+ expect(@commander.elite_rating).toEqual "Poor"
+
+ it "Should award the rating 'Average' after 32 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..31]
+ expect(@commander.elite_rating).toEqual "Average"
+
+ it "Should award the rating 'Above Average' after 64 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..63]
+ expect(@commander.elite_rating).toEqual "Above Average"
+
+ it "Should award the rating 'Competent' after 128 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..127]
+ expect(@commander.elite_rating).toEqual "Competent"
+
+ it "Should award the rating 'Dangerous' after 512 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..511]
+ expect(@commander.elite_rating).toEqual "Dangerous"
+
+ it "Should award the rating 'Deadly' after 2560 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..2559]
+ expect(@commander.elite_rating).toEqual "Deadly"
+
+ it "Should award the rating 'Elite' after 6400 kills", ->
+ @commander.confirmed_kill(1) for kill in [0..6399]
+ expect(@commander.elite_rating).toEqual "Elite"
+
View
@@ -0,0 +1,38 @@
+class Commander
+ legal_status: 'Clean'
+ credits: 100.0
+ current_system: 'Lave'
+ kills: 0
+
+ right_on_commander: ->
+ console.log "Right on, Commander!"
+
+ # Tried to do clever bit manipulation, but became confusing
+ calc_elite_rating: ->
+ galcop_elite_ratings =
+ 0: "Harmless",
+ 8: "Mostly Harmless",
+ 16: "Poor",
+ 32: "Average",
+ 64: "Above Average",
+ 128: "Competent",
+ 512: "Dangerous",
+ 2560: "Deadly",
+ 6400: "Elite"
+
+ largest = 0
+ for i, rating of galcop_elite_ratings
+ largest = i if this.kills >= i
+ this.elite_rating = galcop_elite_ratings[largest]
+
+ confirmed_kill: (bounty) ->
+ this.kills = this.kills + 1
+ this.credits = this.credits + bounty
+ this.calc_elite_rating()
+
+ constructor: (@name = "Jameson") ->
+ this.calc_elite_rating()
+
+# As explained here: http://autotelicum.github.com/Smooth-CoffeeScript/interactive/interactive-coffeescript.html#object-oriented-programming
+(exports ? this).Commander = Commander
+
File renamed without changes.

0 comments on commit 4158fd8

Please sign in to comment.