
-----------------------------------
Alexin
Mon Jun 29, 2009 8:04 pm

Please help me with game
-----------------------------------
Ok im making this game and i need help on several things.

First: When the program is asking how many the user wants to send, if its greater then the amount the user has then ask again until the user inputs an amount of men within the or the amount they have.

Second: Making the "opponent" send a random amount of men within their or the amount of men that they has.

A Thank you for those who help me.

-----------------------------------
Alexin
Mon Jun 29, 2009 8:06 pm

Re: Please help me with game
-----------------------------------
This is what i have so far:




var Fighters, Battleships, Destroyers, Marines, what, turn, turn4, turn3, turn2, attack, Fightershealth, Fightersatk, Battleshipshealth, Battleshipsatk, Destroyershealth, Destroyersatk, Marineshealth, Marinesatk, atk : int
var atkm, atkf, atkb, atkd, Fighters2, Battleships2, Destroyers2, Marines2, what2, turn5, turn8, turn7, turn6, attack2, Fightershealth2, Fightersatk2, Battleshipshealth2, Battleshipsatk2, Destroyershealth2, Destroyersatk2, Marineshealth2, Marinesatk2, fight, fight2, fight3, fight4 : int

put "You are the space Commander and you must build a fleet to destroy the Opposing  Fleet!"
delay (3000)
cls
put "Heres a small fleet to get you started."
delay (2000)
cls

Fighters := 10
Marines := 20
Battleships := 0
Destroyers := 0
Marineshealth := 2
Marinesatk := 1
Fightershealth := 5
Fightersatk := 3
Battleshipshealth := 8
Battleshipsatk := 5
Destroyershealth := 11
Destroyersatk := 7

Fighters2 := 30
Marines2 := 60
Battleships2 := 10
Destroyers2 := 5
Marineshealth2 := 2
Marinesatk2 := 1
Fightershealth2 := 5
Fightersatk2 := 3
Battleshipshealth2 := 8
Battleshipsatk2 := 5
Destroyershealth2 := 11
Destroyersatk2 := 7



turn := 1
turn4 := 1
turn3 := 1
turn2 := 1

turn5 := 1
turn8 := 1
turn7 := 1
turn6 := 1

loop
put "Turn ", turn

put "Marines = ", Marines
put "Fighters = ", Fighters
put "Battleships = ", Battleships
put "Destroyers = ", Destroyers
put skip
put skip
put "Commander what do you want to do?"

put "1 Train Marine (trains 1 marine and takes 1 turn)"
put "2 Train Fighter (trains 1 fighter and takes 2 turns)"
put "3 Train Battleship (trains 1 Battleship and takes 4 turns)"
put "4 Train Destroyer (trains 1 Destroyer and takes 6 turns)"
put "5 Attack the enemy fleet"
put "NOTE: Can only build one of each unit at any one time."

get what 
cls


if what = 1 then
randint (what2, 1, 5)
Marines := Marines + 1
turn := turn + 1
turn4 := turn4 + 1
turn3 := turn3 + 1
turn2 := turn2 + 1
end if

if what = 2 then
randint (what2, 1, 5)
turn := turn + 1
turn4 := turn4 + 1
turn3 := turn3 + 1
turn2 := -2
end if

if what = 3 then
randint (what2, 1, 5)
turn := turn + 1
turn4 := turn4 + 1
turn3 := -4
turn2 := turn2 + 1
end if

if what = 4 then
randint (what2, 1, 5)
turn := turn + 1 
turn4 := -6
turn3 := turn3 + 1
turn2 := turn2 + 1
end if

if turn4 = 0 then
Destroyers := Destroyers + 1
end if

if turn3 = 0 then
Battleships := Battleships + 1
end if

if turn2 = 0 then
Fighters := Fighters + 1
end if


if what = 5 then
put "Enemys Marines: ",Marines2 ,"."
put "Enemys Fighters: ",Fighters2 ,"."
put "Enemys Battleships: ",Battleships2 ,"."
put "Enemys Destroyers: ",Destroyers2 ,"."
put skip
put skip
put "Your Marines: ", Marines
put "Your Fighters: ", Fighters
put "Your Battleships: ", Battleships
put "your Destroyers: ", Destroyers
put "Are you sure? (1 for yes and 2 for no)"
get atk
if atk = 1 then
put "How many Marines would you like to send?"
get fight
if fight > Marines then

end if



put "How many Fighters would you like to send?"
get fight2
put "How many Battleships would you like to send?"
get fight3
put "How many Destroyers would you like to send?"
get fight4
Marineshealth := fight * 2
Fightershealth := fight2 * 5
Battleshipshealth := fight3 * 8
Destroyershealth := fight4 * 11
cls


end if
if atk = 2 then
cls
end if
end if



if what2 = 1 then
Marines2 := Marines2 + 1
turn5 := turn5 + 1
turn8 := turn8 + 1
turn7 := turn7 + 1
turn6 := turn6 + 1
end if

if what2 = 2 then
turn5 := turn5 + 1
turn8 := turn8 + 1
turn7 := turn7 + 1
turn6 := -1
end if

if what2 = 3 then
turn5 := turn5 + 1
turn8 := turn8 + 1
turn7 := -2
turn6 := turn6 + 1
end if

if what2 = 4 then
turn5 := turn5 + 1 
turn8 := -4
turn7 := turn7 + 1
turn6 := turn6 + 1
end if

if turn8 = 0 then
Destroyers2 := Destroyers2 + 1
end if

if turn7 = 0 then
Battleships2 := Battleships2 + 1
end if

if turn6 = 0 then
Fighters2 := Fighters2 + 1
end if


if what2 = 5 then
randint (atkm, 1, 30)
randint (atkf, 1, 30)
randint (atkb, 1, 30)
randint (atkd, 1, 30)
if atkm = 1 then
Marines2 := Marines2 - 2
Marinesatk2 := 2
Marineshealth2 := Marines2 * 2
end if
end if

end loop

-----------------------------------
TheGuardian001
Mon Jun 29, 2009 10:42 pm

Re: Please help me with game
-----------------------------------
For your first problem, just use a loop, and tell it to [tdoc]exit[/tdoc] when the number entered is valid.
[code]
loop
    say "how many troops?"
    get troops
    if troops  Marines then

end if

Can you figyre it out?

-----------------------------------
andrew.
Tue Jun 30, 2009 11:15 am

RE:Please help me with game
-----------------------------------
What was the problem? You can't just post your code and say can you figure it out and expect us to figure out the problem.

-----------------------------------
TheGuardian001
Tue Jun 30, 2009 1:46 pm

Re: Please help me with game
-----------------------------------
The only problem I see there is that you completely ignored the advice to put it into a loop.
And my code uses 