Rpg Shop...
Author |
Message |
Unicornzrcool
|
Posted: Thu Feb 05, 2009 5:27 pm Post subject: Rpg Shop... |
|
|
Ok, here's my question, in the code below I have a shop scenario and the option to buy a weapon and a shield. However, you are able to buy as many of one item as you want. I was wondering if there was some way to change the code so you can only buy 1 of the object. Any help would be greatly appreciated!! =]
Turing: |
var money : int
var damage : real
var armor : real
var option1 : real
var option2 : real
var buy1 : string
money := 50
damage := 0
armor := 0
put "congratulations, you have learned how to fight!"
put "now that you have some money, lets go buy some new equipment"
put " "
put "press any key to continue to the shop"
Input.Pause
cls
loop
put "welcome adventurer, please feel free to look around"
put " "
put "here are the items we currently have for sale"
put " "
put " "
put "1. Metal sword"
put "2. Wooden shield"
put " "
put "you currently have ", money, " gold!"
put "your weapon score is ", damage, "!"
put "your armor score is ", armor, "!"
put " "
put "please select an item to find out more"
get option1
if option1 = 1
then
cls
put "The Metal sword"
put " "
put "The Metal sword is a fine weapon for beginners and will do"
put "more damage than a Wooden sword."
put " "
put "Dmg + 15"
put "Costs 23 gold"
put " "
put "Would you like to buy this sword?"
get buy1
if buy1 = "y"
then
cls
if money > 23
then
put "a fine choice"
damage := damage + 15
money := money - 23
put " "
put "press any key to go back to the shop"
Input.Pause
cls
elsif money < 23
then
put "sorry you do not have enough money"
put " "
put "press any key to go back to the shop"
Input.Pause
cls
end if
elsif buy1 = "n" then
cls
end if
elsif option1 = 2
then
cls
put "The Wooden Shield"
put " "
put "The Wooden Shield will protect the user and provide"
put "more damage reduction."
put " "
put "Arm + 10"
put "Costs 20 gold"
put " "
put "Would you like to buy The Wooden Shield ?"
get buy1
if buy1 = "y"
then
cls
if money > 23
then
put "a fine choice"
armor := armor + 10
money := money - 20
put " "
put "press any key to go back to the shop"
Input.Pause
cls
elsif money < 23
then
put "sorry you do not have enough money"
put " "
put "press any key to go back to the shop"
Input.Pause
cls
end if
elsif buy1 = "n" then
cls
end if
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
yusong
|
Posted: Thu Feb 05, 2009 5:36 pm Post subject: RE:Rpg Shop... |
|
|
var metalsword : bool := false
if the player buys the sword, set it to true
if metalsword is true, then make it so they cant buy it. |
|
|
|
|
|
Unicornzrcool
|
Posted: Thu Feb 05, 2009 7:14 pm Post subject: Re: Rpg Shop... |
|
|
Ok, I followed your instructions and it stops the player from buying more than one sword. However, it skips the part where it is supposed to say "you have already bought this item". Here is the code again with the part you said to add:
Turing: |
if option1 = 1
then
cls
put "The Metal sword"
put " "
put "The Metal sword is a fine weapon for beginners and will do"
put "more damage than a Wooden sword."
put " "
put "Dmg + 15"
put "Costs 23 gold"
put " "
put "Would you like to buy this sword?"
get buy1
if buy1 = "y"
then
cls
if money > 23 then
if metalsword = false then
put "a fine choice"
damage := damage + 15
money := money - 23
metalsword := true
put " "
put "press any key to go back to the shop"
Input.Pause
cls
end if
elsif money < 23 then
put "sorry you do not have enough money"
put " "
put "press any key to go back to the shop"
Input.Pause
cls
elsif metalsword = true then
put "sorry but you have already bought this item"
put " "
put "press any key to go back to the shop"
Input.Pause
cls
end if
elsif buy1 = "n" then
cls
|
Is this even the correct way to put it in, and if so is there any way of making it so that it allows me to say that?
Thanks! |
|
|
|
|
|
Zren
|
Posted: Thu Feb 05, 2009 7:23 pm Post subject: Re: Rpg Shop... |
|
|
btw, what happens when you have exactly 23 gold :S |
|
|
|
|
|
Unicornzrcool
|
Posted: Thu Feb 05, 2009 10:45 pm Post subject: Re: Rpg Shop... |
|
|
Haha nice I didn't notice that before.
Thanks for pointing that out! |
|
|
|
|
|
TheGuardian001
|
Posted: Fri Feb 06, 2009 3:23 pm Post subject: Re: Rpg Shop... |
|
|
why is
code: |
elsif metalsword = true
%wheee....
end if
|
combined with the money checking if statement? think about how if/elsifs work.
Turing: |
if money > 23 then
%do some stuff.
/*-------
if we get to this point, the elsifs WILL NOT BE CHECKED.
-------*/
elsif money < 23 then %IF money is not > 23, we check this, otherwise it is ignored.
%More stuff done.
/*------
if we get to this point, any elsifs/else's below this point WILL NOT BE CHECKED
------*/
elsif metalsword = true then %IF money not > 23 and not whatever condition 2 was, check this, otherwise, ignore it.
%we wont get here UNLESS the user has Exactly $23 AND does not have a metal sword.
%tell user off for being an idiot and trying to buy 2 of the same item.
end if
|
it would make more sense if you combined the metalsword = true in to the same if then else statement as the metalsword = false. |
|
|
|
|
|
|
|