Deal Or No Deal
Blitz3D Forums/Blitz3D Beginners Area/Deal Or No Deal| 
 | ||
| Im updating my version of Deal or No deal to make it look a bit better graphic wise. I posted the original on CodersWorkshop but that don't exist any more. The original was more text based(user input via keyboard). This version will be mouse based. AppTitle "DEAL OR NO DEAL" init_graphics() Global box_state=0 Dim box(22) ;----------------------------------------------------------------------- ;Main Loop ;----------------------------------------------------------------------- While Not KeyHit(1) ClsColor 55,55,55 Cls display_boxes() draw_pointer() Line 0,40,640,40 Line 0,400,640,400 Text 5,5,"Box Picked > "+box_state Flip Wend End ;----------------------------------------------------------------------- ;Functions ;----------------------------------------------------------------------- Function display_boxes() Restore boxdata For n = 1 To 22 Read id$,boxNo$,x,y,w,h If id$="" Then Exit Color 255,0,0 ;top Rect x,y,w,h Color 55,0,0 ;bottom Rect x+1,y+1,w,h Color 200,0,0 ;middle Rect x+1,y+1,w-1,h-1,1 Color 255,255,255 Text x+3,y,boxNo$ check_box(id$,boxNo,x,y,w,h) Next End Function ;----------------------------------------------------------------------- Function check_box(id$,boxNo$,x,y,w,h) If MouseDown(1) If RectsOverlap( MouseX(), MouseY(), 1, 1, x,y,w+1,h+1 ) Then box_state=id$ If box_state=id$ Color 55,55,55 Rect x,y,w+1,h+1,1 End If End If End If End Function ;----------------------------------------------------------------------- Function draw_pointer() Color 255,255,255 Oval MouseX(),MouseY(),4,4,1 End Function ;----------------------------------------------------------------------- Function init_graphics() Graphics3D 640,480,16,2 SetBuffer BackBuffer() SeedRnd MilliSecs() HidePointer End Function ;----------------------------------------------------------------------- ;Data ;----------------------------------------------------------------------- .boxdata Data "1","Box 1",10,100,55,13 Data "2","Box 2",10,120,55,13 Data "3","Box 3",10,140,55,13 Data "4","Box 4",10,160,55,13 Data "5","Box 5",10,180,55,13 Data "6","Box 6",10,200,55,13 Data "7","Box 7",10,220,55,13 Data "8","Box 8",10,240,55,13 Data "9","Box 9",10,260,55,13 Data "10","Box 10",10,280,55,13 Data "11","Box 11",10,300,55,13 Data "12","Box 12",575,100,55,13 Data "13","Box 13",575,120,55,13 Data "14","Box 14",575,140,55,13 Data "15","Box 15",575,160,55,13 Data "16","Box 16",575,180,55,13 Data "17","Box 17",575,200,55,13 Data "18","Box 18",575,220,55,13 Data "19","Box 19",575,240,55,13 Data "20","Box 20",575,260,55,13 Data "21","Box 21",575,280,55,13 Data "22","Box 22",575,300,55,13 Data "","",0,0,0,0 ;----------------------------------------------------------------------- The problem ive got is that the boxes don't deleteafter i have clicked on them. Can any body offer help on this problem Thanks Destroyer :) | 
| 
 | ||
| The simplest way to go would be setting box(box_state) to "1" after clicking on a box. Then, when drawing the boxes, after checking if id$ = "", check if the box(n) = 0 before drawing the box. Another approach would be reading the data only once at the start of the program, and create a type for the boxes. You can than delete a instance from the type to delete a box. | 
| 
 | ||
| Thanks for the reply bram32. I thought about using types for the boxes. Will try your other ideas out Thanks Destroyer :) | 
| 
 | ||
| Ok im using types now but i'm still having problems. 
AppTitle "DEAL OR NO DEAL"
init_graphics()
Type boxes
	Field id$
	Field boxNo$
	Field cash
	Field bx
	Field by
	Field bw
	Field bh
	Field boxState
End Type
Global box.boxes = New boxes
While Not KeyHit(1)
	ClsColor 55,55,55
	Cls
	
	display_boxes()
	
	draw_pointer()
	
	Color 255,255,255;t
	Rect 0,0,640,40
	Color 55,55,55;b
	Rect 1,1,640,40
	Color 150,150,150;m
	Rect 1,1,639,39
	Color 55,55,55
	Text 6,14,"Box State > "+box_state
	
	Color 255,255,255
	Text 5,13,"Box State > "+box_state
		
	Line 0,400,640,400
	
	Flip
Wend
End
;-----------------------------------------------------------------------
;Functions
;-----------------------------------------------------------------------
Function display_boxes()
Restore boxdata
	bData = True
While bData
    
    Read id$
    
    If id$ = ""
       bData = False
    Else
    
    Read boxNo$
    Read bx
    Read by
    Read bh
    Read bw
	box.boxes = New boxes
     	
    If box.boxes <> Null
		box.boxes\id$ = id$
     	box.boxes\boxNo$ = boxNo$
     	box.boxes\bx = bx
     	box.boxes\by = by
     	box.boxes\bh = bh
     	box.boxes\bw = bw
	Else
    	Text 0,0,"ERROR: Could not create an instance of boxes"
           bData = False
        EndIf
    EndIf
Wend
For box.boxes = Each boxes
	Color 255,0,0 ;top
	Rect box\bx,box\by,box\bh,box\bw
	Color 55,0,0 ;bottom
	Rect box\bx+1,box\by+1,box\bh,box\bw
	Color 200,0,0 ;middle
	Rect box\bx+1,box\by+1,box\bh-1,box\bw-1,1
	
	Color 55,55,55
	Text box\bx+4,box\by+1,box\boxNo$
			
	Color 255,255,255
	Text box\bx+3,box\by,box\boxNo$	
Next
check_box(bx,by,bw,bh)
For box.boxes = Each boxes 
     Delete box
Next
End Function
;-----------------------------------------------------------------------
Function check_box(bx,by,bw,bh)
If MouseDown(1)=True
	If RectsOverlap( MouseX(), MouseY(), 1, 1, bx,by,bw+1,bh+1 ) Then
			
			Color 55,55,55 
			Rect bx,by,bw+1,bh+1,1
			
	End If
End If
End Function
;-----------------------------------------------------------------------
Function draw_pointer()
	Color 255,255,255
	Oval MouseX(),MouseY(),4,4,1
	
End Function
;-----------------------------------------------------------------------
Function init_graphics()
	Graphics3D 640,480,16,2
	SetBuffer BackBuffer()
	SeedRnd MilliSecs()
	HidePointer
	
End Function
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
;Data
;-----------------------------------------------------------------------
.boxdata
Data "1","Box  1",10,100,55,13
Data "2","Box  2",10,120,55,13
Data "3","Box  3",10,140,55,13
Data "4","Box  4",10,160,55,13
Data "5","Box  5",10,180,55,13
Data "6","Box  6",10,200,55,13
Data "7","Box  7",10,220,55,13
Data "8","Box  8",10,240,55,13
Data "9","Box  9",10,260,55,13
Data "10","Box 10",10,280,55,13
Data "11","Box 11",10,300,55,13
Data "12","Box 12",575,100,55,13
Data "13","Box 13",575,120,55,13
Data "14","Box 14",575,140,55,13
Data "15","Box 15",575,160,55,13
Data "16","Box 16",575,180,55,13
Data "17","Box 17",575,200,55,13
Data "18","Box 18",575,220,55,13
Data "19","Box 19",575,240,55,13
Data "20","Box 20",575,260,55,13
Data "21","Box 21",575,280,55,13
Data "22","Box 22",575,300,55,13
Data "","",0,0,0,0
;-----------------------------------------------------------------------
now it wont pick a box lol Any ideas Thanks Destroyer :) | 
| 
 | ||
| Ok i can pick boxes again lol Just need to delete them now Thanks Destroyer :) | 
| 
 | ||
| Ok still no lock with this i just cant get it to delete the boxes 
AppTitle "DEAL OR NO DEAL"
init_graphics()
Type boxes
	Field id$
	Field boxNo$
	Field cash
	Field bx
	Field by
	Field bw
	Field bh
	Field boxState
End Type
Global box.boxes = New boxes
Global box_state=0
While Not KeyHit(1)
	ClsColor 55,55,55
	Cls
	
	display_boxes()
	
	draw_pointer()
	Color 255,255,255;t
	Rect 0,0,640,40
	Color 55,55,55;b
	Rect 1,1,640,40
	Color 150,150,150;m
	Rect 1,1,639,39
	Color 55,55,55
	Text 6,14,"Box State > "+box_state
	
	Color 255,255,255
	Text 5,13,"Box State > "+box_state
	
	Color 255,255,255	
	Line 0,400,640,400
	
	Flip
Wend
End
;-----------------------------------------------------------------------
;Functions
;-----------------------------------------------------------------------
Function display_boxes()
Restore boxdata
For n = 1 To 22
    Read id$
	
    If id$ = "" Then Exit
	box_state=0
	
    Read boxNo$
    Read bx
    Read by
    Read bh
    Read bw
	box.boxes = New boxes
     	
    If box.boxes <> Null
	box.boxes\id$ = id$
    box.boxes\boxNo$ = boxNo$
    box.boxes\bx = bx
    box.boxes\by = by
    box.boxes\bh = bh
    box.boxes\bw = bw
    EndIf
Next
For box.boxes = Each boxes
	Color 255,0,0 ;top
	Rect box\bx,box\by,box\bh,box\bw
	Color 55,0,0 ;bottom
	Rect box\bx+1,box\by+1,box\bh,box\bw
	Color 200,0,0 ;middle
	Rect box\bx+1,box\by+1,box\bh-1,box\bw-1,1
	
	Color 55,55,55
	Text box\bx+4,box\by+1,box\boxNo$
			
	Color 255,255,255
	Text box\bx+3,box\by,box\boxNo$	
Next
check_box()
For box.boxes = Each boxes 
     Delete box.boxes
Next
End Function
;-----------------------------------------------------------------------
Function check_box()
For box.boxes = Each boxes
If MouseDown(1)=True
	If RectsOverlap( MouseX(), MouseY(), 1, 1, box\bx,box\by,box\bh+1,box\bw+1 ) Then
			
		box_state=1
		Color 55,55,55 
		Rect box\bx,box\by,box\bh+1,box\bw+1,1
	End If
	
	If box_state=1
		Delete box
	End If
	
End If
Next
End Function
;-----------------------------------------------------------------------
Function draw_pointer()
	Color 255,255,255
	Oval MouseX(),MouseY(),4,4,1
	
End Function
;-----------------------------------------------------------------------
Function init_graphics()
	Graphics3D 640,480,16,2
	SetBuffer BackBuffer()
	SeedRnd MilliSecs()
	HidePointer
	
End Function
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
;Data
;-----------------------------------------------------------------------
.boxdata
Data "1","Box  1",10,100,55,13
Data "2","Box  2",10,120,55,13
Data "3","Box  3",10,140,55,13
Data "4","Box  4",10,160,55,13
Data "5","Box  5",10,180,55,13
Data "6","Box  6",10,200,55,13
Data "7","Box  7",10,220,55,13
Data "8","Box  8",10,240,55,13
Data "9","Box  9",10,260,55,13
Data "10","Box 10",10,280,55,13
Data "11","Box 11",10,300,55,13
Data "12","Box 12",575,100,55,13
Data "13","Box 13",575,120,55,13
Data "14","Box 14",575,140,55,13
Data "15","Box 15",575,160,55,13
Data "16","Box 16",575,180,55,13
Data "17","Box 17",575,200,55,13
Data "18","Box 18",575,220,55,13
Data "19","Box 19",575,240,55,13
Data "20","Box 20",575,260,55,13
Data "21","Box 21",575,280,55,13
Data "22","Box 22",575,300,55,13
Data "","",0,0,0,0
;-----------------------------------------------------------------------
Any help on this Thanks Destroyer :) | 
| 
 | ||
| Each loop you re-create the boxes from the data set, restoring the deleted box...make the box types once, then simply draw them to the screen based on their type data. | 
| 
 | ||
| Replace the restore..read stuff to the start of the program, maybe make an init_boxes function for them. This part: For box.boxes = Each boxes Delete box.boxes Next Should be "Delete Each Box" and should be on the end of the program, after the main loop. To get it to work, the "box_state = 1" command should be "Delete box" and the if box_state = 1 .. etc part should be removed. However, when using the box_state, use box\box_state instead. | 
| 
 | ||
| This works....although it could use some cleaning up... | 
| 
 | ||
| Thanks Bram32 and Mindstorms it works a treat now. Now i can start adding the math functions from the old version Thanks Destroyer :) | 
| 
 | ||
| "deal" :) | 
| 
 | ||
| Here is an optimised version => it will only check the boxes one time per loop. | 
| 
 | ||
| Thanks Bobysait Will use the optimized version Thanks Destroyer :) |