-
-
Save anonymous/b63ee19ffbd493113f25 to your computer and use it in GitHub Desktop.
accepts valid input only on first attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Menu | |
@@Choices = ["New Game", "Load Game", "Options", "Help"] | |
@@VirtualChoice = [1,2,3,4,5,6,7,8,9,10,11,12] | |
def main_menu() | |
puts "Devil Soldiers .Beta" | |
choice = get_input(@@Choices) | |
case choice | |
when 1 | |
new_game() #add this | |
when 2 | |
load_game() #add this | |
when 3 | |
options_menu() #add this | |
when 4 | |
help_menu() #add this | |
else | |
puts "Invalid Command." | |
choice = get_input(@@Choices) | |
end | |
end | |
def get_input(options = []) | |
num = 0 | |
puts "Choose one:" | |
options.each do |option| | |
num += 1 | |
puts " #{num} - #{option}" | |
end | |
choice = gets.chomp.to_i | |
@@VirtualChoice.each do |option| | |
if choice == option | |
return choice | |
else | |
get_input(options) | |
end | |
end | |
end | |
def output(text) | |
puts text | |
end | |
end | |
module Entity | |
def attack() | |
return @stats["attack"] | |
end | |
def defend() | |
return @stats["armour"] | |
end | |
def item_stat() | |
@items.each do |key, value| | |
case key | |
when "Sword" | |
if value == 1 | |
@stats["attack"] += 50 | |
end | |
when "Armour" | |
if value == 1 | |
@stats["armour"] += 100 | |
end | |
when "Helmet" | |
if value == 1 | |
@stats["Helmet"] += 50 | |
end | |
end | |
end | |
end | |
def equip_item(item) | |
@items.each do |key, value| | |
if key == item | |
@items[item] = 1 | |
end | |
end | |
end | |
end | |
class Enemy | |
include Entity | |
def initialize() | |
@who = String.new | |
@level | |
@stats = { | |
"attack" => 80, | |
"armour" => 80 | |
} | |
@items = Hash.new | |
end | |
end | |
class Hero | |
include Entity | |
def initialize(who, type) | |
@who = who | |
@class = type | |
@stats = { | |
"attack" => 100, | |
"armour" => 100 | |
} | |
@items = { | |
"Sword" => 0, | |
"Armour" => 0, | |
"Helmet" => 0 | |
} | |
end | |
end | |
def new_game() | |
newClass = ["warrior", "mage", "warlock", "archer"] | |
puts "Choose a name:" | |
choiceName = gets.chomp.to_s | |
choiceClass = get_input(newClass) | |
player = Hero.new(choiceName, choiceClass) | |
enemy = Enemy.new() | |
end | |
include Menu | |
Menu.main_menu() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment