The dice (shown above) are implemented as a Silverlight user control. You can include this in your own project by adding a reference to the DLL (see downloads below) and modifying the XAML to include the namespace, like this:
xmlns:dice="clr-namespace:Dice3D.Silverlight.DiceUserControl;assembly=Dice3D.Silverlight.DiceControl"
Then when you add the control in the body of the XAML, select the number of dice and dice colours, the container material, the width and height of the control, and other settings:
<dice:DiceControl
Name="diceControl"
Background="Transparent"
Width="700"
Height="320"
Margin="20"
NumDice="8"
MaxDice="8"
ContainerType="Large"
DrawContainer="True"
ContainerMaterial="Beize"
DiceColor="Red"
SpotColor="White"
SpotSize="Medium"
Click="diceControl_Click"
DiceRollComplete="diceControl_DiceRollComplete"
/>
(It is now also possible to specify any RGB colour for the dice, as well as different colours for different dice. It is even possible to use your own images. All this is configured in the XAML - see the example project for more information.)
Then in the code for the page, call the dice control's Roll() method to roll the dice:
this.diceControl.Roll();
and also handle the DiceRollComplete event:
private void OnDiceRolled(object sender, DiceRollCompleteEventArgs e)
{
// e.RolledTotal contains the total score rolled
// e.RolledValues is an array containing the scores rolled on the individual dice
}
The user control works in Silverlight 4 and above. It uses my own home-made 3D library since there's no built-in support for 3D in Silverlight 4.
This example project is a basic skeleton project that includes the dice:
Silverlight 3D Dice Game Template Project
This example project shows the use of mouse events, e.g. clicking on dice:
Silverlight 3D Dice Click Events Demo Project
This project shows the dice control being used in a complete game:
Katego - Complete Game Example project
This is an XNA game component for 3D dice animation, featuring smooth animation and sound effects.
To create a game based on this dice component, first, declare an instance of DiceComponent in your game class:
private DiceComponent diceComponent;
Then instantiate and configure the game component like this:
this.diceComponent = new DiceComponent(this, 4)
.SetNumDice(4)
.SetDiceColors(Color.Red, Color.Blue)
.SetSpotColors(Color.White)
.SetSpotSize(DiceSpotSizeEnum.Large)
.SetContainerMaterial(ContainerMaterialEnum.Wood)
.SetContainerType(ContainerTypeEnum.Large)
.SetCameraPosition(CameraPositionEnum.Side)
.SetMakeSounds(true)
.SetCameraFollow(true)
.SetDrawContainer(true)
.SetLeft(0)
.SetTop(20)
.SetWidth(1200)
.SetHeight(600)
.SetDiceRollComplete(this.OnDiceRollComplete);
All of the above .SetXXX() calls are optional - if a parameter is not configured, a default value will be used.
It is also possible to specify any RGB colour for the dice, as well as different colours for different dice. It is even possible to use your own images. This is configured via the SetDieFaceTextures() method - see the example project for more information.
Register the component in the game's Initialize() method:
protected override void Initialize()
{
this.Components.Add(this.diceComponent);
base.Initialize();
}
Add the event handler OnDiceRollComplete (specified in the SetDiceRollComplete() method call above):
public void OnDiceRollComplete(object sender, DiceRollCompleteEventArgs e)
{
// e.RolledTotal contains the total score rolled
// e.RolledValues is an array containing the scores rolled on the individual dice
}
Then to roll the dice, call the dice component's Roll() method:
this.diceComponent.Roll();
This example project is a basic skeleton project that includes the dice:
XNA 3D Dice Game Template Project
This is a WP7 / XNA game component for 3D dice animation, featuring smooth animation and sound effects.
Here are some screenshots:
To create a game based on this dice component, first, declare an instance of DiceComponent in your game class:
private DiceComponent diceComponent;
Then instantiate and configure the game component like this:
this.diceComponent = new DiceComponent(this, 2)
.SetNumDice(2)
.SetDiceColors(Color.Red, Color.White)
.SetSpotColors(Color.White, Color.Black)
.SetSpotSize(DiceSpotSizeEnum.Large)
.SetContainerMaterial(ContainerMaterialEnum.Wood)
.SetContainerType(ContainerTypeEnum.Small)
.SetCameraPosition(CameraPositionEnum.Overhead)
.SetMakeSounds(true)
.SetCameraFollow(false)
.SetDrawContainer(true)
.SetLeft(0)
.SetTop(220)
.SetWidth(480)
.SetHeight(480)
.SetDiceRollComplete(this.OnDiceRollComplete);
All of the above .SetXXX() calls are optional - if a parameter is not configured, a default value will be used.
It is possible to specify any RGB colour for the dice, as well as different colours for different dice, using SetDiceColors() and SetSpotColors(). It is even possible to use your own images, using the SetDieFaceTextures() method - see the example project for more information.
Register the component in the game's Initialize() method:
protected override void Initialize()
{
this.Components.Add(this.diceComponent);
base.Initialize();
}
Add the event handler OnDiceRollComplete (specified in the SetDiceRollComplete() method call above):
public void OnDiceRollComplete(object sender, DiceRollCompleteEventArgs e)
{
// e.RolledTotal contains the total score rolled
// e.RolledValues is an array containing the scores rolled on the individual dice
}
Then to roll the dice, call the dice component's Roll() method:
this.diceComponent.Roll();
This example project is a basic skeleton project that includes the dice:
Windows Phone 3D Dice Game Template Project
This demo app, which can be downloaded from the Windows Phone Marketplace, demonstrates the dice and provides a settings screen to try various options.
It does the job, however I have no idea why I have to deduct 48 to come to the right figures - in my text boxes boxes(if I don't deduct 48) 1 = 49 2 = 50 3 = 51 etc... Maybe you have an idea why this is.
I will have more questions later on, but I don't want to overload you with questions as surely you have more important things to do.
I managed to integrate your code into mine, I have dice in my game, all I need to do now is put the different code snippets in the right place (not easy considering how I constructed my code and considering my very limited knowledge) but I am sure I can do it.
I promise when I have a complete working model (my part on it's own works perfectly), I will send you the model - You will laugh your head off the way I did it, but it works, so I am actually quite proud about it.
I would appreciate it if you could contact me by email at ........
Thanks again, because of your Dice Simulation, I learned tremendously (It kept me up night after night but it was worth it) - I started this off in Visual Basic but because of your code in C# I had to get to grips with C#
MARC VANDEPUTTE
note :
I live both in France(Dunkirk) and the UK(Minster-Ramsgate) (Always on the shuttle between the 2)