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

Username:   Password: 
 RegisterRegister   
 snake game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Fri Apr 09, 2004 6:30 pm   Post subject: snake game

here's a snake game i made, choose a difficulty, the higher the difficulty the more points youll get... ill post the source later cuz there are some members that like to alter the source to get high scores.... *cough*short1*/cough*

-zylum



snake.zip
 Description:

Download
 Filename:  snake.zip
 Filesize:  275.34 KB
 Downloaded:  1125 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Fri Apr 09, 2004 6:56 pm   Post subject: (No subject)

I got 200 using level 5
Tony




PostPosted: Fri Apr 09, 2004 9:24 pm   Post subject: (No subject)

looks nice and simple Very Happy it's just a bit hard to turn Laughing

oh yeah, I got to 350 or something Confused might have been more, there's no pause when game ends
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
guruguru




PostPosted: Fri Apr 09, 2004 11:42 pm   Post subject: (No subject)

Good job. Works very well. Like it a lot. One suggestion is to have a game over scene where teh snake blows up, it tells u ure score, and then asks if u want to continue. Great job.
zylum




PostPosted: Sat Apr 10, 2004 12:58 pm   Post subject: (No subject)

im glad you guys like it... btw the game keeps track of your highscore so just start a new game and it will be above your current score.

i got something like 1240 on level 4 and like 850 on level 5 so try and beat that! Laughing

ill post the source later tonight Wink
white_dragon




PostPosted: Sat Apr 10, 2004 1:29 pm   Post subject: (No subject)

har har har! i got soooooooooooooo close to zylum's score!!!!!!!!!! i was off by bout hundred points on lvl 4!!!!!!!! grrrrrrrrrrrrrrrrrrrrrrrrrrrrr Evil or Very Mad Evil or Very Mad
zylum




PostPosted: Sun Apr 11, 2004 1:55 pm   Post subject: (No subject)

anyways, here's the source for whoever's interested


snake.t
 Description:

Download
 Filename:  snake.t
 Filesize:  3.98 KB
 Downloaded:  557 Time(s)

josh




PostPosted: Mon Apr 12, 2004 5:46 pm   Post subject: (No subject)

this is a really neat game. It is addictive. Kudos.
Sponsor
Sponsor
Sponsor
sponsor
valor




PostPosted: Mon Apr 19, 2004 8:05 pm   Post subject: (No subject)

cool game i got 400 and something anyway...i found that the controls were a little sticky might just be my computer though. but i doubt it
vorl0n




PostPosted: Thu Sep 20, 2007 10:32 am   Post subject: RE:snake game

Amazing, can someone paste the source here, i have problems with downloading files atm.

thanks
Dan




PostPosted: Thu Sep 20, 2007 10:47 am   Post subject: Re: snake game

This topic is a bit old, it is from 2004.

Here is the code any how tho:

Turing:

setscreen ("graphics:320;350,nooffscreenonly,nobuttonbar")

type snakeCoords :
    record
        x : int
        y : int
    end record

type snakeData :
    record
        dx : int
        dy : int
        speed : int
        clr : int
    end record

type gridData :
    record
        size : int
        width : int
        clr : int
    end record

const foodClr := RGB.AddColor (0.9, 0.1, 0.1)

var grdData : gridData
grdData.size := 30
grdData.width := 10
grdData.clr := RGB.AddColor (0.2, 0.9, 0.2)

var grid : array 1 .. grdData.size, 1 .. grdData.size of int
var snake : flexible array 1 .. 5 of snakeCoords
var snkData : snakeData
var keysDown : array char of boolean
var score, highScore, scoreInc : int := 0
var foodx, foody : int
snkData.clr := RGB.AddColor (0.3, 0.7, 0.3)


