Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dice Roller (Revisited)

Status
Not open for further replies.

foundryqa

Technical User
Joined
Oct 17, 2001
Messages
162
Location
US
This is a continuation from the post I had several days ago. At the moment I have a class called die and a collection class called dice. They both work well and have properties that one would expect and a method for each call .roll(). The die class allows for a die of sides 1 through 20. (These are the limits I put into the constructor.) Now I would like to make a "physical" representation of the die class on the screen. I have thought about bitmaps for the values, so if you roll a 3, the image control shows a die with 3 black spots on it and so on. I would like to incorperate the back end logic, methods, properties, with the front end representation of the die.value. Can someone point me in the right direction to tie a control with my class? Please don't give it all away, because I would like to use this as a learning experiment. I just don't know where to start.

Thanks,

Foundry
 
There are a few ways of doing this. The quickest would likely be to create the .bmps for each value, and then have .roll() return a bitmap. Then on your form you could use picturebox1.picture =loadimage(die.roll(6)) or what not.

Another way would be to give the die class a private bitmap variable m_value. Then add a readonly property called Value that returns a bitmap (m_value). Then in the .roll() function, add the logic to set m_value equal to the bitmap that represents the value of the random number. Then you could use something like the above but with 2 lines. The first to roll the die, the second to load the image die.value.

You'll have to look into it. I'm not sure if there is a bitmap object, and the loadimage command is vb6. I haven't played with graphics in .Net much.

-Rick

----------------------
 
Rick,

Thanks for responding so quickly. What about a new control that inherits picturebox, but is used just for a die? Is that overkill? In that way, you could say diepicture.value= die.roll(6) where value is a custom property of diepicture? Just having fun exploring the boundaries of OO. Trying to find the limit of practicallity on the one hand and learning how to implement OO in the other.

Thanks again.

--Foundry
 
woh! good call. I used that trick in Java to play with some graphics. Yeah, inherit from image or bitmap though, you don't need all the wieght of picturebox. Then just add your .roll function and local variable to it. the in the .value property you can set the image and return Me

in theory it should work ;) and there's about 127 more ways to do this too! Your imagination is the limit.

-Rick

----------------------
 
I would probably just end up drawing them in GDI+, and add the ability to randomize they way that they are positioned, meaning some would be at angles, etc. That's just my preference though.
 
a 3d studio max file ;) Actually I just bumped into a page that had links to a Direct X export plugin for 3DS and the DirectX SDK which apparently has VB.Net samples for using DX 3d files.

-Rick

----------------------
 
Hey guys,

Does it make sense to have a class that does not contain any graphical interface for the user (as I have now) and an additional activex control for the times when I want the user to see a die? Also, do I somehow reference the die class in the creation of the control or do I write all of the logic that is in the current class (non - UI) into the control?

Foundry
 
you could have the graphicless die class, and then inherit it into GraphicalDie that could impliment the graphic object you are using.

-Rick

----------------------
 
Thanks Rick. Once again you both present great dialogue and help.

--Foundry
 
GDI+ is simply a set of namespaces for creating (drawing) graphics on the screen. I was suggesting it as an alternative to creating bitmaps--you would create them on the fly in memory, although it is capable of reading in bitmaps and modifying them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top