Esempio n. 1
0
        /// <summary>
        ///     Konstruktor. Wywołuje konstruktor bazowy.
        /// </summary>
        /// <param name="type">Typ gracza.</param>
        protected Player(Enums.PlayerType type)
        {
            ActualColumns.Add(0);
            ActualRows.Add(0);
            X         = Y = 0;
            _blinking = false;
            _dieTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(3),
            };
            _dieTimer.Tick += DieTimer_Tick;

            switch (type)
            {
            case Enums.PlayerType.Agile:
                _speed = GameConst.PlayerSpeed;
                Fill   = CreateImageBrush(GameConst.PlayerAgile);
                break;

            case Enums.PlayerType.Fast:
                _speed = GameConst.FastSpeed;
                Fill   = CreateImageBrush(GameConst.PlayerFast);
                break;

            case Enums.PlayerType.Shy:
                _speed = GameConst.PlayerSpeed;
                Fill   = CreateImageBrush(GameConst.PlayerShy);
                break;
            }
            switch (Difficulty)
            {
            case Enums.LevelDifficulty.Easy:
                RemainingLifes = GameConst.EasyLifes;
                break;

            case Enums.LevelDifficulty.Medium:
                RemainingLifes = GameConst.MediumLifes;
                break;

            case Enums.LevelDifficulty.Hard:
                RemainingLifes = GameConst.HardLifes;
                break;
            }
            RemainingBombs = GameConst.BombCount;
            _firingRange   = GameConst.PlayerFiringRange;
            _scores        = 0;
            _actualBonuses = new List <Bonus>();

            StartTimer();

            _bombNotSetOrExploded = true;

            _bomb = new Bomb();
            GameParameters.ActualBomb = _bomb;
            _bomb.BombBoom           += Boom;
        }
Esempio n. 2
0
        /// <summary>
        ///     Ustawia wroga w losowej (dostępnej) pozycji na planszy.
        /// </summary>
        private void SetRandomPosition()
        {
            var i = StaticRandom.Rand.Next() % GameParameters.EmptyTiles.Count;

            var row    = GameParameters.EmptyTiles[i].Item1;
            var column = GameParameters.EmptyTiles[i].Item2;

            X = TileSize * column;
            Y = TileSize * row;

            ActualRows.Add(row);
            ActualColumns.Add(column);
            Draw();
        }
Esempio n. 3
0
        /// <summary>
        ///     Porusza graczem uwzględniając możliwe kierunki ruchu zawarte w parametrze wejściowym.
        /// </summary>
        /// <param name="moves">Poprawne kierunki ruchu.</param>
        protected virtual void Move(byte moves)
        {
            if (ActualRows.Count != 0)
            {
                ActualRows.Clear();
            }

            if (ActualColumns.Count != 0)
            {
                ActualColumns.Clear();
            }

            if (Keyboard.IsKeyDown(Key.Left) && (moves & Left) == Left)
            {
                X -= _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Right) && (moves & Right) == Right)
            {
                X += _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Up) && (moves & Up) == Up)
            {
                Y -= _speed;
            }

            else if (Keyboard.IsKeyDown(Key.Down) && (moves & Down) == Down)
            {
                Y += _speed;
            }

            ActualRows.Add((int)(Y / TileSize));
            if ((int)((Y + ObjectSize) / TileSize) != ActualRows.FirstOrDefault())
            {
                ActualRows.Add((int)((Y + ObjectSize) / TileSize));
            }

            ActualColumns.Add((int)(X / TileSize));
            if ((int)((X + ObjectSize) / TileSize) != ActualColumns.FirstOrDefault())
            {
                ActualColumns.Add((int)((X + ObjectSize) / TileSize));
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Wykonuje ruch wroga biorąc pod uwagę dostępne aktualnie ruchy.
        /// </summary>
        /// <param name="moves">Dostępne aktualnie kierunki ruchów.</param>
        protected virtual void Move(byte moves)
        {
            if (ActualRows.Count != 0)
            {
                ActualRows.Clear();
            }

            if (ActualColumns.Count != 0)
            {
                ActualColumns.Clear();
            }

            if ((moves & _direction) == _direction)
            {
                switch (_direction)
                {
                case Right:
                    if ((moves & Right) == Right)
                    {
                        X += 1;
                    }
                    break;

                case Left:
                    if ((moves & Left) == Left)
                    {
                        X -= 1;
                    }
                    break;

                case Up:
                    if ((moves & Up) == Up)
                    {
                        Y -= 1;
                    }
                    break;

                case Down:
                    if ((moves & Down) == Down)
                    {
                        Y += 1;
                    }
                    break;
                }
            }
            else
            {
                var direction = StaticRandom.Rand.Next() % 4;
                switch (direction)
                {
                case 0:
                    _direction = Right;
                    break;

                case 1:
                    _direction = Left;
                    break;

                case 2:
                    _direction = Up;
                    break;

                case 3:
                    _direction = Down;
                    break;
                }
            }

            ActualRows.Add((int)(Y / TileSize));
            if ((int)((Y + ObjectSize) / TileSize) != ActualRows.FirstOrDefault())
            {
                ActualRows.Add((int)((Y + ObjectSize) / TileSize));
            }

            ActualColumns.Add((int)(X / TileSize));
            if ((int)((X + ObjectSize) / TileSize) != ActualColumns.FirstOrDefault())
            {
                ActualColumns.Add((int)((X + ObjectSize) / TileSize));
            }
        }