Jump to content

Roulette


GIMPY73
 Share

Recommended Posts

Ok its been i while :)

 

Ive been busy learning BlitzMax for the last few months , trying to get my head around OOP and what not.

 

Anyway , I started working on a roulette game , and im having a few probs with how to do the table.

 

What i mean is this:

 

Do i use some sort of array grid to store the numbers on the table.

 

Do i use some sort of Tlist to store the numbers on the table.

 

Do i use some sort of OOP magic :lol:

 

Are there any more ways of doing this???

 

EG: if i placed a chip on black 17 , how would i check that it is on black 17???

 

Any help on this :)

 

Thanks

Gimpy73 :)

Link to comment
Share on other sites

Is this 2D or 3D Gimpy?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Hey MG.

 

Its 2D at the mo using pure BlitzMax.

 

Once i get the 2D version done i'll then switch over to using LeadWerks , and will model the table and wheel in Cinema4D.

 

Thanks

Gimpy73 :)

Link to comment
Share on other sites

I'd use an image to show the table.

 

Then create a class/type to store all information needed for the numbers, eg:

 

Type Tnumber

Field x:Int
Field y:Int
Field Color:String ' green/black/red

End Type

Local number:TNumber[37]
For Local i = 0 To 36
number[i] = New Tnumber
If i Mod 2 = 0 Then number[i].Color = "black" Else number[i].Color = "red"
Next
number[0].Color = "green"

 

You can then do stuff like:

 

SeedRnd(MilliSecs())
Local nr:int = rnd(0,36)
Notify "The number is: " + nr
Notify "the color is: " + number[nr].Color
Notify "the X position on the table: " + number[nr].x

 

Good luck!

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

Thanks Cocopino.

 

I do use an image of the table as a background , and thought i could map a grid over it.

 

Then if the mouse is on a certain grid number , it equals the table number ;)

 

Well that was one of my ideas :P

 

I'll have a play with your code and see what i can come up with.

 

Thanks

Gimpy73 :)

Link to comment
Share on other sites

Yes, that's the idea with the x and y position, to create a grid.

You can then use this position to create an image (like a stack of chips) there.

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

  • 2 weeks later...

Ok this is what ive got so far :P

 

SuperStrict

AppTitle = "Roulette"

Graphics 800,600

SeedRnd MilliSecs()

Const GRID_WIDTH:Int = 13
Const GRID_HEIGHT:Int = 1

Const GRID_WIDTH1:Int = 14
Const GRID_HEIGHT1:Int = 1

Const GRID_WIDTH2:Int = 3
Const GRID_HEIGHT2:Int = 1

Const GRID_WIDTH3:Int = 6
Const GRID_HEIGHT3:Int = 1

Const GRID_SIZEX:Int = 32
Const GRID_SIZEY:Int = 32

Const GRID_SIZEX1:Int = 128
Const GRID_SIZEY1:Int = 32

Const GRID_SIZEX2:Int = 64
Const GRID_SIZEY2:Int = 32

Global grid:Int[GRID_WIDTH,GRID_HEIGHT]
Global grid1:Int[GRID_WIDTH1,GRID_HEIGHT1]
Global grid2:Int[GRID_WIDTH2,GRID_HEIGHT2]
Global grid3:Int[GRID_WIDTH3,GRID_HEIGHT3]
Global grid4:String[GRID_WIDTH2,GRID_HEIGHT2]
Global grid5:String[GRID_WIDTH3,GRID_HEIGHT3]

Local tiles:TImage=CreateImage(32,96,5)

SetColor 255,255,0	'yellow
DrawRect 0,0,32,32
GrabImage tiles,0,0,0

SetColor 155,0,0		'red
DrawRect 1,1,30,30
GrabImage tiles,0,0,1

SetColor 1,1,1		'black
DrawRect 1,1,30,30
GrabImage tiles,0,0,2

SetColor 50,100,50	'green
DrawRect 1,1,30,30
GrabImage tiles,0,0,3

SetColor 50,80,50		'background
DrawRect 0,0,32,32
GrabImage tiles,0,0,4

Local tiles1:TImage=CreateImage(130,32,2)

SetColor 255,255,0	'yellow
DrawRect 0,0,130,32
GrabImage tiles1,0,0,0

SetColor 50,100,50	'green
DrawRect 1,1,128,30
GrabImage tiles1,0,0,1

Local tiles2:TImage=CreateImage(64,32,4)

SetColor 255,255,0	'yellow
DrawRect 0,0,64,32
GrabImage tiles2,0,0,0

SetColor 50,100,50	'green
DrawRect 1,1,62,30
GrabImage tiles2,0,0,1

SetRotation 45
SetScale (.6,.6)
SetColor 155,0,0		'red
DrawRect 31,2,32,32
GrabImage tiles2,0,0,2

SetColor 1,1,1		'black
DrawRect 31,2,32,32
GrabImage tiles2,0,0,3
SetRotation 0

Global gridData:Int
Global grid1Data:Int
Global grid2Data:Int
Global grid3Data:Int
Global grid4Data:Int

Global numbdata:Int
Global numb1data:Int
Global numb2data:Int

Global textdata:String
Global text1data:String

Global numberpicked:Int

Local mx:Int,my:Int
Local gx:Int,gy:Int

Local offsetx:Int = 200
Local offsety:Int = 350
Local px:Int 
Local py:Int

Cls 
While Not KeyHit(KEY_ESCAPE)

SetBlend alphablend
SetClsColor 50,80,50

mx = MouseX()
my = MouseY()

SetColor 255,255,255

SetRotation 0
SetScale(.98,.98)
RestoreData griddata
'Draw grid
For Local loopy:Int = 0 To GRID_HEIGHT-1
	For Local loopx:Int =0 To GRID_WIDTH-1
		ReadData griddata
		grid:Int[loopx,loopy] = griddata
		DrawImage tiles,loopx * GRID_SIZEX+ offsetx, loopy * GRID_SIZEY+ offsety,grid[loopx,loopy]
	Next
Next

RestoreData grid1data
'Draw grid
For Local loopy:Int = 0 To GRID_HEIGHT1-1
	For Local loopx:Int =0 To GRID_WIDTH1-1
		ReadData grid1data
		grid1:Int[loopx,loopy] = grid1data
		DrawImage tiles,loopx * GRID_SIZEX+ offsetx-32, loopy * GRID_SIZEY+ offsety+32,grid1[loopx,loopy]
	Next
Next

RestoreData grid2data
'Draw grid
For Local loopy:Int = 0 To GRID_HEIGHT-1
	For Local loopx:Int =0 To GRID_WIDTH-1
		ReadData grid2data
		grid:Int[loopx,loopy] = grid2data
		DrawImage tiles,loopx * GRID_SIZEX+ offsetx, loopy * GRID_SIZEY+ offsety+64,grid[loopx,loopy]
	Next
Next

RestoreData grid3data
'Draw grid
For Local loopy:Int = 0 To GRID_HEIGHT2-1
	For Local loopx:Int =0 To GRID_WIDTH2-1
		ReadData grid3data
		grid2:Int[loopx,loopy] = grid3data
		DrawImage tiles1,loopx * GRID_SIZEX1+ offsetx, loopy * GRID_SIZEY1+ offsety+96,grid2[loopx,loopy]
	Next
Next

RestoreData grid4data
'Draw grid
For Local loopy:Int = 0 To GRID_HEIGHT3-1
	For Local loopx:Int =0 To GRID_WIDTH3-1
		ReadData grid4data
		grid3:Int[loopx,loopy] = grid4data
		DrawImage tiles2,loopx * GRID_SIZEX2+ offsetx, loopy * GRID_SIZEY2+ offsety+128,grid3[loopx,loopy]
	Next
Next

'Highlight square 
If MouseX() > 5*GRID_SIZEX And MouseY() > 11*GRID_SIZEY Then

	If MouseX() < 19*GRID_SIZEX And MouseY() < 14*GRID_SIZEY Then
		SetBlend lightblend
		Px = Floor(MouseX()/GRID_SIZEX)
		Py = Floor(MouseY()/GRID_SIZEY)
		SetColor 150,200,150
		DrawRect Px*GRID_SIZEX+9,Py*GRID_SIZEY-1,GRID_SIZEX-2,GRID_SIZEY-2

	EndIf

EndIf

'Highlight square 
If MouseX() > 8*GRID_SIZEX And MouseY() > 14*GRID_SIZEY Then

	If MouseX() < 18*GRID_SIZEX And MouseY() < 15*GRID_SIZEY Then
		SetBlend lightblend
		Px = Floor(MouseX()/GRID_SIZEX1)
		Py = Floor(MouseY()/GRID_SIZEY1)
		SetColor 150,200,150
		DrawRect Px*GRID_SIZEX1-55,Py*GRID_SIZEY1+28,GRID_SIZEX1,GRID_SIZEY1-160

	EndIf

EndIf

'Highlight square 
If MouseX() > 7*GRID_SIZEX And MouseY() > 15*GRID_SIZEY Then

	If MouseX() < 18*GRID_SIZEX And MouseY() < 16*GRID_SIZEY Then
		SetBlend lightblend
		Px = Floor(MouseX()/GRID_SIZEX2)
		Py = Floor(MouseY()/GRID_SIZEY2)
		SetColor 150,200,150
		DrawRect Px*GRID_SIZEX2+8,Py*GRID_SIZEY2-1,GRID_SIZEX2,GRID_SIZEY2-2

	EndIf

EndIf

If MouseDown(1) 

	SetScale(1,1)
	SetColor 255,255,255
	numberpicked = grid1data

End If

RestoreData numbdata
'Draw grid1
For Local loopy:Int = 0 To GRID_HEIGHT-1
	For Local loopx:Int = 0 To GRID_WIDTH-1
		ReadData numbdata
		grid:Int[loopx,loopy] = numbdata
		SetColor 255,255,255
		'SetScale(2,2)
		DrawText numbdata,loopx*GRID_SIZEX+8 + offsetx ,loopy*GRID_SIZEY+8 + offsety
		SetScale(1,1)
	Next
Next

RestoreData numb1data
'Draw grid1
For Local loopy:Int = 0 To GRID_HEIGHT1-1
	For Local loopx:Int = 0 To GRID_WIDTH1-1
		ReadData numb1data
		grid1:Int[loopx,loopy] = numb1data
		SetColor 255,255,255
		'SetScale(2,2)
		DrawText numb1data,loopx*GRID_SIZEX+8 + offsetx-32 ,loopy*GRID_SIZEY+8 + offsety+32
		SetScale(1,1)
	Next
Next

RestoreData numb2data
'Draw grid1
For Local loopy:Int = 0 To GRID_HEIGHT-1
	For Local loopx:Int = 0 To GRID_WIDTH-1
		ReadData numb2data
		grid:Int[loopx,loopy] = numb2data
		SetColor 255,255,255
		'SetScale(2,2)
		DrawText numb2data,loopx*GRID_SIZEX+8 + offsetx ,loopy*GRID_SIZEY+8 + offsety+64
		SetScale(1,1)
	Next
Next

RestoreData textdata
'Draw grid1
For Local loopy:Int = 0 To GRID_HEIGHT2-1
	For Local loopx:Int = 0 To GRID_WIDTH2-1
		ReadData textdata
		grid4:String[loopx,loopy] = textdata
		SetColor 255,255,255
		'SetScale(2,2)
		DrawText textdata,loopx*GRID_SIZEX1+8 + offsetx ,loopy*GRID_SIZEY1+8 + offsety+96
		SetScale(1,1)
	Next
Next

RestoreData text1data
'Draw grid1
For Local loopy:Int = 0 To GRID_HEIGHT3-1
	For Local loopx:Int = 0 To GRID_WIDTH3-1
		ReadData text1data
		grid5:String[loopx,loopy] = text1data
		SetColor 255,255,255
		'SetScale(2,2)
		DrawText text1data,loopx*GRID_SIZEX2 + offsetx+6 ,loopy*GRID_SIZEY2+8 + offsety+128
		SetScale(1,1)
	Next
Next

gx = (mx - offsetx) / GRID_SIZEX
gy = (my - offsety) / GRID_SIZEY

If gx>=0 And gx<=GRID_WIDTH-1 And gy>=0 And gy<=GRID_HEIGHT-1 
	gridData = grid[gx, gy]
	grid1Data = grid1[gx, gy]
EndIf

SetColor 255,255,255
'DrawText "Number: "+numberpicked ,10,570
Flip ; Cls
Wend
End

#gridData
DefData 1,2,1,1,2,1,1,2,1,1,2,1,3
#grid1Data
DefData 3,2,1,2,2,1,2,2,1,2,2,1,2,3
#grid2data
DefData 1,2,1,2,2,1,1,2,1,2,2,1,3
#grid3data
DefData 1,1,1
#grid4data
DefData 1,1,2,3,1,1

#numbdata
DefData 3,6,9,12,15,18,21,24,27,30,33,36,3
#numb1data
DefData 0,2,5,8,11,14,17,20,23,26,29,32,35,2
#numb2data
DefData 1,4,7,10,13,16,19,22,25,28,31,34,1

#textdata
DefData "    1st 12","    2nd 12","    3rd 12"
#text1data
DefData " 1to18"," EVEN","",""," ODD","19to36"

 

Its rough code but does what i need.

 

Thanks

Gimpy73 :o

Link to comment
Share on other sites

A good thing to remember when coding is: when you're copying the same code over and over again, there must be a simpler way :blink:

 

A function like this (not tested, hope you get the general idea):

function BuildGrid(maxX:int,maxY:int,numbdata:int)

       For Local loopy:Int = 0 To maxY
               For Local loopx:Int = 0 To maxX
                       ReadData numbdata
                       grid:Int[loopx,loopy] = numbdata
                       SetColor 255,255,255
                       'SetScale(2,2)
                       DrawText numbdata,loopx*GRID_SIZEX+8 + offsetx ,loopy*GRID_SIZEY+8 + offsety
                       SetScale(1,1)
               Next
       Next
end function

 

will half your code in size. More importantly, when you want to change anything you'll only need to do that once instead of tracing your code in every single loop you made. You can call the function like this (example):

 

BuildGrid(GRID_HEIGHT-1,GRID_WIDTH1-1,numbdata1)

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...