Snake: Difference between revisions
Content added Content deleted
Wiredsister (talk | contribs) (Adding an example of Snake in FSharp) |
m (Craft Basic moved to the BASIC section.) |
||
Line 1,154: | Line 1,154: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|Craft Basic}}=== |
|||
[[File:Craft Basic Snake.png|right]] |
|||
<syntaxhighlight lang="basic">rem Snake example game for Craft Basic |
|||
rem by Gemino Smothers 2022 |
|||
rem www.lucidapogee.com |
|||
define gfxx = 330, gfxy = 296 |
|||
define upkey = 0, rightkey = 0, downkey = 0, leftkey = 0, esckey = 0 |
|||
define speed = 0, delay = 0, score = 0, game = 1 |
|||
define maxsize = 1000, size = 9, direction = int(rnd * 4) + 1 |
|||
define rx = int(rnd * (gfxx - 24)) + 12 |
|||
define ry = int(rnd * (gfxy - 40)) + 25 |
|||
dim sx[maxsize] |
|||
dim sy[maxsize] |
|||
let sx[0] = gfxx / 2 |
|||
let sy[0] = gfxy / 2 |
|||
title "Snake!" |
|||
resize 0, 0, gfxx + 10, gfxy + 56 |
|||
center |
|||
fill on |
|||
bgcolor 128, 64, 0 |
|||
cls |
|||
alert "Snake! by Gemino Smothers 2022" |
|||
alert "Get the gray little rodents and avoid hitting yourself or walls." |
|||
alert "Use arrow keys to move. Esc to exit." |
|||
input "Enter game speed between 0 to 100+", speed |
|||
fgcolor 0, 80, 0 |
|||
rect 0, 0, gfxx, gfxy |
|||
do |
|||
button upkey, 38 |
|||
button rightkey, 39 |
|||
button downkey, 40 |
|||
button leftkey, 37 |
|||
button esckey, 27 |
|||
if upkey = 1 and direction <> 3 then |
|||
let direction = 1 |
|||
endif |
|||
if rightkey = 1 and direction <> 4 then |
|||
let direction = 2 |
|||
endif |
|||
if downkey = 1 and direction <> 1 then |
|||
let direction = 3 |
|||
endif |
|||
if leftkey = 1 and direction <> 2 then |
|||
let direction = 4 |
|||
endif |
|||
fgcolor 0, 80, 0 |
|||
oval sx[size], sy[size], 15, 15 |
|||
let i = size + 1 |
|||
do |
|||
let i = i - 1 |
|||
let c = i - 1 |
|||
if sx[0] = sx[i] and sy[0] = sy[i] = 1 then |
|||
let game = 0 |
|||
endif |
|||
let sx[i] = sx[c] |
|||
let sy[i] = sy[c] |
|||
fgcolor 0, 255, 0 |
|||
oval sx[i], sy[i], 15, 15 |
|||
loop i > 1 |
|||
fgcolor 0, 0, 255 |
|||
oval sx[0] + 5, sy[0] + 5, 3, 3 |
|||
oval sx[0] + 9, sy[0] + 5, 3, 3 |
|||
if direction = 1 then |
|||
let sy[0] = sy[0] - 15 |
|||
endif |
|||
if direction = 2 then |
|||
let sx[0] = sx[0] + 15 |
|||
endif |
|||
if direction = 3 then |
|||
let sy[0] = sy[0] + 15 |
|||
endif |
|||
if direction = 4 then |
|||
let sx[0] = sx[0] - 15 |
|||
endif |
|||
if sx[0] <= -10 or sx[0] >= gfxx or sy[0] <= -10 or sy[0] >= gfxy = 1 then |
|||
let game = 0 |
|||
endif |
|||
if sx[0] + 15 >= rx and sx[0] <= rx + 15 and sy[0] + 15 >= ry and sy[0] <= ry + 15 = 1 then |
|||
playwave "examples\tada.wav" |
|||
fgcolor 0, 80, 0 |
|||
rect 0, 0, gfxx, gfxy |
|||
let rx = int(rnd * (gfxx - 24)) + 12 |
|||
let ry = int(rnd * (gfxy - 40)) + 25 |
|||
let size = size + 3 |
|||
let score = score + 1 |
|||
endif |
|||
fgcolor 100,100,100 |
|||
oval rx, ry, 15, 15 |
|||
fgcolor 255, 0, 0 |
|||
oval rx + 5, ry + 5, 3, 3 |
|||
oval rx + 9, ry + 5, 3, 3 |
|||
fgcolor 255, 255, 0 |
|||
cursor 1, 1 |
|||
print "Score: ", score |
|||
let delay = clock |
|||
do |
|||
wait |
|||
loop clock < delay + speed |
|||
loop esckey <> 1 and game = 1 |
|||
playwave "examples\boom.wav" |
|||
alert "Game over! Score: ", score |
|||
end</syntaxhighlight> |
|||
==={{header|FreeBASIC}}=== |
==={{header|FreeBASIC}}=== |
||
Line 1,669: | Line 1,837: | ||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Craft Basic}}== |
|||
[[File:Craft Basic Snake.png|right]] |
|||
<syntaxhighlight lang="basic">rem Snake example game for Craft Basic |
|||
rem by Gemino Smothers 2022 |
|||
rem www.lucidapogee.com |
|||
define gfxx = 330, gfxy = 296 |
|||
define upkey = 0, rightkey = 0, downkey = 0, leftkey = 0, esckey = 0 |
|||
define speed = 0, delay = 0, score = 0, game = 1 |
|||
define maxsize = 1000, size = 9, direction = int(rnd * 4) + 1 |
|||
define rx = int(rnd * (gfxx - 24)) + 12 |
|||
define ry = int(rnd * (gfxy - 40)) + 25 |
|||
dim sx[maxsize] |
|||
dim sy[maxsize] |
|||
let sx[0] = gfxx / 2 |
|||
let sy[0] = gfxy / 2 |
|||
title "Snake!" |
|||
resize 0, 0, gfxx + 10, gfxy + 56 |
|||
center |
|||
fill on |
|||
bgcolor 128, 64, 0 |
|||
cls |
|||
alert "Snake! by Gemino Smothers 2022" |
|||
alert "Get the gray little rodents and avoid hitting yourself or walls." |
|||
alert "Use arrow keys to move. Esc to exit." |
|||
input "Enter game speed between 0 to 100+", speed |
|||
fgcolor 0, 80, 0 |
|||
rect 0, 0, gfxx, gfxy |
|||
do |
|||
button upkey, 38 |
|||
button rightkey, 39 |
|||
button downkey, 40 |
|||
button leftkey, 37 |
|||
button esckey, 27 |
|||
if upkey = 1 and direction <> 3 then |
|||
let direction = 1 |
|||
endif |
|||
if rightkey = 1 and direction <> 4 then |
|||
let direction = 2 |
|||
endif |
|||
if downkey = 1 and direction <> 1 then |
|||
let direction = 3 |
|||
endif |
|||
if leftkey = 1 and direction <> 2 then |
|||
let direction = 4 |
|||
endif |
|||
fgcolor 0, 80, 0 |
|||
oval sx[size], sy[size], 15, 15 |
|||
let i = size + 1 |
|||
do |
|||
let i = i - 1 |
|||
let c = i - 1 |
|||
if sx[0] = sx[i] and sy[0] = sy[i] = 1 then |
|||
let game = 0 |
|||
endif |
|||
let sx[i] = sx[c] |
|||
let sy[i] = sy[c] |
|||
fgcolor 0, 255, 0 |
|||
oval sx[i], sy[i], 15, 15 |
|||
loop i > 1 |
|||
fgcolor 0, 0, 255 |
|||
oval sx[0] + 5, sy[0] + 5, 3, 3 |
|||
oval sx[0] + 9, sy[0] + 5, 3, 3 |
|||
if direction = 1 then |
|||
let sy[0] = sy[0] - 15 |
|||
endif |
|||
if direction = 2 then |
|||
let sx[0] = sx[0] + 15 |
|||
endif |
|||
if direction = 3 then |
|||
let sy[0] = sy[0] + 15 |
|||
endif |
|||
if direction = 4 then |
|||
let sx[0] = sx[0] - 15 |
|||
endif |
|||
if sx[0] <= -10 or sx[0] >= gfxx or sy[0] <= -10 or sy[0] >= gfxy = 1 then |
|||
let game = 0 |
|||
endif |
|||
if sx[0] + 15 >= rx and sx[0] <= rx + 15 and sy[0] + 15 >= ry and sy[0] <= ry + 15 = 1 then |
|||
playwave "examples\tada.wav" |
|||
fgcolor 0, 80, 0 |
|||
rect 0, 0, gfxx, gfxy |
|||
let rx = int(rnd * (gfxx - 24)) + 12 |
|||
let ry = int(rnd * (gfxy - 40)) + 25 |
|||
let size = size + 3 |
|||
let score = score + 1 |
|||
endif |
|||
fgcolor 100,100,100 |
|||
oval rx, ry, 15, 15 |
|||
fgcolor 255, 0, 0 |
|||
oval rx + 5, ry + 5, 3, 3 |
|||
oval rx + 9, ry + 5, 3, 3 |
|||
fgcolor 255, 255, 0 |
|||
cursor 1, 1 |
|||
print "Score: ", score |
|||
let delay = clock |
|||
do |
|||
wait |
|||
loop clock < delay + speed |
|||
loop esckey <> 1 and game = 1 |
|||
playwave "examples\boom.wav" |
|||
alert "Game over! Score: ", score |
|||
end</syntaxhighlight> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |