-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.coffee
57 lines (47 loc) · 1.49 KB
/
game.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
models = require './models.coffee'
class Game
constructor: (settings) ->
# Use default settings
settings = new Settings() if settings == undefined
@time = 1
@players = []
@field = new models.Field(settings.mapWidth, settings.mapHeight)
for deckPattern, i in settings.deckPatterns
deck = @prepareDeck(deckPattern)
player = new models.Player(deck, i, @field)
homeLocation = new models.Point((i%2) * 50, (i/2 % 2) * 50)
home = new models.Building(homeLocation, models.HomeTemplate, 0)
@constructBuilding(player, homeLocation, home)
@players.push(player)
start: ->
for p in @players
p.drawCards(models.Constants.INITIAL_CARD_COUNT)
getMapStr: ->
@field.str()
advance: ->
@time += 1
for p in @players
p.advance(this)
sortie: (player, fromBuilding, toBuilding, power) ->
return null if fromBuilding.power < power
fromBuilding.power -= power
army = new models.Army(fromBuilding, toBuilding, power)
player.armies.push(army)
army
constructBuilding: (player, location, building) ->
player.buildings.push(building)
@field.setObject(location, building)
prepareDeck: (name_num_pairs) ->
ret = []
for name, num of name_num_pairs
for i in [0 ... num]
ret.push models.AllCards[name]
ret
class Settings
constructor: ->
@mapWidth = 100
@mapHeight = 100
@maxTime = 10000
@deckPatterns = [[], [], [], []]
exports.Game = Game
exports.Settings = Settings