Beispiel #1
0
        public override void Move()
        {
            int    counter    = 1;
            Random randomizer = new Random();

            while (true)
            {
                Thread.Sleep(GameModel.gameSpeed);
                int x = X;
                int y = Y;

                ChangeCoordinates(ref x, ref y, currentDirection); //out?

                switch (Collision(x, y))
                {
                case collisionType.Wall:
                    currentDirection = ChooseNewDirection(currentDirection);
                    break;

                case collisionType.Tank:
                    currentDirection = ChooseOppositeDirection(currentDirection);
                    ChangeOtherTankDirection(x, y);
                    ChangeCoordinates(ref x, ref y, currentDirection);
                    if (counter % (2 * ownHeight) == 0)   //Сделать возможность не только для квадратов?
                    {
                        counter = 1;
                    }
                    break;

                default:     //Если столкнулся с яблоком или ни с чем
                    X = x;
                    Y = y;
                    break;
                }


                if (counter % (2 * ownHeight) == 0)
                {
                    currentDirection = ChooseNewDirection(currentDirection);
                }

                counter++;

                tankView.ChangeImage(currentDirection);
            }
        }