Type SoundWork
	soundClip(10) As String*128
	totalNumberOfClips As Integer
	CurentTrek As Integer
	Declare Constructor()
End Type

Type FileWork
	BgCatalog(10) As String*64
	fieldCatalog(10) As String*64
	sizeBgCatalog As Integer
	sizefieldCatalog As Integer
	curentBg As Integer
	curentField As Integer
	Declare Sub ReadCatalog(n As Integer)
	Declare Sub WriteFile()
	Declare Sub ReadFile()
	Declare Constructor()
	Declare sub LoadIm(n As Integer, Pnb As Integer , ByRef im As Any ptr )
End Type

Constructor FileWork()
	ReadCatalog(0)
	ReadCatalog(1)
	ReadFile()
End Constructor

Constructor SoundWork()
	Dim clip As String=Dir(ExePath() & "/res/music/*xm",32)
	dim f as Integer = freefile
	For i As Integer = 0 To 10
		If clip<>"" Then
			soundClip(i) = ExePath() & "/res/music/" & clip
			totalNumberOfClips+=1
		Else
			Exit For
		EndIf
		clip= Dir()		
	Next
End Constructor

Sub FileWork.ReadCatalog(n As Integer)
	Dim path As String
	Dim tempS As String
	Dim tempI As Integer
	If n=1 Then
		path = ExePath & "/res/bg/*"
	Else
		path = ExePath & "/res/field/*"
	EndIf
	tempS = Dir(path,32)
	If tempS<>"" Then
		Do
			If n=1 Then
				BgCatalog(tempI) = tempS
			Else
				fieldCatalog(tempI) = tempS
			EndIf
			tempI+=1
			tempS= Dir()
		Loop until tempS=""
	EndIf
	If n=1 Then
		sizeBgCatalog = tempI
	Else
		sizefieldCatalog = tempI
	EndIf
End Sub

Sub FileWork.LoadIm(n As Integer, Pnb As Integer , ByRef im As Any ptr )
	If n = 1 Then
		If Pnb = 3 Then
			curentBg -= 1
			If curentBg<0 Then
				curentBg = 0
				Exit Sub
			EndIf
		ElseIf Pnb = 4 Then
			curentBg += 1
			If curentBg > (sizeBgCatalog-1) Then
				curentBg = sizeBgCatalog-1
				Exit Sub
			EndIf
		EndIf
		ImageDestroy(im)
		im = ImageCreate(640,480,0)
		BLoad(ExePath & "/res/bg/" & BgCatalog(curentBg) ,im)
	ElseIf n=2 Then
		If Pnb = 1 Then
			curentField -= 1
			If curentField<0 Then
				curentField = 0
				Exit Sub
			EndIf
		ElseIf Pnb = 2 Then
			curentField += 1
			If curentField > (sizefieldCatalog-1) Then
				curentField = sizefieldCatalog-1
				Exit Sub
			EndIf
		EndIf
		ImageDestroy(im)
		im = ImageCreate(369,318,0)
		BLoad(ExePath & "/res/field/" & fieldCatalog(curentfield) ,im)
	ElseIf n = -1 Then
		BLoad(ExePath & "/res/bg/" & BgCatalog(curentBg) ,im)
	ElseIf n = -2 Then
		BLoad(ExePath & "/res/field/" & fieldCatalog(curentfield) ,im)
	EndIf
	WriteFile()
End Sub

Sub FileWork.ReadFile()
	Open ExePath & "/Option" For Binary As #1
	Get #1,,curentBg
	Get #1,,curentfield
	Close #1
End Sub

Sub FileWork.WriteFile()
	Open ExePath & "/Option" For Binary As #1
	Put #1,,curentBg
	put #1,,curentfield
	Close #1
End Sub
