
-----------------------------------
jasonhan416
Wed Jan 14, 2009 5:26 am

BATTLE SHIP making an ending (PLEASE! FOR LOVE OF ALL THE NATURE)
-----------------------------------
THis is my final destiniation and i need help with it.
Basically, all my coding works but i need to know how to end the program.
Like, if the user attacks all the ship, the game is over kind of ending.
How do i do that?
anyone help?


var board1 : array 1 .. 10, 1 .. 10 of int
var board2 : array 1 .. 10, 1 .. 10 of int
var atkBoard1 : array 1 .. 10, 1 .. 10 of int
var atkBoard2 : array 1 .. 10, 1 .. 10 of int
var window : int := Window.Open ("position:50;130,graphics:900;650")
var key : string (1)
var xLoc, yLoc : int
var rangeX, rangeY, button : int
var clicked : boolean := false
var font, font1, battlefont, battlefont1 : int
var EMPTY : int := 0
var SHIP : int := 1
var HIT : int := 2
%Font declaration
font := Font.New ("serif:50")
font1 := Font.New ("serif:15")
battlefont := Font.New ("serif:20")
battlefont1 := Font.New ("serif:12")
%drawing board
procedure drawRect (xPos : int, yPos : int, width : int, height : int, col : int)
    drawbox (xPos, yPos, xPos + width, yPos + height, col)
end drawRect
%drawing ship
procedure drawFillRect (xPos : int, yPos : int, width : int, height : int, col : int)
    drawfillbox (xPos, yPos, xPos + width, yPos + height, col)
end drawFillRect

procedure title
    cls
    locate (1, 35)
    put "BattleShip"
end title

procedure pauseProgram

    put "Press any key to continue"
    getch (key)
end pauseProgram



procedure hitWnd
    title
    put ""
    put "You hit the ship!"
    pauseProgram
end hitWnd

procedure missedWnd
    title
    put ""
    put "You missed the ship!"
    pauseProgram
end missedWnd

procedure setAtkBoard1
    for x : 1 .. 10
        for y : 1 .. 10
            atkBoard1 (y, x) := EMPTY
        end for
    end for
end setAtkBoard1

procedure setAtkBoard2
    for x : 1 .. 10
        for y : 1 .. 10
            atkBoard2 (y, x) := EMPTY
        end for
    end for
end setAtkBoard2

procedure drawAttackBoard1
    drawbox (70, 40, 400, 260, 7)
    %line vertical player 1
    drawline (100, 240, 100, 260, 7)
    drawline (130, 240, 130, 260, 7)
    drawline (160, 240, 160, 260, 7)
    drawline (190, 240, 190, 260, 7)
    drawline (220, 240, 220, 260, 7)
    drawline (250, 240, 250, 260, 7)
    drawline (280, 240, 280, 260, 7)
    drawline (310, 240, 310, 260, 7)
    drawline (340, 240, 340, 260, 7)
    drawline (370, 240, 370, 260, 7)
    %line horizontal player 1
    drawline (70, 40, 100, 40, 7)
    drawline (70, 60, 100, 60, 7)
    drawline (70, 80, 100, 80, 7)
    drawline (70, 100, 100, 100, 7)
    drawline (70, 120, 100, 120, 7)
    drawline (70, 140, 100, 140, 7)
    drawline (70, 160, 100, 160, 7)
    drawline (70, 180, 100, 180, 7)
    drawline (70, 200, 100, 200, 7)
    drawline (70, 220, 100, 220, 7)
    drawline (70, 240, 100, 240, 7)
    %numbers player 1 declare
    Font.Draw ("1", 78, 225, battlefont1, black)
    Font.Draw ("2", 78, 205, battlefont1, black)
    Font.Draw ("3", 78, 185, battlefont1, black)
    Font.Draw ("4", 78, 165, battlefont1, black)
    Font.Draw ("5", 78, 145, battlefont1, black)
    Font.Draw ("6", 78, 125, battlefont1, black)
    Font.Draw ("7", 78, 105, battlefont1, black)
    Font.Draw ("8", 78, 85, battlefont1, black)
    Font.Draw ("9", 78, 65, battlefont1, black)
    Font.Draw ("10", 78, 45, battlefont1, black)
    %letters player 1 declare
    Font.Draw ("A", 110, 245, battlefont1, black)
    Font.Draw ("B", 140, 245, battlefont1, black)
    Font.Draw ("C", 170, 245, battlefont1, black)
    Font.Draw ("D", 200, 245, battlefont1, black)
    Font.Draw ("E", 230, 245, battlefont1, black)
    Font.Draw ("F", 260, 245, battlefont1, black)
    Font.Draw ("G", 290, 245, battlefont1, black)
    Font.Draw ("H", 320, 245, battlefont1, black)
    Font.Draw ("I", 350, 245, battlefont1, black)
    Font.Draw ("J", 380, 245, battlefont1, black)
    for x : 1 .. 10
        for y : 1 .. 10
            if atkBoard1 (y, x) = EMPTY then
                drawRect (70 + x * 30, 240 - y * 20, 30, 20, black)
            else
                drawline (70 + x * 30, 260 - y * 20, x * 30 + 100, 260 - y * 20 - 20, red)
                drawline (70 + x * 30, 260 - y * 20 - 20, x * 30 + 100, 260 - y * 20, red)
            end if
        end for
    end for
