简体   繁体   English

分数未记录c#silverlight

[英]score not recording c# silverlight

I have a very simple game where if the red balloon is clicked it should increment the score by one. 我有一个非常简单的游戏,如果单击红色气球,它将使得分增加一。

My c# code 我的C#代码

namespace Game { public partial class MainPage : UserControl { int speed, radius, degree, x, y; 名称空间游戏{公共局部类MainPage:UserControl {int速度,半径,度,x,y; double radian; 双弧度 private int PopBalloonCount = 0; 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 XAML代码

<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>

You need to update score's content whenever PopBallonCount is incremented: 每当PopBallonCount递增时,您就需要更新乐谱的内容:

  private void redballoon_click(object sender, MouseButtonEventArgs e)
    {
        PopBalloonCount++;
        score.Content = "Score" + " " + Convert.ToString(PopBalloonCount); 
    }   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM