Computer Science Canada

Battle Procedure (Very Long)

Author:  Archi [ Mon Jun 23, 2003 9:33 pm ]
Post subject:  Battle Procedure (Very Long)

Here is the code that i'm using for my battle sequence. I'm curious if anyone of you can make it shorter but still do the same thing.

%Enemy Variables
var elvl : int := 0
var emdp : int
var etdmb : int
var enhp : int
var enhpl : int
var edef : int
var edeb : int
var enag : int
var edmb : int
var edmp : int
var ermdm : int
var estr : int
var eagi : int
var edm : int
% Our Variables
var lvl : int := 1
var hpl : int
var hp : int := 150
var rmdm : int
var str : int := 2
var defe : int := 2
var deb : int := 2
var agi : int := 2
var abi : int := 2
var rmab : int
var magi : int
var mp : int := 35
var mpl : int
%Experience
var xp : int := 0
var xpg : int
var tdmd : int := 0
var tdmr : int := 0
var dea : int
var kil : int
var xpn : array 2 .. 100 of real

for i : 2 .. 100
xpn (i) := 10 * (2 * i + 2) ** 3
end for
%Misc
var choice : string
var run : int
var nme : int
%Attacks/Abilities
var tdmp : int := 0
var att : array 1 .. 2 of string
var atb : array 1 .. 2 of int
var admb : array 1 .. 3 of int
var tdmb : int := 0
var dmb : int := 4
var dmdp : int
var drmul : int
var abt : array 1 .. 3 of string %Ability Name
var abb : array 1 .. 3 of int %Ability Bonus
var abd : array 1 .. 3 of int %Ability Drain
var ablv : array 1 .. 3 of int %Ability lvl
mpl := mp
%Attacks
att (1) := "Jab(j)"
att (2) := "DoubleSlash(ds)"
atb (1) := 2
atb (2) := 4
%Abilities
abt (1) := "Deflect(de)(-2)"
abd (1) := 2
ablv (1) := 2
abt (2) := "Fury(f)(-4)"
abb (2) := 10
abd (2) := 4
ablv (1) := 10
abt (3) := "Drain(dr)(-7)"
abb (3) := 0
abd (3) := 7
ablv (2) := 18

hpl := 100
randomize

procedure lvlup
for i : 2 .. 100
if lvl = i - 1 and xp >= xpn (i) then
elvl := lvl - 1
lvl := lvl + 1
str := str + 3
defe := defe + 3
hp := hp + (lvl * 20)
mp := mp + (lvl * 5)
agi := agi + 3
hpl := hp
put " "
put "You Have Leveled up to lvl, ", lvl
put "New Stats Are:"
put " "
put "HP: ", hp
put "MP: ", mp
put "Strength: ", str
put "Defense: ", defe
put "Agility: ", agi
put "You now need: ", xpn (i + 2) - xp, " exp for lvl, ", i + 1
delay (21000)
cls
exit
elsif lvl = i - 1 and xp < xpn (i) then
put "Current Exp is: ", xp, "/", xpn (i + 1)
put "You need, ", xpn (i + 1) - xp, " Exp for your lvl, ", i
delay (10000)
cls
exit
end if
end for
end lvlup

