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

Username:   Password: 
 RegisterRegister   
 Array Help Really Fast Please
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ajones88




PostPosted: Thu Dec 17, 2009 8:25 pm   Post subject: Array Help Really Fast Please

Please help fast, is due tomorrow and ran into some unexpected trouble, thankyou.


What is it you are trying to achieve?
a check for battleship, trying to use arrays, but am getting an error.


What is the problem you are having?
error when trying to run program, problem with my arrays



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


setscreen ("graphics: 660;660;offscreenonly;nocursor")
var z := 1
var w := 1
var hx, hy, mx, my : int
var hit : array 1 .. 17 of int
var miss : array 1 .. 83 of int
var shiplocx:array 1..18 of int
var shiplocy:array 1..18 of int
var gridcheckx:=335
var gridchecky:=305
var a:=1
var x := 30
var y := 570
var subx := 30
var suby := 540
var desx := 30
var desy := 540
var pboatmov, submov, desmov,batmov,acmov : array char of boolean
var map : array 1 .. 2 of int
var sbcheck := 0
var subcount, descount,batcount,account := 1
var compx, compy, compx1, compy1, compx2, compy2, compx3, compy3,compx4,compy4, dir, dir1, dir2, dir3,dir4 : int
var compcount := 0
var gridx, gridy, gridx1, gridy1 : int
var patrol, sub, des,bat,ac : int
var next := 0
var batx := 30
var acx := 30
var baty := 510
var acy := 480
var guesscheck:=0
var guessloc:=0
patrol := Pic.FileNew ("pboat.gif")
sub := Pic.FileNew ("submarine.gif")
des := Pic.FileNew ("destroyer.gif")
var pboatcheck, subcheck, descheck,batcheck,accheck := 0
var subrotatecheck : int
var subrtate, pboatrotate, desrotatecheck,batrotatecheck,acrotatecheck : int
var target:int
var guessx,guessy:int
guessx:=330
guessy:=300
var guess:array char of boolean
subrtate := 0
pboatrotate := 0
subrotatecheck := 0
desrotatecheck := 0
batrotatecheck:=0
acrotatecheck:=0
var compcheck:=0
proc Guess
if guesscheck=1 then   
target := Pic.FileNew ("target.gif")
    Pic.Draw (target, guessx, guessy, picMerge)
    Pic.Free (target)
    Input.KeyDown (guess)
    if guess (KEY_UP_ARROW) and guessy<300 then
        guessy += 30
    elsif guess (KEY_DOWN_ARROW) and guessy>30 then
        guessy -= 30
    elsif guess (KEY_LEFT_ARROW) and guessx>330 then
        guessx -= 30
    elsif guess (KEY_RIGHT_ARROW) and guessx<600then
        guessx += 30
    elsif guess (KEY_ENTER) then
       guessloc:=1
    end if
    end if
end Guess

proc gridcheck
    loop
        if whatdotcolor (gridcheckx,gridchecky) = 15 then
            shiplocx(a):=gridcheckx
            shiplocy(a):=gridchecky
            a+=1           
        end if
        gridcheckx+=30
        if gridcheckx >630 then
            gridcheckx:=335
            gridchecky-=30
        end if
    exit when a=17 or gridcheckx>=600 and gridchecky <30
    end loop
end gridcheck
proc compgrid


 
end compgrid
proc grid
    var gridx, gridy, gridx1, gridy1 : int
    gridx := Pic.FileNew ("1-10.jpg")
    gridy := Pic.FileNew ("1-10-2.jpg")
   gridx1 := Pic.FileNew ("1-10-reverse.jpg")
    gridy1 := Pic.FileNew ("1-10-2-reverse.jpg")
    drawfillbox (0, 660, 330, 330, black)
    drawbox (0, 660, 330, 330, brightred)
    drawbox (1, 659, 329, 331, brightred)
    drawline (30, 660, 30, 330, brightred)
    drawline (60, 660, 60, 330, brightred)
    drawline (90, 660, 90, 330, brightred)
    drawline (120, 660, 120, 330, brightred)
    drawline (150, 660, 150, 330, brightred)
    drawline (180, 660, 180, 330, brightred)
    drawline (210, 660, 210, 330, brightred)
    drawline (240, 660, 240, 330, brightred)
    drawline (270, 660, 270, 330, brightred)
    drawline (300, 660, 300, 330, brightred)
    drawline (0, 630, 330, 630, brightred)
    drawline (0, 600, 330, 600, brightred)
    drawline (0, 570, 330, 570, brightred)
    drawline (0, 540, 330, 540, brightred)
    drawline (0, 510, 330, 510, brightred)
    drawline (0, 480, 330, 480, brightred)
    drawline (0, 450, 330, 450, brightred)
    drawline (0, 420, 330, 420, brightred)
    drawline (0, 390, 330, 390, brightred)
    drawline (0, 360, 330, 360, brightred)
    Pic.Draw (gridx, 0, 630, picCopy)
    Pic.Draw (gridy, 0, 330, picCopy)
    Pic.Free (gridx)
    Pic.Free (gridy)
    drawfillbox (330, 330, 660, 0, black)
    drawbox (330, 330, 660, 0, brightred)
    drawbox (331, 329, 659, 1, brightred)
    drawline (360, 330, 360, 0, brightred)
    drawline (390, 330, 390, 0, brightred)
    drawline (420, 330, 420, 0, brightred)
    drawline (450, 330, 450, 0, brightred)
    drawline (480, 330, 480, 0, brightred)
    drawline (510, 330, 510, 0, brightred)
    drawline (540, 330, 540, 0, brightred)
    drawline (570, 330, 570, 0, brightred)
    drawline (600, 330, 600, 0, brightred)
    drawline (630, 330, 630, 0, brightred)
    drawline (330, 300, 660, 300, brightred)
    drawline (330, 270, 660, 270, brightred)
    drawline (330, 240, 660, 240, brightred)
    drawline (330, 210, 660, 210, brightred)
    drawline (330, 180, 660, 180, brightred)
    drawline (330, 150, 660, 150, brightred)
    drawline (330, 120, 660, 120, brightred)
    drawline (330, 90, 660, 90, brightred)
    drawline (330, 60, 660, 60, brightred)
    drawline (330, 30, 660, 30, brightred)
    Pic.Draw (gridx1, 330, 0, picCopy)
    Pic.Draw (gridy1, 630, 0, picCopy)
    Pic.Free (gridx1)
    Pic.Free (gridy1)
end grid
proc draw
    if hit (1) = 1 then
        drawfillbox (hx (1), hy (1), hx (1) + 30, hy (1) + 30, red)
    end if
    if hit (2) = 1 then
        drawfillbox (hx (2), hy (2), hx (2) + 30, hy (2) + 30, red)
    end if
    if hit (3) = 1 then
        drawfillbox (hx (3), hy (1), hx (3) + 30, hy (3) + 30, red)
    end if
    if hit (4) = 1 then
        drawfillbox (hx (4), hy (4), hx (4) + 30, hy (4) + 30, red)
    end if
    if hit (5) = 1 then
        drawfillbox (hx (5), hy (5), hx (5) + 30, hy (5) + 30, red)
    end if
    if hit (6) = 1 then
        drawfillbox (hx (6), hy (6), hx (6) + 30, hy (6) + 30, red)
    end if
    if hit (7) = 1 then
        drawfillbox (hx (7), hy (7), hx (7) + 30, hy (7) + 30, red)
    end if
    if hit (8) = 1 then
        drawfillbox (hx (8), hy (8), hx (8) + 30, hy (8) + 30, red)
    end if
    if hit (9) = 1 then
        drawfillbox (hx (9), hy (9), hx (9) + 30, hy (9) + 30, red)
    end if
    if hit (10) = 1 then
        drawfillbox (hx (10), hy (10), hx (10) + 30, hy (10) + 30, red)
    end if
    if hit (11) = 1 then
        drawfillbox (hx (11), hy (11), hx (11) + 30, hy (11) + 30, red)
    end if
    if hit (12) = 1 then
        drawfillbox (hx (12), hy (12), hx (12) + 30, hy (12) + 30, red)
    end if
    if hit (13) = 1 then
        drawfillbox (hx (13), hy (13), hx (13) + 30, hy (13) + 30, red)
    end if
    if hit (14) = 1 then
        drawfillbox (hx (14), hy (14), hx (14) + 30, hy (14) + 30, red)
    end if
    if hit (15) = 1 then
        drawfillbox (hx (15), hy (15), hx (15) + 30, hy (15) + 30, red)
    end if
    if hit (16) = 1 then
        drawfillbox (hx (16), hy (16), hx (16) + 30, hy (16) + 30, red)
    end if
    if hit (17) = 1 then
        drawfillbox (hx (17), hy (17), hx (17) + 30, hy (17) + 30, red)
    end if
end draw

proc check
    if guessloc = 1 then
        if guessx + 5 = shiplocx (1) and guessy + 5 = shiplocy (1) or guessx + 5 = shiplocx (2) and guessy + 5 = shiplocy (2) or guessx + 5 = shiplocx (3) and guessy + 5 = shiplocy (3) or guessx + 5
                = shiplocx (4)
                and guessy + 5 = shiplocy (4) or guessx + 5 = shiplocx (5) and guessy + 5 = shiplocy (5) or guessx + 5 = shiplocx (6) and guessy + 5 = shiplocy (6) or guessx + 5 = shiplocx (7) and
                guessy + 5 = shiplocy (7) or
                guessx + 5 = shiplocx (8) and guessy + 5 = shiplocy (8) or guessx + 5 = shiplocx (9) and guessy + 5 = shiplocy (9) or guessx + 5 = shiplocx (10) and guessy + 5 = shiplocy (10) or
                guessx + 5 = shiplocx (11)
                and guessy + 5 = shiplocy (11) or guessx + 5 = shiplocx (12) and guessy + 5 = shiplocy (12) or guessx + 5 = shiplocx (123) and guessy + 5 = shiplocy (13) or guessx + 5 = shiplocx (14)
                and guessy + 5 = shiplocy (14) or
                guessx + 5 = shiplocx (15) and guessy + 5 = shiplocy (15) or guessx + 5 = shiplocx (16) and guessy + 5 = shiplocy (16) or guessx + 5 = shiplocx (17) and guessy + 5 = shiplocy (17) then
            hx (z) := guessx
            hy (z) := guessy
            hit (z) := 1
            z += 1
        else
            mx (w) := guessx
            my (w) := guessy
            miss (w) := 1
            w += 1
        end if
    end if
end check



proc comp
if compcheck=0 then

loop
    randint (compx, 1, 10)
    randint (compy, 1, 10)
    compx := 330 + compx * 30
    compy := compy * 30
    randint (dir, 1, 4)
    if dir = 1 and compy < 270 and compx < 630 then
        drawfillbox (compx, compy, compx + 30, compy + 60, darkgrey)
        drawbox (compx, compy, compx + 30, compy + 60, black)
        compcount := 1
    elsif dir = 2 and compy > 90 and compx < 630 then
        drawfillbox (compx, compy, compx + 30, compy - 60, darkgrey)
        drawbox (compx, compy, compx + 30, compy - 60, black)
        compcount := 1
    elsif dir = 3 and compx > 390 and compy < 300 then
        drawfillbox (compx, compy, compx - 60, compy + 30, darkgrey)
        drawbox (compx, compy, compx - 60, compy + 30, black)
        compcount := 1
    elsif dir = 4 and compx < 600 and compy < 300 then
        drawfillbox (compx, compy, compx + 60, compy + 30, darkgrey)
        drawbox (compx, compy, compx + 60, compy + 30, black)
        compcount := 1
    else
        randint (compx, 1, 10)
        randint (compy, 1, 10)
        compx := 330 + compx * 30
        compy := compy * 30
        randint (dir, 1, 4)
    end if
    exit when compcount = 1
end loop

loop
    randint (compx1, 1, 10)
    randint (compy1, 1, 10)
    compx1 := 330 + compx1 * 30
    compy1 := compy1 * 30
    randint (dir1, 1, 4)
    if dir1 = 1 and compy1 < 240 and compx1 < 630 and whatdotcolor (compx1 + 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 5, compy1 + 35) not= darkgrey and whatdotcolor (compx1 + 5, compy1 + 65) not= darkgrey then %UP
        drawfillbox (compx1, compy1, compx1 + 30, compy1 + 90, darkgrey)
        drawbox (compx1, compy1, compx1 + 30, compy1 + 90, black)
        compcount := 2
    elsif dir1 = 2 and compy1 > 120 and compx1 < 630 and whatdotcolor (compx1 + 5, compy1 - 5) not= darkgrey and whatdotcolor (compx1 + 5, compy1 - 35) not= darkgrey and whatdotcolor (compx1 + 5, compy1 - 65) not= darkgrey then
        %DOWN
        drawfillbox (compx1, compy1, compx1 + 30, compy1 - 90, darkgrey)
        drawbox (compx1, compy1, compx1 + 30, compy1 - 90, 7)
        compcount := 2
    elsif dir1 = 3 and compx1 > 420 and compy1 < 300 and whatdotcolor (compx1 - 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 - 35, compy1 + 5) not= darkgrey and whatdotcolor (compx1 - 65, compy1 + 5) not= darkgrey then
        %LEFT
        drawfillbox (compx1, compy1, compx1 - 90, compy1 + 30, darkgrey)
        drawbox (compx1, compy1, compx1 - 90, compy1 + 30, 7)
        compcount := 2
    elsif dir1 = 4 and compx1 < 570 and compy1 < 300 and whatdotcolor (compx1 + 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 35, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 65, compy1 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx1, compy1, compx1 + 90, compy1 + 30, darkgrey)
        drawbox (compx1, compy1, compx1 + 90, compy1 + 30, 7)
        compcount := 2
    else
        randint (compx1, 1, 10)
        randint (compy1, 1, 10)
        compx1 := 330 + compx1 * 30
        compy1 := compy1 * 30
        randint (dir1, 1, 4)
    end if
    exit when compcount = 2
end loop

loop
    randint (compx2, 1, 10)
    randint (compy2, 1, 10)
    compx2 := 330 + compx2 * 30
    compy2 := compy2 * 30
    randint (dir2, 1, 4)
    if dir2 = 1 and compy2 < 240 and compx2 < 630 and whatdotcolor (compx2 + 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 5, compy2 + 35) not= darkgrey and whatdotcolor (compx2 + 5, compy2 + 65) not= darkgrey then %UP
        drawfillbox (compx2, compy2, compx2 + 30, compy2 + 90, darkgrey)
        drawbox (compx2, compy2, compx2 + 30, compy2 + 90, 7)
        compcount := 3
    elsif dir2 = 2 and compy2 > 120 and compx2 < 630 and whatdotcolor (compx2 + 5, compy2 - 5) not= darkgrey and whatdotcolor (compx2 + 5, compy2 - 35) not= darkgrey and whatdotcolor (compx2 + 5, compy2 - 65) not= darkgrey then
        %DOWN
        drawfillbox (compx2, compy2, compx2 + 30, compy2 - 90, darkgrey)
        drawbox (compx2, compy2, compx2 + 30, compy2 - 90, 7)
        compcount := 3
    elsif dir2 = 3 and compx2 > 420 and compy2 < 300 and whatdotcolor (compx2 - 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 - 35, compy2 + 5) not= darkgrey and whatdotcolor (compx2 - 65, compy2 + 5) not= darkgrey then
        %LEFT
        drawfillbox (compx2, compy2, compx2 - 90, compy2 + 30, darkgrey)
        drawbox (compx2, compy2, compx2 - 90, compy2 + 30, 7)
        compcount := 3
    elsif dir2 = 4 and compx2 < 570 and compy2 < 300 and whatdotcolor (compx2 + 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 35, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 65, compy2 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx2, compy2, compx2 + 90, compy2 + 30, darkgrey)
        drawbox (compx2, compy2, compx2 + 90, compy2 + 30, 7)
        compcount := 3
    else
        randint (compx2, 1, 10)
        randint (compy2, 1, 10)
        compx2 := 330 + compx2 * 30
        compy2 := compy2 * 30
        randint (dir2, 1, 4)
    end if
    exit when compcount = 3
