Computer Science Canada

help with nibbles-like program

Author:  WhatAmIDoing [ Thu Mar 04, 2004 9:12 am ]
Post subject:  help with nibbles-like program

hey i need some help can anyone help me fix this program
code:

setscreen ("graphics")
var chars : array char of boolean
var x, y, a, b, count, c : int
count := 15
x := maxx div 2
y := maxy div 2

procedure box
    randint (a, 20, maxx - 20)
    randint (b, 20, maxy - 20)
    drawfillbox (a, b, a + 20, b + 20, green)
end box

loop
    drawfillbox (0, 0, maxx, maxy, black)
    box
    loop
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            y += 10
        elsif chars (KEY_DOWN_ARROW) then
            y -= 10
        elsif chars (KEY_LEFT_ARROW) then
            x -= 10
        elsif chars (KEY_RIGHT_ARROW) then
            x += 10
        end if
        if x > a and x < a + 20 and y > b and y < b + 20 then
            drawfillbox (a, b, a + 20, b + 20, white)
            count += 10
            exit
        end if
        randint (c, 0, 50)
        drawfilloval (x, y, 5, 5, c)
        drawfillbox (a, b, a + 20, b + 20, green)
        drawfilloval (x, y + count, 10, 10, black)
        drawfilloval (x, y - count, 10, 10, black)
        drawfilloval (x + count, y, 10, 10, black)
        drawfilloval (x - count, y, 10, 10, black)
        delay (20)
    end loop
end loop


mod edit: please post in the right section next time, and please use a better topic name (and if at all possible, be more descriptive about your problem).

Author:  McKenzie [ Thu Mar 04, 2004 11:28 am ]
Post subject: 

You are assuming that the snake travels in a straight line. You need to keep track of each segment of the snake in an array then you can draw and erase them one at a time.


: