Question

I have a very simple game where if the red balloon is clicked it should increment the score by one.

My c# code

namespace Game { public partial class MainPage : UserControl { int speed, radius, degree, x, y; double radian; private int PopBalloonCount = 0;

    public MainPage()
    {
        InitializeComponent();
        speed = 1;
        radius = 200;
        x =250;
        y = 250;
        degree = 0;
        CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

        score.Content = "Score" + " " + Convert.ToString(PopBalloonCount);  

     }

    public void CompositionTarget_Rendering(Object sender, EventArgs e)
    {
        degree += speed;
        radian = (double)degree / (double)180 * Math.PI;

            Canvas.SetTop(red, y + Math.Sin(radian / 1) * radius);
            Canvas.SetLeft(red, x + Math.Cos(radian * 1) * radius);

    }

        private void redballoon_click(object sender, MouseButtonEventArgs e)
        {
            PopBalloonCount++;
        }    

XAML Code

<Canvas x:Name="LayoutRoot" Background="White" RenderTransformOrigin="0.55,0.541">
    <Image Height="53" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="red" Stretch="Fill" VerticalAlignment="Top" Width="48" Source="red.png" MouseLeftButtonDown="redballoon_click" Canvas.Left="194" Canvas.Top="161" RenderTransformOrigin="0.938,0.536" />
   <sdk:Label x:Name="score" Height="28" Canvas.Left="54" Canvas.Top="206" Width="120" Background="#FFF1CACA"/>
</Canvas>
Was it helpful?

Solution

You need to update score's content whenever PopBallonCount is incremented:

  private void redballoon_click(object sender, MouseButtonEventArgs e)
    {
        PopBalloonCount++;
        score.Content = "Score" + " " + Convert.ToString(PopBalloonCount); 
    }   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top