Skip to content

Commit

Permalink
Added room and enemies, close to making the game non-linear
Browse files Browse the repository at this point in the history
  • Loading branch information
benfb committed Jan 15, 2012
1 parent 5f9ef55 commit 2506c83
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 34 deletions.
53 changes: 30 additions & 23 deletions byticus.rb
Expand Up @@ -4,30 +4,37 @@
require 'god'
require 'actor'
require 'player'
require 'room'
require 'enemy'

@god = God.new()

# Creates the rooms
@old_lady = Enemy.new('Old Lady', 5, rand(11))
@goblin = Enemy.new('Goblin', 5, rand(11))
@wall = Room.new('Wall', nil, @dark_hallway, nil, nil, @goblin, 0)
@dark_hallway = Room.new('Dark Hallway', @wall, nil, nil, nil, @old_lady, 5)

puts 'Welcome to B Y T I C U S !'
puts 'What be your name, oh great adventurer?'

@player = Player.new('Ben', 100)
puts 'Greetings, ' + @player.name + '!'
$player = Player.new('Ben', 100, 5, @dark_hallway)
puts 'Greetings, ' + $player.name + '!'
puts 'You have ' + $player.denarii.to_s + ' denarii and ' + $player.health.to_s + ' health.'
@god.wait
puts 'The game will now begin!'
puts ''
@god.wait
puts 'You\'re walking down a dark hallway, when you see an ugly old lady. You decide to talk to her. You say:'
puts 'You\'re walking down a ' + @dark_hallway.name + '. There is an ' + @dark_hallway.npc.name.to_s + ' in the room. If you go to the north, you will climb a ' + @dark_hallway.n.name.to_s + '. You decide to talk to her. You say:'

@god.input
@god.check

puts @god.inv.to_s

@player.hurt
$player.hurt

puts 'The lady gets angry and kicks your shins. You lose ' + @player.wound.to_s + ' health!'
puts 'The lady gets angry and kicks your shins. You lose ' + $player.wound.to_s + ' health!'

puts 'You now have ' + @player.health.to_s + ' health remaining.'
puts 'You now have ' + $player.health.to_s + ' health remaining.'
puts ''
@god.wait
puts 'Ouch, you say. Type in fight to attack the lady!'
Expand All @@ -39,15 +46,15 @@
puts 'Time is money! Type in fight to attack'
@god.input
@god.check

puts @god.inv.to_s
end

if $input == 'fight'
puts 'You attack. The poor lady flees in terror.'
end

puts 'You see a wall. It looks like you can climb it. It may be a shortcut.'
$player.location = @wall

puts 'You see a wall. It looks like you can climb it. It may be a shortcut. There is a ' + $player.location.npc.name.to_s + ' in the room.'
@god.wait
puts 'There is also a pathway to the north.'
@god.wait
Expand All @@ -65,17 +72,17 @@
@chance = rand(6)/5

if $input == 'climb' and @chance <= 0.8
@player.hurt
puts 'You try to climb the wall, but it is too slippery. you fall and lose ' + @player.wound.to_s + ' health!'
$player.hurt
puts 'You try to climb the wall, but it is too slippery. you fall and lose ' + $player.wound.to_s + ' health!'
@god.wait
puts 'You now have ' + @player.health.to_s + ' health remaining.'
puts 'You now have ' + $player.health.to_s + ' health remaining.'
@god.wait
puts 'After your fall, you decide to either walk along the path or try to climb it again.'
else
puts 'You\'ve won a million dollars!'
end

@player.heal
$player.heal

until $input == 'walk north'
puts 'Type in walk north to walk along the path.'
Expand All @@ -84,9 +91,9 @@
end

if $input == 'walk north'
puts 'You walk along the path. You then come into a clearing, and see a lake. You wash yourself in it. It restores ' + @player.healing.to_s + ' health!'
puts 'You walk along the path. You then come into a clearing, and see a lake. You wash yourself in it. It restores ' + $player.healing.to_s + ' health!'
@god.wait
puts 'You now have ' + @player.health.to_s + ' health!'
puts 'You now have ' + $player.health.to_s + ' health!'
end
@god.wait
puts 'Suddenly, you hear footsteps and a low growl. Do you want to [flee], or [attack]?'
Expand All @@ -95,18 +102,18 @@
@god.check

if $input == 'flee'
@player.infected
puts 'While attempting to flee your leg gets bitten by an infected dog. You lose ' + @player.infected_hurting.to_s + ' health over the next five minutes and have to rest!'
$player.infected
puts 'While attempting to flee your leg gets bitten by an infected dog. You lose ' + $player.infected_hurting.to_s + ' health over the next five minutes and have to rest!'
sleep 10
puts 'You awaken with ' + @player.health.to_s + ' health remaining.'
puts 'You awaken with ' + $player.health.to_s + ' health remaining.'
end

if $input == 'attack'
@player.rest
puts 'You shoot an arrow towards the noise, killing a beast. You skin the beast and eat the meat, restoring ' + @player.rest_healing.to_s + ' health.'
$player.rest
puts 'You shoot an arrow towards the noise, killing a beast. You skin the beast and eat the meat, restoring ' + $player.rest_healing.to_s + ' health.'
$item = 'meat'
@god.add
puts 'You now have ' + @player.health.to_s + ' health remaining.'
puts 'You now have ' + $player.health.to_s + ' health remaining.'
@god.list
@god.input
@god.check
Expand Down
8 changes: 8 additions & 0 deletions enemy.rb
@@ -0,0 +1,8 @@
class Enemy
attr_accessor :name, :health, :strength
def initialize(name, health, strength)
@name = name
@health = health
@strength = strength
end
end
87 changes: 78 additions & 9 deletions god.rb
@@ -1,7 +1,7 @@
class God
# Defines global variables

attr_reader :inv
# Defines global variables

@@wait_time = 2

@@inv = []
Expand All @@ -23,17 +23,86 @@ def add
def list
puts @@inv.each {|i|} unless @@inv.empty?
if @@inv.empty?
puts 'You are carrying nothing!™'
puts 'You are carrying nothing. Whimp!'
end
end

def get
puts 'What do you want to get?'
$item = gets.chomp.downcase
add
end

def n
unless $player.location.n == nil
$player.location = $player.location.n
puts 'You are now in ' + $player.location.name + '.'
end
if $player.location.n == nil
puts 'You can\'t go that way.'
end
end

def s
unless $player.location.s == nil
$player.location = $player.location.s
puts 'You are now in ' + $player.location.name + '.'
end
if $player.location.s == nil
puts 'You can\'t go that way.'
end
end

def e
unless $player.location.e == nil
$player.location = $player.location.e
puts 'You are now in ' + $player.location.name + '.'
end
if $player.location.e == nil
puts 'You can\'t go that way.'
end
end

def w
unless $player.location.w == nil
$player.location = $player.location.w
puts 'You are now in ' + $player.location.name + '.'
end
if $player.location.w == nil
puts 'You can\'t go that way.'
end
end

def search
if $player.location.denarii > 0
$player.gain
puts 'You find ' + $player.location.denarii.to_s + ' denarii in the room. You now have ' + $player.denarii.to_s + ' denarii.'
$player.location.denarii = 0
else
puts 'There is no money in this room.'
end
end

def check
if $input == 'inv'
list
elsif $input == 'get'
puts 'What do you want to get?'
$item = gets.chomp.downcase
add
case $input
when 'inv'
list
when 'get'
get
add
when 'n'
n
when 's'
s
when 'e'
e
when 'w'
w
when 'search'
search
when 'buy'
buy
else puts 'That is not a valid command.'
end
end
end
15 changes: 13 additions & 2 deletions player.rb
@@ -1,10 +1,13 @@
class Player
# Defines instance variables
attr_reader :wound, :name, :health, :healing, :rest_healing, :infected_hurting
attr_reader :wound, :name, :health, :healing, :rest_healing, :infected_hurting, :denarii
attr_accessor :location

def initialize(name, health)
def initialize(name, health, denarii, location)
@name = name
@health = health
@denarii = denarii
@location = location
end

def name?
Expand All @@ -30,4 +33,12 @@ def rest
@rest_healing = rand(5)*3
@health = @health + @rest_healing
end

def gain
@denarii = @denarii + @location.denarii
end

def spend
@denarii = @denarii - @location.item.cost
end
end
13 changes: 13 additions & 0 deletions room.rb
@@ -0,0 +1,13 @@
class Room
attr_accessor :name, :n, :s, :e, :w, :npc, :denarii
def initialize(name, n, s, e, w, npc, denarii)
@name = name
@n = n
@s = s
@e = e
@w = w
@npc = npc
@denarii = denarii
end
end

0 comments on commit 2506c83

Please sign in to comment.