Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 hi....i need some help w/ my battleship game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
belldandy_angel




PostPosted: Tue Jun 01, 2004 5:35 pm   Post subject: hi....i need some help w/ my battleship game

hi..can someone help me w/ my battleship game????

if u can...thanx a bunch!!!! love u!!! hehehe

this is wut i have so far...



setscreen ("graphics:500;350")

%%%%%%%%%%%%%%%%%%%%
%declare variables %
%%%%%%%%%%%%%%%%%%%%
var font1, font2, font3, font4, font5 : int
var pti, ptf : int
var picID : int
var mousex, mousey, button : int := 0

%%%%%%%%%%%%%%
%subprograms %
%%%%%%%%%%%%%%

%procedure for the introduction
proc intro

drawfillbox (0, 0, 250, 350, 37)
drawfillbox (500, 0, 250, 360, 240)
font1 := Font.New ("eddie:50:bold")
font2 := Font.New ("times new roman:13")
font3 := Font.New ("comic sans ms :8")
font4 := Font.New ("eddie:40")
font5 := Font.New ("times new roman:24:bold")

Font.Draw ("BATTL", 30, 300, font1, 240)
Font.Draw ("ESHIP", 280, 300, font1, 37)
Font.Draw ("game", 180, 220, font4, 81)
Font.Draw ("By: Annie Ng", 414, 15, font3, 101)
Font.Draw ("Krystal Chiu", 430, 5, font3, 101)
Font.Draw ("PLAYER", 74, 130, font2, 101)
Font.Draw ("V S", 223, 60, font5, 101)
Font.Draw ("CPU", 384, 130, font2, 101)

picID := Pic.FileNew ("ba.bmp")
Pic.Draw (picID, 60, 30, picCopy)
Pic.Free (picID)
picID := Pic.FileNew ("ba1.bmp")
Pic.Draw (picID, 360, 30, picCopy)
Pic.Free (picID)
delay (700)
cls
end intro

proc grid
drawbox (0, 0, 255, 299, 42)

drawbox (0, 0, 25, 299, 42)
drawbox (0, 0, 50, 299, 42)
drawbox (0, 0, 75, 299, 42)
drawbox (0, 0, 100, 299, 42)
drawbox (0, 0, 125, 299, 42)
drawbox (0, 0, 150, 299, 42)
drawbox (0, 0, 175, 299, 42)
drawbox (0, 0, 200, 299, 42)
drawbox (0, 0, 225, 299, 42)
drawbox (253, 25, 2, 2, 42)
drawbox (253, 50, 2, 2, 42)
drawbox (253, 75, 2, 2, 42)
drawbox (253, 100, 2, 2, 42)
drawbox (253, 125, 2, 2, 42)
drawbox (253, 150, 2, 2, 42)
drawbox (253, 175, 2, 2, 42)
drawbox (253, 200, 2, 2, 42)
drawbox (253, 225, 2, 2, 42)
drawbox (253, 250, 2, 2, 42)
drawbox (253, 275, 2, 2, 42)
drawbox (253, 297, 2, 2, 42)



drawbox (0, 0, 280, 299, 42)
drawbox (0, 0, 305, 299, 42)
drawbox (0, 0, 330, 299, 42)
drawbox (0, 0, 355, 299, 42)
drawbox (0, 0, 380, 299, 42)
drawbox (0, 0, 405, 299, 42)
drawbox (0, 0, 430, 299, 42)
drawbox (0, 0, 455, 299, 42)
drawbox (0, 0, 480, 299, 42)
drawbox (0, 0, 499, 299, 42)
drawbox (497, 25, 0, 2, 42)
drawbox (497, 50, 0, 2, 42)
drawbox (497, 75, 0, 2, 42)
drawbox (497, 100, 0, 2, 42)
drawbox (497, 125, 0, 2, 42)
drawbox (497, 150, 0, 2, 42)
drawbox (497, 175, 0, 2, 42)
drawbox (497, 200, 0, 2, 42)
drawbox (497, 225, 0, 2, 42)
drawbox (497, 250, 0, 2, 42)
drawbox (497, 275, 0, 2, 42)
drawbox (497, 297, 0, 2, 42)
end grid


%procedure to assign
proc assign
%placing three units
put "Please click on an open square on the board to place one end "
put "of your ship (leave three units)"
grid
delay (500)
%placing five units
% put "Please click on an open square on the board to place one end "
% put "of your ship (leave five units)"
% grid
% put "Please click on an open square on the board to place one end "
% put "of your ship (leave two units)"
% put "Please click on an open square on the board to place one end "
% put "of your ship (leave two units)"
% put "Please click on an open square on the board to place one end "
% put "of your ship (leave three units)"

end assign


%%%%%%%%%%%%%%%
%Main Program %
%%%%%%%%%%%%%%%
intro
grid
assign
loop
mousewhere (mousex, mousey, button)
if button not= 0 and mousex + 8 < 250 then
Draw.Oval (mousex, mousey, 5, 5, red)
drawfill (mousex, mousey, red, red)
end if
end loop





again thanx!!!!
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Tue Jun 01, 2004 5:46 pm   Post subject: (No subject)

well, easiest is if you do arrays.

by keeping an array of positions for the grid, you can do this

1. whenever someone clicks, check for which square he clicked on
2. then draw a circle (or whatever picture) on that square, by making use of the coordinates of those squares stored in the array.

now, you are only drawing a circle wherever the user clicks. You need to be able to keep track of where is the position of every square of the grid.
belldandy_angel




PostPosted: Tue Jun 01, 2004 5:48 pm   Post subject: (No subject)

okay....how do i do that???
hhehehe

^^;
AsianSensation




PostPosted: Tue Jun 01, 2004 5:51 pm   Post subject: (No subject)

well, for arrays, I suggest you learn them first.

http://www.compsci.ca/v2/viewtopic.php?t=1117
belldandy_angel




PostPosted: Tue Jun 01, 2004 5:53 pm   Post subject: (No subject)

i know how to do array...
but

how do i check wut square they clicked on?? and how do i keep trackk?
Paul




PostPosted: Tue Jun 01, 2004 5:53 pm   Post subject: (No subject)

well first you should make use of something called "variables" and "loops" Laughing
example:
this code:
code:

drawbox (0, 0, 25, 299, 42)
drawbox (0, 0, 50, 299, 42)
drawbox (0, 0, 75, 299, 42)
drawbox (0, 0, 100, 299, 42)
drawbox (0, 0, 125, 299, 42)
drawbox (0, 0, 150, 299, 42)
drawbox (0, 0, 175, 299, 42)
drawbox (0, 0, 200, 299, 42)
drawbox (0, 0, 225, 299, 42)

can be reduced to
code:

for a: 1..9
drawbox (0, 0, a*(25), 299, 42)
end for

You get what I mean?
For what he said, you could map out the field with a 2D array, you could have 2 of those, one for the x position and one for the y position of each square, run a for loop to do that. Then each time you click, run a loop to check which square is clicked and use the predetermined coordinates stored in your arrays to draw a circle.
P.S. I love you too Rolling Eyes Laughing
belldandy_angel




PostPosted: Tue Jun 01, 2004 6:22 pm   Post subject: (No subject)

hey...
haha...im sowwie...i dunt reallie get it...
and no one can help me.... Crying or Very sad

sooo after u click u need to store the coordinates...

argh...i dunt know how to do this... Evil or Very Mad Evil or Very Mad Evil or Very Mad

Crying or Very sad Crying or Very sad



love u too!!!!! Embarassed
Paul




PostPosted: Tue Jun 01, 2004 6:22 pm   Post subject: (No subject)

Here I simplified ur code for you
code:

setscreen ("graphics:500;350")

%%%%%%%%%%%%%%%%%%%%
%declare variables %
%%%%%%%%%%%%%%%%%%%%
var font1, font2, font3, font4, font5 : int
var pti, ptf : int
var picID : int
var mousex, mousey, button : int := 0

%%%%%%%%%%%%%%
%subprograms %
%%%%%%%%%%%%%%

%procedure for the introduction
proc intro

    drawfillbox (0, 0, 250, 350, 37)
    drawfillbox (500, 0, 250, 360, 240)
    font1 := Font.New ("eddie:50:bold")
    font2 := Font.New ("times new roman:13")
    font3 := Font.New ("comic sans ms :8")
    font4 := Font.New ("eddie:40")
    font5 := Font.New ("times new roman:24:bold")

    Font.Draw ("BATTL", 30, 300, font1, 240)
    Font.Draw ("ESHIP", 280, 300, font1, 37)
    Font.Draw ("game", 180, 220, font4, 81)
    Font.Draw ("By: Annie Ng", 414, 15, font3, 101)
    Font.Draw ("Krystal Chiu", 430, 5, font3, 101)
    Font.Draw ("PLAYER", 74, 130, font2, 101)
    Font.Draw ("V S", 223, 60, font5, 101)
    Font.Draw ("CPU", 384, 130, font2, 101)

picID := Pic.FileNew ("ba.bmp")
Pic.Draw (picID, 60, 30, picCopy)
Pic.Free (picID)
picID := Pic.FileNew ("ba1.bmp")
Pic.Draw (picID, 360, 30, picCopy)
Pic.Free (picID)

    delay (700)
    cls
end intro
var y, x : int := 0
proc grid
    drawbox (0, 0, 255, 299, 42)
    for a : 1 .. 2
        for b : 1 .. 9
            drawbox (0, 0, x + (b * 25), 299, 42)
        end for
        x := 255
    end for
    y := 0
    x := 0
    for b : 1 .. 2
        for a : 1 .. 11
            drawbox (x, y + (a * 25), 2, 2, 42)
        end for
        x := 497
    end for
    drawbox (253, 297, 2, 2, 42)
    drawbox (497, 297, 0, 2, 42)
    drawbox (0, 0, 499, 299, 42)
end grid


%procedure to assign
proc assign
    %placing three units
    put "Please click on an open square on the board to place one end "
    put "of your ship (leave three units)"
    grid
    delay (500)
    %placing five units
    % put "Please click on an open square on the board to place one end "
    % put "of your ship (leave five units)"
    % grid
    % put "Please click on an open square on the board to place one end "
    % put "of your ship (leave two units)"
    % put "Please click on an open square on the board to place one end "
    % put "of your ship (leave two units)"
    % put "Please click on an open square on the board to place one end "
    % put "of your ship (leave three units)"

end assign


%%%%%%%%%%%%%%%
%Main Program %
%%%%%%%%%%%%%%%
intro
grid
assign
loop
    mousewhere (mousex, mousey, button)
    if button not= 0 and mousex + 8 < 250 then
        Draw.Oval (mousex, mousey, 5, 5, red)
        drawfill (mousex, mousey, red, red)
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
belldandy_angel




PostPosted: Tue Jun 01, 2004 6:30 pm   Post subject: (No subject)

thanks!!!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: