Skip to content

Instantly share code, notes, and snippets.

@RyanSnodgrass
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save RyanSnodgrass/9958053 to your computer and use it in GitHub Desktop.

Select an option

Save RyanSnodgrass/9958053 to your computer and use it in GitHub Desktop.
class Game
attr_reader :horse_graphic, :matz_track, :user_track, :command_explanation
def initialize
@my_horse = Horse.new(true)
@matz = Horse.new
@david = Horse.new
@horse_graphic = %{
(\\(\\_
_.0 o\\\\\\\\
("_ ))))
'---' (((( .=,
) )))___.-""-./=;\\\\\\
/ ((( \\ ))))
; | |//
/\\ | | ((
( \\ /__.-'\\ / )
\\` | / \\ \\ |
\\ \\ ; \\(\\(
|| || || ||
|| || || ||
/_< /_< /_</_<
This is your horse #{@my_horse.name}.
...He looks a little off.
}
puts @horse_graphic
@walking_graphic = %{
_(\\_/)
,((((^`\\
(((( (6 \\
,((((( , \\
,,,_ ,((((( /"._ ,`,
((((\\ ,... ,(((( / `-.-'
))) ;' `"'"'""(((( (
((( / ((( \\
)) | |
(( | . ' |
)) \ _ ' `t ,.')
( | y;- -,-""'"-.\\ \\/
) / ./ ) / `\\ \\
|./ ( ( / /'
|| \\ //'|
|| \\ _//'||
|| )) |_/ ||
\\_\\ |_/ \\ \\
Well, your horse only moved 1 space
}
@trotting_graphic = %{
) `-=--.
)/ ._.-'
_.-=-...-' /
\{\{| , |
\{\{\\ | \\ /_
)) \\,'---'\\___\\
\{ )/\\ \\ >\\
// >\ >\`-
`- ` - `-
Congrats, your horse moved 2 spaces
}
@galloping_graphic = %{
`';;;;;;;;;;;;;, `'. .--'-._';,
,;;';;''/ `;_ `';;;;' `'.
| . '-._ ,;;:' / '<a'.
| ; \\ '.,;;' | \\
\\ \\ | ;._. ,-'`.
/`'-`;.`'._ / / `-.\\_/
; .-._ .-' .' |
/ / '\\ .-'`. _/
_.-' / \\\\ '-._ /
(_/_.' __.) / `;--.._/ (
(_/__/ \\ `, \\
\\ | \\ \\
\\ \\ `\\ |
\\ \\ \\ \\
\\_\\ \\ \\
)-`\ \\_\\
`==` )-`\\
Sweet! your horse moves 3 spaces!
}
@zero_graphic = %{
./|,,/|
< o o)\\'
<\\ ( |
<\\\\ |\\ |
<\\\\\\ |(__)
<\\\\\\\\ |
THE HORSE GIVES YOU A BLANK LOOK
AND DOES NOTHING
}
draw_tracks
end
def draw_tracks
@user_track = ["|====|", @my_horse.name]
@matz_track = ["|====|", "matz"]
@david_track = ["|====|", "david"]
play_game
end
def play_game
puts "Before we race, here's how the commands work:"
@command_explanation = %{
'spur' to spur your horse
'snap' to snap the reigns
'hyah' to yell real loud
'whip' to whip the horse}
puts @command_explanation
puts "when you're ready, press any key and hit enter"
initializer = gets.chomp
countdown = 3
while countdown > 0
system 'clear'
puts "READY?"
puts countdown
sleep 1
countdown -= 1
end
puts "GO!"
print "\n #{@user_track*""}"
print "\n #{@matz_track*""}"
print "\n #{@david_track*""}"
until @user_track.flatten.length > 12 or @matz_track.flatten.length > 12 or @david_track.flatten.length > 12
run_command
@matz.bot_run.to_i
@david.bot_run.to_i
display_track
end
if @user_track.flatten.length > 12
puts "Game over. Did you win?"
return
# elsif @matz_track.flatten.length > 12
# puts "aww, matz won"
# return
# elsif @david_track.flatten.length > 12
# puts "shoot, david won"
# return
end
end
def display_track
system 'clear'
@user_track.insert(1, [@my_horse.gallops] * @progress)
@user_track.flatten!.reject! { |a| a.empty?}
@matz_track.insert(1, [@matz.gallops] * @matz.bot_progress)
@matz_track.flatten!
@david_track.insert(1, [@david.gallops] * @david.bot_progress)
@david_track.flatten!
print @user_track*""
print "\n"
print @matz_track*""
print "\n"
print @david_track*""
case @progress
when 1
puts @walking_graphic
when 2
puts @trotting_graphic
when 3
puts @galloping_graphic
else
puts @zero_graphic
end
end
def run_command
@base_roll = rand(10)
puts @command_explanation
#should display the meaning of the commands
#like spur is reliable but not fast
#while whip is hihgly effective but has a high chance for failure
@command = gets.chomp
case @command
when "spur"
@new_roll = @base_roll * (rand(6..10))
when "snap"
@new_roll = @base_roll * (rand(7..8))
when "hyah"
@new_roll = @base_roll * (rand(1..7))
when "whip"
@new_roll = @base_roll * (rand(6..9))
else
puts "Hurry up! Only enter 'kick' 'snap' hyah' or 'whip'!"
run_command
end
case @new_roll
when (1..30)
@progress = 1
when (31..60)
@progress = 2
when (60..90)
@progress = 3
else
@progress = 0
end
end
end
class Horse
attr_reader :name, :gallops, :bot_progress
def initialize(users_horse = false)
users_horse = users_horse
if users_horse == true
get_name
else
bot_run
end
@gallops = "-_ "
end
def get_name
puts "what is your horse's name?"
@name = gets.chomp
end
def bot_run
@bot_progress = rand(1..2)
end
end
Game.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment