2048: Difference between revisions

191 bytes removed ,  15 days ago
m
→‎{{header|FutureBasic}}: Remove FutureBasic 'Output' label
m (→‎{{header|FutureBasic}}: Remove FutureBasic 'Output' label)
 
(9 intermediate revisions by 3 users not shown)
Line 11:
:*   All tiles move as far as possible in that direction, some move more than others.
:*   Two adjacent tiles (in that direction only) with matching numbers combine into one bearing the sum of those numbers.
:*   A move is valid when at least one tile can be moved,   if onlyincluding by combination.
:*   A new tile with the value of   '''2'''   is spawned at the end of each turn at a randomly chosen empty square   (if there is one).
:*   Adding a new tile on a blank space.   Most of the time,   a new   '''2'''   is to be added,   andbut occasionally   ('''10%''' of the time),   a   '''4'''.
:*   To win,   the player must create a tile with the number   '''2048'''.
:*   The player loses if no valid moves are possible.
 
Line 22:
 
;Requirements:
* &nbsp; "Non-greedy" movement. &nbsp; <br>&nbsp; The tiles that were created by combining other tiles should not be combined again during the same turn (move). &nbsp; <br>&nbsp; That is to say, &nbsp; that moving the tile row of:
 
<big><big> [2][2][2][2] </big></big>
Line 34:
<big><big> .........[8] </big></big>
 
* &nbsp; "Move direction priority". &nbsp; <br>&nbsp; If more than one variant of combining is possible, &nbsp; move direction shall indicate which combination will take effect. <br>&nbsp; For example, moving the tile row of:
 
<big><big> ...[2][2][2] </big></big>
Line 48:
 
 
* &nbsp; Check for valid moves. &nbsp; The player shouldn't be able to skipgain theirnew turntile by trying a move that doesn't change the board.
* &nbsp; Check for a &nbsp;win condition.
* &nbsp; Check for a lose condition.
<br><br>
Line 8,137:
 
=={{header|FutureBasic}}==
 
<syntaxhighlight lang="futurebasic">
 
begin enum 123
_lf
Line 8,153 ⟶ 8,151:
 
void local fn initialize
subclass window 1, @"2048",(0,0,438,440438)
fn WindowSetBackgroundColor( 1, fn ColorBlack )
color(0) = fn ColorDarkGray
color(1) = fn ColorGray
color(2) = fn ColorLightGray
color(3) = fn ColorBrownColorBlue
color(4) = fn ColorBlueColorBrown
color(5) = fn ColorCyan
color(6) = fn ColorGreen
Line 8,225 ⟶ 8,223:
short a, b, c, t, moved = 0
// SHIFT
for a = st to st + rd * 3 step rd
// SHIFT
t = a
for b = a to a + cd * 3 step cd
Line 8,234 ⟶ 8,232:
end if
next
// MERGE
next
// MERGE
for a = st to st + rd * 3 step rd
for b = a to a + cd * 2 step cd
if bd[b] > 0 && bd[b] == bd[b+cd]
bd[b]++ : c = b + cd
// FILL IN
while c <> a+cd*3
bd[c] = bd[c+cd] : c += cd
wend
bd[c] = 0
// CHECK FOR WIN
if bd[b] == 11 then fn drawBoard : fn finish( yes ) : exit fn
zs ++ : moved ++
Line 8,252 ⟶ 8,247:
next
next
fn drawBoard
if moved == 0 then exit fn
Line 8,262 ⟶ 8,259:
if rnd(10) - 1 then bd[b]++ else bd[b] = 2
zs--
timerbegin 0.25
fn drawBoard
fn drawBoard
timerend
if zs then exit fn
Line 8,301 ⟶ 8,300:
handleevents
</syntaxhighlight>
[[File:FutureBasic 2048 Game Window.png]]
{{out}}
[[File:2048 Game Window.png]]
 
=={{header|Go}}==
Line 16,704 ⟶ 16,702:
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./dynamic" for Enum, Struct
import "random" for Random
import "./ioutil" for Input
import "./fmt" for Fmt
import "./str" for Str
 
var MoveDirection = Enum.create("MoveDirection", ["up", "down", "left", "right"])
408

edits