
-----------------------------------
equs
Tue May 18, 2004 9:40 pm

Snake
-----------------------------------
hi i need some help with my program. The snake only grows when you clikc in the opposite direction its going in and i also want to make food grow afteryou collect good food, and this food is that when you collect it you die. PLease help me thx. 

var choice : string (1)
var chars : array char of boolean
var cellsize := 16
var lsnake := 3
var count := 1
var limit := 400 div cellsize
var delaytime := 80
var points := 0
var ate := false
var colorfood := black
var colorsnake := 7
var temprow, tempcol := 0
var leftright, updown := 0
var trigger := false
var trig3 := false
type coor :
    record
        row, col : int
    end record
var snake : flexible array 1 .. lsnake of coor

proc drawboard
    drawbox (0, 0, maxx, maxy, 7)
    for i : 1 .. limit
        drawline (i * cellsize, 0, i * cellsize, maxy, 7)
        drawline (0, i * cellsize, maxx, i * cellsize, 7)
    end for
end drawboard

proc drawcell (col, row, clr : int)
    var temprow1 := row - 1
    var tempcol1 := col - 1
    drawfillbox (temprow1 * cellsize, tempcol1 * cellsize, row * cellsize, col * cellsize, clr)
end drawcell

proc clear
    updown := 0
    leftright := 0
end clear

proc checkfood (rownum, colnum : int)
    var center := cellsize div 2
    if View.WhatDotColor (colnum * cellsize - center, rownum * cellsize - center) = colorfood then
        points += 1
        ate := false
        trig3 := true
    elsif View.WhatDotColor (colnum * cellsize - center, rownum * cellsize - center) = colorsnake then
        trigger := true
    end if

end checkfood

proc movement
    if updown = 1 then
        checkfood (snake (lsnake).row + 1, snake (lsnake).col)
        snake (lsnake).row += 1
    elsif updown = 2 then
        checkfood (snake (lsnake).row - 1, snake (lsnake).col)
        snake (lsnake).row -= 1
    elsif leftright = 1 then
        checkfood (snake (lsnake).row, snake (lsnake).col - 1)
        snake (lsnake).col -= 1
    elsif leftright = 2 then
        checkfood (snake (lsnake).row, snake (lsnake).col + 1)
        snake (lsnake).col += 1
    end if
end movement

proc food
    var count := 0
    if ate = false then
        loop
            loop
                tempcol := Rand.Int (1, limit)
                for i : 1 .. lsnake
                    if tempcol not= snake (i).col then
                        count += 1
                    end if
                end for
                exit when count = lsnake
                count := 0
            end loop
            temprow := Rand.Int (1, limit)
            count := 0
            for i : 1 .. lsnake
                if temprow not= snake (i).row then
                    count += 1
                end if
            end for
            exit when count = lsnake
        end loop
        ate := true
    end if
end food

var tlen, trow, tcol := 0

for i : 1 .. lsnake
    snake (i).row := limit div 2
    snake (i).col := limit div 2
end for

var trig2 := true

loop
    tlen := lsnake
    trow := snake (lsnake).row
    tcol := snake (lsnake).col

    if points mod 5 = 0 and points not= 0 then
        if trig2 = false then
            lsnake += 1
            new snake, lsnake
            trig2 := true
        elsif trig3 = true then
            trig2 := false
            trig3 := false
        end if
    end if



    snake (lsnake).row := trow
    snake (lsnake).col := tcol

    Input.Flush
    Input.KeyDown (chars)
    for i : 1 .. lsnake - 1
        snake (i).row := snake (i + 1).row
        snake (i).col := snake (i + 1).col
    end for

    if snake (lsnake).row >= 0 and snake (lsnake).row = 0 and snake (lsnake).col 