gameworks 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/{README → README.md} +112 -39
- data/lib/gameworks/notifier.rb +2 -1
- data/lib/gameworks/version.rb +1 -1
- metadata +4 -5
- data/build.sh +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01d5ecb9664001e09d3f01c6c77d9a12f9547576
|
4
|
+
data.tar.gz: 9f62c669b47d6259e171ed8ad064dc472dfb40fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 659f986391dbd3b06b6bec347bdca19594faa67449e09b330d7035694a62ecf0c1766400ef4e9e7bed5819a71a34a4277544f54d19c7e8f9cc05260204dc3050
|
7
|
+
data.tar.gz: 395bad2789fcbe1590770df68eeee522341bd12ecf2515b43ae1f3cc511f0a14d9d21fdcadb0ce686f1baec99196b60d51e8a2ed79b68687f20c77e012703c4a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gameworks (1.0
|
4
|
+
gameworks (2.1.0)
|
5
5
|
eventmachine (~> 1.0, >= 1.0.7)
|
6
6
|
json (~> 1.8, >= 1.8.3)
|
7
7
|
rake (~> 10.0)
|
@@ -12,7 +12,7 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
daemons (1.2.3)
|
14
14
|
diff-lcs (1.2.5)
|
15
|
-
eventmachine (1.0.
|
15
|
+
eventmachine (1.0.8)
|
16
16
|
json (1.8.3)
|
17
17
|
rack (1.6.4)
|
18
18
|
rake (10.4.2)
|
@@ -20,15 +20,15 @@ GEM
|
|
20
20
|
rspec-core (~> 3.3.0)
|
21
21
|
rspec-expectations (~> 3.3.0)
|
22
22
|
rspec-mocks (~> 3.3.0)
|
23
|
-
rspec-core (3.3.
|
23
|
+
rspec-core (3.3.2)
|
24
24
|
rspec-support (~> 3.3.0)
|
25
25
|
rspec-eventmachine (0.2.0)
|
26
26
|
eventmachine (>= 0.12.0)
|
27
27
|
rspec (>= 2.0, < 4.0)
|
28
|
-
rspec-expectations (3.3.
|
28
|
+
rspec-expectations (3.3.1)
|
29
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
30
|
rspec-support (~> 3.3.0)
|
31
|
-
rspec-mocks (3.3.
|
31
|
+
rspec-mocks (3.3.2)
|
32
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
33
|
rspec-support (~> 3.3.0)
|
34
34
|
rspec-support (3.3.0)
|
@@ -47,4 +47,4 @@ DEPENDENCIES
|
|
47
47
|
rspec-eventmachine (~> 0.2)
|
48
48
|
|
49
49
|
BUNDLED WITH
|
50
|
-
1.10.
|
50
|
+
1.10.6
|
data/{README → README.md}
RENAMED
@@ -1,48 +1,119 @@
|
|
1
|
-
|
1
|
+
# Gameworks
|
2
2
|
|
3
|
-
|
4
|
-
bundle install
|
5
|
-
bundle exec thin start
|
3
|
+
## About
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
Gameworks is a framework for creating turn-based games hosted by a server, that
|
6
|
+
can be interacted with via an API. At Instructure, we use it to create games
|
7
|
+
for the final round of our coding competition: Mebipenny.
|
9
8
|
|
10
|
-
|
11
|
-
All request and response payloads are serialized JSON data.
|
9
|
+
## Installation
|
12
10
|
|
13
|
-
|
11
|
+
Add `gem 'gameworks'` to your Gemfile, or install manually with `gem install gameworks`
|
14
12
|
|
15
|
-
|
13
|
+
## Usage
|
16
14
|
|
17
|
-
|
15
|
+
You will create classes to extend this engine, and then be able to interact
|
16
|
+
with the game via an API. Let's go over how all that works.
|
17
|
+
|
18
|
+
### Implementation
|
19
|
+
|
20
|
+
At minimum, you'll need a 3 files, that will look something like the following:
|
21
|
+
|
22
|
+
`config.ru`:
|
23
|
+
```ruby
|
24
|
+
#!ruby
|
25
|
+
|
26
|
+
require_relative 'your_game/server'
|
27
|
+
use Rack::CommonLogger
|
28
|
+
|
29
|
+
# Override Lint middleware to handle async callback (-1 http response)
|
30
|
+
module Rack
|
31
|
+
class Lint
|
32
|
+
def call(env = nil)
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
run YourGame::Server.new
|
39
|
+
```
|
40
|
+
|
41
|
+
`your_game/server.rb`:
|
42
|
+
```ruby
|
43
|
+
require 'gameworks'
|
44
|
+
require_relative 'game'
|
45
|
+
|
46
|
+
module YourGame
|
47
|
+
class Server < Gameworks::Server
|
48
|
+
def game_class
|
49
|
+
YourGame::Game
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
`your_game/game.rb`:
|
56
|
+
```ruby
|
57
|
+
require 'gameworks'
|
58
|
+
|
59
|
+
module YourGame
|
60
|
+
class Game < Gameworks::Game
|
61
|
+
# you're reached player capacity
|
62
|
+
def full?
|
63
|
+
end
|
64
|
+
|
65
|
+
# an array of players currently taking a turn
|
66
|
+
def active_players
|
67
|
+
end
|
68
|
+
|
69
|
+
# given a json payload, create a move object
|
70
|
+
def build_move(payload, player)
|
71
|
+
end
|
72
|
+
|
73
|
+
# given a move object, is it legal
|
74
|
+
def move_legal?(move, player)
|
75
|
+
end
|
18
76
|
|
19
|
-
|
77
|
+
# given a lecal move, apply it
|
78
|
+
def process_move(move, player)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
20
83
|
|
21
|
-
|
84
|
+
### API Data Types
|
22
85
|
|
86
|
+
The following are the default request/response data. You game implementation
|
87
|
+
may extend any/all of these.
|
88
|
+
|
89
|
+
#### New Player (request)
|
90
|
+
|
91
|
+
```
|
92
|
+
{name: <string>}
|
93
|
+
```
|
94
|
+
|
95
|
+
#### Player (response)
|
96
|
+
|
97
|
+
```
|
23
98
|
{name: <string>,
|
24
99
|
score: <integer>,
|
25
100
|
disqualified: <boolean>}
|
101
|
+
```
|
26
102
|
|
27
|
-
|
28
|
-
extend this.
|
29
|
-
|
30
|
-
== New Game (request)
|
103
|
+
#### New Game (request)
|
31
104
|
|
32
|
-
determined by
|
105
|
+
Nothing by default, determined by your game implementation.
|
33
106
|
|
34
|
-
|
107
|
+
#### Game (response)
|
35
108
|
|
109
|
+
```
|
36
110
|
{players: [<Player>*],
|
37
111
|
state: <Game State>}
|
112
|
+
```
|
38
113
|
|
39
114
|
players is the set of Players joined to the game.
|
40
115
|
|
41
|
-
|
42
|
-
|
43
|
-
the game engine may extend this.
|
44
|
-
|
45
|
-
== Game Delta (response)
|
116
|
+
#### Game Delta (response)
|
46
117
|
|
47
118
|
{players: [<Player>*],
|
48
119
|
state: <Game State>}
|
@@ -50,29 +121,27 @@ the game engine may extend this.
|
|
50
121
|
players is the set of Players whose scores have changed since the request
|
51
122
|
began.
|
52
123
|
|
53
|
-
|
54
|
-
|
55
|
-
the game engine may extend this.
|
56
|
-
|
57
|
-
== Game State (response)
|
124
|
+
#### Game State (response)
|
58
125
|
|
59
126
|
'initiating', 'in play', or 'completed'
|
60
127
|
|
61
128
|
See descriptions of game states below.
|
62
129
|
|
63
|
-
|
130
|
+
#### New Move (request)
|
64
131
|
|
65
|
-
determined by
|
132
|
+
Nothing by default, determined by your game implementation.
|
66
133
|
|
67
|
-
|
134
|
+
### Using the API
|
135
|
+
|
136
|
+
#### Starting a Game
|
68
137
|
|
69
138
|
To spawn a new game on the server, POST to / with a New Game object as payload.
|
70
139
|
You will receive a 201 Created response with the game's root path (henceforth
|
71
140
|
<game path>) in the Location HTTP response header.
|
72
141
|
|
73
|
-
|
142
|
+
#### Game States
|
74
143
|
|
75
|
-
|
144
|
+
##### Initiating
|
76
145
|
|
77
146
|
The game begins in this state. You join a game by POSTing to
|
78
147
|
<game path>/players with a Player object as payload.
|
@@ -87,7 +156,7 @@ longer be joined.
|
|
87
156
|
|
88
157
|
Once the game is full the game moves to the in play state.
|
89
158
|
|
90
|
-
|
159
|
+
##### In Play
|
91
160
|
|
92
161
|
In this state, players POST to <game path>/moves with Line objects as payload.
|
93
162
|
These requests must include an X-Turn-Token HTTP request header with the value
|
@@ -110,17 +179,17 @@ After a 200 OK response, the game may have moved to the completed state. This
|
|
110
179
|
state change will be indicated in the Game Delta object. Once the game is
|
111
180
|
completed, further moves are ignored with a 410 Gone response.
|
112
181
|
|
113
|
-
|
182
|
+
##### Completed
|
114
183
|
|
115
184
|
Play is complete. Game state can still be pulled, but no new POSTs are
|
116
185
|
accepted.
|
117
186
|
|
118
|
-
|
187
|
+
#### Idempotent View
|
119
188
|
|
120
189
|
At any point, the full game state can be requested with a GET request to
|
121
190
|
<game path>. You will receive an immediate 200 OK response with a Game object.
|
122
191
|
|
123
|
-
|
192
|
+
#### Observers (v1)
|
124
193
|
|
125
194
|
(Intended for use by game viewer, but may be used by others.)
|
126
195
|
|
@@ -142,7 +211,11 @@ replacing the first %s. For instance, a HTML comet technique:
|
|
142
211
|
|
143
212
|
{ "wrapper": "<script type='text/javascript'>myUpdater(%s);</script>\n" }
|
144
213
|
|
145
|
-
|
214
|
+
#### Observers (v2)
|
215
|
+
|
216
|
+
TODO: notes about push
|
217
|
+
|
218
|
+
#### Matchmaking
|
146
219
|
|
147
220
|
When you have a bot you'd like to try against others, but you don't want to set
|
148
221
|
up a game yourself and you don't care who your opponent is, you can connect
|
data/lib/gameworks/notifier.rb
CHANGED
@@ -11,11 +11,12 @@ module Gameworks
|
|
11
11
|
|
12
12
|
uri = URI(build_url(game))
|
13
13
|
req = Net::HTTP::Post.new(uri)
|
14
|
+
ssl = uri.scheme == 'https'
|
14
15
|
|
15
16
|
req.basic_auth(key, secret)
|
16
17
|
req.body = body
|
17
18
|
req["Content-Type"] = "application/json"
|
18
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl:
|
19
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: ssl) do |http|
|
19
20
|
http.request(req)
|
20
21
|
end
|
21
22
|
end
|
data/lib/gameworks/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gameworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Palmer
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-
|
15
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -150,11 +150,10 @@ extra_rdoc_files: []
|
|
150
150
|
files:
|
151
151
|
- Gemfile
|
152
152
|
- Gemfile.lock
|
153
|
-
- README
|
153
|
+
- README.md
|
154
154
|
- Rakefile
|
155
155
|
- bin/console
|
156
156
|
- bin/setup
|
157
|
-
- build.sh
|
158
157
|
- gameworks.gemspec
|
159
158
|
- lib/gameworks.rb
|
160
159
|
- lib/gameworks/fuse.rb
|
@@ -192,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
191
|
version: '0'
|
193
192
|
requirements: []
|
194
193
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.4.
|
194
|
+
rubygems_version: 2.4.7
|
196
195
|
signing_key:
|
197
196
|
specification_version: 4
|
198
197
|
summary: A game framework
|