It's the Gadget Game :)

BlitzMax Forums/BlitzMax Programming/It's the Gadget Game :)

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi,

Here's a silly game made with MaxGUI, you should make some too!


'
' It's the Gadget Game
'
' Have fun with it!
'

Strict

?win32
	Framework brl.maxgui
	Import brl.win32maxgui
	Import brl.random
	Import brl.timer
	Import brl.retro
?

SeedRnd MilliSecs()

Global maintext:String = "ASDHVJBCAKJSDHAUEKAFJALKSJIHRERNVAHSDFKNVIEHFKLSJFBNJDKAB"
Global mainchar:String = Chr(maintext[Rand(0,maintext.length-1)])

Local desk:TGadget = Desktop()

Local w:Int = 400
Local h:Int = 20
Local x:Int = (GadgetWidth(desk)-w)/2
Local y:Int = (GadgetHeight(desk)-h)/2

Global win:TGadget = CreateWindow("Gadget Game | By Mikkel Fredborg",x,y,w,h,Null,WINDOW_TITLEBAR|WINDOW_STATUS|WINDOW_CLIENTCOORDS)

Local txt:TGadget = CreateTextArea(0,0,ClientWidth(win),20,win)
SetGadgetFilter(txt,TextFilter)

SetGadgetText(txt,maintext)
ActivateGadget txt

Global sel:Int = 0
Global energy:Int = 5
Global stimmy:Int = MilliSecs()
Global timmy:Int
UpdateStatus()

Notify "DELETE THE "+mainchar+"'S"

Local tickdelay:Int = 3
Local tim:TTimer = CreateTimer(tickdelay)
stimmy = MilliSecs()

While WaitEvent()

	timmy = MilliSecs()-stimmy
	UpdateStatus()

	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
			
		Case EVENT_TIMERTICK
			sel:+1
			If sel=>TextAreaText(txt).length 
				sel = 0
				tickdelay = tickdelay+1
				If tickdelay>10 Then tickdelay = 10
				StopTimer tim
				tim = CreateTimer(tickdelay)
			EndIf
			
			SelectTextAreaText txt,sel,1,0

		Case EVENT_GADGETACTION
			If TextAreaText(txt).find(mainchar) < 0
				Notify "YOU WIN!~nYOU DELETED ALL THE "+mainchar+"'S IN "+MSH(timmy)+"!"
				End
			EndIf

		Case EVENT_GADGETSELECT
			SelectTextAreaText txt,sel,1,0
			
		Default
			ActivateGadget txt
			SelectTextAreaText txt,sel,1,0
								
	EndSelect

Wend

Function TextFilter(event:TEvent,context:Object)

	Select event.id
		Case EVENT_KEYDOWN
			If event.data = KEY_DELETE Or event.data = KEY_BACKSPACE
				Local t:String = TextAreaText(TGadget(event.source),sel,1,0)
				If t=mainchar
					If energy<5 Then energy = energy+1
				
					Return 1
				Else
					energy= energy-1
					
					If energy = 0
						Notify "GAME OVER!"
						End
					EndIf
					
					Return 0
				EndIf
				
			EndIf
	EndSelect

	Return 0

End Function

Function MSH:String(mill)

	Local minu:Int = mill/(1000*60)
	Local seco:Int = (mill/1000) - (minu*60)
	Local hund:Int = (mill-(minu*1000*60)-(seco*1000))/10
	
	Return Replace(RSet(minu,2)," ","0")+":"+Replace(RSet(seco,2)," ","0")+":"+Replace(RSet(hund,2)," ","0")

EndFunction

Function UpdateStatus()
	SetStatusText win,"ENERGY: "+energy+" | TIME: "+MSH(timmy)+" | DELETE THE "+mainchar+"'S"
End Function