コード例 #1
0
        private void Worm_OnLivesChanged(object obj, Directions direct, int posx, int posy)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                Worm worm = (obj as Worm);
                if (posx < 0)
                {
                    posx = world.Width + posx + 1;
                }
                else if (posx > world.Width)
                {
                    posx = posx - world.Width - 1;
                }
                worm.PosX = posx;
                if (posy < 0)
                {
                    posy = world.Height + posy + 1;
                }
                else if (posy > world.Height)
                {
                    posy = posy - world.Height - 1;
                }
                worm.PosY = posy;
                Canvas.SetLeft(_rectangle, worm.PosX * world.Dimantion);
                Canvas.SetTop(_rectangle, worm.PosY * world.Dimantion);

                switch (direct)
                {
                case Directions.North:
                    lblDirection.Content = "NORTH";
                    break;

                case Directions.South:
                    lblDirection.Content = "SOUTH";
                    break;

                case Directions.West:
                    lblDirection.Content = "WEST";
                    break;

                case Directions.East:
                    lblDirection.Content = "EAST";
                    break;
                }
                lblLifes.Content = worm.Lives.ToString();
                lblDist.Content  = worm.Distance.ToString();
            }));
        }
コード例 #2
0
ファイル: World.cs プロジェクト: hardhill/Worm2
 public void SeedWorm()
 {
     Worm = new Worm();
     (Worm.PosX, Worm.PosY) = RandomPosition();
 }