Author Topic: Flip It  (Read 6294 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Flip It
« on: November 03, 2019, 03:17:28 am »
A simple little solitaire style card game which I was playing around with: Flip It

Code: [Select]
$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.)
Cards.bmp
* Cards.bmp (Filesize: 1.03 MB, Dimensions: 936x384, Views: 208)
* OLDENGL.TTF (Filesize: 90.89 KB, Downloads: 145)
« Last Edit: November 03, 2019, 05:53:18 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Flip It
« Reply #1 on: November 03, 2019, 04:44:01 am »
Hi Steve. Very nice font, nice workmanship, but I had to use your IDE version (or I already have an outdated version and your $COLOR: 32 metacommand is already part of the IDE developer version?
I have one question to shuffle cards: on row 87 you have a command:

SWAP Deck (i), Deck (INT (RND * 52))

 What if INT (RND * 52)) returns the same value more than once?  I'm afraid this may cause the card OLD Deck (i)  to fall out of the deck.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Flip It
« Reply #2 on: November 03, 2019, 05:44:27 am »
Hi Steve. Very nice font, nice workmanship, but I had to use your IDE version (or I already have an outdated version and your $COLOR: 32 metacommand is already part of the IDE developer version?
I have one question to shuffle cards: on row 87 you have a command:

SWAP Deck (i), Deck (INT (RND * 52))

 What if INT (RND * 52)) returns the same value more than once?  I'm afraid this may cause the card OLD Deck (i)  to fall out of the deck.

$COLOR:32 should already be in the dev version.  ;)

As for the RND question, it’s fine as it.

Let’s say we have a deck of 4 cards...  0, 1, 2, 3 are their values, and the initial order.

Now, we shuffle:

FOR I = 0 TO 3
   SWAP Deck(I), Deck(INT(RND * 4))
NEXT

With I = 0, we generate a random number of 3...  This makes the order 3, 1, 2, 0
With I = 1, we get that same random number 3...  The order is now 3, 0, 2, 1

Even if it’s the same number generated, the spot we swap it with incremented, so it’s never going to “fall out of deck”.

Each swap just shuffles the values back and forth in the deck so the cards go somewhere else, and since we run the loop once for each card there’s no chance of repeating the same sequence. 

It’s the simplest way I know to quickly implement a shuffle style routine for an array.  ;)

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Flip It
« Reply #3 on: November 03, 2019, 06:29:35 am »
Now that I read your answer, I get it. You're right. I don't know, why I didn't realize it right away. Thanks for the explanation.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #4 on: November 03, 2019, 01:25:31 pm »
Hi Steve,

I did find the reason this sort of sort is a little bit off, probably have to be a statistician to "see" it, but I am wondering if you saw that reason in F-Y discussion, said "f*** mathematics and started this game to show defiance? ;-))

Maybe you missed it: https://www.qb64.org/forum/index.php?topic=1800.msg110521#msg110521
« Last Edit: November 03, 2019, 02:02:19 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Flip It
« Reply #5 on: November 03, 2019, 02:05:45 pm »
Hi Steve,

I did find the reason this sort of sort is a little bit off, probably have to be a statistician to "see" it, but I am wondering if you saw that reason in F-Y discussion, said "f*** mathematics and started this game to show defiance? ;-))

I saw the link you posted, but I’m a simple fellow.  Games don’t need perfect randomization to work.  (Good thing too, since RND itself isn’t truly random!)  The method I used is just what I’m used to plugging in to shuffle things, and I just popped it in there automatically.

What made me think of doing a little game like this was a video I saw on YouTube with some math lady talking about binary values and making a game with cards to flip them, and I thought, “Heck, that’d be easy enough to simulate.”  If I can hunt down the link again later, I’ll share it after the game is completed.  (I don’t want to share it early, as it gives several clues to solving the patterns, deciphering what’s not winnable at all, and which games you can win, unless you play stupidly...).

Sunday is family time around here, so I’m hoping to get it sit and finish this little project up tomorrow.  It’s simple enough to code, in my opinion, so just an hour or so of free time and I can knock it out, I think.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #6 on: November 03, 2019, 02:27:40 pm »
LOL, I just realized if it's about binary tricks then it doesn't matter the cards are shuffled or not, all we should be worried about is if the card is turned over or not and where in the whole pattern the 1 or 0 sits.


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Flip It
« Reply #7 on: November 03, 2019, 02:33:22 pm »
LOL, I just realized if it's about binary tricks then it doesn't matter the cards are shuffled or not, all we should be worried about is if the card is turned over or not and where in the whole pattern the 1 or 0 sits.

Which is why I didn’t think it’d matter if I had statistically accurate shuffling.  The cards are just a graphical representation of our bits — Face up (1) or face down (0).  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #8 on: November 03, 2019, 05:15:32 pm »
I am intrigued, trying the game with cards, small sets, haven't ended up with all face down yet...

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Flip It
« Reply #9 on: November 04, 2019, 02:17:56 pm »
Here's a version where you should be able to actually flip the cards and enjoy some basic cardplay:

Code: QB64: [Select]
  1. DEFLNG A-Z
  2. SCREEN _NEWIMAGE(1024, 720, 32) '720p screen
  3. _TITLE "Flip It"
  4. DIM SHARED CardImage AS LONG: CardImage = _LOADIMAGE("Cards.bmp", 32)
  5. DIM SHARED CardWide, CardHigh: CardWide = 72: CardHigh = 96
  6. DIM SHARED Deck(51) AS INTEGER 'an array to hold the cards
  7. REDIM SHARED Visible(0) AS INTEGER 'an array to see if the cards are visible or hidden
  8. DIM SHARED Result
  9. DIM SHARED OldEnglish, NumOfCards
  10. OldEnglish = _LOADFONT("OLDENGL.TTF", 32)
  11.  
  12.     NumOfCards = ChooseDifficulty
  13.     Shuffle
  14.     FOR i = 1 TO NumOfCards
  15.         DisplayCards
  16.         IF Result = 0 THEN EXIT FOR
  17.     NEXT
  18.     IF i = NumOfCards + 1 THEN DisplayCards: Result = -1 'flip the last card and win
  19.     WinOrLose
  20.  
  21. SUB WinOrLose
  22.     _FONT OldEnglish
  23.     IF Result THEN
  24.         PRINT "YOU WIN!!!"
  25.     ELSE
  26.         PRINT "YOU LOSE!!!"
  27.     END IF
  28.     _DELAY 3
  29.  
  30. SUB DisplayCards
  31.     CLS
  32.     _FONT 16
  33.     xstep = _WIDTH / NumOfCards
  34.     scale = xstep / CardWide
  35.     ystart = _HEIGHT / 2 - CardHigh * scale / 2
  36.  
  37.     FOR i = 0 TO NumOfCards - 1
  38.         IF Visible(i) = -1 THEN
  39.             suit = Deck(i) \ 13: value = Deck(i) MOD 13
  40.             _PUTIMAGE (xstep * i, ystart)-STEP(xstep, CardHigh * scale), CardImage, 0, (value * CardWide, suit * CardHigh)-STEP(CardWide, CardHigh)
  41.         ELSEIF Visible(i) = 0 THEN
  42.             LINE (xstep * i, ystart)-STEP(xstep, CardHigh * scale), White, BF
  43.             LINE (xstep * i + 2, ystart + 2)-STEP(xstep - 4, CardHigh * scale - 4), Blue, BF
  44.         ELSE
  45.             'We don't draw squat.  The card has been removed from play
  46.         END IF
  47.     NEXT
  48.  
  49.     Result = 0
  50.     FOR i = 0 TO NumOfCards - 1
  51.         IF Visible(i) < 0 THEN Result = -1: EXIT FOR 'there's still visible cards to play with
  52.     NEXT
  53.     IF Result = 0 THEN EXIT SUB
  54.  
  55.  
  56.  
  57.     oldmouse = -1 'cycle one to make certain mouse is up before we count a down event
  58.     DO
  59.         WHILE _MOUSEINPUT: WEND
  60.         mb = _MOUSEBUTTON(1)
  61.         IF oldmouse = 0 AND mb THEN
  62.             IF _MOUSEY >= ystart AND _MOUSEY <= ystart + CardHigh * scale THEN 'we're in the right rows for a valid mouse click
  63.                 choice = _MOUSEX \ xstep
  64.                 IF choice >= 0 AND choice <= NumOfCards AND Visible(choice) = -1 THEN finished = -1
  65.             END IF
  66.         END IF
  67.         oldmouse = mb
  68.         _LIMIT 30
  69.     LOOP UNTIL finished
  70.     Visible(choice) = 1
  71.     IF choice > 0 THEN
  72.         IF Visible(choice - 1) < 1 THEN Visible(choice - 1) = NOT Visible(choice - 1)
  73.     END IF
  74.     IF choice < NumOfCards THEN
  75.         IF Visible(choice + 1) < 1 THEN Visible(choice + 1) = NOT Visible(choice + 1)
  76.     END IF
  77.  
  78.  
  79.  
  80. FUNCTION ChooseDifficulty
  81.     CLS
  82.     _FONT OldEnglish
  83.     COLOR White
  84.     CenterText 0, 200, _WIDTH, 300, "Choose Difficulty"
  85.     COLOR Black
  86.  
  87.     FOR i = 0 TO 9
  88.         x = 5 + 102 * i
  89.         y = 300
  90.         LINE (x, y)-STEP(100, 100), Yellow, BF
  91.         CenterText x, y, x + 100, y + 100, _TRIM$(STR$(i + 6))
  92.     NEXT
  93.  
  94.     oldmouse = -1 'cycle one to make certain mouse is up before we count a down event
  95.     DO
  96.         WHILE _MOUSEINPUT: WEND
  97.         mb = _MOUSEBUTTON(1)
  98.         IF oldmouse = 0 AND mb THEN
  99.             IF _MOUSEY >= 300 AND _MOUSEY <= 400 THEN 'we're in the right rows for a valid mouse clice
  100.                 choice = (_MOUSEX - 5) \ 102
  101.                 IF choice >= 0 AND choice <= 9 THEN finished = -1
  102.             END IF
  103.         END IF
  104.         oldmouse = mb
  105.         _LIMIT 30
  106.     LOOP UNTIL finished
  107.     COLOR White
  108.     ChooseDifficulty = choice + 6
  109.  
  110. SUB CenterText (x1, y1, x2, y2, text$)
  111.     pw = _PRINTWIDTH(text$)
  112.     px = x1 + (x2 - x1) / 2 - pw / 2
  113.     py = y1 + (y2 - y1) / 2 - _FONTHEIGHT / 2
  114.     _PRINTSTRING (px, py), text$
  115.  
  116. SUB Shuffle
  117.     STATIC InitDeck
  118.     IF NOT InitDeck THEN
  119.         InitDeck = -1
  120.         FOR i = 0 TO 51: Deck(i) = i: NEXT 'put the cards in the deck
  121.     END IF
  122.     FOR i = 0 TO 51
  123.         SWAP Deck(i), Deck(INT(RND * 52)) 'shuffle the deck
  124.     NEXT
  125.     REDIM Visible(NumOfCards) AS INTEGER
  126.     FOR i = 0 TO NumOfCards - 1
  127.         Visible(i) = -INT(RND * 2)
  128.     NEXT
  129.  

Note:You'll either need the Dev build of QB64 to compile this, or else you'll need to manually swap in some color values in place of the $COLOR:32 statement.

I don't have this where it tracks money, or any form of betting yet, but it generates the game for us and lets us go about flipping our cards until we either get to a win or a loss with the game.

Some questions for all the math addicts out there:

1) What's the odds of generating a winnable game vs generating one which can't be won no matter how well we play?  Is there some trick to knowing instantly if a game is winnable or not?

2) What's the trick to always win, if the game does have a winnable solution?

I'll give you guys a few days to play around with things, and then I'll try and hunt down the youtube video which explains the theory and all behind the game and its mechanics.  (And, if I get a little extra free time after cleaning up the mess Halloween left all around the farm, I'll go in and finish this little "game" by adding in a small betting system so you can play and try and win an imaginary fortune on Flip It!)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #10 on: November 04, 2019, 04:34:14 pm »
All that's needed (if you dont have Dev Build) is to replace first line with this:
Code: QB64: [Select]
  1. CONST white = &HFFFFFFFF, black = &HFF000000, yellow = &HFFFFFF00, blue = &HFF0000FF    

Oh! I guess I had invented my own game of Flip It, not like this one, mine was N x M array of cards and the play was a little different thanks to my misunderstanding of Steve's rules above :D

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Flip It
« Reply #11 on: November 04, 2019, 05:51:32 pm »
Thanks Bplus
I'm just asking if using
Code: QB64: [Select]
  1. '$COLOR:32
  2. CONST White = _RGBA32(255, 255, 255, 255), Black = _RGBA32(0, 0, 0, 255)
  3. CONST Yellow = _RGBA32(255, 255, 0, 255), Blue = _RGBA32(0, 0, 255, 255)
  4.  
I got the same result.
(PS I have loosen a color ! :-)  )
« Last Edit: November 04, 2019, 05:55:11 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #12 on: November 04, 2019, 08:10:56 pm »
Well I know one thing, if you have one card up, you have a sure win!

Two things, if you have two cards up at an end you are dead meat, wait it might be 2 cards up anywhere.
« Last Edit: November 04, 2019, 08:14:34 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flip It
« Reply #13 on: November 05, 2019, 03:52:20 pm »
OK I've got the read of win or no way, and a strategy to assure the win when possible, very simple from some experiments starting with one or two cards face up, here is code for such experiments:
Code: QB64: [Select]
  1. _TITLE "Quick Flip It experiments" 'b+ started 2019-11-05
  2. ' inspired by Steve's recent QB64 thread:
  3. ' https://www.qb64.org/forum/index.php?topic=1831.msg110717#msg110717
  4. ' "experiments" allows control over number of face cards you want to test.
  5.  
  6. CONST yOff = 50, cw = 50, ch = 100, spacer = 10, nCards = 10 'should be enough to get the gist of what is going on
  7. CONST cardUp = &HFFBBBBBB, cardDown = &HFF000066, cardOut = &HFF000000
  8. CONST xmax = 610, ymax = 200
  9.  
  10. TYPE card
  11.     x AS INTEGER
  12.     y AS INTEGER
  13.     state AS INTEGER ' up = 1, down = 0, gone = -1
  14. DIM SHARED cards(1 TO nCards) AS card, gameOver
  15.  
  16. SCREEN _NEWIMAGE(xmax, ymax, 32)
  17. _SCREENMOVE 300, 100
  18.  
  19. gameOver = 1
  20. WHILE _KEYDOWN(27) = 0
  21.     IF gameOver THEN initRound
  22.     i = getCardClicked 'this card is removed and cards on either side (if any) are toggled up/down
  23.     IF i THEN
  24.         IF cards(i).state = 1 THEN
  25.             IF i > 1 THEN
  26.                 IF cards(i - 1).state <> -1 THEN cards(i - 1).state = 1 - cards(i - 1).state
  27.             END IF
  28.             IF i < nCards THEN
  29.                 IF cards(i + 1).state <> -1 THEN cards(i + 1).state = 1 - cards(i + 1).state
  30.             END IF
  31.             cards(i).state = -1
  32.         END IF
  33.     END IF
  34.     updateScreen
  35.     _DISPLAY
  36.     _LIMIT 60
  37.  
  38. FUNCTION getCardClicked
  39.     mb = _MOUSEBUTTON(1) '            left button down
  40.     IF mb THEN '                      get last place mouse button was down
  41.         WHILE mb '                    wait for mouse button release as a "click"
  42.             m = _MOUSEINPUT: mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  43.         WEND
  44.         FOR i = 1 TO nCards '         now find which box was clicked
  45.             IF mx > cards(i).x AND mx < cards(i).x + cw THEN
  46.                 IF my > cards(i).y AND my < cards(i).y + ch THEN
  47.                     getCardClicked = i: EXIT FUNCTION
  48.                 END IF
  49.             END IF
  50.         NEXT
  51.     END IF
  52.  
  53. SUB updateScreen 'and count the ups and downs of cards
  54.     CLS
  55.     ups = 0: downs = 0 'count cards while displaying
  56.     FOR i = 1 TO nCards
  57.         IF cards(i).state = 1 THEN
  58.             ups = ups + 1: clr~& = cardUp
  59.         ELSEIF cards(i).state = 0 THEN
  60.             downs = downs + 1: clr~& = cardDown
  61.         ELSEIF cards(i).state = -1 THEN
  62.             clr~& = cardOut
  63.         END IF
  64.         LINE (cards(i).x, cards(i).y)-STEP(cw, ch), clr~&, BF
  65.     NEXT
  66.     'check win
  67.     IF ups = 0 THEN
  68.         gameOver = 1
  69.         IF downs > 0 THEN
  70.             _PRINTSTRING (270, 10), "No win"
  71.         ELSE
  72.             _PRINTSTRING (290, 10), "Win"
  73.         END IF
  74.         _DISPLAY: _DELAY 5
  75.     END IF
  76.  
  77. SUB initRound 'reassign letters and hide them all
  78.     CLS
  79.     INPUT "Enter the amount of cards (of 10) to show as up (lighter color), 0 quits "; upStart
  80.     IF upStart > 0 AND upStart <= nCards THEN
  81.         FOR i = 1 TO nCards  ' yeah I know x, y doesn't have to be redone each round
  82.             cards(i).x = spacer + (i - 1) * (cw + spacer): cards(i).y = yOff
  83.             IF i <= upStart THEN cards(i).state = 1 ELSE cards(i).state = 0
  84.         NEXT
  85.         FOR i = nCards TO 2 STEP -1 ' shuffle stuff in array
  86.             SWAP cards(i).state, cards(INT(i * RND) + 1).state
  87.         NEXT
  88.         gameOver = 0: updateScreen
  89.     ELSEIF upStart = 0 THEN  '<< EDIT: added in else
  90.         END
  91.     END IF
  92.  

EDIT: oops, forgot the 0 signal to quit, fixed now.
« Last Edit: November 05, 2019, 07:09:57 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Flip It
« Reply #14 on: November 05, 2019, 03:58:12 pm »
Here’s the video where I first say the lady explaining this little exercise:
&t=381s

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!