forked from fmdkdd/sparkets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-ship.coffee
125 lines (99 loc) · 2.22 KB
/
test-ship.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
vows = require('vows')
assert = require('assert')
# Setup
require('./support/common')
Ship = require('../build/server/ship').Ship
# Mock-up game class.
class MockGame
constructor: () ->
@bullets = {}
@events =
push: () ->
@prefs =
mapSize:
w: 2000
h: 2000
ship:
states:
'spawned':
next: 'alive'
countdown: 1500
'alive':
next: 'exploding'
countdown: null
'exploding':
next: 'dead'
countdown: 1000
'dead':
next: 'alive'
countdown: null
hitRadius: 9
dirInc: 0.12
speed: 0.3
frictionDecay: 0.97
minFirepower: 1.3
firepowerInc: 0.1
maxFirepower: 3
cannonCooldown: 20
maxExploFrame: 50
enableGravity: false
bullet:
hitRadius: 2
EMP:
shipPush: -200
newGameObject: (fun) ->
fun(0)
collidesWithPlanet: (ship) ->
no
exports.suite = vows.describe('Server ship')
events = require('events')
exports.suite.addBatch
'ship spawning':
topic: () ->
game = new MockGame()
ship = new Ship(0, game, 0)
ship.on 'spawned', waiter(@callback)
ship.spawn()
return
'should send `spawned` event': (err, ship) ->
assert.isNull(err)
assert.isObject(ship)
assert.strictEqual(ship.type, 'ship')
'ship moving':
topic: () ->
game = new MockGame()
ship = new Ship(0, game, 0)
ship.on 'moved', waiter(@callback)
ship.move()
return
'should send `moved` event': (err, ship) ->
assert.isNull(err)
assert.isObject(ship)
assert.strictEqual(ship.type, 'ship')
'ship firing':
topic: () ->
game = new MockGame()
ship = new Ship(0, game, 0)
ship.on 'fired', waiter(@callback)
ship.spawn()
ship.nextState()
ship.fire()
return
'should send `fired` event': (err, ship, bullet) ->
assert.isNull(err)
assert.isObject(ship)
assert.strictEqual(ship.type, 'ship')
assert.isObject(bullet)
assert.strictEqual(bullet.type, 'bullet')
'ship exploding':
topic: () ->
game = new MockGame()
ship = new Ship(0, game, 0)
ship.on 'exploded', waiter(@callback)
ship.spawn()
ship.explode()
return
'should send `exploded` event': (err, ship) ->
assert.isNull(err)
assert.isObject(ship)
assert.strictEqual(ship.type, 'ship')