Skip to content

Instantly share code, notes, and snippets.

@nthx
Created January 24, 2012 00:16
Show Gist options
  • Select an option

  • Save nthx/1666812 to your computer and use it in GitHub Desktop.

Select an option

Save nthx/1666812 to your computer and use it in GitHub Desktop.
sample_scenario = ->
game = new BoardGame('Arkham')
tom = new Player('tomasz')
game.generate_example_move(tom)
alert game.calculate_bonus_for_player(tom)
class BoardGame
constructor: () ->
@board_cells = []
generate_example_move: (player) ->
#..
calculate_bonus_for_player: (player) =>
player_cell = player.current_cell()
"Your gained points is #{player_cell.get_points_bonus()}"
class Player
constructor: (@name) ->
current_cell: () =>
return @_example_board_cell()
_example_board_cell: () =>
cell = new BoardCell("37", "Dark Gate")
cell.define_card(new LoosingDueToLowWillAndMonster(
"Monster too good for you..",
"You loose few HP; encountered monster was so scary
you can't resist and run away"
))
cell
class BoardCell
constructor: (@name, @position) ->
@cards = []
define_card: (card) =>
@cards.push card
card
get_points_bonus: () =>
bonus = 0
MyMath.sum_of (card.point_bonus() for card in @cards)
class LoosingDueToLowWillAndMonster
constructor: (@name, @definition) ->
point_bonus: () =>
-7
class MyMath
@sum_of: (list) ->
list.reduce (t, s) -> t + s
sample_scenario()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment