fifteen (game)
fifteen (game)
Last edited by AZJIO on Mon Mar 13, 2023 4:51 pm, edited 13 times in total.
Re: fifteen (game)
Tiny ASCII version -> https://rosettacode.org/wiki/15_puzzle_game#PureBasic
Re: fifteen (game)
@AZJIO: nice! Runs also fine as WebApp with SpiderBasic
Code: Select all
; AZJIO, converting my code from AutoIt from 2012.07.17
; AZJIO, преобразование моего кода из AutoIt от 2012.07.17
; DiGe Adapted for SpiderBasic 2021.02.17
EnableExplicit
#Window = 0
#Refresh = 17
Global s=50, x.b, y.b, i,b, evg, bRefresh = #True
Global Dim aXY(16, 4)
Declare reButton(i)
Declare Refresh()
Declare reArr(o, u, n)
Global Dim Lng.s(2)
; Строки интерфейса даже если языковой файл не найден
Lng(1) = "Fifteen"
Lng(2) = "Mix"
Lng(0) = "Excellently!"
Procedure Events()
evg = EventGadget()
Select evg
Case 1 To 15
; Debug evg
If bRefresh
Refresh()
ProcedureReturn
EndIf
If (aXY(evg, 2) = aXY(16, 2) And (aXY(evg, 3) = aXY(16, 3) + 1 Or aXY(evg, 3) = aXY(16, 3) - 1)) Or (aXY(evg, 3) = aXY(16, 3) And (aXY(evg, 2) = aXY(16, 2) + 1 Or aXY(evg, 2) = aXY(16, 2) - 1))
reButton(evg)
EndIf
; displacement on 2-3 buttons.
If aXY(evg, 2) = aXY(16, 2)
If aXY(evg, 3) = aXY(16, 3) + 2 ; from below upwards
reArr(0, 1, 2)
ElseIf aXY(evg, 3) = aXY(16, 3) + 3
reArr(0, 1, 3)
ElseIf aXY(evg, 3) = aXY(16, 3) - 2 ; from top to bottom
reArr(0, -1, 2)
ElseIf aXY(evg, 3) = aXY(16, 3) - 3
reArr(0, -1, 3)
EndIf
ElseIf aXY(evg, 3) = aXY(16, 3)
If aXY(evg, 2) = aXY(16, 2) + 2 ; right to left
reArr(1, 0, 2)
ElseIf aXY(evg, 2) = aXY(16, 2) + 3
reArr(1, 0, 3)
ElseIf aXY(evg, 2) = aXY(16, 2) - 2 ; left to right
reArr(-1, 0, 2)
ElseIf aXY(evg, 2) = aXY(16, 2) - 3
reArr(-1, 0, 3)
EndIf
EndIf
; проверяем с конца последовательности, как наименее вероятную. Проверка только после нажатия кнопки.
If aXY(16, 2) = 3 And aXY(16, 3) = 3 And aXY(15, 2) = 2 And aXY(15, 3) = 3 And aXY(14, 2) = 1 And aXY(14, 3) = 3 And aXY(13, 2) = 0 And aXY(13, 3) = 3 And aXY(12, 2) = 3 And aXY(12, 3) = 2 And aXY(11, 2) = 2 And aXY(11, 3) = 2 And aXY(10, 2) = 1 And aXY(10, 3) = 2 And aXY(9, 2) = 0 And aXY(9, 3) = 2 And aXY(8, 2) = 3 And aXY(8, 3) = 1 And aXY(7, 2) = 2 And aXY(7, 3) = 1 And aXY(6, 2) = 1 And aXY(6, 3) = 1 And aXY(5, 2) = 0 And aXY(5, 3) = 1 And aXY(4, 2) = 3 And aXY(4, 3) = 0 And aXY(3, 2) = 2 And aXY(3, 3) = 0 And aXY(2, 2) = 1 And aXY(2, 3) = 0 And aXY(1, 2) = 0 And aXY(1, 3) = 0
bRefresh = #True
; Delay(500)
MessageRequester(Lng(0))
; Refresh()
EndIf
Case #Refresh
Refresh()
EndSelect
EndProcedure
If OpenWindow(#Window, 0, 0, 4*s, 4*s + 37, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; Генерируем кнопки
y = 0
x = 0
For i = 1 To 16
aXY(i, 0) = i
Select i
Case 1 To 4
y = 0
x = 1
Case 5 To 8
y = 1
x = 5
Case 9 To 12
y = 2
x = 9
Case 13 To 16
y = 3
x = 13
EndSelect
aXY(i, 2) = i - x
aXY(i, 3) = y
; Debug aXY(i, 0)
If i < 16
ButtonGadget(aXY(i, 0), aXY(i, 2) * s, aXY(i, 3) * s, s, s, Str(i))
BindGadgetEvent(aXY(i, 0), @Events(), #PB_EventType_LeftClick)
EndIf
Next
; конец => Генерируем кнопки
ButtonGadget(#Refresh, 0, 200, 200, 20, Lng(2))
BindGadgetEvent(#Refresh, @Refresh(), #PB_EventType_LeftClick)
EndIf
Procedure Refresh()
Protected u
bRefresh = #False
For u = 1 To 500
Select Random(4, 1)
Case 1
For i = 1 To 16
If aXY(i, 2) = aXY(16, 2) + 1 And aXY(i, 3) = aXY(16, 3)
reButton(i)
EndIf
Next
Case 2
For i = 1 To 16
If aXY(i, 2) = aXY(16, 2) - 1 And aXY(i, 3) = aXY(16, 3)
reButton(i)
EndIf
Next
Case 3
For i = 1 To 16
If aXY(i, 2) = aXY(16, 2) And aXY(i, 3) = aXY(16, 3) + 1
reButton(i)
EndIf
Next
Case 4
For i = 1 To 16
If aXY(i, 2) = aXY(16, 2) And aXY(i, 3) = aXY(16, 3) - 1
reButton(i)
EndIf
Next
EndSelect
Next
EndProcedure
Procedure reButton(i)
Protected tmp2, tmp3
ResizeGadget(aXY(i, 0), aXY(16, 2)*s, aXY(16, 3)*s, #PB_Ignore, #PB_Ignore)
tmp2 = aXY(i, 2)
tmp3 = aXY(i, 3)
aXY(i, 2) = aXY(16, 2)
aXY(i, 3) = aXY(16, 3)
aXY(16, 2) = tmp2
aXY(16, 3) = tmp3
EndProcedure
Procedure reArr(o, u, n)
Protected j, i
For j = 1 To n
For i = 1 To 16
If aXY(i, 2) = aXY(16, 2) + o And aXY(i, 3) = aXY(16, 3) + u
reButton(i)
Break
EndIf
Next
Next
EndProcedure
"Daddy, I'll run faster, then it is not so far..."
Re: fifteen (game)
Increased font buttons.
Optimization, mixing occurs virtually, before positioning visually.
Optimization, mixing occurs virtually, before positioning visually.
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: fifteen (game)
Nice game, thanks for sharing
Thanks also to DIGE spider version works too
Thanks also to DIGE spider version works too
The happiness is a road...
Not a destination
Not a destination
Re: fifteen (game)
You can try my updated source for android.
Download
ResizeGadget - works in the browser, but does not work in the APK, so I removed this piece of code.
Download
ResizeGadget - works in the browser, but does not work in the APK, so I removed this piece of code.
Code: Select all
BindEvent(#PB_Event_SizeWindow, @Events())
Re: fifteen (game)
Nice, thanks for sharing
Re: fifteen (game)
Thanks AZJIO,
I'm just getting started with SpiderBasic and the fact that you have both PureBasic and SpiderBasic included helps a lot (to see the differences)
Now if a 'SpiderPerson' would do a step by step procedure to convert the SB code to an Android APK.. that would help a beginner.
I've recently got a 10" Android tablet that needs some apps.
I'm just getting started with SpiderBasic and the fact that you have both PureBasic and SpiderBasic included helps a lot (to see the differences)
Now if a 'SpiderPerson' would do a step by step procedure to convert the SB code to an Android APK.. that would help a beginner.
I've recently got a 10" Android tablet that needs some apps.
- It was too lonely at the top.
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem