fifteen (game)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

fifteen (game)

Post by AZJIO »

fifteen (game)

Download: yandex upload.ee (Linux/Windows + Source)
Download (apk): yandex

Image Image
Last edited by AZJIO on Mon Mar 13, 2023 4:51 pm, edited 13 times in total.
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: fifteen (game)

Post by Kiffi »

What is this? An explanation or a screenshot would be helpful.
Hygge
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: fifteen (game)

Post by BarryG »

infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: fifteen (game)

Post by infratec »

BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: fifteen (game)

Post by BarryG »

dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: fifteen (game)

Post by dige »

@AZJIO: nice! Runs also fine as WebApp with SpiderBasic :D

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..."
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: fifteen (game)

Post by AZJIO »

Increased font buttons.
Optimization, mixing occurs virtually, before positioning visually.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: fifteen (game)

Post by Kwai chang caine »

Nice game, thanks for sharing 8)
Thanks also to DIGE spider version works too :wink:
ImageThe happiness is a road...
Not a destination
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: fifteen (game)

Post by AZJIO »

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.

Code: Select all

BindEvent(#PB_Event_SizeWindow, @Events())
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: fifteen (game)

Post by Mijikai »

Nice, thanks for sharing :)
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: fifteen (game)

Post by AZJIO »

Update. Used Canvas
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: fifteen (game)

Post by blueb »

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. :D
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply