Author Topic: Game Magic8  (Read 1789 times)

0 Members and 1 Guest are viewing this topic.

Aaron

  • Guest
Game Magic8
« on: March 04, 2014, 05:26:39 AM »
Hello,

A nerves game for fidgety boys and girls.
Click on a number,

If you want to win the game, you have to have this number construction:

1 2 3 
4 5 6
7 8
Code: [Select]
Include "gp.inc"

OpenWindow 198,268,1
fo = LoadFont "arial",18,0

Def BLUE    &HFF0000FF
Def DBLUE   &HFF000080
Def RED     &HFFFF0000
Def DRED    &HFF800000
Def GREEN   &HFF00FF00
Def DGREEN  &HFF008000
Def YELLOW  &HFFFFFF00

Dim xPos, yPos, x, y, j, n, m, num, a, i, jx As Long
Dim moves, click, won As Long
Dim Value(20) As Long
Dim Map(26)   As Long
Dim Buf(10)   As Long

For j=0 To 25
    Map(j) =255
Next

Num = LoadImage "media/number.png",8
w1  = LoadWav   "media/won.wav"
w2  = LoadWav   "media/clic.wav"

Sub CheckWon()
    iF Won=1 Then Exit Sub
       sys jx
       For y=0 To 2
           For x=0 To 2
               j= y*3 + x
               jx +=1
               iF jx=9 Then jx=0
               iF Map(j) <> jx Then Exit Sub
           Next
       Next
    PlayWav w1
    won=1
End Sub

Sub PushNumber()
iF MouseButton()=1 and click=0 and won=0
xPos = Trunc( xMouse()/64 )
yPos = Trunc( yMouse()/64 )
j = yPos*3 + xPos
iF Map(j) =0 or yPos >2 Then Exit Sub
   iF Map(j+1)=0 and click=0
      Map(j+1) = Map(j)
      Map(j)=0
      moves +=1
      click=1
      PlayWav w2
   ElseiF Map(j-1)=0 and xPos >0 and click=0 
      Map(j-1) = Map(j)
      Map(j)=0
      moves +=1
      click=1
      PlayWav w2
   ElseiF Map(j-3)=0 and yPos >0 and click=0
      Map(j-3) = Map(j)
      Map(j)=0
      moves +=1
      click=1
      PlayWav w2
   ElseiF Map(j+3)=0 and click=0
      Map(j+3) = Map(j)
      Map(j)=0
      moves +=1
      click=1
      PlayWav w2
   EndiF
EndiF
End Sub

Sub ShowMap()
Long px
For y=0 To 2
For x=0 To 2
j= y*3 + x
iF Map(j)=9
   Map(j)=0
ElseiF Map(j) >=1 and Map(j) <=8
   DrawImage num, x*64,y*64, Map(j)-1
End iF
Next
Next
End Sub

Sub CheckBuffer()
a = Rnd(1,9)
For m=0 To 9
    iF Buf(m)=a Then Exit Sub
Next
Buf(n)=a
n +=1
End Sub

Sub SetNumber()
n=0

While n < 9
CheckBuffer
Wend
For y=0 To 2
For x=0 To 2
    j= y*3 + x
    Map(j) = Buf(j)
Next
Next
End Sub

Sub NewGame()
iF MouseButton()=1 and click=0
iF xMouse()/18 >=3 and xMouse()/18 <=6 and (yMouse()/18) =11 Then
   moves =0
   won =0
   click =1
   For i=0 To 9
       Buf(i) =0
   Next
   For y=0 To 2
   For x=0 To 2
       j= y*3 + x
       Map(j) =0
   Next
   Next
   SetNumber
End iF
End iF
End Sub

SetNumber()

While KeyDown(27)=0
ClsColor BLUE
ShowMap
NewGame
PushNumber
CheckWon
DrawLine 0,193,192,193,1,GREEN
DrawText fo,62,198,"NEW",GREEN
DrawText fo,16,218,"MOVES " + moves,GREEN
iF Won=1
   DrawText fo,62,245,"YOU WIN",YELLOW
End iF   
Sync()
iF MouseButton()=0 Then click=0
Wend
CloseWindow




.