Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2012 10:59
Show Gist options
  • Save anonymous/4352111 to your computer and use it in GitHub Desktop.
Save anonymous/4352111 to your computer and use it in GitHub Desktop.
def loop
if @turn == 1
beginQuest
elsif @turn == 0
gameOver
elsif @turn%5 == 0
monsterTurn
else
humanTurn
end
end
def beginQuest
system "clear"
p "Greetings Traveler"
p "Welcome to Basic Quest"
p "Navigate by typing the direction you would like to go"
p "N for North, S for South, E for East, and W for West."
p "Good Luck, and beware the Grue..."
print "\n"
humanTurn
end
def humanTurn
if @human.isDead?
p "The Grue has eaten you"
@turn = 0
loop
else
p "You are in the " + @human.room.name + " room"
if @human.room.teleport and @human.getGems >= 5
p "The gems open a portal. You Win"
@turn = 0
loop
elsif @human.room.gem and @human.room == @monster.room
@human.addGem
p "You scare the Grue and he drops a Gem!", "You have " + @human.getGems.to_s + "/5"
@monster.move @world.nextRandRoom(@monster.room)
p "You found a gem!", "Take? (Y/N)"
ans = gets.chomp
if ans == "Y" or ans == "y"
@human.addGem
@human.room.gem = false
p "You added a gem!", "You have " + @human.getGems.to_s + "/5"
@turn += 1
loop
else
@human.room.gem = false
return humanTurn
end
elsif @human.room.gem
p "You found a gem!", "Take? (Y/N)"
ans = gets.chomp
if ans == "Y" or ans == "y"
@human.addGem
@human.room.gem = false
p "You added a gem!", "You have " + @human.getGems.to_s + "/5"
@turn += 1
loop
else
@human.room.gem = false
return humanTurn
end
elsif @human.room == @monster.room
@human.addGem
p "You scare the Grue and he drops a Gem!", "You have " + @human.getGems.to_s + "/5"
@monster.move @world.nextRandRoom(@monster.room)
return humanTurn
else
end
if @human.room.teleport
p "You notice a glowing dias in the center of this room"
end
playerMove
@turn += 1
loop
end
end
def monsterTurn
@monster.move @world.nextMonsterRoom(@monster.room, @human.room)
if @monster.room == @human.room
@human.setDead
end
@turn += 1
loop
end
def gameOver
p "Would you like to play again? (Y/N?)"
ans = gets.chomp
if ans == "Y" or ans == "y"
game = Game.new
game.start
else
abort('Thanks For Playing!')
end
end
def playerMove
# p "youroom", @human.room
# p "monster", @monster.room
p "Which way will you go?"
current = @human.room
direction = gets.chomp
if direction == "N" or direction == "n"
if current.north == {}
p "Can't go that way."
return playerMove
elsif current.north == @human.lastRoom
p "You can't go back"
return playerMove
else
@human.move @world.getRoom current.north
end
elsif direction == "S" or direction == "s"
if current.south == {}
p "Can't go that way."
return playerMove
elsif current.south == @human.lastRoom
p "You can't go back"
return playerMove
else
@human.move @world.getRoom current.south
end
elsif direction == "E" or direction == "e"
if current.east == {}
p "Can't go that way."
return playerMove
elsif current.east == @human.lastRoom
p "You can't go back"
return playerMove
else
@human.move @world.getRoom current.east
end
elsif direction == "W" or direction == "w"
if current.west == {}
p "Can't go that way."
return playerMove
elsif current.west == @human.lastRoom
p "You can't go back"
return playerMove
else
@human.move @world.getRoom current.west
end
else
return playerMove
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment