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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34f4cd0c5ccea108d3136d6b0cb7b91f8e2d0dd7
4
- data.tar.gz: 65ced3f4d6b49d967296459a19b790f258febbc3
3
+ metadata.gz: 219a487b560c910ee67860b3fdf7be871d17807e
4
+ data.tar.gz: d225ad1e81162c1bb94a4aa3bf360df4117031f2
5
5
  SHA512:
6
- metadata.gz: 72ee7622dbd0ea0dd69905ef6d93b731166caec6cceb29867f6d55d2242ddc67ec417b1f58499a5634a17f9d33d6ea797c8055da911d80dddd24139dea5a7f13
7
- data.tar.gz: 0bd05848f581f46e46f03b1a226fd2e07088e8c02dd263ef546a1973fe22c7e45ba4e014d0843429d8f6dbf359c404f07096ab603dfd92ad1cce80da19dcf5b6
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://d3s6mut3hikguw.cloudfront.net/github/FuriKuri/maze-server.png" />}[https://codeclimate.com/github/FuriKuri/maze-server]
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
 
@@ -9,12 +9,12 @@ class Maze
9
9
  @fields = MazeGenerator.new(width, height).create
10
10
  end
11
11
 
12
- def directions_of_way_fields(position)
12
+ def possible_directions(position)
13
13
  way_fields = []
14
- way_fields << :top if way_field? position, [0, -1]
15
- way_fields << :bottom if way_field? position, [0, +1]
16
- way_fields << :left if way_field? position, [-1, 0]
17
- way_fields << :right if way_field? position, [+1, 0]
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 way_field?(position, diff)
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)
@@ -14,7 +14,7 @@ class MazeGame
14
14
 
15
15
  def show_next_moves(client)
16
16
  player_position = @players[client].current_position
17
- @maze.directions_of_way_fields player_position
17
+ @maze.possible_directions player_position
18
18
  end
19
19
 
20
20
  def move(client, orientation)
@@ -36,18 +36,29 @@ class MazeServer
36
36
 
37
37
  def start_game
38
38
  until @maze_game.reached_player_exit?
39
- @players.each do |player_number, client|
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
@@ -1,3 +1,3 @@
1
1
  module Server
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -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] => :way,
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.directions_of_way_fields([2, 2]).should == [:top, :bottom, :right]
63
- @maze.directions_of_way_fields([1, 2]).should == [:right]
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler