Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NPC
- attr_accessor :level, :name, :health, :mana, :strength, :dexterity, :agility, :intellect, :constitution, :wisdom, :charisma, :inventory
- def initialize(level, name, health, mana, strength, dexterity, agility, intellect, constitution, wisdom, charisma)
- @level = level
- @name = name
- @health = health
- @mana = mana
- @strength = strength
- @dexterity = dexterity
- @agility = agility
- @intellect = intellect
- @constitution = constitution
- @wisdom = wisdom
- @charisma = charisma
- @inventory = Inventory.new
- end
- end
- class Player < NPC
- attr_accessor :level, :name, :health, :mana, :strength, :dexterity, :agility, :intellect, :constitution, :wisdom, :charisma, :inventory, :skills
- def initialize(level, name, health, mana, strength, dexterity, agility, intellect, constitution, wisdom, charisma, skills=Skills.new)
- super(level, name, health, mana, strength, dexterity, agility, intellect, constitution, wisdom, charisma)
- @skills = skills
- end
- def survey
- # skill: attempt to survey current tile to reveal tile info
- end
- def harvest_metal
- # skill: attempt to harvest metal from current tile
- end
- def harvest_wood
- # skill: attempt to harvest wood from current tile
- end
- def harvest_animals
- # skill: attempt to harvest game animals from current tile
- end
- def harvest_foragables
- # skill: attempt to harvest foragables from current tile
- end
- end
- class Monster < NPC
- attr_accessor :level, :name, :health, :mana, :strength, :dexterity, :agility, :intellect, :constitution, :wisdom, :charisma, :inventory
- def initialize(level, name, health, mana, strength, dexterity, agility, intellect, constitution, wisdom, charisma)
- super(level, name, health, mana, strength, dexterity, agility, intellect, constitution, wisdom, charisma)
- end
- end
- class Item
- attr_accessor :item_level, :name, :rarity
- def initialize(item_level, name, rarity=:normal)
- @item_level = item_level
- @name = name
- @rarity = rarity
- end
- end
- class Weapon < Item
- attr_accessor :item_level, :name, :rarity, :weapon_damage, :weapon_speed
- def initialize(item_level, name, rarity=:normal, weapon_damage, weapon_speed)
- super(item_level, name, rarity)
- @weapon_damage = weapon_damage
- @weapon_speed = weapon_speed
- @bonus_health = 0
- @bonus_mana = 0
- if rarity == :magical
- @bonus_health = 10
- @bonus_mana = 10
- end
- end
- end
- class Armor < Item
- attr_accessor :item_level, :name, :rarity, :armor_value
- def initialize(item_level, name, rarity=:normal, armor_value)
- super(item_level, name, rarity)
- @armor_value = armor_value
- @bonus_health = 0
- @bonus_mana = 0
- if rarity == :magical
- @bonus_health = 10
- @bonus_mana = 10
- end
- myGame.init_weapons
- myGame.init_armor
- end
- end
- class Inventory
- def initialize
- @inventory = {}
- end
- def get_item(name)
- @inventory[name]
- end
- def add_item(name, item)
- @inventory[name] = item
- end
- def remove_item(name)
- @inventory.delete(name)
- end
- def to_s
- @inventory.inspect
- end
- end
- class Tile
- attr_accessor :type, :danger_level, :wood, :metal, :animals, :foraging
- def initialize(type)
- @type = type
- @danger_level = rand(100)
- if type == :prairie
- @wood = 0
- @metal = rand(10)
- @animals = rand(30)
- @foraging = rand(30)
- elsif type == :swamp
- @wood = rand(20)
- @metal = rand(10)
- @animals = rand(15)
- @foraging = rand(15)
- elsif type == :desert
- @wood = 0
- @metal = rand(20)
- @animals = rand(5)
- @foraging = rand(5)
- elsif type == :mountain
- @wood = rand(10)
- @metal = rand(30)
- @animals = rand(10)
- @foraging = rand(10)
- elsif type == :forest
- @wood = rand(30)
- @metal = rand(5)
- @animals = rand(15)
- @foraging = rand(15)
- else
- @wood = rand(20)
- @metal = rand(10)
- @animals = rand(20)
- @foraging = rand(25)
- end
- end
- def to_s
- puts "Tile type: #{type}"
- puts "Danger level: #{danger_level}"
- puts "Wood available: #{wood}"
- puts "Metal available: #{metal}"
- puts "Animals available: #{animals}"
- puts "Foraging available: #{foraging}"
- end
- end
- class GameMap
- attr_accessor :game_map, :tile_set, :player_col, :player_row
- def initialize
- @game_map = Array.new(5) { Array.new(5, 0) }
- @tile_set = [:Prairie, :Swamp, :Desert, :Mountain, :Forest, :Jungle]
- @player_row = 3
- @player_col = 3
- end
- def fill_game_map
- (0..4).each do |i|
- (0..4).each do |j|
- @game_map[i][j] = Tile.new(@tile_set[rand(5)])
- end
- end
- end
- def is_valid_move(direction)
- if direction == "n"
- if @player_row == 0
- return false
- else
- return true
- end
- elsif direction == "s"
- if @player_row == @game_map.size
- return false
- else
- return true
- end
- elsif direction == "e"
- if @player_col == @game_map.size
- return false
- else
- return true
- end
- elsif direction == "w"
- if @player_col == 0
- return false
- else
- return true
- end
- else
- # do nothing
- end
- end
- end
- class Skills
- attr_accessor :skills
- def initialize
- @skills = {"Piercing" => 0.0, "Slashing" => 0.0, "Mace Fighting" => 0.0, "Hand-to-Hand" => 0.0, "Mining" => 0.0,
- "Lumberjacking" => 0.0, "Hunting" => 0.0, "Foraging" => 0.0}
- end
- # all skills have a (100.0 - current skill value)% chance of increasing each time they're used
- def skill_up(skill, value)
- if rand(100.0) >= value
- @skills[skill] += 0.1
- puts "Your #{skill} skill has increased to #{@skills[skill]}!"
- else
- # no increase
- end
- end
- end
- class Game
- attr_accessor :player, :game_map, :weapons, :armor
- def initialize(player=Player.new(1, "Bloog", 100, 100, 10, 10, 10, 10, 10, 10, 10), game_map=GameMap.new)
- @player = player
- @game_map = game_map
- end
- def init_weapons
- @weapons = []
- @weapons.push(Weapon.new(1, "Longsword", 10, 30))
- @weapons.push(Weapon.new(1, "Broadsword", 12, 20))
- @weapons.push(Weapon.new(1, "Dagger", 6, 60))
- @weapons.push(Weapon.new(1, "Mace", 14, 15))
- @weapons.push(Weapon.new(1, "Axe", 16, 12))
- end
- def init_armor
- @armor = []
- @armor.push(Armor.new(1, "Leather Tunic", 4))
- @armor.push(Armor.new(1, "Leather Leggings", 4))
- @armor.push(Armor.new(1, "Leather Cap", 2))
- @armor.push(Armor.new(1, "Leather Gloves", 2))
- end
- def move(direction)
- if direction == "n"
- if game_map.is_valid_move("n") == true
- game_map.player_row -= 1
- else
- puts "That is not a valid move"
- end
- elsif direction == "s"
- if game_map.is_valid_move("s") == true
- game_map.player_row += 1
- else
- puts "That is not a valid move"
- end
- elsif direction == "e"
- if game_map.is_valid_move("e") == true
- game_map.player_col += 1
- else
- puts "That is not a valid move"
- end
- elsif direction == "w"
- if game_map.is_valid_move("w") == true
- game_map.player_col -= 1
- else
- puts "That is not a valid move"
- end
- else
- # do nothing
- end
- end
- def print_map
- (0..4).each do |i|
- (0..4).each do |j|
- if i == @game_map.player_row && j == @game_map.player_col
- print "x"
- else
- print @game_map.game_map[i][j]
- end
- end
- print "\n"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment