maze-server 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/maze/game/maze.rb +7 -7
- data/lib/maze/game/maze_game.rb +1 -1
- data/lib/maze/server/maze_server.rb +19 -8
- data/lib/maze/server/version.rb +1 -1
- data/spec/maze/game/maze_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 219a487b560c910ee67860b3fdf7be871d17807e
|
4
|
+
data.tar.gz: d225ad1e81162c1bb94a4aa3bf360df4117031f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29752cebc50961b1f4bfb7393d99ac3242c60c3c8820b158b049d3c08ca555564925502f1e20120e3c677577438378a564ef1e7cad1e0b8030472083ac90addd
|
7
|
+
data.tar.gz: d66524a0e626b1f154f3818336cd4df5c6ab934328f0aada84666ff5c782869c9aeaf5171e8034cf5a109cba150c8da9ecf44372fe159754ccb5d1d04429845b
|
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
= \Maze Server
|
2
|
-
|
2
|
+
* {<img src="https://badge.fury.io/rb/maze-server.png" alt="Gem Version" />}[http://badge.fury.io/rb/maze-server]
|
3
3
|
* {<img src="https://drone.io/github.com/FuriKuri/maze-server/status.png"/>}[https://drone.io/github.com/FuriKuri/maze-server/latest]
|
4
4
|
* {<img src="https://gemnasium.com/FuriKuri/maze-server.png"/>}[https://gemnasium.com/FuriKuri/maze-server]
|
5
|
-
* {<img src="https://
|
5
|
+
* {<img src="https://codeclimate.com/github/FuriKuri/maze-server.png" />}[https://codeclimate.com/github/FuriKuri/maze-server]
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
data/lib/maze/game/maze.rb
CHANGED
@@ -9,12 +9,12 @@ class Maze
|
|
9
9
|
@fields = MazeGenerator.new(width, height).create
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def possible_directions(position)
|
13
13
|
way_fields = []
|
14
|
-
way_fields << :top if
|
15
|
-
way_fields << :bottom if
|
16
|
-
way_fields << :left if
|
17
|
-
way_fields << :right if
|
14
|
+
way_fields << :top if way_or_exit_field? position, [0, -1]
|
15
|
+
way_fields << :bottom if way_or_exit_field? position, [0, +1]
|
16
|
+
way_fields << :left if way_or_exit_field? position, [-1, 0]
|
17
|
+
way_fields << :right if way_or_exit_field? position, [+1, 0]
|
18
18
|
way_fields
|
19
19
|
end
|
20
20
|
|
@@ -42,9 +42,9 @@ class Maze
|
|
42
42
|
field_as_string
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def way_or_exit_field?(position, diff)
|
46
46
|
position = [position[0] + diff[0], position[1] + diff[1]]
|
47
|
-
@fields[position] == :way
|
47
|
+
@fields[position] == :way || @fields[position] == :exit
|
48
48
|
end
|
49
49
|
|
50
50
|
def map_field_element(position, player_number, player_position)
|
data/lib/maze/game/maze_game.rb
CHANGED
@@ -36,18 +36,29 @@ class MazeServer
|
|
36
36
|
|
37
37
|
def start_game
|
38
38
|
until @maze_game.reached_player_exit?
|
39
|
-
|
40
|
-
puts "Print maze for player #{client.name}"
|
41
|
-
puts @maze_game.maze(client)
|
42
|
-
next_moves = @maze_game.show_next_moves(client).map { |move| move.to_s }
|
43
|
-
client.socket.puts('{"operation" : "NEXT_MOVE", "messageId" : 2, "type": "REQUEST", "data" : ' + next_moves.to_s + '}')
|
44
|
-
move = JSON.parse(client.socket.gets.chop)['move'].to_sym
|
45
|
-
@maze_game.move(client, move)
|
46
|
-
end
|
39
|
+
do_moves
|
47
40
|
end
|
48
41
|
puts @maze_game.winning_players
|
42
|
+
confirm_clients
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def do_moves
|
47
|
+
@players.each do |player_number, client|
|
48
|
+
puts "Print maze for player #{client.name}"
|
49
|
+
puts @maze_game.maze(client)
|
50
|
+
next_moves = @maze_game.show_next_moves(client).map { |move| move.to_s }
|
51
|
+
client.socket.puts('{"operation" : "NEXT_MOVE", "messageId" : 2, "type": "REQUEST", "data" : ' + next_moves.to_s + '}')
|
52
|
+
move = JSON.parse(client.socket.gets.chop)['move'].to_sym
|
53
|
+
@maze_game.move(client, move)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def confirm_clients
|
49
58
|
@players.each do |player_number, client|
|
50
59
|
client.socket.puts('{"operation" : "WINNING_PLAYERS", "messageId" : 3, "type": "NOTIFICATION", "data" : ' + @maze_game.winning_players.to_s + '}')
|
60
|
+
client_msg = client.socket.gets.chop
|
61
|
+
puts "#{client.name} send message #{client_msg}"
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
data/lib/maze/server/version.rb
CHANGED
data/spec/maze/game/maze_spec.rb
CHANGED
@@ -52,15 +52,15 @@ describe Maze do
|
|
52
52
|
[2, 2] => :way,
|
53
53
|
[2, 3] => :way,
|
54
54
|
[3, 1] => :wall,
|
55
|
-
[3, 2] => :
|
55
|
+
[3, 2] => :exit,
|
56
56
|
[3, 3] => :wall
|
57
57
|
})
|
58
58
|
@maze = Maze.new(3, 3)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'show all directions for a way' do
|
62
|
-
@maze.
|
63
|
-
@maze.
|
62
|
+
@maze.possible_directions([2, 2]).should == [:top, :bottom, :right]
|
63
|
+
@maze.possible_directions([1, 2]).should == [:right]
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maze-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Pack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|