Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flip It!
#1
A little card game where the goal is to remove all the cards from the screen.

Game play is simple, click on a card with an open face to remove it, but doing so will FLIP the cards beside it.  You can pick and choose which cards to flip (as long as they're face up), and the goal is to flip them all until you can remove them all from the screen.

Code: (Select All)
$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 Result
Dim Shared OldEnglish, NumOfCards
OldEnglish = _LoadFont("OLDENGL.TTF", 32)
_PrintMode _KeepBackground

Do
NumOfCards = ChooseDifficulty
Shuffle
For i = 1 To NumOfCards
DisplayCards
If Result = 0 Then Exit For
Next
If i = NumOfCards + 1 Then DisplayCards: Result = -1 'flip the last card and win
WinOrLose
Loop

Sub WinOrLose
_Font OldEnglish
If Result Then
Print "YOU WIN!!!"
Else
Print "YOU LOSE!!!"
End If
_Delay 3
End Sub

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) = -1 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)
ElseIf Visible(i) = 0 Then
Line (xstep * i, ystart)-Step(xstep, CardHigh * scale), White, BF
Line (xstep * i + 2, ystart + 2)-Step(xstep - 4, CardHigh * scale - 4), Blue, BF
Else
'We don't draw squat. The card has been removed from play
End If
Next

Result = 0
For i = 0 To NumOfCards - 1
If Visible(i) < 0 Then Result = -1: Exit For 'there's still visible cards to play with
Next
If Result = 0 Then Exit Sub



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 >= ystart And _MouseY <= ystart + CardHigh * scale Then 'we're in the right rows for a valid mouse click
choice = _MouseX \ xstep
If choice >= 0 And choice <= NumOfCards And Visible(choice) = -1 Then finished = -1
End If
End If
oldmouse = mb
_Limit 30
Loop Until finished
Visible(choice) = 1
If choice > 0 Then
If Visible(choice - 1) < 1 Then Visible(choice - 1) = Not Visible(choice - 1)
End If
If choice < NumOfCards Then
If Visible(choice + 1) < 1 Then Visible(choice + 1) = Not Visible(choice + 1)
End If
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


Attached Files Image(s)
   
Reply


Messages In This Thread
Flip It! - by SMcNeill - 10-17-2024, 05:59 PM



Users browsing this thread: 1 Guest(s)