Example #1
0
        //cikula na igrata
        public void StartGame()
        {
            timer.Interval = TimeSpan.FromMilliseconds(GlobalConstants.timerFramesIntervalInMiliSeconds);
            timer.Tick    += (sender, args) =>
            {
                CollisionDetector.CheckForRebounce(this.rebouncableObjects, this.movingObjects);

                var screenSize = GameObjectsFactory.GenerateNewSize(this.renderer.ScreenWidth, this.renderer.ScreenHeight);

                if (CollisionDetector.CheckForBoundariesRebound(movingObjects, screenSize))
                {
                    timer.Stop();
                    this.renderer.ShowEndGameScreen();
                }

                //proverka za udar i smqna na skorosta i posokata pri udar //maha udarenite ot bricks
                foreach (var movingObject in this.movingObjects)
                {
                    var posibleCollision = CollisionDetector.CheckForCollisionWithBricks(movingObject, this.Bricks, screenSize);
                    if (posibleCollision.CollideteStaticElementIndex != -1)
                    {
                        if (posibleCollision.Side == HitTypeEnum.horizontal)
                        {
                            movingObject.Speed = GameObjectsFactory.GenerateNewPosition(movingObject.Speed.Left, -movingObject.Speed.Top);
                        }
                        else
                        {
                            movingObject.Speed = GameObjectsFactory.GenerateNewPosition(-movingObject.Speed.Left, movingObject.Speed.Top);
                        }
                        this.bricks[posibleCollision.CollideteStaticElementIndex].DestroyMe();
                    }
                }

                //za vsqko ubito increase na highscore

                int score = 0;

                foreach (var brick in this.bricks)
                {
                    if (brick.IsAlive == false)
                    {
                        score += brick.PointsForBraking;
                    }
                }

                (this.HighScore as HighScore).IncreaseHighScore(score);

                this.bricks.RemoveAll(x => x.IsAlive == false);

                if (this.bricks.Count == 0)
                {
                    timer.Stop();
                    this.renderer.ShowWinGameScreen(HighScore.Text);
                }

                this.renderer.Clear();

                foreach (var bal in movingObjects)
                {
                    bal.MoveWithCurrentSpeed(); //premestva topkata sys segashnata i skorost
                }

                //draw bricks,pad and ball
                this.renderer.Draw(this.HighScore);
                this.renderer.Draw(this.RebouncableObjects.ToArray());
                this.renderer.Draw(this.movingObjects.ToArray());
                this.renderer.Draw(this.bricks.Where(x => x.IsAlive == true).ToArray());
            };
            timer.Start();
        }