proc resetData
    cls
    var temp : int
    score := 0

    snkData.dx := 0
    snkData.dy := -1

    setscreen ("graphics:320;350,nooffscreenonly,nobuttonbar")
    put "what is the difficulty? (1-5)"
    get temp
    cls
    locate (maxrow div 2, maxcol div 2)
    put "3"
    delay (1000)
    cls
    locate (maxrow div 2, maxcol div 2)
    put "2"
    delay (1000)
    cls
    locate (maxrow div 2, maxcol div 2)
    put "1"
    delay (1000)
    cls
    setscreen ("graphics:320;350,offscreenonly,nobuttonbar")
    cls

    if temp > 5 then
        temp := 5
    elsif temp < 1 then
        temp := 1
    end if

    scoreInc := temp ** 2

    snkData.speed := (6 - temp) * 10 + 10

    new snake, 5

    for i : 1 .. upper (snake)
        snake (i).x := grdData.size div 2
        snake (i).y := grdData.size
    end for
end resetData

proc moveFood
    var done : boolean
    loop
        done := true
        foodx := Rand.Int (1, grdData.size)
        foody := Rand.Int (1, grdData.size)
        for i : 1 .. upper (snake)
            if snake (i).x = foodx and snake (i).y = foody then
                done := false
            end if
        end for
        exit when done = true
    end loop
end moveFood

proc moveSnake
    var tempx, tempy : int
    if snake (1).x = foodx and snake (1).y = foody then
        score += scoreInc
        moveFood
        new snake, upper (snake) + 1
    end if
    tempx := snake (1).x
    tempy := snake (1).y
    for decreasing i : upper (snake) .. 2
        snake (i).x := snake (i - 1).x
        snake (i).y := snake (i - 1).y
    end for
    snake (1).x := tempx + snkData.dx
    snake (1).y := tempy + snkData.dy
end moveSnake

proc updateSnakeData
    Input.KeyDown (keysDown)
    if keysDown (KEY_RIGHT_ARROW) and snkData.dx not= -1 then
        snkData.dx := 1
        snkData.dy := 0
    elsif keysDown (KEY_LEFT_ARROW) and snkData.dx not= 1 then
        snkData.dx := -1
        snkData.dy := 0
    elsif keysDown (KEY_UP_ARROW) and snkData.dy not= -1 then
        snkData.dx := 0
        snkData.dy := 1
    elsif keysDown (KEY_DOWN_ARROW) and snkData.dy not= 1 then
        snkData.dx := 0
        snkData.dy := -1
    end if
end updateSnakeData

proc drawGrid
    drawfillbox (grdData.width, grdData.width, grdData.size * grdData.width + grdData.width, grdData.size * grdData.width + grdData.width, grdData.clr)
    drawfillbox (foodx * grdData.width, foody * grdData.width, foodx * grdData.width + grdData.width, foody * grdData.width + grdData.width, foodClr)
    for i : 1 .. upper (snake)
        drawfillbox (snake (i).x * grdData.width, snake (i).y * grdData.width, snake (i).x * grdData.width + grdData.width, snake (i).y * grdData.width + grdData.width, snkData.clr)
    end for
end drawGrid

proc checkIfDead
    for i : 2 .. upper (snake)
        if (snake (1).x = snake (i).x and snake (1).y = snake (i).y) or snake (1).x < 1 or snake (1).x > grdData.size or snake (1).y < 1 or snake (1).y > grdData.size then
            if score > highScore then
                highScore := score
            end if
            resetData
            moveFood
            return
        end if
    end for
end checkIfDead

resetData
moveFood
loop
    updateSnakeData
    moveSnake
    drawGrid
    checkIfDead
    locate (1, 1)
    put "HIGH:  ", highScore
    put "SCORE: ", score
    View.Update
    delay (snkData.speed)
    cls
end loop



Note: this is not my code and i was no way inlvoed in making it.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
petree08




PostPosted: Thu Sep 20, 2007 5:34 pm   Post subject: RE:snake game

yeah this is an old post, still its kinda neat. mind you theres been A LOT cooler stuff you could have pulled up. still its nice to see people look that far back lol.
allrace1337




PostPosted: Thu Sep 20, 2007 9:01 pm   Post subject: RE:snake game

Thanks for sharing! Now I have something to do in class... it is so boring, we're still learning about var and if stuff
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: