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

Username:   Password: 
 RegisterRegister   
 Help again...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lebigcheese




PostPosted: Sun Jan 09, 2005 2:32 pm   Post subject: Help again...

Hi... it's me again...i got the snake to build up whenever it eats the food However i can't manage to erase some of the left over tail...plx help..this is what i hav so far...

code:
setscreen ("offscreenonly,title:Snake,graphics:300;300")

var lengtx : int := 0
var lengty : int := 0
var x, y : int := 28
var die : int := 0

%   drawfillbox (x, y, x2 + 9, y2 + 9, clr)

var key : array char of boolean
var move : int := 0
var dir : string := "up"

proc maze2
    drawline (9, 9, 9, 290, 7)
    drawline (9, 9, 290, 9, 7)
    drawline (290, 9, 290, 290, 7)
    drawline (9, 290, 290, 290, 7)
end maze2

maze2

var foodx, foody, food : int := 0

proc up
    y += 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "up"
end up

proc down
    y -= 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "down"
end down

proc left
    x -= 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "left"
end left

proc right
    x += 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "right"
end right

var tail : array 1 .. 200, 1 .. 2 of int
var i := 0
var snake_length : int := 4

var delx, dely : array 1 .. 1000 of int
var count : int := 0

loop
    count += 1


    delx (count) := x
    dely (count) := y

    drawfilloval (x, y, 7, 7, 0)

    if dir = "up" then
        drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif dir = "down" then
        drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif dir = "right" then
        drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif dir = "left" then
        drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    end if

    die := 0

    if food = 0 then
        if snake_length not= 0 and whatdotcolor (foodx, foody) not= 1 then
            drawfilloval (foodx, foody, 7, 7, 0)
        end if
        loop
            randint (foodx, 20, 270)
            randint (foody, 20, 270)
            if foodx mod 14 = 0 then
                if foody mod 14 = 0 then
                    if whatdotcolor (foodx, foody) = 0 then
                        if x + 10 <= foodx and x >= foodx and y + 10 <= foody and y + 10 >= foody then
                            drawfilloval (foodx, foody, 7, 7, 0)
                            exit
                        else
                            drawfilloval (foodx, foody, 7, 7, 7)
                            exit
                        end if
                    end if
                end if
            end if
        end loop
        food := 1
    end if



    Input.KeyDown (key)

    if key (KEY_UP_ARROW) and dir not= "down" then     %up arrow
        up
        %drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif key (KEY_UP_ARROW) and dir = "down" then
        down
        %drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif key (KEY_DOWN_ARROW) and dir not= "up" then     %down
        down
        %drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif key (KEY_DOWN_ARROW) and dir = "up" then
        up
        %drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif key (KEY_LEFT_ARROW) and dir not= "right" then                      %left
        left
        %drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_LEFT_ARROW) and dir = "right" then
        right
        %drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_RIGHT_ARROW) and dir not= "left" then              %right
        right
        %drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_RIGHT_ARROW) and dir = "left" then
        left
        %drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    else
        if dir = "down" then
            down
            %drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
        elsif dir = "up" then
            up
            %drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 7)
        elsif dir = "right" then
            right
            %drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
        elsif dir = "left" then
            left
            %drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
        end if
    end if

    exit when x < 10| x > 285| y < 10| y > 285

    View.Update

    if whatdotcolor (foodx, foody) = 1| whatdotcolor (foodx + 7, foody + 7) = 1 then
        food := 0
        snake_length += 1
    end if

    maze2

    delay (100)

end loop

Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sun Jan 09, 2005 5:58 pm   Post subject: (No subject)

i remember your code from a few posts before and i think to make your life easier u shouldn't have changed the snake to be an oval from a square. when it is a square it doesn't leave anything (tail). but when its a oval it does. if u really want it to be an oval then u will have to make a grid to line things up. i think there might be a tutorial on how to do this. good luck Smile
cool dude




PostPosted: Sun Jan 09, 2005 6:02 pm   Post subject: Re: Help again...

lebigcheese wrote:
Hi... it's me again...i got the snake to build up whenever it eats the food


it doesn't build up everytime u eat the food
Cervantes




PostPosted: Sun Jan 09, 2005 6:09 pm   Post subject: (No subject)

Maybe it's just me, but I don't see the snake growing in size. Thinking
Edit: Oh. Apparently, it's not just me.
lebigcheese




PostPosted: Mon Jan 10, 2005 10:08 am   Post subject: (No subject)

my friend helped me with this one...wuts wrong wit it?

code:
setscreen ("offscreenonly,title:Snake,graphics:300;300")

var lengtx : int := 0
var lengty : int := 0
var tail : array 1 .. 200, 1 .. 2 of int
var tail_length : int := 1
tail (1, 1) := 20
tail (1, 2) := 20

proc snake (clr : int)
    for draw_snake : 1 .. tail_length
        drawfillbox (tail (draw_snake, 1), tail (draw_snake, 2), tail (draw_snake, 1) + 9, tail (draw_snake, 2) + 9, clr)
    end for
end snake

var key : array char of boolean
var move : int := 0
var dir : string := "up"

proc maze2
    drawline (9, 9, 9, 290, 7)
    drawline (9, 9, 290, 9, 7)
    drawline (290, 9, 290, 290, 7)
    drawline (9, 290, 290, 290, 7)
end maze2

maze2

var foodx, foody, food : int := 0

proc up
    for tail_move : tail_length .. 1
        if tail_length not= 1 then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        else
            tail (tail_length, 2) += 10
        end if
    end for
    dir := "up"
end up

proc down
    for tail_move : tail_length .. 1
        if tail_length not= 1 then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        else
            tail (tail_move, 2) -= 10
        end if
    end for
    dir := "down"
end down

proc left
    for tail_move : tail_length .. 1
        if tail_length not= 1 then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        else
            tail (tail_move, 1) -= 10
        end if
    end for
    dir := "left"
end left

proc right
    for tail_move : tail_length .. 1
        if tail_length not= 1 then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        else
            tail (tail_move, 1) += 10
        end if
    end for
    dir := "right"
end right

function finish : int
    var done : int := 0
    for check_done : 1 .. tail_length
        if tail (check_done, 1) <= 9| tail (check_done, 1) + 9 >= 290 then
            done := 1
        elsif tail (check_done, 2) <= 9| tail (check_done, 2) + 9 >= 290 then
            done := 1
        end if
    end for
    result done
end finish

loop
    if food = 0 then %checks if there is food on screen
        loop
            randint (foodx, 20, 270)
            randint (foody, 20, 270)
            if intstr (foodx) (*) = "0" then
                if intstr (foody) (*) = "0" then
                    if whatdotcolor (foodx, foody) = 0 then
                        drawfillbox (foodx, foody, foodx + 9, foody + 9, 7)
                        exit
                    end if
                end if
            end if
        end loop
        food := 1
    end if

    snake (0)

    Input.KeyDown (key)

    if key (KEY_UP_ARROW) then  %up arrow
        if dir not= "down" then
            up
        else
            down
        end if
    elsif key (KEY_DOWN_ARROW) then          %down
        if dir not= "up" then
            down
        else
            up
        end if
    elsif key (KEY_LEFT_ARROW) then                  %left
        if dir not= "right" then
            left
        else
            right
        end if
    elsif key (KEY_RIGHT_ARROW) then          %right
        if dir not= "left" then
            right
        else
            left
        end if
    else
        if dir = "up" then
            up
        elsif dir = "down" then
            down
        elsif dir = "left" then
            left
        elsif dir = "right" then
            right
        end if
    end if

    snake (1)

    exit when finish = 1



    if whatdotcolor (foodx, foody) = 1 then
        drawfillbox (foodx, foody, foodx + 9, foody + 9, 0)
        food := 0
        tail_length += 1
        if dir = "up" then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2) - 10
        elsif dir = "down" then
            tail (tail_length, 1) := tail (tail_length - 1, 1)
            tail (tail_length, 2) := tail (tail_length - 1, 2) + 10
        elsif dir = "left" then
            tail (tail_length, 1) := tail (tail_length - 1, 1) + 10
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        elsif dir = "right" then
            tail (tail_length, 1) := tail (tail_length - 1, 1) - 10
            tail (tail_length, 2) := tail (tail_length - 1, 2)
        end if
    end if

    View.Update

    delay (50)

end loop

maze2

lebigcheese




PostPosted: Mon Jan 10, 2005 10:09 am   Post subject: (No subject)

if that doesnt work i got the oval thing to work...except the streaks r still there Confused

code:
setscreen ("offscreenonly,title:Snake,graphics:300;300")

var lengtx : int := 0
var lengty : int := 0
var x, y : int := 28
var die : int := 0

%   drawfillbox (x, y, x2 + 9, y2 + 9, clr)

var key : array char of boolean
var move : int := 0
var dir : string := "up"

proc maze2
    drawline (9, 9, 9, 290, 7)
    drawline (9, 9, 290, 9, 7)
    drawline (290, 9, 290, 290, 7)
    drawline (9, 290, 290, 290, 7)
end maze2

maze2

var foodx, foody, food : int := 0

proc up
    y += 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "up"
end up

proc down
    y -= 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "down"
end down

proc left
    x -= 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "left"
end left

proc right
    x += 14
    if whatdotcolor (x, y) not= 1 then
        drawfilloval (x, y, 7, 7, 1)
    else
        die := 1
    end if
    dir := "right"
end right

var tail : array 1 .. 200, 1 .. 2 of int
var i := 0
var snake_length : int := 4

var delx, dely : array 1 .. 1000 of int
var count : int := 0

loop
    count += 1


    delx (count) := x
    dely (count) := y

    %drawfilloval (x, y, 7, 7, 0)

    if dir = "up" then
        drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif dir = "down" then
        drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif dir = "right" then
        drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif dir = "left" then
        drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    end if

    die := 0

    if food = 0 then
        if snake_length not= 0 and whatdotcolor (foodx, foody) not= 1 then
            drawfilloval (foodx, foody, 7, 7, 0)
        end if
        loop
            randint (foodx, 20, 270)
            randint (foody, 20, 270)
            if foodx mod 14 = 0 then
                if foody mod 14 = 0 then
                    if whatdotcolor (foodx, foody) = 0 then
                        if x + 10 <= foodx and x >= foodx and y + 10 <= foody and y + 10 >= foody then
                            drawfilloval (foodx, foody, 7, 7, 0)
                            exit
                        else
                            drawfilloval (foodx, foody, 7, 7, 7)
                            exit
                        end if
                    end if
                end if
            end if
        end loop
        food := 1
    end if



    Input.KeyDown (key)

    if key (KEY_UP_ARROW) and dir not= "down" then     %up arrow
        up
        drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif key (KEY_UP_ARROW) and dir = "down" then
        down
        drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif key (KEY_DOWN_ARROW) and dir not= "up" then     %down
        down
        drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
    elsif key (KEY_DOWN_ARROW) and dir = "up" then
        up
        drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
    elsif key (KEY_LEFT_ARROW) and dir not= "right" then                      %left
        left
        drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_LEFT_ARROW) and dir = "right" then
        right
        drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_RIGHT_ARROW) and dir not= "left" then              %right
        right
        drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
    elsif key (KEY_RIGHT_ARROW) and dir = "left" then
        left
        drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
    else
        if dir = "down" then
            down
            drawfilloval (delx (count), dely (count) + (snake_length * 14), 7, 7, 0)
        elsif dir = "up" then
            up
            drawfilloval (delx (count), dely (count) - (snake_length * 14), 7, 7, 0)
        elsif dir = "right" then
            right
            drawfilloval (delx (count) - (snake_length * 14), dely (count), 7, 7, 0)
        elsif dir = "left" then
            left
            drawfilloval (delx (count) + (snake_length * 14), dely (count), 7, 7, 0)
        end if
    end if

    exit when x < 10| x > 285| y < 10| y > 285

    View.Update

    if whatdotcolor (foodx, foody) = 1| whatdotcolor (foodx + 7, foody + 7) = 1 then
        food := 0
        snake_length += 1
    end if

    maze2

    delay (100)

end loop
scottyrush13




PostPosted: Mon Jan 10, 2005 9:12 pm   Post subject: (No subject)

ok for serious buddy, everybody here is more than happy to help you, but when you continually post HUGE codes it makes it hard and annoying. if you would direct your attention towards the submit button at the bottom of the page when you are posting a reply you will notice a preview button to the left of it, and a little north-west, there is a button that says "Add an Attachment". Not only does adding an attachment instead of putting a long code make the page look better, and easier to read, it will make people want to answer your questions more.
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: