
-----------------------------------
PaPaJi
Tue May 13, 2008 7:41 am

I need help with snake game!
-----------------------------------
here is the code, i am having trouble with getting the game to end when the snake hits itself
if someone could type the code that would work with my program, I would greatly appreciate it
thanks




import GUI
var name : string
var LEFT_ARROW, RIGHT_ARROW, DOWN_ARROW, UP_ARROW : string
var ss1, ss2 : int
var x1, y1 : int := 300
var N, E, S, W : int := 0
var response : string
var timerunning : int := 0
var counter : int := 0
var score : int := 0
var level : string

LEFT_ARROW := chr (203)
RIGHT_ARROW := chr (205)
UP_ARROW := chr (200)
DOWN_ARROW := chr (208)
% The introduction
put "Welcome to Humza's Personal Snake Game!"
delay (2000)
put "What is your name?"
get name %user enters his or hers name
put "Thank you for choosing to play Humza's game, ", name
delay (1000)
cls
put name, " ,please enter the level you would like to play at (1-3)"
get level % lets the user enter the level they want to play
if level > "3" then
    level := "3"
elsif level  x1 and ss1 - 10 < x1 and y1 > ss2 - 10 and y1 < ss2 + 10 then
            drawfilloval (x1, y1, 5, 5, green) % the apple goes away into the background
            randint (x1, 10, maxx - 10) % places the new snake in random place
            randint (y1, 10, maxy - 10)
            delay (5)
            drawfilloval (x1, y1, 5, 5, brightred)
            counter := counter + 1
            % the below code adds up the score
            if level = "1" then
                score := score + 40
            elsif level = "2" then
                score := score + 80
            elsif level = "3" then
                score := score + 120
            end if
        end if
        % the below code counts the time
        timerunning := Time.Elapsed
        if timerunning < 10000 then
            score := score + 2000
        elsif timerunning > 50000 then
            score := score + 4000
        elsif timerunning > 100000 then
            score := score + 6000
        elsif timerunning > 200000 then
            score := score + 8000
        elsif timerunning > 400000 then
            score := score + 10000
        end if
        % below code ends the game when the snake hits the borders
        if ss1 >= maxx - 10 or ss1 < 10 or ss2 >= maxy - 10 or ss2 < 10 then
        var font14 := Font.New("Impact :20")
        var text14 := "Game Over"
        var width14 := Font.Width (text14, font14)
        Font.Draw (text14, 230, 230, font14, red)
            exit
        end if
    end loop
    delay(1000)
    % below code is the conclusion of the program and tallies up the persons score
    cls
    put ""
    put "You ate ", counter, " apples"
    put ""
    put "Your time taken in seconds was ", timerunning div 1000
    put "You scored, ", score, ", ", name, "!"
    put "Thank you for playing Humza's game! He greatly appreciates it"
end game
% below code gets the buttons before the game starts
var button1 : int := GUI.CreateButton (230, 1, 200, "Play Game", game)
procedure instructions
    colourback (green)
    color (white)
    locate (2, 1)
    % below are the instructions of the game when the user clicks instructions
    put "*********************************Instructions*********************************"
    put "1. Use your arrow keys to move the snake."
    put "2. Try to get the apples to make the snake grow."
    put "3. Use P to pause the game."
    put "4. If you have paused the game, then use the arrows keys to resume."
    put "5. Try to get the apples to increase your score."
    put "6. Try not to collide with the wall or the body of the snake."
    % below ends everything
end instructions
var button2 : int := GUI.CreateButton (230, 380, 200, "Instructions", instructions)
loop
    exit when GUI.ProcessEvent
end loop

-----------------------------------
S_Grimm
Tue May 13, 2008 11:35 am

RE:I need help with snake game!
-----------------------------------
try whatdotcolor

-----------------------------------
Asherel
Tue May 13, 2008 12:02 pm

RE:I need help with snake game!
-----------------------------------
I believe you will need to compare the ss1 value to see if it equals the end of your snake. If it does then.


exit

