-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_old.coffee
109 lines (77 loc) · 1.67 KB
/
game_old.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require './util'
class Building
constructor: (@name, @x, @y, @sight, @influence, @production) ->
@forces = []
enter: (playerIndex, force) ->
@forces[playerIndex] += force
getX: ->
@x
getY: ->
@y
str: ->
'o'
class Tile
constructor: (@building) ->
build: (building) ->
@building = building
str: ->
if @building == null
'.'
else
@building.str()
class Army
MOVE_SPEED: 1
constructor: (@playerIndex, @force, @source, @destination) ->
@elapsedTime = 0
@necessaryTime =
Math.sqrt( Math.pow(destination.getX() - source.getX())
+ Math.pow(destination.getY() - source.getY()) )
move: ->
elapsedTime++
if elapsedTime >= necessaryTime
@destination.enter(@playerIndex, @force)
false
else
true
class Map
constructor: (@width, @height) ->
@tiles = []
for x in [0 .. @width-1]
@tiles.push([])
for y in [0 .. @height-1]
@tiles[x].push(new Tile(null))
build: (x, y, building) ->
@tiles[x][y].build(building)
str: ->
ret = ''
for x in [0 .. @width - 1]
for y in [0 .. @height - 1]
ret += @tiles[x][y].str()
ret += '\n'
ret
class Hand
constructor: ->
@cards = []
class Deck
constructor: ->
@cards = []
shuffle: ->
util.shuffle @cards
class Player
constructor: ->
@hand = new Hand()
@deck = new Deck()
@soldiers = []
class Game
constructor: ->
console.log "new Game()"
@time = 1
@players = []
@map = new Map(5, 5)
for i in [0 .. 4]
@players.push(new Player())
getMapStr: ->
@map.str()
advance: ->
@time += 1
exports.Game = Game