end drawAttackBoard1

procedure drawAttackBoard2
    drawbox (70, 40, 400, 260, 7)
    %line vertical player 1
    drawline (100, 240, 100, 260, 7)
    drawline (130, 240, 130, 260, 7)
    drawline (160, 240, 160, 260, 7)
    drawline (190, 240, 190, 260, 7)
    drawline (220, 240, 220, 260, 7)
    drawline (250, 240, 250, 260, 7)
    drawline (280, 240, 280, 260, 7)
    drawline (310, 240, 310, 260, 7)
    drawline (340, 240, 340, 260, 7)
    drawline (370, 240, 370, 260, 7)
    %line horizontal player 1
    drawline (70, 40, 100, 40, 7)
    drawline (70, 60, 100, 60, 7)
    drawline (70, 80, 100, 80, 7)
    drawline (70, 100, 100, 100, 7)
    drawline (70, 120, 100, 120, 7)
    drawline (70, 140, 100, 140, 7)
    drawline (70, 160, 100, 160, 7)
    drawline (70, 180, 100, 180, 7)
    drawline (70, 200, 100, 200, 7)
    drawline (70, 220, 100, 220, 7)
    drawline (70, 240, 100, 240, 7)
    %numbers player 1 declare
    Font.Draw ("1", 78, 225, battlefont1, black)
    Font.Draw ("2", 78, 205, battlefont1, black)
    Font.Draw ("3", 78, 185, battlefont1, black)
    Font.Draw ("4", 78, 165, battlefont1, black)
    Font.Draw ("5", 78, 145, battlefont1, black)
    Font.Draw ("6", 78, 125, battlefont1, black)
    Font.Draw ("7", 78, 105, battlefont1, black)
    Font.Draw ("8", 78, 85, battlefont1, black)
    Font.Draw ("9", 78, 65, battlefont1, black)
    Font.Draw ("10", 78, 45, battlefont1, black)
    %letters player 1 declare
    Font.Draw ("A", 110, 245, battlefont1, black)
    Font.Draw ("B", 140, 245, battlefont1, black)
    Font.Draw ("C", 170, 245, battlefont1, black)
    Font.Draw ("D", 200, 245, battlefont1, black)
    Font.Draw ("E", 230, 245, battlefont1, black)
    Font.Draw ("F", 260, 245, battlefont1, black)
    Font.Draw ("G", 290, 245, battlefont1, black)
    Font.Draw ("H", 320, 245, battlefont1, black)
    Font.Draw ("I", 350, 245, battlefont1, black)
    Font.Draw ("J", 380, 245, battlefont1, black)
    for x : 1 .. 10
        for y : 1 .. 10
            if atkBoard2 (y, x) = EMPTY then
                drawRect (70 + x * 30, 240 - y * 20, 30, 20, black)
            else
                drawline (70 + x * 30, 260 - y * 20, x * 30 + 100, 260 - y * 20 - 20, red)
                drawline (70 + x * 30, 260 - y * 20 - 20, x * 30 + 100, 260 - y * 20, red)
            end if
        end for
    end for
end drawAttackBoard2

