gameworks 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +4 -2
- data/lib/gameworks/game.rb +5 -1
- data/lib/gameworks/player.rb +9 -4
- data/lib/gameworks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8af89aede594bc27285d2a3c08d9e02257a6b184
|
4
|
+
data.tar.gz: d12c91d8de8d29b506f03c1450c0e68059a73854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc7293bf7d3b9db2bfc1b0876124d0bf96dcf6484a3b00d965ae0852179a1fb4dc8734d206b2361445eebc3ad0acc0c4a1030f58da3d50bc45cceb85b814e9c
|
7
|
+
data.tar.gz: 51bf5e753319b8726d6fd22d4838703d0466fc4126037eec5b5bb3c6fd2ed646dc46ac8823ca04d3975ebd402d33110e5222c368176d756b5678dafdedf08c3c
|
data/README
CHANGED
@@ -21,9 +21,11 @@ name of the new player. the game engine may extend this.
|
|
21
21
|
== Player (response)
|
22
22
|
|
23
23
|
{name: <string>,
|
24
|
-
score: <integer
|
24
|
+
score: <integer>,
|
25
|
+
disqualified: <boolean>}
|
25
26
|
|
26
|
-
name
|
27
|
+
name, current score, and disqualified status of the player. the game engine may
|
28
|
+
extend this.
|
27
29
|
|
28
30
|
== New Game (request)
|
29
31
|
|
data/lib/gameworks/game.rb
CHANGED
@@ -110,6 +110,8 @@ module Gameworks
|
|
110
110
|
active_players.each do |player|
|
111
111
|
token = generate_uuid
|
112
112
|
@turns[token] = player
|
113
|
+
# This may no longer be necessary, since we abort the players' fuses
|
114
|
+
# when they submit turns in #add_move.
|
113
115
|
@fuses[player].abort if @fuses[player]
|
114
116
|
@fuses[player] = Gameworks::Fuse.new(TURN_TIME_LIMIT) { disqualify(player) }
|
115
117
|
player.signal_turn(token)
|
@@ -121,6 +123,8 @@ module Gameworks
|
|
121
123
|
end
|
122
124
|
|
123
125
|
def add_move(payload, player)
|
126
|
+
@fuses[player].abort
|
127
|
+
|
124
128
|
move, error = build_move(payload, player)
|
125
129
|
return false, error unless move
|
126
130
|
legal, error = move_legal?(move, player)
|
@@ -145,7 +149,7 @@ module Gameworks
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def disqualify(player)
|
148
|
-
player.
|
152
|
+
player.disqualify!
|
149
153
|
update_observers
|
150
154
|
if @players.select { |p| !p.disqualified? }.size < 2
|
151
155
|
end_game
|
data/lib/gameworks/player.rb
CHANGED
@@ -4,6 +4,7 @@ module Gameworks
|
|
4
4
|
class Player
|
5
5
|
attr_reader :name
|
6
6
|
attr_accessor :score
|
7
|
+
attr_reader :disqualified
|
7
8
|
|
8
9
|
def initialize(payload={})
|
9
10
|
unless payload.is_a?(Hash) &&
|
@@ -15,6 +16,7 @@ module Gameworks
|
|
15
16
|
|
16
17
|
@name = payload['name']
|
17
18
|
@score = 0
|
19
|
+
@disqualified = false
|
18
20
|
|
19
21
|
# used for evented "block until it's my turn". the game will push a token
|
20
22
|
# on this queue when it's the player's turn, or will push a nil when the
|
@@ -26,8 +28,10 @@ module Gameworks
|
|
26
28
|
!@invalid
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
alias_method :disqualified?, :disqualified
|
32
|
+
|
33
|
+
def disqualify!
|
34
|
+
@disqualified = true
|
31
35
|
end
|
32
36
|
|
33
37
|
def signal_turn(token)
|
@@ -39,8 +43,9 @@ module Gameworks
|
|
39
43
|
end
|
40
44
|
|
41
45
|
def as_json(for_player=nil)
|
42
|
-
{ :name
|
43
|
-
:score
|
46
|
+
{ name: name,
|
47
|
+
score: score,
|
48
|
+
disqualified: disqualified }
|
44
49
|
end
|
45
50
|
|
46
51
|
def to_json(for_player=nil)
|
data/lib/gameworks/version.rb
CHANGED