Snake: Difference between revisions
m
→{{header|EasyLang}}
(5 intermediate revisions by 4 users not shown) | |||
Line 1,223:
rem by Gemino Smothers 2022
rem www.lucidapogee.com
title "Snake!"▼
define gfxx = 330, gfxy = 296
Line 1,237 ⟶ 1,239:
let sy[0] = gfxy / 2
fill on▼
▲title "Snake!"
bgcolor 128, 64, 0▼
cls graphics
resize 0, 0, gfxx + 10, gfxy + 56
center
formid 1
▲fill on
staticform 1, 1, 100, 14
▲bgcolor 128, 64, 0
fgcolor 255, 255, 0
bgcolor 0, 80, 0
colorform
alert "Snake! by Gemino Smothers 2022"
Line 1,368 ⟶ 1,374:
fgcolor 255, 255, 0
updateform
let delay = clock
Line 1,382 ⟶ 1,389:
playwave "examples\boom.wav"
alert "Game over! Score: ", score</syntaxhighlight>▼
▲alert "Game over! Score: ", score
==={{header|FreeBASIC}}===
Line 2,289 ⟶ 2,293:
=={{header|EasyLang}}==
[https://easylang.dev/apps/
{{Trans|Craft Basic}}
<syntaxhighlight
subr fruit
rx = (
ry = (
.
subr start
game = 1
sx[] = [ 52.5 0 0 0 0 ]
sy[] = [ 52.5 0 0 0 0 ]
dir =
timer 0
.
Line 2,310 ⟶ 2,314:
text "SNAKE"
textsize 5
move
text "
move
text "
#
on key
if
return
elif keybkey = "ArrowRight" and dir <> 4▼
else
if keybkey = "ArrowUp"
dir = 1
dir = 3
.
.
.
on mouse_down
if game = 0
start
return
.
if dir mod 2 = 1
if mouse_x < sx
dir = 4
else
dir = 2
.
else
if mouse_y < sy
dir = 3
else
dir = 1
.
.
.
Line 2,331 ⟶ 2,360:
clear
color 997
move 2
text "Score: " & 10 * len sx[] - 50
color 966
move rx ry
circle 1.5
#
sx = sx[1] ; sy = sy[1]
if dir = 1
Line 2,379 ⟶ 2,408:
len sx[] len sx[] + 3
len sy[] len sy[] + 3
.
sx[1] = sx ; sy[1] = sy
Line 2,387 ⟶ 2,416:
color 997
move 10 10
text "
.
.
Line 3,261 ⟶ 3,290:
=={{header|Julia}}==
▲<syntaxhighlight lang="julia">using Makie
mutable struct SnakeGame
height::Int
width::Int
snake::Vector{CartesianIndex{2}}
food::CartesianIndex{2}
end
Line 3,307 ⟶ 3,335:
function play(;n=10,t=0.5)
game =
scene = Scene(resolution = (1000, 1000), raw = true, camera = campixel!)
display(scene)
Line 3,328 ⟶ 3,356:
score_text = @lift("Score: $(length($game.snake)-1)")
text!(scene, score_text, color=:gray, position = @lift((widths($area)[1]/2, widths($area)[2])),
direction = Ref{Any}(nothing)
on(events(scene).
if
direction[] = CartesianIndex(-1,0)
direction[] = CartesianIndex(0,1)
direction[] = CartesianIndex(0,-1)
direction[] = CartesianIndex(1,0)
end
end
end
Line 5,090 ⟶ 5,120:
{{libheader|Wren-dynamic}}
An embedded program so we can ask the C host to call ncurses and another library function for us.
<syntaxhighlight lang="
import "random" for Random
Line 5,228 ⟶ 5,258:
<br>
Now embed this script in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc
#include <stdio.h>
Line 5,374 ⟶ 5,404:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
|