procedure battle
hpl := hp
randint (nme, 1, 4)
randint (enhp, 20 + lvl, 30 + lvl)
enhp := enhp + 70 * nme
enhpl := enhp
randint (estr, 1 + lvl, 3 + lvl)
randint (edef, 1 + lvl, 3 + lvl)
randint (edeb, 1 + lvl, 4 + lvl)
randint (edmb, 5 + lvl, 9 + lvl)
randint (eagi, 1 + lvl, 4 + lvl)
randint (enag, 1 + lvl, eagi + lvl)
randint (rmdm, str - 2, str + 2)
randint (magi, 1, agi)
if nme = 2 then
estr := estr + 2
edef := edef + 2
edeb := edeb + 2
eagi := eagi + 2
enag := enag + 2
elsif nme = 3 then
estr := estr + 3
edef := edef + 3
edeb := edeb + 3
eagi := eagi + 3
enag := enag + 3
elsif nme = 4 then
estr := estr + 4
edef := edef + 4
edeb := edeb + 4
eagi := eagi + 4
enag := enag + 4
end if
put " "
put "You've walked upon an area where there are, ", nme, " enemies. Do you wish to fight, or run?"
get choice
if choice = "run" then
randint (run, 1, 2)
if run = 1 then
put "You failed to run. They attacked you before you were ready."
hpl := hpl - (25 + nme)
put "They damaged you for, ", 25 + nme
else
put "You got away successfully"
end if
elsif choice = "fight" then
loop
tdmp := 0
edm := 0
randint (rmdm, str - 2, str + 3)
dmdp := (rmdm + tdmb) * tdmb - (edef + edeb) div enag
randint (ermdm, estr - 2, estr)
emdp := ((ermdm + edmb) * edmb - ((defe + deb) * defe)) div (magi + lvl + agi)
randint (rmab, abi - 1, abi + 2)
admb (2) := (abb (2) + rmab) * abi - (edef + edeb)
admb (3) := (abb (3) + rmab) * abi - (edef + edeb)
put " "
put "Attack(att), Defend(def), Ability(abi)"
put " "
get choice
if choice = "att" then
put "Choose your attack?"
put " "
put att (1)
put att (2)
put " "
get choice
if choice = "j" then
tdmb := dmb + atb (1)
if dmdp <= 0 then
put "You missed your enemy"
tdmp := tdmp + 0
else
put "You attacked the enemy and dealt, ", dmdp, " points of damage"
enhpl := enhpl - dmdp
tdmd := tdmd + dmdp
tdmp := tdmp + dmdp
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
end if
elsif choice = "ds" then
tdmb := dmb + atb (2)
if dmdp <= 0 then
put "You missed your enemy"
tdmp := tdmp + 0
else
put "You attacked the enemy and dealt, ", dmdp, " points of damage"
enhpl := enhpl - dmdp
tdmd := tdmd + dmdp
tdmp := tdmp + dmdp
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
end if
end if
elsif choice = "def" and hpl < hp then
put "You have defended and gained some health back"
edm := 1
put edm
tdmp := tdmp + 0
hpl := hpl + 10
if hpl > hp then
hpl := hp
end if
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif choice = "def" then
put "You have defended and recieved no damage"
edm := 1
tdmp := tdmp + 0
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif choice = "abi" and mpl > 0 then
put "Choose your ability"
put " "
put abt (1)
put abt (2)
put abt (3)
put " "
get choice
if choice = "de" and mpl > 2 then
put "You deflected your enemies attack but dealt no damage."
mpl := mpl - abd (1)
tdmp := tdmp + 0
put " "
put edm
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif choice = "de" and mpl <= 2 then
put "You don't have enough MP to use this ability"
tdmp := tdmp + 0
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif choice = "f" and mpl > 4 then
if admb (2) <= 0 then
admb (2) := admb (2) * -1
end if
put "You've summoned all of your rage and attacked your enemy(s) for, ", admb (2), " points"
mpl := mpl - abd (2)
enhpl := enhpl - admb (2)
tdmd := tdmd + admb (2)
tdmp := tdmp + admb (2)
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif choice = "dr" and mpl > 7 then
randint (drmul, 0, 3)
if drmul = 0 then
put "You've failed to drain any hp from your enemies."
mpl := mpl - abd (3)
tdmp := tdmp + 0
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif drmul = 1 then
if admb (3) <= 0 then
admb (3) := admb (3) * -1
end if
put "You've managed to drain, ", admb (3), " HP, and recieved it as your own."
tdmd := tdmd + admb (3)
tdmp := tdmp + admb (3)
enhpl := enhpl - admb (3)
mpl := mpl - abd (3)
hpl := hpl + admb (3)
if hpl > hp then
hpl := hp
end if
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif drmul = 2 then
if admb (3) <= 0 then
admb (3) := admb (3) * -1
end if
put "You've managed to drain, ", admb (3) * 2, " HP, and recieved it as your own."
tdmd := tdmd + admb (3) * 2
tdmp := tdmp + admb (3) * 2
enhpl := enhpl - admb (3) * 2
mpl := mpl - abd (3)
hpl := hpl + admb (3) * 2
if hpl > hp then
hpl := hp
end if
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
elsif drmul = 3 then
if admb (3) <= 0 then
admb (3) := admb (3) * -1
end if
put "You've managed to drain, ", admb (3) * 3, " HP, and recieved it as your own."
tdmd := tdmd + admb (3) * 3
tdmp := tdmp + admb (3) * 3
enhpl := enhpl - admb (3) * 3
mpl := mpl - abd (3)
hpl := hpl + admb (3) * 3
if hpl > hp then
hpl := hp
end if
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
end if
elsif choice = "dr" and mpl <= 7 then
put "You do not have enough MP to use this ability."
put " "
tdmp := tdmp + 0
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
end if
else
edm := 0
end if
%Enemy Attacking
if tdmp = 0 and edm = 1 then
put "Your enemies attack dealt no damage."
elsif tdmp = 0 and edm = 0 then
put "Your enemy decided to be nice and stabbed your back for, ", (nme + 4), " dmg"
put " "
hpl := hpl - (nme + 4)
put "Our hp is currently: ", hpl, "/", hp
put "Enemies hp is currently: ", enhpl, "/", enhp
elsif tdmp >= 1 and tdmp <= 25 and edm = 1 then
put "Your enemies attack dealt no damage."
elsif tdmp >= 1 and tdmp <= 25 and edm = 0 then
emdp := emdp
if emdp <= 0 then
emdp := emdp * -1
end if
put "The enemy attacked you casually for, ", emdp, " dmg."
put " "
hpl := hpl - emdp
put "Our hp is currently: ", hpl, "/", hp
put "Enemies hp is currently: ", enhpl, "/", enhp
elsif tdmp >= 25 and tdmp <= 50 and edm = 1 then
put "Your enemies attack dealt no damage."
elsif tdmp >= 25 and tdmp <= 50 and edm = 0 then
emdp := emdp + nme + 2
if emdp <= 0 then
emdp := emdp * -1
end if
put "The enemy attacked you harder this time for, ", emdp, " dmg"
put " "
hpl := hpl - emdp
put "Our hp is currently: ", hpl, "/", hp
put "Enemies hp is currently: ", enhpl, "/", enhp
elsif tdmp > 50 and edm = 1 then
put "Your enemies attack dealt no damage."
elsif tdmp > 50 and edm = 0 then
emdp := emdp + nme + 4
if emdp <= 0 then
emdp := emdp * -1
end if
put "The enemy attacked you full out for, ", emdp, " dmg"
hpl := hpl - emdp
put " "
put "Our hp is currently: ", hpl, "/", hp
put "Enemies hp is currently: ", enhpl, "/", enhp
end if
%Checking Death
if enhpl <= 0 and hpl > 0 then
dea := 1
kil := 1
xpg := (tdmd * elvl) - tdmr * elvl + (hpl + 1) * (dea + kil + nme)
if xpg < 0 then
xpg := xpg * -1
end if
xp := xp + xpg
delay (2000)
cls
put "Killed your enemy. Experience gained is: ", xpg
put "You dealt a total of, ", tdmd, " dmg to your enemy."
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
exit
elsif enhpl <= 0 and hpl <= 0 then
dea := 0
kil := 1
xpg := (tdmd * elvl) - tdmr * elvl + (hpl + 1) * (dea + kil + nme)
if xpg < 0 then
xpg := xpg * -1
end if
xp := xp + xpg
delay (2000)
cls
put "You killed your enemy but he killed you. Experience gained is: ", xpg
put "You dealt a total of, ", tdmd, " dmg to your enemy."
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
exit
elsif enhpl > 0 and hpl <= 0 then
dea := 0
kil := 0
xpg := (tdmd * lvl) - tdmr * elvl + (hpl + 1) * (dea + kil + nme)
if xpg < 0 then
xpg := xpg * -1
end if
xp := xp + xpg
delay (2000)
cls
put "Your enemy killed you. You gained, ", xpg, " Exp."
put "You dealt a total of, ", tdmd, " dmg to your enemy."
put " "
put "Enemies hp is currently: ", enhpl, "/", enhp
put "Our hp is currently: ", hpl, "/", hp
put "MP left: ", mpl, "/", mp
put " "
exit
end if
end loop
end if
end battle
loop
battle
lvlup
end loop

Author:  AsianSensation [ Mon Jun 23, 2003 9:47 pm ]
Post subject: 

ok..........many many many many suggestions here

first of all, attach the source, so it doesn't eat up bandwidth.

now get to the problem:

when you declare your stats variables:

...
var etdmb : int
var enhp : int
var enhpl : int
var edef : int
var edeb : int
var enag : int
etc...

you could just do this:
var enemystat :array 1.. 10(or however many u want) of int
then keep a text file of which one is which, like:

stat.txt
1) attack
2) defense
3) magic
etc...

doing this will let you declare all those variables in one line, and you can reference to it by checking the textfile which is which.

When you assign stats:

if you followed my approach, and declare an array for the variables, then you can setup a for loop for all those conditions:

if nme = 2 then
estr := estr + 2
edef := edef + 2
edeb := edeb + 2
eagi := eagi + 2
enag := enag + 2
elsif nme = 3 then
estr := estr + 3
edef := edef + 3
edeb := edeb + 3
etc...

instead, you could use:

for rep: 1..5
enemystat(rep)+=3
end for

Lastly: make all the dialogues procedures, so you dont have to type everything out again.

following those steps will make your game much much more compact.

Author:  Andy [ Tue Jun 24, 2003 10:36 am ]
Post subject: 

and meng hurry up and work on our game instead of wasting time here, we have only a little above 2 month left Evil or Very Mad


: