Hopefully its as easy as just typing in a command word.
Anyways, im basically writing a text based adventure game, and would love to have the ability to save the game, so i can pick up where i left off.
Any help would be much appreciated.
~L




Posted 29 May 2011 - 09:51 PM
Posted 29 May 2011 - 10:28 PM
Posted 31 May 2011 - 04:34 PM
This post has been edited by NotarySojac: 31 May 2011 - 04:36 PM
Posted 21 June 2011 - 02:50 AM
#######################################################################
puts ' '
puts '+--//Empire Rising\\\--+'
puts 'Press enter to advance'
gets
puts 'Welcome. Unfortunately at this time there is no save option, so if you have played before you will have to create a new character. Sorry for the inconvenience.'
gets
puts 'To start, you will need to tell me what you are.'
gets
puts 'To make your selection, type in the number corrosponding to the class and press enter to confirm your selection. Eg. You wish to play a Human. Which is "1. Human." Type in "1" and press Enter'
gets
#######################################################################
def yesno
puts '1. Yes'
puts '2. No'
end
######################################################################
def gender_selection
puts 'Please tell me if you are Male or Female.'
puts '1. Male'
puts '2. Female'
a1 = gets.chomp
if a1 == '1'
return 'Male'
else
if a1 == '2'
return 'Female'
else
puts 'Please type in "1" if you are Male.'
puts 'Or "2" if you are Female.'
puts 'Then press enter.'
puts ' '
return gender_selection
end
end
end
##################################################################
@gender = gender_selection
puts 'So you are '+@gender+'. Cool.'
gets
##################################################################
def race_selection
puts 'Please choose what race you are. Racial descriptions are given upon selection.'
puts '1. Human'
puts '2. Elf'
puts '3. Dwarf'
a1 = gets.chomp
if a1 == '1'
puts 'Humans are very versatile. They learn quick, but have a hard time mastering anything.'
puts 'It is easy to pick up a sword for the first time and get the hang of it within a couple of hours, but will never surpass the skill of an Elf.'
puts '--Humans gain +2 to Charisma and Intelligence, and gain an additional skill point at level 1. But take a -1 to Wisdom as they are a young race--'
b1 = 'Human'
else
if a1 == '2'
puts 'Elves are very graceful, but earthy at the same time. Most inhabit forests and other wild territory, and defend it with their lives.'
puts 'Surviving out in the wild has given them great perception as well as the skill to stay silent and stalk a target for miles.'
puts 'Other Elves have been raised in cities as slaves. These Elves have endured beatings and been forced to work long hours. They have lost the perception their woodland relatives have, but still retain grace in their movement, provided to them by their bone structure.'
puts '--Elves gain +2 to Dexterity and Wisdom. +1 to Intelligence. But -1 to Constitution due to their finer stature--'
b1 = 'Elf'
else
if a1 == '3'
puts 'Dwarves are sturdy, strongwilled defenders and stonecrafters. They have unbelievable endurance and strength.'
puts 'Most live in mountain keeps, deep underground, similar to cities called "A Ineth" ("A" pronounced "Ah").'
puts '--Dwarves recieve +2 to Constitution and Strength. +1 to Wisdom. But -1 to Dexterity due to their bulky bodies--'
b1 = 'Dwarf'
else
puts 'Invalid choice. Please try again'
puts ' '
return race_selection
end
end
end
puts ' '
puts 'Is this your race?'
yesno
c1 = gets.chomp
if c1 == '1' or c1 == ''
return b1
else
if c1 == '2'
return race_selection
else
puts 'I assume you meant "No" so I\'ll take you back to race selection.'
gets
return race_selection
end
end
end
###################################################
@playerrace = race_selection
puts 'Alright, so you are a '+@gender+' '+@playerrace+'.'
if @playerrace == 'Human'
@strength = 10
@dexterity = 10
@constitution = 10
@intelligence = 12
@wisdom = 9
@charisma = 12
@gold = 200
#+1 to skills
else
if @playerrace == 'Elf'
@strength = 10
@dexterity = 12
@constitution = 9
@intelligence = 11
@wisdom = 12
@charisma = 10
@gold = 200
else
if @playerrace == 'Dwarf'
@strength = 12
@dexterity = 9
@constitution = 12
@intelligence = 10
@wisdom = 11
@charisma = 10
@gold = 200
end
end
end
gets
################################################
def bad_answer
puts 'Sorry but the choice you made is invalid.'
gets
end
def stat_page
puts 'Strength ======== ['+@strength.to_s+']'
puts 'Dexterity ======= ['+@dexterity.to_s+']'
puts 'Constitution ==== ['+@constitution.to_s+']'
puts 'Intelligence ==== ['+@intelligence.to_s+']'
puts 'Wisdom ========== ['+@wisdom.to_s+']'
puts 'Charisma ======== ['+@charisma.to_s+']'
puts '======================='
puts 'Gold ============ ['+@gold.to_s+'g]'
gets
main_menu
end
def inventory_page
puts 'This is the inventory page'
gets
main_menu
end
def shop_page
puts 'This is the inventory page'
gets
main_menu
end
def arena_page
puts 'This is the arena page'
gets
main_menu
end
def main_menu
puts '=Main Menu='
puts '1. Stats'
puts '2. Inventory'
puts '3. Shop'
puts '4. Arena'
a1 = gets.chomp
if a1 == '1'
stat_page
else
if a1 == '2'
inventory_page
else
if a1 == '3'
shop_page
else
if a1 =='4'
arena_page
else
bad_answer
main_menu
end
end
end
end
end
main_menu
Posted 21 June 2011 - 01:04 PM
<Game>
<loadScreen>
<msg>+--//Empire Rising\\\--+</msg> <!-- we could have just called this tag "puts" instead of "msg" -->
<msg>Press enter to advance</msg>
<gets/>
<msg>Welcome. Unfortunately at this time there is no save option, so if you have played before you will have to create a new character. Sorry for the inconvenience.</msg>
<gets/>
<msg>To start, you will need to tell me what you are.</msg>
</loadScreen>
<prompt name='gender' type='numbers'>
<msg>Please tell me if you are Male or Female.</msg>
<option>Male</option>
<option>Male</option>
</prompt>
</Game>
<saves>
<Save name='What Name You Saved as' time='2011-6-1-20:11' index='0'>
<items>
<item id='001'>A Big Sword</item>
<item id='002'>A Dagger</item>
</items>
<gold>3000</gold>
<baseStats>
<str>21</str>
</baseStats>
<currentHP></currentHP>
<location id="001">Town</location>
<bossesDefeated> <!-- here's the interesting part, to track a games progress, you need to decide on milestones, such as dungeons defeated, bosses defeated, unique items collected, -->
<boss id='000'/>
<boss id='001'/> <!-- in this save, our hero has defeated the first two bosses/ arenas -->
</bossesDefeated>
</Save>
</Saves>
puts "this will read c:/script.xml"
puts
file_path = 'c:\\script.xml'
#
##### Ignore this section for now, you'll get it at the very bottom (I miss c#)
#
#
def new_game
puts "If you can call this using a text string, then you're getting pretty good."
end
def load_game
end
def settings_menu
end
#/
#
##### How to load an XML file, and operate on it from a very high level
#
#
require 'rexml/document'
xml_data = File.read(file_path) # simply read a file on the computer
#puts xml # you'll see the contents of the xml file here, it's just a string at this point
doc = REXML::document.new(xml_data) # this makes it into an REXML document,
# which lets you do awesome stuff with it, you'll see below
load_screen = doc.elements['Game/loadScreen'] # this creates an xmlDoc
# with just <loadscreen> as the elements...
#puts load_screen
#/
#
##### How to Read an XML, node by node
#
#
load_screen.elements.each do |thingy| # this will rifled down all elements in loadScreen, one by one
case thingy.name
when 'msg'
puts thingy.text
when 'gets'
gets
end
end
#/
#
#### How to get an elements attributes
#
#
doc.elements['Game/titleMenu'].elements.each do |element|
puts " The option's command was: " + element.attributes['cmd']
send(element.attributes['cmd']) # this calls a method BY NAME! As in, from a string!
end
#/
<prompt name='gender' type='numbers'>
<msg>Please tell me if you are Male or Female.</msg>
<option>Male</option>
<option>Male</option>
</prompt>
<storyLine>
<getVariable name='gender'>
<msg>Please tell me if you are Male or Female.</msg>
<msg>1. Male</msg>
<msg>2. Male</msg>
<gets name='gender'> </gets>
</getVariable>
<Chapter id="1" name="Escape Into The Fire Swamp">
<!-- BEGIN setting up game variables -->
<location id='0' name='The Fire Swamp'></location> <!-- ruby will place the location in a variable -->
<characters> <!-- ruby will set the characters in the party as it rolls over this -->
<char id=0 name='Westly'> <!-- but in ruby, you can change characters thereafter -->
<equiped> <!-- and later set them again in the xml, as it gets read -->
<head>
<item id=20>
<enchant id=0 name="Obsidian" def=1/> <!-- there's lots of ways to handle enchantments, decide before your start coding too much for them -->
</item>
</head>
</equiped>
<char id=1 name='Buttercup'>
</characters>
<inventory>
<item id=1/>
</inventory>
<!-- END setting up game variables -->
<!-- cutscene/ dialog -->
<line speaker='Westley (or ID)'> Ha! Your pig fiance is too late. A few more steps and
we'll be safe in the fire swamp.</line>
<battle>
<mobs>
<mob id=0>
</mobs>
</battle>
<!-- after the battle is fought and won, it should return you to main menue, with your location set to "id='0' name='The Fire Swamp'" as specified above-->
<chapterCompletionTriggers> <!-- after all of the criteria is met, it will jump you into the next chapter, showing cutscenes/Lines if needed -->
<bossKilled>
<location id='0' houseID='0'/> <!-- must go back to hometown, and into your house (not sure if you plan on doing houses in your game) -->
</chapterCompletionTriggers>
</Chapter>
</storyLine>
Posted 21 June 2011 - 01:49 PM
<Game> <!-- your ruby code should be set up to just riffle down this file, displaying messages as it rolls over them -->
<loadScreen>
<msg>+--//Empire Rising\\\--+</msg> <!-- we could have just called this tag "puts" instead of "msg" -->
<msg>Press enter to advance</msg>
<gets/>
<msg>Welcome. Unfortunately at this time there is no save option, so if you have played before you will have to create a new character. Sorry for the inconvenience.</msg>
<gets/>
<msg>To start, you will need to tell me what you are.</msg>
</loadScreen>
<titleMenu>
<option cmd='new_game'>New Game</option> <!-- Your ruby code should automatically present these options on the screen with automatic numbering -->
<option cmd='load_game'>Load Game</option> <!-- and do a 'gets' collecting the number, and converting it into the string, say, "New Game" -->
<option cmd='settings_menu'>Settings</option> <!-- Your code will then invoke the 'cmd' specified for that number (complicated, look into reflection) -->
</titleMenu>
<worldMenu>
<msg>=Main Menu=</msg>
<msg>1. Stats</msg>
<msg>2. Inventory</msg>
<msg>3. Shop</msg>
<msg>4. Arena</msg>
</worldMenu>
<gameOverScreen>
</gameOverScreen>
<victoryScreen>
</victoryScreen>
<characterCreation>
<getVariable name='gender'>
<msg>Please tell me if you are Male or Female.</msg>
<msg>1. Male</msg>
<msg>2. Male</msg>
<gets name='gender'> </gets>
</getVariable>
</characterCreation>
<storyLine>
<chapter id="1" name="Escape Into The Fire Swamp">
<!-- BEGIN setting up game variables -->
<location id='0' name='The Fire Swamp'></location> <!-- ruby will place the location in a variable -->
<characters> <!-- ruby will set the characters in the party as it rolls over this -->
<char id=0 name='Westly'> <!-- but in ruby, you can change characters thereafter -->
<equiped> <!-- and later set them again in the xml, as it gets read -->
<head>
<item id=20>
<enchant id=0 name="Obsidian" def=1/> <!-- there's lots of ways to handle enchantments, decide before your start coding too much for them -->
</item>
</head>
</equiped>
<char id=1 name='Buttercup'>
</characters>
<inventory>
<item id=1/>
</inventory>
<!-- END setting up game variables -->
<!-- cutscene/ dialog -->
<line speaker='Westley (or ID)'> Ha! Your pig fiance is too late. A few more steps and
we'll be safe in the fire swamp.</line>
<battle>
<mobs>
<mob id=0>
</mobs>
</battle>
<!-- after the battle is fought and won, it should return you to main menue, with your location set to "id='0' name='The Fire Swamp'" as specified above-->
<chapterCompletionTriggers> <!-- after all of the criteria is met, it will jump you into the next chapter, showing cutscenes/Lines if needed -->
<bossKilled>
<location id='0' houseID='0'/> <!-- must go back to hometown, and into your house (not sure if you plan on doing houses in your game) -->
</chapterCompletionTriggers>
</chapter>
</storyLine>
<characters>
<character name='Westly' id=0 str=20 vit=20 int=20 dex=20 spi=10/>
</characters>
<races>
</races>
<items>
<item id=0>
<item id=20 name='Black Bandana' def=3/>
</items>
<mobs> <!-- you gotta deal with this very mathematically or it will be a pain to maintain. It's all based on 't' or TTK as I sometime write "Time Till Kill", and also, dmg dealt to your heros -->
<mob id=0 name='Fire Flem' class='Level3_flem'>
<statmods fireResist='80' attack='fire' />
</mob>
<class name='Level3_flem' class='Level3'>
<statmods def='40' magResist='-40' />
</class>
<class name='Level3'>
<statmods def='3' magResist='3' str='3' hp='30'/>
</class>
</mobs>
</Game>
puts "this will read c:/script.xml"
puts "It's how I'd start the script engine"
puts
file_path = 'c:\\script.xml'
#
##### Ignore this section for now, you'll get it at the very bottom (I miss c#)
#
#
def new_game
puts "Begining New Game"
puts "please wait while I think of how to do this..."
puts
puts "Run Character Creation Code"
#character_creation @story_line.elements['storyLine/characterCreation']
puts "Load Chapter 1 from the @story_line"
end
def load_game
end
def settings_menu
end
# XML Data
@title_menu
@load_screen
@story_line
# Game Variables
# Characters[] >> Race, stats, equipment
#
def display_screen(xml)
20.times {puts}
bool_do_gets = false
choice_i = 0
xml.elements.each do |thingy| # this will rifled down all elements in loadScreen, one by one
case thingy.name
when 'msg'
puts thingy.text
# impliment gets here too?
when 'gets'
gets
when 'option'
choice_i += 1
puts choice_i.to_s + ". " + thingy.text
bool_do_gets = true
end
end
if bool_do_gets #all things that have <option> tag will do a gets, and make the function return their choice
choice = gets.chomp
return choice
end
end
def character_creation(xml)
#puts xml
# To impliment this, finish filling out the script.xml to include everythin relevant to your characterCreation at startup
=begin
Currently, it's just:
<characterCreation>
<getVariable name='gender'>
<msg>Please tell me if you are Male or Female.</msg>
<msg>1. Male</msg>
<msg>2. Male</msg>
<gets name='gender'> </gets>
</getVariable>
</characterCreation>
=end
#
# then load them all into the variable, I laid them out already
# But you might want to think about converting your game data into objects first
# I started creating the character object, but I gotta move on
end
def begin_chapter(xml)
xml.elements.each do |node|
case node.name
when 'getVariable' # you should move this to a different section, like <characterCreater> and run that first thing that happens when they choose newgame
#DO NOT IMPLIMENT HERE, I MADE A MISTAKE
when 'chapter'
# Do chapter cut scene for chapter's ID
end
end
end
#/
#
##### How to load an XML file, and operate on it from a very high level
#
#
require 'rexml/document'
xml_data = File.read(file_path) # simply read a file on the computer
#puts xml # you'll see the contents of the xml file here, it's just a string at this point
doc = REXML::document.new(xml_data) # this makes it into an REXML document,
# which lets you do awesome stuff with it, you'll see below
Game = doc.elements['Game'] # this creates an xmlDoc
# with just <loadscreen> as the elements...
# read the whole script.xml file here into discrete node variables to be used later
Game.elements.each do |node|
#puts node.name
case node.name
when 'loadScreen'
@load_screen = node
when 'titleMenu'
@title_menu = node
when 'storyLine'
@story_line = node
end
end
# setup the chapters here
display_screen(@load_screen)
their_choice = display_screen(@title_menu)
puts "they chose option number: " + their_choice
send(@title_menu.elements[their_choice.to_i].attributes['cmd'])
Process.exit
Posted 21 June 2011 - 03:15 PM
Posted 22 June 2011 - 10:51 AM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
