Graphics 800,600
SetBuffer BackBuffer()
SeedRnd MilliSecs()
pointer_img=LoadImage("pointer.bmp")
Dim cards(52)
Dim face_up(52)
Dim card_imgs(52)
Dim on_table(52)
cards_init()
cards_shuffle()
last_n=0
Repeat
Cls
cards_display()
DrawImage pointer_img,MouseX(),MouseY()
Flip
If MouseHit(1)
n=cards_which_one()
If n>0 Then
face_up(n)=True
If last_n=0 Then
last_n=n
Else
cards_display()
Flip
Delay 2000
card=cards(n)
last_card=cards(last_n)
d=Abs(card-last_card)
If d=13 Or d=26 Or d=39 Then
on_table(n)=False
on_table(last_n)=False
Else
face_up(n)=False
face_up(last_n)=False
End If
last_n=0
End If
End If
End If
Until KeyHit(1)
End
Function cards_init()
card_imgs(0)=LoadImage("back.png")
For i=1 To 52
cards(i)=i
face_up(i)=False
card_imgs(i)=LoadImage(i+".png")
on_table(i)=True
Next
End Function
Function cards_shuffle()
For i=1 To 500
r1=Rand(52)
r2=Rand(52)
t=cards(r1)
cards(r1)=cards(r2)
cards(r2)=t
Next
End Function
Function cards_display()
n=1
y=8
For row=1 To 6
x=68
For col=1 To 9
card=0
If on_table(n) Then
If face_up(n) Then card=cards(n)
DrawBlock card_imgs(card),x,y
End If
x=x+74
n=n+1
If n=53 Then Exit
Next
y=y+98
Next
End Function
Function cards_which_one()
card=0
n=1
y=8
For row=1 To 6
x=68
For col=1 To 9
If mouse_in(x,y,x+74,y+98) Then If Not face_up(n) Then card=n
x=x+74
n=n+1
If n=53 Then Exit
Next
y=y+98
Next
Return card
End Function
Function mouse_in(x1,y1,x2,y2)
x=MouseX(): y=MouseY()
m=True
If x<x1 Then m=False
If x>x2 Then m=False
If y<y1 Then m=False
If y>y2 Then m=False
Return m
End Function