Please help me with game
Author |
Message |
Alexin
|
Posted: Mon Jun 29, 2009 8:04 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Mon Jun 29, 2009 8:06 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Mon Jun 29, 2009 10:42 pm Post subject: Re: Please help me with game |
|
|
For your first problem, just use a loop, and tell it to exit when the number entered is valid.
code: |
loop
say "how many troops?"
get troops
if troops <= max then
exit
else
put "too many."
end if
end loop
|
For the second problem, just use Rand.Int(1,Number_of_troops). |
|
|
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Tue Jun 30, 2009 10:42 am Post subject: RE:Please help me with game |
|
|
That wont work i just tried irt and there was a problem
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
Can you figyre it out? |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Tue Jun 30, 2009 11:15 am Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Tue Jun 30, 2009 1:46 pm Post subject: 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 <=, but you should be able to figure that one out. |
|
|
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Tue Jun 30, 2009 1:56 pm Post subject: RE:Please help me with game |
|
|
I did but it didnt work because it started messing up ifs farther down in the code saying that it expected end loop and the whole code is in a loop. |
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Tue Jun 30, 2009 2:58 pm Post subject: Re: Please help me with game |
|
|
You have to end your loops... always...
if your entire code is in a loop, you clearly know how a loop works. just take the part you want to repeat and loop it.
code: |
loop
%Main game code goes here
%more code...
%even more code...
%Oh! we're checking how many people the player wants to send here!
%we want to repeat this, so we'd better use a
loop
get NumTroops %hot many troops to send
if NumTroops <= MaxTroops then %its a valid number!
exit %get out of the loop
end if
end loop %The loop is over! so we use end loop! because that's what you do with loops, you end them!
%Rest of code
%continuing...
%for a while....
end loop %program over, end loop.
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Tue Jun 30, 2009 5:23 pm Post subject: RE:Please help me with game |
|
|
i got the first one to work but not the second one |
|
|
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Tue Jun 30, 2009 7:14 pm Post subject: RE:Please help me with game |
|
|
When i do the second one it says :
Expression is not a procedure and hence cannot be called |
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Tue Jun 30, 2009 8:14 pm Post subject: Re: Please help me with game |
|
|
Rand.Int is a function, which means it returns a value. you have to tell the computer where to put this value.
You can assign it to a variable
Turing: |
var X : int := Rand.Int(1,5)
|
you can output it to the screen
Turing: |
put Rand.Int(1,5)
|
or you can even pass it as a value to another function/procedure.
Turing: |
var x : int
x := Rand.Int(Rand.Int(1,5), Rand.Int(10,20))
|
as long as you do something with the value it gives back. |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Tue Jun 30, 2009 8:15 pm Post subject: RE:Please help me with game |
|
|
Whatever you're calling is a function. That means that it returns a value and you have to do something with that value.
Example:
Turing: |
% My function. It returns a string.
function myFunction : string
result "Hello"
end myFunction
var myString : string
% I can take the string from myFunction and put it in myString
myString := myFunction
% I can print the result of myFunction right to the screen
put myFunction
% I can compare the string returned by myFunction to a string
if myFunction = myString then
put "A function can act as a variable because it returns a value."
put "Since this happens, I can compare the string myFunction returns with an actual string."
end if
% I can't just call myFunction because the returned value has no where to go. This will give an error.
myFunction
|
|
|
|
|
|
![](images/spacer.gif) |
Alexin
|
Posted: Wed Jul 01, 2009 10:54 am Post subject: RE:Please help me with game |
|
|
ok ill try it later |
|
|
|
|
![](images/spacer.gif) |
|
|