procedure drawBoard1
    cls
    drawbox (70, 310, 400, 530, 7)
    %line vertical player 1
    drawline (100, 500, 100, 530, 7)
    drawline (130, 500, 130, 530, 7)
    drawline (160, 500, 160, 530, 7)
    drawline (190, 500, 190, 530, 7)
    drawline (220, 500, 220, 530, 7)
    drawline (250, 500, 250, 530, 7)
    drawline (280, 500, 280, 530, 7)
    drawline (310, 500, 310, 530, 7)
    drawline (340, 500, 340, 530, 7)
    drawline (370, 500, 370, 530, 7)
    %line horizontal player 1
    drawline (70, 330, 100, 330, 7)
    drawline (70, 350, 100, 350, 7)
    drawline (70, 370, 100, 370, 7)
    drawline (70, 390, 100, 390, 7)
    drawline (70, 410, 100, 410, 7)
    drawline (70, 430, 100, 430, 7)
    drawline (70, 450, 100, 450, 7)
    drawline (70, 470, 100, 470, 7)
    drawline (70, 490, 100, 490, 7)
    drawline (70, 510, 100, 510, 7)
    %numbers player 1
    Font.Draw ("1", 78, 495, battlefont1, black)
    Font.Draw ("2", 78, 475, battlefont1, black)
    Font.Draw ("3", 78, 455, battlefont1, black)
    Font.Draw ("4", 78, 435, battlefont1, black)
    Font.Draw ("5", 78, 415, battlefont1, black)
    Font.Draw ("6", 78, 395, battlefont1, black)
    Font.Draw ("7", 78, 375, battlefont1, black)
    Font.Draw ("8", 78, 355, battlefont1, black)
    Font.Draw ("9", 78, 335, battlefont1, black)
    Font.Draw ("10", 78, 315, battlefont1, black)
    %letters player 1
    Font.Draw ("A", 110, 512, battlefont1, black)
    Font.Draw ("B", 140, 512, battlefont1, black)
    Font.Draw ("C", 170, 512, battlefont1, black)
    Font.Draw ("D", 200, 512, battlefont1, black)
    Font.Draw ("E", 230, 512, battlefont1, black)
    Font.Draw ("F", 260, 512, battlefont1, black)
    Font.Draw ("G", 290, 512, battlefont1, black)
    Font.Draw ("H", 320, 512, battlefont1, black)
    Font.Draw ("I", 350, 512, battlefont1, black)
    Font.Draw ("J", 380, 512, battlefont1, black)
    for x : 1 .. 10
        for y : 1 .. 10
            if board1 (y, x) = SHIP then
                drawFillRect (40 + x * 30 + 30, 510 - y * 20, 30, 20, black)
            elsif board1 (y, x) = EMPTY then
                drawRect (40 + x * 30 + 30, 510 - y * 20, 30, 20, black)
            end if
        end for
    end for
end drawBoard1


procedure drawBoard2
    cls
    drawbox (70, 310, 400, 530, 7)
    %line vertical player 1
    drawline (100, 500, 100, 530, 7)
    drawline (130, 500, 130, 530, 7)
    drawline (160, 500, 160, 530, 7)
    drawline (190, 500, 190, 530, 7)
    drawline (220, 500, 220, 530, 7)
    drawline (250, 500, 250, 530, 7)
    drawline (280, 500, 280, 530, 7)
    drawline (310, 500, 310, 530, 7)
    drawline (340, 500, 340, 530, 7)
    drawline (370, 500, 370, 530, 7)
    %line horizontal player 1
    drawline (70, 330, 100, 330, 7)
    drawline (70, 350, 100, 350, 7)
    drawline (70, 370, 100, 370, 7)
    drawline (70, 390, 100, 390, 7)
    drawline (70, 410, 100, 410, 7)
    drawline (70, 430, 100, 430, 7)
    drawline (70, 450, 100, 450, 7)
    drawline (70, 470, 100, 470, 7)
    drawline (70, 490, 100, 490, 7)
    drawline (70, 510, 100, 510, 7)
    %numbers player 1
    Font.Draw ("1", 78, 495, battlefont1, black)
    Font.Draw ("2", 78, 475, battlefont1, black)
    Font.Draw ("3", 78, 455, battlefont1, black)
    Font.Draw ("4", 78, 435, battlefont1, black)
    Font.Draw ("5", 78, 415, battlefont1, black)
    Font.Draw ("6", 78, 395, battlefont1, black)
    Font.Draw ("7", 78, 375, battlefont1, black)
    Font.Draw ("8", 78, 355, battlefont1, black)
    Font.Draw ("9", 78, 335, battlefont1, black)
    Font.Draw ("10", 78, 315, battlefont1, black)
    %letters player 1
    Font.Draw ("A", 110, 512, battlefont1, black)
    Font.Draw ("B", 140, 512, battlefont1, black)
    Font.Draw ("C", 170, 512, battlefont1, black)
    Font.Draw ("D", 200, 512, battlefont1, black)
    Font.Draw ("E", 230, 512, battlefont1, black)
    Font.Draw ("F", 260, 512, battlefont1, black)
    Font.Draw ("G", 290, 512, battlefont1, black)
    Font.Draw ("H", 320, 512, battlefont1, black)
    Font.Draw ("I", 350, 512, battlefont1, black)
    Font.Draw ("J", 380, 512, battlefont1, black)
    for x : 1 .. 10
        for y : 1 .. 10
            if board2 (y, x) = SHIP then
                drawFillRect (40 + x * 30 + 30, 510 - y * 20, 30, 20, black)
            elsif board2 (y, x) = EMPTY then
                drawRect (40 + x * 30 + 30, 510 - y * 20, 30, 20, black)
            end if
        end for
    end for
end drawBoard2


procedure user1Turn1
    title
    clicked := false
    put "This is player 1's turn to attack"
    drawBoard1
    drawAttackBoard1
    loop
        mousewhere (rangeX, rangeY, button)

        if button = 1 then
            xLoc := ((rangeX - rangeX mod 30 - 60) div 30)
            yLoc := ((rangeY - rangeY mod 20 - 20) div 20)
            if yLoc = 10 then
                yLoc := 1
            elsif yLoc = 9 then
                yLoc := 2
            elsif yLoc = 8 then
                yLoc := 3
            elsif yLoc = 7 then
                yLoc := 4
            elsif yLoc = 6 then
                yLoc := 5
            elsif yLoc = 5 then
                yLoc := 6
            elsif yLoc = 4 then
                yLoc := 7
            elsif yLoc = 3 then
                yLoc := 8
            elsif yLoc = 2 then
                yLoc := 9
            elsif yLoc = 1 then
                yLoc := 10
            end if
            clicked := true
        end if
        exit when clicked
    end loop


    atkBoard1 (yLoc, xLoc) := HIT
    drawAttackBoard1

    delay (50)

    if board2 (yLoc, xLoc) = SHIP then
        board2 (yLoc, xLoc) := HIT
        hitWnd
        user1Turn1
    else
        if board2 (yLoc, xLoc) = EMPTY then
            missedWnd
        end if
    end if


end user1Turn1

procedure user2Turn1
    title
    clicked := false
    put "This is plaer 2's turn to attack"
    drawBoard2
    drawAttackBoard2
    loop
        mousewhere (rangeX, rangeY, button)

        if button = 1 then
            xLoc := ((rangeX - rangeX mod 30 - 60) div 30)
            yLoc := ((rangeY - rangeY mod 20 - 20) div 20)
            if yLoc = 10 then
                yLoc := 1
            elsif yLoc = 9 then
                yLoc := 2
            elsif yLoc = 8 then
                yLoc := 3
            elsif yLoc = 7 then
                yLoc := 4
            elsif yLoc = 6 then
                yLoc := 5
            elsif yLoc = 5 then
                yLoc := 6
            elsif yLoc = 4 then
                yLoc := 7
            elsif yLoc = 3 then
                yLoc := 8
            elsif yLoc = 2 then
                yLoc := 9
            elsif yLoc = 1 then
                yLoc := 10
            end if
            clicked := true
        end if
        exit when clicked
    end loop

    atkBoard2 (yLoc, xLoc) := HIT
    drawAttackBoard2

    delay (50)

    if board1 (yLoc, xLoc) = SHIP then
        board1 (yLoc, xLoc) := HIT
        hitWnd
        user2Turn1
    else
        if board1 (yLoc, xLoc) = EMPTY then
            missedWnd
        end if
    end if


end user2Turn1



procedure setBoard1
    title
    for x : 1 .. 10
        for y : 1 .. 10
            %First piece
            if x = 3 and y = 2 then
                board1 (y, x) := SHIP
            elsif x = 4 and y = 2 then
                board1 (y, x) := SHIP
            elsif x = 5 and y = 2 then
                board1 (y, x) := SHIP
                %Second piece
            elsif x = 3 and y = 4 then
                board1 (y, x) := SHIP
            elsif x = 3 and y = 5 then
                board1 (y, x) := SHIP
            elsif x = 3 and y = 6 then
                board1 (y, x) := SHIP
            elsif x = 3 and y = 7 then
                board1 (y, x) := SHIP
            elsif x = 3 and y = 8 then
                board1 (y, x) := SHIP
                %Third piece
            elsif x = 6 and y = 6 then
                board1 (y, x) := SHIP
            elsif x = 6 and y = 7 then
                board1 (y, x) := SHIP
            elsif x = 6 and y = 8 then
                board1 (y, x) := SHIP
                %Fourth piece
            elsif x = 4 and y = 10 then
                board1 (y, x) := SHIP
            elsif x = 5 and y = 10 then
                board1 (y, x) := SHIP
            elsif x = 6 and y = 10 then
                board1 (y, x) := SHIP
            elsif x = 7 and y = 10 then
                board1 (y, x) := SHIP
                %Fifth piece
            elsif x = 8 and y = 4 then
                board1 (y, x) := SHIP
            elsif x = 8 and y = 5 then
                board1 (y, x) := SHIP
            else
                board1 (y, x) := EMPTY
            end if
            atkBoard1 (y, x) := EMPTY
        end for
    end for

end setBoard1

procedure setBoard2
    title
    for x : 1 .. 10
        for y : 1 .. 10
            %First piece
            if x = 6 and y = 2 then
                board2 (y, x) := SHIP
            elsif x = 7 and y = 2 then
                board2 (y, x) := SHIP
            elsif x = 8 and y = 2 then
                board2 (y, x) := SHIP
                %Second piece
            elsif x = 4 and y = 6 then
                board2 (y, x) := SHIP
            elsif x = 5 and y = 6 then
                board2 (y, x) := SHIP
            elsif x = 6 and y = 6 then
                board2 (y, x) := SHIP
            elsif x = 7 and y = 6 then
                board2 (y, x) := SHIP
            elsif x = 8 and y = 6 then
                board2 (y, x) := SHIP
                %Third piece
            elsif x = 1 and y = 2 then
                board2 (y, x) := SHIP
            elsif x = 1 and y = 3 then
                board2 (y, x) := SHIP
            elsif x = 1 and y = 4 then
                board2 (y, x) := SHIP
                %Fourth piece
            elsif x = 10 and y = 7 then
                board2 (y, x) := SHIP
            elsif x = 10 and y = 8 then
                board2 (y, x) := SHIP
            elsif x = 10 and y = 9 then
                board2 (y, x) := SHIP
            elsif x = 10 and y = 10 then
                board2 (y, x) := SHIP
                %Fifth piece
            elsif x = 2 and y = 10 then
                board2 (y, x) := SHIP
            elsif x = 3 and y = 10 then
                board2 (y, x) := SHIP
            else
                board2 (y, x) := EMPTY
            end if
            atkBoard2 (y, x) := EMPTY
        end for
    end for

end setBoard2

procedure usershit
    setBoard1
    setBoard2
    setAtkBoard1
    setAtkBoard2
    loop
        user1Turn1
        user2Turn1
    end loop
end usershit

usershit


-----------------------------------
Parker
Wed Jan 14, 2009 8:20 am

RE:BATTLE SHIP making an ending (PLEASE! FOR LOVE OF ALL THE NATURE)
-----------------------------------
What do you mean you need help with that? If player sinks a ship have a counter that says counter + 1, or if there is 15 hits the player has to make in total have a "hitcounter" that adds each time you make a hit. Once the counter reaches 15 exit your main loop and then at the end of the game just put a simple screen that says "Game Over"...

-----------------------------------
chrisbrown
Wed Jan 14, 2009 10:03 am

Re: BATTLE SHIP making an ending (PLEASE! FOR LOVE OF ALL THE NATURE)
-----------------------------------

if yLoc = 10 then
yLoc := 1
elsif yLoc = 9 then
yLoc := 2
elsif yLoc = 8 then
yLoc := 3
elsif yLoc = 7 then
yLoc := 4
elsif yLoc = 6 then
yLoc := 5
elsif yLoc = 5 then
yLoc := 6
elsif yLoc = 4 then
yLoc := 7
elsif yLoc = 3 then
yLoc := 8
elsif yLoc = 2 then
yLoc := 9
elsif yLoc = 1 then
yLoc := 10
end if

I'm not even going to say anything..

yLoc := 11 - yLoc