end loop
loop
    randint (compx3, 1, 10)
    randint (compy3, 1, 10)
    compx3 := 330 + compx3 * 30
    compy3 := compy3 * 30
    randint (dir3, 1, 4)
    if dir3 = 1 and compy3 < 210 and compx3 < 630 and whatdotcolor (compx3 + 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 35) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 65) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 95) not= darkgrey then %UP
        drawfillbox (compx3, compy3, compx3 + 30, compy3 + 120, darkgrey)
        drawbox (compx3, compy3, compx3 + 30, compy3 + 120, 7)
        compcount := 4
    elsif dir3 = 2 and compy3 > 150 and compx3 < 630 and whatdotcolor (compx3 + 5, compy3 - 5) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 35) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 65) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 95) not= darkgrey then
        %DOWN
        drawfillbox (compx3, compy3, compx3 + 30, compy3 - 120, darkgrey)
        drawbox (compx3, compy3, compx3 + 30, compy3 - 120, 7)
        compcount := 4
    elsif dir3 = 3 and compx3 > 450 and compy3 < 300 and whatdotcolor (compx3 - 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 - 35, compy3 + 5) not= darkgrey and whatdotcolor (compx3 - 65, compy3 + 5) not= darkgrey  and whatdotcolor (compx3 -95, compy3 +5) not= darkgrey then
        %LEFT
        drawfillbox (compx3, compy3, compx3 - 120, compy3 + 30, darkgrey)
        drawbox (compx3, compy3, compx3 - 120, compy3 + 30, 7)
        compcount := 4
    elsif dir3 = 4 and compx3 < 540 and compy3 < 300 and whatdotcolor (compx3 + 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 35, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 65, compy3 + 5) not= darkgrey  and whatdotcolor (compx3 + 95, compy3 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx3, compy3, compx3 + 120, compy3 + 30, darkgrey)
        drawbox (compx3, compy3, compx3 + 120, compy3 + 30, 7)
        compcount := 4
    else
        randint (compx3, 1, 10)
        randint (compy3, 1, 10)
        compx3 := 330 + compx3 * 30
        compy3 := compy3 * 30
        randint (dir3, 1, 4)
    end if
    exit when compcount = 4
end loop

loop
    randint (compx4, 1, 10)
    randint (compy4, 1, 10)
    compx4 := 330 + compx4 * 30
    compy4 := compy4 * 30
    randint (dir4, 1, 4)
    if dir4 = 1 and compy4 < 180 and compx4 < 630 and whatdotcolor (compx4 + 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 35) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 65) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 95) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 125) not= darkgrey then %UP
        drawfillbox (compx4, compy4, compx4 + 30, compy4 + 150, darkgrey)
        drawbox (compx4, compy4, compx4 + 30, compy4 + 150, 7)
        compcount := 5
    elsif dir4 = 2 and compy4 > 180 and compx4 < 630 and whatdotcolor (compx4 + 5, compy4 - 5) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 35) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 65) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 95) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 125) not= darkgrey then
        %DOWN
        drawfillbox (compx4, compy4, compx4 + 30, compy4 - 150, darkgrey)
        drawbox (compx4, compy4, compx4 + 30, compy4 - 150, 7)
        compcount := 5
    elsif dir4 = 3 and compx4 > 480 and compy4 < 300 and whatdotcolor (compx4 - 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 - 35, compy4 + 5) not= darkgrey and whatdotcolor (compx4 - 65, compy4 + 5) not= darkgrey  and whatdotcolor (compx4 -95, compy4 +5) not= darkgrey and whatdotcolor (compx4 -125, compy4 +5) not= darkgrey then
        %LEFT
        drawfillbox (compx4, compy4, compx4 - 150, compy4 + 30, darkgrey)
        drawbox (compx4, compy4, compx4 - 150, compy4 + 30, 7)
        compcount := 5
    elsif dir4 = 4 and compx4 < 510 and compy4 < 300 and whatdotcolor (compx4 + 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 35, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 65, compy4 + 5) not= darkgrey  and whatdotcolor (compx4 + 95, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 125, compy4 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx4, compy4, compx4 + 150, compy4 + 30, darkgrey)
        drawbox (compx4, compy4, compx4 + 150, compy4 + 30, 7)
        compcount := 5
    else
        randint (compx4, 1, 10)
        randint (compy4, 1, 10)
        compx4 := 330 + compx4 * 30
        compy4 := compy4 * 30
        randint (dir4, 1, 4)
    end if
    exit when compcount =5
end loop
compcheck:=1
elsif compcheck=1 then
if dir = 1 and compy < 270 and compx < 630 then
        drawfillbox (compx, compy, compx + 30, compy + 60, darkgrey)
        drawbox (compx, compy, compx + 30, compy + 60, black)
        compcount := 1
    elsif dir = 2 and compy > 90 and compx < 630 then
        drawfillbox (compx, compy, compx + 30, compy - 60, darkgrey)
        drawbox (compx, compy, compx + 30, compy - 60, black)
        compcount := 1
    elsif dir = 3 and compx > 390 and compy < 300 then
        drawfillbox (compx, compy, compx - 60, compy + 30, darkgrey)
        drawbox (compx, compy, compx - 60, compy + 30, black)
        compcount := 1
    elsif dir = 4 and compx < 600 and compy < 300 then
        drawfillbox (compx, compy, compx + 60, compy + 30, darkgrey)
        drawbox (compx, compy, compx + 60, compy + 30, black)
        compcount := 1
end if
if dir1 = 1 and compy1 < 240 and compx1 < 630 and whatdotcolor (compx1 + 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 5, compy1 + 35) not= darkgrey and whatdotcolor (compx1 + 5, compy1 + 65) not= darkgrey then %UP
        drawfillbox (compx1, compy1, compx1 + 30, compy1 + 90, darkgrey)
        drawbox (compx1, compy1, compx1 + 30, compy1 + 90, black)
        compcount := 2
    elsif dir1 = 2 and compy1 > 120 and compx1 < 630 and whatdotcolor (compx1 + 5, compy1 - 5) not= darkgrey and whatdotcolor (compx1 + 5, compy1 - 35) not= darkgrey and whatdotcolor (compx1 + 5, compy1 - 65) not= darkgrey then
        %DOWN
        drawfillbox (compx1, compy1, compx1 + 30, compy1 - 90, darkgrey)
        drawbox (compx1, compy1, compx1 + 30, compy1 - 90, 7)
        compcount := 2
    elsif dir1 = 3 and compx1 > 420 and compy1 < 300 and whatdotcolor (compx1 - 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 - 35, compy1 + 5) not= darkgrey and whatdotcolor (compx1 - 65, compy1 + 5) not= darkgrey then
        %LEFT
        drawfillbox (compx1, compy1, compx1 - 90, compy1 + 30, darkgrey)
        drawbox (compx1, compy1, compx1 - 90, compy1 + 30, 7)
        compcount := 2
    elsif dir1 = 4 and compx1 < 570 and compy1 < 300 and whatdotcolor (compx1 + 5, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 35, compy1 + 5) not= darkgrey and whatdotcolor (compx1 + 65, compy1 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx1, compy1, compx1 + 90, compy1 + 30, darkgrey)
        drawbox (compx1, compy1, compx1 + 90, compy1 + 30, 7)
        compcount := 2
end if
if dir2 = 1 and compy2 < 240 and compx2 < 630 and whatdotcolor (compx2 + 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 5, compy2 + 35) not= darkgrey and whatdotcolor (compx2 + 5, compy2 + 65) not= darkgrey then %UP
        drawfillbox (compx2, compy2, compx2 + 30, compy2 + 90, darkgrey)
        drawbox (compx2, compy2, compx2 + 30, compy2 + 90, 7)
        compcount := 3
    elsif dir2 = 2 and compy2 > 120 and compx2 < 630 and whatdotcolor (compx2 + 5, compy2 - 5) not= darkgrey and whatdotcolor (compx2 + 5, compy2 - 35) not= darkgrey and whatdotcolor (compx2 + 5, compy2 - 65) not= darkgrey then
        %DOWN
        drawfillbox (compx2, compy2, compx2 + 30, compy2 - 90, darkgrey)
        drawbox (compx2, compy2, compx2 + 30, compy2 - 90, 7)
        compcount := 3
    elsif dir2 = 3 and compx2 > 420 and compy2 < 300 and whatdotcolor (compx2 - 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 - 35, compy2 + 5) not= darkgrey and whatdotcolor (compx2 - 65, compy2 + 5) not= darkgrey then
        %LEFT
        drawfillbox (compx2, compy2, compx2 - 90, compy2 + 30, darkgrey)
        drawbox (compx2, compy2, compx2 - 90, compy2 + 30, 7)
        compcount := 3
    elsif dir2 = 4 and compx2 < 570 and compy2 < 300 and whatdotcolor (compx2 + 5, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 35, compy2 + 5) not= darkgrey and whatdotcolor (compx2 + 65, compy2 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx2, compy2, compx2 + 90, compy2 + 30, darkgrey)
        drawbox (compx2, compy2, compx2 + 90, compy2 + 30, 7)
        compcount := 3
end if
if dir3 = 1 and compy3 < 210 and compx3 < 630 and whatdotcolor (compx3 + 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 35) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 65) not= darkgrey and whatdotcolor (compx3 + 5, compy3 + 95) not= darkgrey then %UP
        drawfillbox (compx3, compy3, compx3 + 30, compy3 + 120, darkgrey)
        drawbox (compx3, compy3, compx3 + 30, compy3 + 120, 7)
        compcount := 4
    elsif dir3 = 2 and compy3 > 150 and compx3 < 630 and whatdotcolor (compx3 + 5, compy3 - 5) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 35) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 65) not= darkgrey and whatdotcolor (compx3 + 5, compy3 - 95) not= darkgrey then
        %DOWN
        drawfillbox (compx3, compy3, compx3 + 30, compy3 - 120, darkgrey)
        drawbox (compx3, compy3, compx3 + 30, compy3 - 120, 7)
        compcount := 4
    elsif dir3 = 3 and compx3 > 450 and compy3 < 300 and whatdotcolor (compx3 - 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 - 35, compy3 + 5) not= darkgrey and whatdotcolor (compx3 - 65, compy3 + 5) not= darkgrey  and whatdotcolor (compx3 -95, compy3 +5) not= darkgrey then
        %LEFT
        drawfillbox (compx3, compy3, compx3 - 120, compy3 + 30, darkgrey)
        drawbox (compx3, compy3, compx3 - 120, compy3 + 30, 7)
        compcount := 4
    elsif dir3 = 4 and compx3 < 540 and compy3 < 300 and whatdotcolor (compx3 + 5, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 35, compy3 + 5) not= darkgrey and whatdotcolor (compx3 + 65, compy3 + 5) not= darkgrey  and whatdotcolor (compx3 + 95, compy3 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx3, compy3, compx3 + 120, compy3 + 30, darkgrey)
        drawbox (compx3, compy3, compx3 + 120, compy3 + 30, 7)
        compcount := 4
end if
if dir4 = 1 and compy4 < 180 and compx4 < 630 and whatdotcolor (compx4 + 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 35) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 65) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 95) not= darkgrey and whatdotcolor (compx4 + 5, compy4 + 125) not= darkgrey then %UP
        drawfillbox (compx4, compy4, compx4 + 30, compy4 + 150, darkgrey)
        drawbox (compx4, compy4, compx4 + 30, compy4 + 150, 7)
        compcount := 5
    elsif dir4 = 2 and compy4 > 180 and compx4 < 630 and whatdotcolor (compx4 + 5, compy4 - 5) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 35) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 65) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 95) not= darkgrey and whatdotcolor (compx4 + 5, compy4 - 125) not= darkgrey then
        %DOWN
        drawfillbox (compx4, compy4, compx4 + 30, compy4 - 150, darkgrey)
        drawbox (compx4, compy4, compx4 + 30, compy4 - 150, 7)
        compcount := 5
    elsif dir4 = 3 and compx4 > 480 and compy4 < 300 and whatdotcolor (compx4 - 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 - 35, compy4 + 5) not= darkgrey and whatdotcolor (compx4 - 65, compy4 + 5) not= darkgrey  and whatdotcolor (compx4 -95, compy4 +5) not= darkgrey and whatdotcolor (compx4 -125, compy4 +5) not= darkgrey then
        %LEFT
        drawfillbox (compx4, compy4, compx4 - 150, compy4 + 30, darkgrey)
        drawbox (compx4, compy4, compx4 - 150, compy4 + 30, 7)
        compcount := 5
    elsif dir4 = 4 and compx4 < 510 and compy4 < 300 and whatdotcolor (compx4 + 5, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 35, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 65, compy4 + 5) not= darkgrey  and whatdotcolor (compx4 + 95, compy4 + 5) not= darkgrey and whatdotcolor (compx4 + 125, compy4 + 5) not= darkgrey then
        %RIGHT
        drawfillbox (compx4, compy4, compx4 + 150, compy4 + 30, darkgrey)
        drawbox (compx4, compy4, compx4 + 150, compy4 + 30, 7)
        compcount := 5
end if

end if
end comp


proc place
    Pic.Free (patrol)
    patrol := Pic.FileNew ("pboat.gif")
    if pboatrotate = 1 then
        patrol := Pic.Rotate (patrol, 90, -1, -1)
    end if
    Pic.Draw (patrol, x, y, picCopy)
    if pboatcheck = 0 then
        Input.KeyDown (pboatmov)
        if pboatmov (KEY_UP_ARROW) and y < 570 and pboatrotate = 0 then
            y += 30
        elsif pboatmov (KEY_UP_ARROW) and y < 600 and pboatrotate = 1 then
            y += 30
        end if

        if pboatmov (KEY_DOWN_ARROW) and y > 350 and pboatrotate = 0 then
            y -= 30
        elsif pboatmov (KEY_DOWN_ARROW) and y > 350 and pboatrotate = 1 then
            y -= 30
        end if

        if pboatmov (KEY_LEFT_ARROW) and x > 30 and pboatrotate = 0 then
            x -= 30
        elsif pboatmov (KEY_LEFT_ARROW) and x > 30 and pboatrotate = 1 then
            x -= 30
        end if

        if pboatmov (KEY_RIGHT_ARROW) and x < 300 and pboatrotate = 0 then
            x += 30
        elsif pboatmov (KEY_RIGHT_ARROW) and x < 270 and pboatrotate = 1 then
            x += 30
        end if

        if pboatmov (' ') then
            if pboatrotate = 0 and x + 35 < 300 then

                pboatrotate := 1
            elsif pboatrotate = 1 and y + 35 < 570 then

                pboatrotate := 0
            end if
        end if
        if pboatmov (KEY_ENTER) then
           pboatcheck := 1
           subcheck := 1
        end if


    end if

    if pboatcheck = 1 then
       
        sub := Pic.FileNew ("submarine.gif")
        if subrotatecheck = 1 then
            sub := Pic.Rotate (sub, 90, -1, -1)
        end if
        Pic.Draw (sub, subx, suby, picCopy)
        Pic.Free (sub)

    end if
    if subcheck = 1 then

        Input.KeyDown (submov)
        if submov (KEY_UP_ARROW) then
            if subrotatecheck = 0 and whatdotcolor (subx + 5, suby + 95) not= 15 and suby < 540 then
                suby += 30
            elsif subrotatecheck = 1 and whatdotcolor (subx + 5, suby + 35) not= 15 and whatdotcolor (subx + 35, suby + 35) not= 15 and whatdotcolor (subx + 65, suby + 35) not= 15 and suby < 600
                    then
                suby += 30
            end if

        elsif submov (KEY_DOWN_ARROW) and suby > 350 then
            if subrotatecheck = 0 and whatdotcolor (subx + 5, suby - 5) not= 15 then
                suby -= 30
            elsif subrotatecheck = 1 and whatdotcolor (subx + 5, suby - 5) not= 15 and whatdotcolor (subx + 35, suby - 5) not= 15 and whatdotcolor (subx + 65, suby - 5) not= 15 then
                suby -= 30
            end if


        elsif submov (KEY_LEFT_ARROW) and subx > 30 then
            if subrotatecheck = 0 and whatdotcolor (subx - 5, suby + 5) not= 15 and whatdotcolor (subx - 5, suby + 35) not= 15 and whatdotcolor (subx - 5, suby + 65) not= 15 then
                subx -= 30
            elsif subrotatecheck = 1 and whatdotcolor (subx - 5, suby + 5) not= 15 then
                subx -= 30
            end if


        elsif submov (KEY_RIGHT_ARROW) then
            if subrotatecheck = 0 and whatdotcolor (subx + 35, suby + 5) not= 15 and whatdotcolor (subx + 35, suby + 35) not= 15 and whatdotcolor (subx + 35, suby + 65) not= 15 and subx < 300 then
                subx += 30
            elsif subrotatecheck = 1 and whatdotcolor (subx + 95, suby + 5) not= 15 and subx < 240 then
                subx += 30
            end if



        elsif submov (' ') then
            if subrotatecheck = 0 and whatdotcolor (subx + 38, suby + 3) not= 15 and whatdotcolor (subx + 64, suby + 3) not= 15 and subx+89 <330 then

                subrotatecheck := 1
            elsif subrotatecheck = 1 and whatdotcolor (subx + 3, suby + 38) not= 15 and whatdotcolor (subx + 3, suby + 64) not= 15 and suby+95<660 then

                subrotatecheck := 0
            end if
        elsif submov (KEY_ENTER) and subcount = 2 then
           
                sbcheck := 2
                subcheck := 2
             
        end if
   
    end if
    if pboatcheck = 1 then
        subcount := 2
    end if

    if sbcheck >= 2 then
        des := Pic.FileNew ("submarine.gif")
        if desrotatecheck = 1 then
            des := Pic.Rotate (des, 90, -1, -1)
        end if
        Pic.Draw (des, desx, desy, picCopy)
         Pic.Free (des)
    end if
    if subcheck = 2 then

        Input.KeyDown (desmov)
        if desmov (KEY_UP_ARROW) then
            if desrotatecheck = 0 and whatdotcolor (desx + 5, desy + 95) not= 15 and desy < 540 then
                desy += 30
            elsif desrotatecheck = 1 and whatdotcolor (desx + 5, desy + 35) not= 15 and whatdotcolor (desx + 35, desy + 35) not= 15 and whatdotcolor (desx + 65, desy + 35) not= 15 and desy < 600
                    then
                desy += 30
            end if

        elsif desmov (KEY_DOWN_ARROW) and desy > 350 then
            if desrotatecheck = 0 and whatdotcolor (desx + 5, desy - 5) not= 15 then
                desy -= 30
            elsif desrotatecheck = 1 and whatdotcolor (desx + 5, desy - 5) not= 15 and whatdotcolor (desx + 35, desy - 5) not= 15 and whatdotcolor (desx + 65, desy - 5) not= 15 then
                desy -= 30
            end if


        elsif desmov (KEY_LEFT_ARROW) and desx > 30 then
            if desrotatecheck = 0 and whatdotcolor (desx - 5, desy + 5) not= 15 and whatdotcolor (desx - 5, desy + 35) not= 15 and whatdotcolor (desx - 5, desy + 65) not= 15 then
                desx -= 30
            elsif desrotatecheck = 1 and whatdotcolor (desx - 5, desy + 5) not= 15 then
                desx -= 30
            end if


        elsif desmov (KEY_RIGHT_ARROW) then
            if desrotatecheck = 0 and whatdotcolor (desx + 35, desy + 5) not= 15 and whatdotcolor (desx + 35, desy + 35) not= 15 and whatdotcolor (desx + 35, desy + 65) not= 15 and desx < 300 then
                desx += 30
            elsif desrotatecheck = 1 and whatdotcolor (desx + 95, desy + 5) not= 15 and desx < 240 then
                desx += 30
            end if
        elsif desmov (' ') then
            if desrotatecheck = 0 and whatdotcolor (desx + 38, desy + 3) not= 15 and whatdotcolor (desx + 64, desy + 3) not= 15 and desx+89 <330 then

                desrotatecheck := 1
            elsif desrotatecheck = 1 and whatdotcolor (desx + 3, desy + 38) not= 15 and whatdotcolor (desx + 3, desy + 64) not= 15 and desy+95<660 then
                desrotatecheck := 0
            end if
        elsif desmov (KEY_ENTER) and descount = 2 then
            subcheck :=3
            sbcheck:=3
        end if
    end if
    if subcheck= 2 then
        descount := 2
       
    end if

if sbcheck >= 3 then
        bat := Pic.FileNew ("battleship.gif")
        if batrotatecheck = 1 then
            bat := Pic.Rotate (bat, 90, -1, -1)
        end if
        Pic.Draw (bat, batx, baty, picCopy)
         Pic.Free (bat)
    end if
       
    if subcheck = 3 then

        Input.KeyDown (batmov)
        if batmov (KEY_UP_ARROW) then
            if batrotatecheck = 0 and whatdotcolor (batx + 5, baty + 125) not= 15 and baty < 510 then
                baty += 30
            elsif batrotatecheck = 1 and whatdotcolor (batx + 5, baty + 35) not= 15 and whatdotcolor (batx + 35, baty + 35) not= 15 and whatdotcolor (batx + 65, baty + 35) not= 15 and whatdotcolor (batx + 95, baty + 35) not= 15  and baty < 600
                    then
                baty += 30
            end if

        elsif batmov (KEY_DOWN_ARROW) and baty > 350 then
            if batrotatecheck = 0 and whatdotcolor (batx + 5, baty - 5) not= 15 then
                baty -= 30
            elsif batrotatecheck = 1 and whatdotcolor (batx + 5, baty - 5) not= 15 and whatdotcolor (batx + 35, baty - 5) not= 15 and whatdotcolor (batx + 65, baty - 5) not= 15 then
                baty -= 30
            end if


        elsif batmov (KEY_LEFT_ARROW) and batx > 30 then
            if batrotatecheck = 0 and whatdotcolor (batx - 5, baty + 5) not= 15 and whatdotcolor (batx - 5, baty + 35) not= 15 and whatdotcolor (batx - 5, baty + 65) not= 15 and whatdotcolor (batx - 5, baty + 95) not= 15 then
                batx -= 30
            elsif batrotatecheck = 1 and whatdotcolor (batx - 5, baty + 5) not= 15 then
                batx -= 30
            end if


        elsif batmov (KEY_RIGHT_ARROW) then
            if batrotatecheck = 0 and whatdotcolor (batx + 35, baty + 5) not= 15 and whatdotcolor (batx + 35, baty +35) not= 15 and whatdotcolor (batx + 35, baty + 65) not= 15 and whatdotcolor (batx + 35, baty + 95) not= 15 and batx < 300 then
                batx += 30
            elsif batrotatecheck = 1 and whatdotcolor (batx + 125, baty + 5) not= 15 and batx < 210 then
                batx += 30
            end if



        elsif batmov (' ') then
            if batrotatecheck = 0 and whatdotcolor (batx + 38, baty + 3) not= 15 and whatdotcolor (batx + 64, baty + 3) not= 15 and batx+119 <330 then

                batrotatecheck := 1
            elsif batrotatecheck = 1 and whatdotcolor (batx + 3, baty + 38) not= 15 and whatdotcolor (batx + 3, baty + 64) not= 15 and baty+125<660 then

                batrotatecheck := 0
            end if
        elsif batmov (KEY_ENTER) and batcount = 2 then
            batcheck := 2
            sbcheck:=4
            subcheck:=4
        end if
   end if
        if subcheck = 3 then
        batcount := 2
    end if
   
if sbcheck >= 4 then
        ac := Pic.FileNew ("carrier.gif")
        if acrotatecheck = 1 then
            ac := Pic.Rotate (ac, 90, -1, -1)
        end if
        Pic.Draw (ac, acx,acy, picCopy)
         Pic.Free (ac)
    end if
    if subcheck = 4 then

        Input.KeyDown (acmov)
        if acmov (KEY_UP_ARROW) then
            if acrotatecheck = 0 and whatdotcolor (acx + 5, acy + 95) not= 15 and acy < 540 then
                acy += 30
            elsif acrotatecheck = 1 and whatdotcolor (acx + 5, acy + 35) not= 15 and whatdotcolor (acx + 35, acy + 35) not= 15 and whatdotcolor (acx + 65, acy + 35) not= 15 and acy < 600
                    then
                acy += 30
            end if

        elsif acmov (KEY_DOWN_ARROW) and acy > 350 then
            if acrotatecheck = 0 and whatdotcolor (acx + 5, acy - 5) not= 15 then
                acy -= 30
            elsif acrotatecheck = 1 and whatdotcolor (acx + 5, acy - 5) not= 15 and whatdotcolor (acx + 35, acy - 5) not= 15 and whatdotcolor (acx + 65, acy - 5) not= 15 then
                acy -= 30
            end if


        elsif acmov (KEY_LEFT_ARROW) and acx > 30 then
            if acrotatecheck = 0 and whatdotcolor (acx - 5, acy + 5) not= 15 and whatdotcolor (acx - 5, acy + 35) not= 15 and whatdotcolor (acx - 5, acy + 65) not= 15 then
                acx -= 30
            elsif acrotatecheck = 1 and whatdotcolor (acx - 5, acy + 5) not= 15 then
                acx -= 30
            end if


        elsif acmov (KEY_RIGHT_ARROW) then
            if acrotatecheck = 0 and whatdotcolor (acx + 35, acy + 5) not= 15 and whatdotcolor (acx + 35, acy + 35) not= 15 and whatdotcolor (acx + 35, acy + 65) not= 15 and acx < 300 then
                acx += 30
            elsif acrotatecheck = 1 and whatdotcolor (acx + 95, acy + 5) not= 15 and acx < 240 then
                acx += 30
            end if



        elsif acmov (' ') then
            if acrotatecheck = 0 and whatdotcolor (acx + 38, acy + 3) not= 15 and whatdotcolor (acx + 64, acy + 3) not= 15 and acx+149 <330 then

                acrotatecheck := 1
            elsif acrotatecheck = 1 and whatdotcolor (acx + 3, acy + 38) not= 15 and whatdotcolor (acx + 3, acy + 64) not= 15 and acy+155<660 then

                acrotatecheck := 0
            end if
        elsif acmov (KEY_ENTER) and account = 2 then
            subcheck:=5
            guesscheck:=1
            end if
        end if
        if subcheck = 4 then
        account:=2
        end if

end place


proc main
    cls
    grid
    comp
    grid
    gridcheck
    place
    Guess
    check
    draw
    delay (100)
    View.Update
end main

loop

    loop
        main
    end loop
end loop




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
apomb




PostPosted: Thu Dec 17, 2009 9:18 pm   Post subject: RE:Array Help Really Fast Please

do you keep posting the same problem multiple times?
ah, here they are: http://compsci.ca/v3/viewtopic.php?t=23161
and http://compsci.ca/v3/viewtopic.php?t=23163

If you are having problems with the same "battleship" program, try and keep it in one topic, instead of spreading it to three different threads.
ajones88




PostPosted: Thu Dec 17, 2009 9:38 pm   Post subject: Re: RE:Array Help Really Fast Please

apomb @ Thu Dec 17, 2009 9:18 pm wrote:
do you keep posting the same problem multiple times?
ah, here they are: http://compsci.ca/v3/viewtopic.php?t=23161
and http://compsci.ca/v3/viewtopic.php?t=23163

If you are having problems with the same "battleship" program, try and keep it in one topic, instead of spreading it to three different threads.


well, the one with the same title was an accident, and this one is a different problem and i made a new topic because this is due tomorrow, therefore need some help fast.
TheGuardian001




PostPosted: Thu Dec 17, 2009 10:15 pm   Post subject: Re: Array Help Really Fast Please

Making it look like you're spamming won't make us help you any faster.

And your problem is that you are trying to access hx as an array, when you didn't declare it as one.
ajones88




PostPosted: Thu Dec 17, 2009 11:33 pm   Post subject: Re: Array Help Really Fast Please

TheGuardian001 @ Thu Dec 17, 2009 10:15 pm wrote:
Making it look like you're spamming won't make us help you any faster.

And your problem is that you are trying to access hx as an array, when you didn't declare it as one.


WOw, im sorry for bothering you about this, i feel really dumb right now, thanks for the help.
TheGuardian001




PostPosted: Thu Dec 17, 2009 11:56 pm   Post subject: Re: Array Help Really Fast Please

Not a problem. Stupid mistakes happen to everybody. And when they do, you'll rarely find them on your own.
mirhagk




PostPosted: Fri Dec 18, 2009 7:45 am   Post subject: RE:Array Help Really Fast Please

it's true. the worst mistakes are the simplest ones. Every once in a while I replace an x value somewhere with a y-value and then everything doesn't work.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: