Finally, it is time to combine the three new gauges with the 3D scenes and add the necessary update logic to the game.
1. Open the project
3DInvadersSilverlight
in Visual Studio or Visual C#.2. Open
MainPage.xaml.cs
the C# code forMainPage.xaml
.3. Add the following
private
variable in thepublic partial class MainPage : UserControl
, to hold instances for each newUserControl
subclass that defines a gauge:private BonusGauge _bonusGauge; private FuelGauge _fuelGauge; private LifeGauge _lifeGauge;
4. Add the following
public
method to update the values shown in the different gauges:public void SetBonus(int newBonus) { _bonusGauge.SetBonus(newBonus); } public void SetFuelLevel(int newFuelLevel) { _fuelGauge.SetFuelLevel(newFuelLevel); } public void SetLives(int newLives) { _lifeGauge.SetLives(newLives); }
5. Add the following lines of code before the end of the
btnStartGame
button'sClick
event, to create and add each newUserControl
subclass...