i need help!please fix my battleship game!!!i dont know what to do!!
Author |
Message |
mhar_0525
|
Posted: Thu Nov 08, 2007 9:00 am Post subject: i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
code: |
%%%%%%Battleship Main Menu%%%%%%
procedure Main_Menu (start : int)
var PicBackGround : int
var game : string
PicBackGround := Pic.FileNew ("battleship.jpg") %background if the user is playing
PicBackGround := Pic.Scale (PicBackGround, maxx, maxy)
Pic.Draw (PicBackGround, 0, 0, picCopy)
Main_Menu (start)
Pic.Draw (PicBackGround, 0, 0, picCopy)
%%%%%%Instructions%%%%%%%
var Instructions : int
var reply : string (1)
put "Would you like to see instruction?(y/n)"
getch (reply)
if game = "y" then
put "Your mission is to find the ship of your opponent" %this is the instructions
put "You only have 10 tries to find the ship"
put "Goodluck"
end if
cls
procedure drawgrid ()
for r : 1 .. 10
for c : 1 .. 10
drawbox (100 + 36 * (c - 1), 8 + 36 * (r - 1), 100 + 36 * c, 8 + 36 * r, 5)
end for
end for
end drawgrid
var star, picback : int
var gam : string
picback := Pic.FileNew ("mhar.bmp")
picback := Pic.Scale (picback, maxx, maxy)
Pic.Draw (picback, 0, 0, picCopy)
drawgrid ()
var mx, my, gx, gy, sx, sy, XY, button : int
var d : real
randint (sx, 1, 10)
randint (sy, 1, 10)
var count : int
count := 0
loop
loop
gx := 0
gy := 0
Mouse.Where (mx, my, button)
if button = 1 then
drawfillmapleleaf (mx - 10, my - 10, mx + 10, my + 10, red)
gx := ceil ((mx - 100) / 36)
gy := ceil ((my - 8) / 36)
end if
delay (100)
exit when gx > 0 and gy > 0 and gx < 11 and gy < 11
end loop
if gx = sx and gy = sy then
cls
%%%%%winning or losing screen%%%%%%
var font3 : int
font3 := Font.New ("Ariel Black:36:italic")
assert font3 > 0
Font.Draw ("Congratulations!You Won ", 250, 350, font3, red) %if the player wins, this will be displayed
font3 := Font.New ("Tahoma:24:bold,italic")
quit
elsif count > 9 then
cls
var font4 : int
font4 := Font.New ("Ariel Black:36:italic")
assert font4 > 0
font4 := Font.New ("Tahoma:24:bold,italic")
var star1, picback1 : int
picback1 := Pic.FileNew ("face.jpg")
picback1 := Pic.Scale (picback1, maxx, maxy)
Pic.Draw (picback1, 0, 0, picCopy)
Font.Draw ("Loser!Better luck next time!! ", 80, 320, font4, green) %if the player lose, this will be displayed
quit
else
d := sqrt ((sx - gx) ** 2 + (sy - gy) ** 2)
locate (1, 1)
put d
count := count + 1
put count
end if
end loop
end Main_Menu |
Edited by Clayton: CODE TAGS!!!! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Thu Nov 08, 2007 9:11 am Post subject: RE:i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
Well the first thing worng with it that i see is that you have a procedure in another procedure. You can not have procedures in procedures in turing.
2ndly you seem to have a producure called Main_Menu warped around everything, this is not needed in turing and you do not even call it out side of it's self any way so it whould never be ran even if it did work.
If you simple remove the Main_Menu procudure and the call to it, the code at least seems to run (tho it stops at the images for me since i do not have them).
P.S. It seems odd to me that you could make so much code yet cleary have none of it work. I hope you are not copying off some one. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
mhar_0525
|
Posted: Thu Nov 08, 2007 9:49 am Post subject: RE:i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
i base it on the examples!i'm just new in turing!
thats why i cant figure it out!!
if i remove the main_menu then it will not work!! |
|
|
|
|
|
Zampano
|
Posted: Thu Nov 08, 2007 9:55 am Post subject: Re: i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
What Dan meant was to end the Main_Menu procedure before moving into the actual game
When I did that and took care of the extra 'end Main-Menu', the program worked until the pictures appeared, like Dan said. |
|
|
|
|
|
Dan
|
Posted: Thu Nov 08, 2007 10:01 am Post subject: Re: i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
Zampano @ 8th November 2007, 9:55 am wrote: What Dan meant was to end the Main_Menu procedure before moving into the actual game
When I did that and took care of the extra 'end Main-Menu', the program worked until the pictures appeared, like Dan said.
Well you can either restrucer Main_Menu or just remove it and it's call as it is just warped around the hole code.
@mhar_0525, it may be a bit advenced to jump right from knowing nothing about turing to using images. I sugest you read up about turing in the turing walk threw we have here at: http://compsci.ca/v3/viewtopic.php?t=8808 and make shure you understand each turotial and step.
As for your code, the easyest way to get it working is to remove the procedure Main_Menu(start:int) line, the end Main_Menu line where it ends the process and the call to it at Main_Menu(start). If you are geting an error at the pic line, either you named your files worng, put them in the wrong place or you realy did steal most of this code and in witch case i could not help even if i whonted to. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Tony
|
Posted: Thu Nov 08, 2007 2:15 pm Post subject: RE:i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
Most of this code is, very obviously, not original.
mhar_0525 -- even if you didn't copy it from someone in your class, it's easy to tell that you have copied parts from somewhere. Be prepared to explain "your" code, else the fact that it runs will have little meaning |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Clayton
|
Posted: Thu Nov 08, 2007 2:28 pm Post subject: RE:i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
Click! |
|
|
|
|
|
Clayton
|
Posted: Thu Nov 08, 2007 11:52 pm Post subject: Re: i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
Also note that if that code ever could run, it would suffer from a stack overflow error every single time because you keep calling Main_Menu within main menu, with no exit condition. Just something else to put out there. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
mhar_0525
|
Posted: Fri Nov 09, 2007 9:55 am Post subject: Re: i need help!please fix my battleship game!!!i dont know what to do!! |
|
|
yeah it works!
tnx a lot |
|
|
|
|
|
|
|