A simple little solitaire style card game which I was playing around with: Flip It
$COLOR:32
DEFLNG A-Z
RANDOMIZE TIMER
SCREEN _NEWIMAGE(1024, 720, 32) '720p screen
_TITLE "Flip It"
DIM SHARED CardImage AS LONG: CardImage = _LOADIMAGE("Cards.bmp", 32)
DIM SHARED CardWide, CardHigh: CardWide = 72: CardHigh = 96
DIM SHARED Deck(51) AS INTEGER 'an array to hold the cards
REDIM SHARED Visible(0) AS INTEGER 'an array to see if the cards are visible or hidden
DIM SHARED OldEnglish, NumOfCards
OldEnglish = _LOADFONT("OLDENGL.TTF", 32)
_PRINTMODE _KEEPBACKGROUND
DO
NumOfCards = ChooseDifficulty
Shuffle
DisplayCards
SLEEP
LOOP
SUB DisplayCards
CLS
_FONT 16
xstep = _WIDTH / NumOfCards
scale = xstep / CardWide
ystart = _HEIGHT / 2 - CardHigh * scale / 2
FOR i = 0 TO NumOfCards - 1
IF Visible(i) THEN
suit = Deck(i) \ 13: value = Deck(i) MOD 13
_PUTIMAGE (xstep * i, ystart)-STEP(xstep, CardHigh * scale), CardImage, 0, (value * CardWide, suit * CardHigh)-STEP(CardWide, CardHigh)
ELSE
LINE (xstep * i, ystart)-STEP(xstep, CardHigh * scale), White, BF
LINE (xstep * i + 2, ystart + 2)-STEP(xstep - 4, CardHigh * scale - 4), Blue, BF
END IF
NEXT
END SUB
FUNCTION ChooseDifficulty
CLS
_FONT OldEnglish
COLOR White
CenterText 0, 200, _WIDTH, 300, "Choose Difficulty"
COLOR Black
FOR i = 0 TO 9
x = 5 + 102 * i
y = 300
LINE (x, y)-STEP(100, 100), Yellow, BF
CenterText x, y, x + 100, y + 100, _TRIM$(STR$(i + 6))
NEXT
oldmouse = -1 'cycle one to make certain mouse is up before we count a down event
DO
WHILE _MOUSEINPUT: WEND
mb = _MOUSEBUTTON(1)
IF oldmouse = 0 AND mb THEN
IF _MOUSEY >= 300 AND _MOUSEY <= 400 THEN 'we're in the right rows for a valid mouse clice
choice = (_MOUSEX - 5) \ 102
IF choice >= 0 AND choice <= 9 THEN finished = -1
END IF
END IF
oldmouse = mb
_LIMIT 30
LOOP UNTIL finished
COLOR White
ChooseDifficulty = choice + 6
END FUNCTION
SUB CenterText (x1, y1, x2, y2, text$)
pw = _PRINTWIDTH(text$)
px = x1 + (x2 - x1) / 2 - pw / 2
py = y1 + (y2 - y1) / 2 - _FONTHEIGHT / 2
_PRINTSTRING (px, py), text$
END SUB
SUB Shuffle
STATIC InitDeck
IF NOT InitDeck THEN
InitDeck = -1
FOR i = 0 TO 51: Deck(i) = i: NEXT 'put the cards in the deck
END IF
FOR i = 0 TO 51
SWAP Deck(i), Deck(INT(RND * 52)) 'shuffle the deck
NEXT
REDIM Visible(NumOfCards) AS INTEGER
FOR i = 0 TO NumOfCards - 1
Visible(i) = INT(RND * 2)
NEXT
END SUB
All we do at this point is get some cards and display them on the screen, but I thought I'd go ahead and share just for folks who might be interested in seeing the centering/resizing routines before they get lost in the rest of the game.
All that's left at this point is to add a screen so the user can make a bet on whether they can win or not (Larger hands have a higher return payout, though not a lot higher -- there's a secret to this game, which our math nerds might enjoy figuring out..), and then to add the "Flip It" routine to see if the user can win.
The point of this game is rather simple:
1) Only cards which are face up and visible can be removed from the game.
2) The user can only choose 1 card per turn.
3) When a card is removed from the game, the cards adjacent to it are "flipped". Cards face up are turned down; cards down are turned up.
4) You play until all cards are removed (a win!), or until all cards left are face down (loser!).
I figure to add a little extra pizzazz to it, I'll make this a gambling solitaire game where you can make bets on whether you can win with a hand or not -- and that's the point where the game is currently up to. Once you set your bet, gameplay starts, and you go until you win or lose, and you'll be able to play until you go broke...
Currently, it's an incomplete version of the game, but the logic behind everything is rather simple and easy to follow, so I thought I'd go ahead and share it in case anybody is interested in the scaling/positioning/mousehandling and such which is going on in it already before it gets any longer or more complicated. ;)
*NOTE: You’ll need the QB64-Development version to compile and run this, as Petr pointed out below. (Or my personal test QB64 version, downloadable via my repo link in my signature.)