battle-on 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -3
- data/lib/battle_on/register_game.rb +1 -2
- data/lib/battle_on/send_attack.rb +7 -4
- data/lib/battle_on/version.rb +1 -1
- data/lib/battle_on.rb +4 -8
- data/spec/battle_on_spec.rb +25 -0
- data/spec/spec_helper_base.rb +1 -0
- metadata +8 -6
- /data/spec/{register_game_spec.rb → battle_on/register_game_spec.rb} +0 -0
- /data/spec/{send_attack_spec.rb → battle_on/send_attack_spec.rb} +0 -0
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# BattleOn
|
2
2
|
|
3
|
-
|
3
|
+
A little weapon to help fight Platform45's Battleship API
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,38 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install battle-on
|
18
18
|
|
19
|
+
Now you're ready to attack!
|
20
|
+
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
When you're in the middle of game of Battleship you want to focus on
|
24
|
+
your attack - we help you do that.
|
25
|
+
|
26
|
+
First, require 'battle-on'
|
27
|
+
|
28
|
+
require 'battle_on'
|
29
|
+
|
30
|
+
Now you're ready to begin the game. To start a new game, all that's
|
31
|
+
required is your name and email:
|
32
|
+
|
33
|
+
BattleOn.begin("Johnny Johnson", "Johnny@example.com")
|
34
|
+
|
35
|
+
This will return a hash with your game id and Platform45's first attack:
|
36
|
+
|
37
|
+
{:id => 101, :x => 3, :y => 8}
|
38
|
+
|
39
|
+
Once you've started a game, you can launch your attacks. It expects your
|
40
|
+
game id and the attack coordinates as two arguments passed to the attack
|
41
|
+
method:
|
42
|
+
|
43
|
+
BattleOn.attack(101, {:x => 1, :y => 7})
|
44
|
+
|
45
|
+
This will return a hash with the status of your last attack, whether it
|
46
|
+
was a hit or miss, and Platform45's next attack. Expect it to look like
|
47
|
+
this:
|
48
|
+
|
49
|
+
{:status => "hit", :x => 5, :y => 5}
|
50
|
+
|
22
51
|
|
23
52
|
## Contributing
|
24
53
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'JSON'
|
2
|
+
|
1
3
|
module BattleOn
|
2
4
|
|
3
5
|
#mandatory parameters:
|
@@ -29,9 +31,11 @@ module BattleOn
|
|
29
31
|
private
|
30
32
|
|
31
33
|
def attack
|
32
|
-
RestClient.post "http://battle.platform45.com/nuke",
|
33
|
-
|
34
|
-
|
34
|
+
RestClient.post "http://battle.platform45.com/nuke", attack_params
|
35
|
+
end
|
36
|
+
|
37
|
+
def attack_params
|
38
|
+
{ x: x_axis, y: y_axis, id: game_id}.to_json
|
35
39
|
end
|
36
40
|
|
37
41
|
def get_x(args)
|
@@ -41,5 +45,4 @@ module BattleOn
|
|
41
45
|
end
|
42
46
|
|
43
47
|
end
|
44
|
-
|
45
48
|
end
|
data/lib/battle_on/version.rb
CHANGED
data/lib/battle_on.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require "battle_on/version"
|
2
|
-
|
3
|
-
|
4
|
-
#module On
|
2
|
+
require "battle_on/register_game"
|
3
|
+
require "battle_on/send_attack"
|
5
4
|
|
6
5
|
module BattleOn
|
7
6
|
|
8
7
|
def self.begin(name, email)
|
9
|
-
RegisterGame.execute(name
|
8
|
+
RegisterGame.execute(name, email)
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.attack(game_id, attack={})
|
13
|
-
SendAttack.execute(game_id
|
12
|
+
SendAttack.execute(game_id, attack)
|
14
13
|
end
|
15
14
|
|
16
15
|
end
|
17
|
-
|
18
|
-
#end
|
19
|
-
#end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper_base'
|
2
|
+
|
3
|
+
describe BattleOn do
|
4
|
+
|
5
|
+
describe ".begin" do
|
6
|
+
|
7
|
+
it "delegates to RegisterGame" do
|
8
|
+
#expect
|
9
|
+
BattleOn::RegisterGame.should_receive(:execute).with("foo bar", "foo@bar.com")
|
10
|
+
#when
|
11
|
+
BattleOn.begin("foo bar", "foo@bar.com")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".attack" do
|
16
|
+
|
17
|
+
it "delegates to SendAttack" do
|
18
|
+
#expect
|
19
|
+
BattleOn::SendAttack.should_receive(:execute).with(101, {:x_axis => 3, :y_axis => 2})
|
20
|
+
#when
|
21
|
+
BattleOn.attack(101, {:x_axis => 3, :y_axis => 2})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper_base.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battle-on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -77,10 +77,11 @@ files:
|
|
77
77
|
- lib/battle_on/register_game.rb
|
78
78
|
- lib/battle_on/send_attack.rb
|
79
79
|
- lib/battle_on/version.rb
|
80
|
+
- spec/battle_on/register_game_spec.rb
|
81
|
+
- spec/battle_on/send_attack_spec.rb
|
82
|
+
- spec/battle_on_spec.rb
|
80
83
|
- spec/helpers/register_game_spec_helper.rb
|
81
84
|
- spec/helpers/send_attack_spec_helper.rb
|
82
|
-
- spec/register_game_spec.rb
|
83
|
-
- spec/send_attack_spec.rb
|
84
85
|
- spec/spec_helper_base.rb
|
85
86
|
homepage: ''
|
86
87
|
licenses: []
|
@@ -107,8 +108,9 @@ signing_key:
|
|
107
108
|
specification_version: 3
|
108
109
|
summary: A little weapon to help fight Platform45's Battleship API.
|
109
110
|
test_files:
|
111
|
+
- spec/battle_on/register_game_spec.rb
|
112
|
+
- spec/battle_on/send_attack_spec.rb
|
113
|
+
- spec/battle_on_spec.rb
|
110
114
|
- spec/helpers/register_game_spec_helper.rb
|
111
115
|
- spec/helpers/send_attack_spec_helper.rb
|
112
|
-
- spec/register_game_spec.rb
|
113
|
-
- spec/send_attack_spec.rb
|
114
116
|
- spec/spec_helper_base.rb
|
File without changes
|
File without changes
|