Permalink
Browse files

simplify sample game using TextClient

  • Loading branch information...
1 parent 6d85c11 commit 5211eeffec6989a6f5312ba04cb5f86bb313976b @practicingruby committed Oct 26, 2011
Showing with 5 additions and 9 deletions.
  1. +5 −9 example/sample_game.rb
View
@@ -4,6 +4,8 @@
game = StackWars::Game.new(field)
moves = File.foreach("#{File.dirname(__FILE__)}/sample-moves.txt")
+client = StackWars::TextClient.new(game)
+
message = catch(:game_over) do
loop do
system "clear"
@@ -15,16 +17,10 @@
"#{game.opponent.color}: "+
"#{game.opponent.successful_invasions}"
- input = moves.next
- print "#{game.active_player.color}:#{game.active_player.reserves} > #{input}"
-
- md = input.match(/^ *(?<pos1>\d+ +\d+) *(?<pos2>\d+ +\d+)? *$/)
+ command = moves.next
+ print "#{game.active_player.color}:#{game.active_player.reserves} > #{command}"
+ client.play(command)
- if md[:pos2]
- game.play(md[:pos1].scan(/\d+/).map(&:to_i), md[:pos2].scan(/\d+/).map(&:to_i))
- else
- game.play(md[:pos1].scan(/\d+/).map(&:to_i))
- end
puts "hit enter to continue"
gets

0 comments on commit 5211eef

Please sign in to comment.