Permalink
Browse files

add round prompt

  • Loading branch information...
1 parent 719b69b commit 542ea8b3e4ea668665eec4edc0b861e3f7f41df9 @jackiekircher committed Nov 4, 2011
Showing with 56 additions and 2 deletions.
  1. +56 −2 lib/gorillas/gorillas_game.rb
View
58 lib/gorillas/gorillas_game.rb
@@ -16,16 +16,41 @@ def initialize(buffer=VIM::Buffer.current)
end
def start_game
+ display_splash
+ wait_for_input("any")
display_menu
end
- def display_menu
+ def display_splash
clear_screen
print_to_screen((@width/2)-6, (@height/2)-2, "( G\u00f6rillas )")
- print_to_screen((@width/2)-7, (@height/2)+2, "press space to")
+ print_to_screen((@width/2)-8, (@height/2)+2, "press any key to")
print_to_screen((@width/2)-5, (@height/2)+3, "start game")
end
+ def display_menu
+ clear_screen
+
+ @rounds = prompt("Number of rounds? ").to_i
+ @rounds = 3 if @rounds < 1
+
+ round_str = "First to #{@rounds} "
+ round_offset = (@width/2)-10
+
+ round_offset += print_to_screen(round_offset, @height/2, round_str)
+
+ wait 500
+ round_offset += print_to_screen(round_offset, @height/2, ".")
+ wait 500
+ round_offset += print_to_screen(round_offset, @height/2, ".")
+ wait 500
+ round_offset += print_to_screen(round_offset, @height/2, ". ")
+ wait 800
+ print_to_screen(round_offset, @height/2,"Fight!")
+
+ wait 1000
+ end
+
private
@@ -36,6 +61,9 @@ def print_to_screen(x, y, str)
new_line = @buffer[y]
new_line[x, str.length] = str
@buffer[y] = new_line
+ redraw
+
+ return str.length
end
def clear_screen
@@ -46,4 +74,30 @@ def clear_screen
@buffer.append(line, blank_line)
end
end
+
+ def wait_for_input(args)
+ valid_input = args.split(",")
+ if valid_input.first == "any"
+ VIM::evaluate("getchar()")
+ else
+ while true
+ break if valid_input.include?(VIM::evaluate("getchar()"))
+ end
+ end
+
+ return
+ end
+
+ def redraw
+ VIM::command("redraw")
+ end
+
+ def prompt(question)
+ VIM::message('prompting...')
+ return VIM::evaluate("input('#{question}')")
+ end
+
+ def wait(time)
+ VIM::command("sleep #{time}m")
+ end
end

0 comments on commit 542ea8b

Please sign in to comment.