Exemple #1
0
        public void Place(MovementWay way)
        {
            if (_catched)
            {
                return;
            }

            _movement = way;

            OnPaint(new PaintEventArgs(CreateGraphics(), ClientRectangle));

            if (!IsBlock())
            {
                switch (way)
                {
                case MovementWay.Up:
                    Location = new Point(Location.X, Location.Y);
                    break;

                case MovementWay.Down:
                    Location = new Point(Location.X, Location.Y);
                    break;

                case MovementWay.Left:
                    Location = new Point(Location.X, Location.Y);
                    break;

                case MovementWay.Right:
                    Location = new Point(Location.X, Location.Y);
                    break;
                }
            }
        }
Exemple #2
0
        public new void Move(MovementWay way)
        {
            switch (way)
            {
            case MovementWay.Up:
                this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                break;

            case MovementWay.Down:
                this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                break;

            case MovementWay.Left:
                this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                break;

            case MovementWay.Right:
                this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                break;
            }

            if (_pacman != null)
            {
                Enemy_Movement(this, this.Location);
                return;
            }

            if (Enemy_Movement != null)
            {
                Enemy_Movement(this, this.Location);
            }
        }
Exemple #3
0
        void GameInitialization()
        {
            LoadBlocks();
            _pack = new Pacman(ref _blocks)
            {
                Location = new Point(40, 40)
            };
            _currentX  = 40;
            _currentY  = 40;
            _direction = MovementWay.Right;

            PacmanGroupBox.Controls.Add(_pack);
            lblReport.Text = _pack.Location.ToText(MovementWay.Right);

            var directions = new[] {
                new { Name = "NORTH", Direction = MovementWay.Up },
                new { Name = "SOUTH", Direction = MovementWay.Down },
                new { Name = "EAST", Direction = MovementWay.Right },
                new { Name = "WEST", Direction = MovementWay.Left }
            }.ToList();

            ddlDirection.DataSource    = directions;
            ddlDirection.DisplayMember = "Name";
            ddlDirection.ValueMember   = "Direction";
            ddlDirection.SelectedIndex = 2;
        }
Exemple #4
0
        public static void Draw(ref PaintEventArgs e, CharacterType type, MovementWay way = MovementWay.Right)
        {
            switch (type)
            {
            case CharacterType.Packman:
                e.Graphics.Clear(SystemColors.Control);
                e.Graphics.FillEllipse(Brushes.Yellow, new Rectangle(0, 0, 40, 40));
                switch (way)
                {
                case MovementWay.Right:
                    e.Graphics.FillPolygon(SystemBrushes.Control, new[] { new Point(40, 0), new Point(20, 20), new Point(40, 40) });
                    e.Graphics.FillEllipse(Brushes.Black, new Rectangle(10, 10, 5, 5));
                    break;

                case MovementWay.Left:
                    e.Graphics.FillPolygon(SystemBrushes.Control, new[] { new Point(0, 0), new Point(20, 20), new Point(0, 40) });
                    e.Graphics.FillEllipse(Brushes.Black, new Rectangle(20, 10, 5, 5));
                    break;

                case MovementWay.Up:
                    e.Graphics.FillPolygon(SystemBrushes.Control, new[] { new Point(0, 0), new Point(20, 20), new Point(40, 0) });
                    e.Graphics.FillEllipse(Brushes.Black, new Rectangle(10, 20, 5, 5));
                    break;

                case MovementWay.Down:
                    e.Graphics.FillPolygon(SystemBrushes.Control, new[] { new Point(0, 40), new Point(20, 20), new Point(40, 40) });
                    e.Graphics.FillEllipse(Brushes.Black, new Rectangle(10, 10, 5, 5));
                    break;
                }
                break;
            }
        }
Exemple #5
0
        public new void Move(MovementWay way)
        {
            if (_Catched)
            {
                return;
            }

            _Movement = way;

            OnPaint(new System.Windows.Forms.PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));

            if (!IsBlock())
            {
                switch (way)
                {
                case MovementWay.Up:
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                    break;

                case MovementWay.Down:
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                    break;

                case MovementWay.Left:
                    this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                    break;

                case MovementWay.Right:
                    this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                    break;
                }
            }
            Pacman_Movement?.Invoke(this, this.Location);
        }
Exemple #6
0
        public new void Move(MovementWay way)
        {
            switch (way)
            {
                case MovementWay.Up:
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                    break;

                case MovementWay.Down:
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                    break;

                case MovementWay.Left:
                    this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                    break;

                case MovementWay.Right:
                    this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                    break;
            }

            if (_pacman != null)
            {
                Enemy_Movement(this, this.Location);
                return;
            }

            if (Enemy_Movement != null)
                Enemy_Movement(this, this.Location);
        }
Exemple #7
0
 private void btnPlace_Click(object sender, EventArgs e)
 {
     _currentX  = Convert.ToInt32((updownX.Value + 1) * 20);
     _currentY  = Convert.ToInt32((updownY.Value + 1) * 20);
     _direction = (MovementWay)Enum.Parse(typeof(MovementWay), ddlDirection.SelectedValue.ToString());
     PlacePackman();
 }
Exemple #8
0
        public static void Draw(ref System.Windows.Forms.PaintEventArgs e, CharacterType type, MovementWay way = MovementWay.Right)
        {
            switch (type)
            {
                case CharacterType.Packman:
                    e.Graphics.Clear(System.Drawing.SystemColors.Control);
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Yellow, 0, 0, 20, 20);
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(6, 7, 3, 3));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(12, 7, 3, 3));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(12, 7, 3, 3));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(8, 12, 6, 2));
                    break;

                case CharacterType.Enemy:
                    e.Graphics.Clear(System.Drawing.SystemColors.Control);
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Blue, new System.Drawing.Rectangle(0, 0, 20, 25));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(4, 8, 3, 3));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(13, 8, 3, 3));
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control,
                                            new System.Drawing.Point[] {
                                                    new System.Drawing.Point(1, 20),
                                                    new System.Drawing.Point(4, 15),
                                                    new System.Drawing.Point(7, 20),
                                                    new System.Drawing.Point(10, 15),
                                                    new System.Drawing.Point(13, 20),
                                                    new System.Drawing.Point(16, 15),
                                                    new System.Drawing.Point(19, 20)});
                    break;
            }
        }
Exemple #9
0
        public new void Move(MovementWay way)
        {
            switch (way)
            {
            case MovementWay.Up:
                Location = new Point(Location.X, Location.Y - Speed);
                break;

            case MovementWay.Down:
                Location = new Point(Location.X, Location.Y + Speed);
                break;

            case MovementWay.Left:
                Location = new Point(Location.X - Speed, Location.Y);
                break;

            case MovementWay.Right:
                Location = new Point(Location.X + Speed, Location.Y);
                break;
            }

            if (_pacman != null)
            {
                Enemy_Movement(this, Location);
                return;
            }

            Enemy_Movement?.Invoke(this, Location);
        }
Exemple #10
0
        public static void Draw(ref System.Windows.Forms.PaintEventArgs e, CharacterType type,MovementWay way = MovementWay.Right)
        {
            switch (type)
            {
                case CharacterType.Packman:
                    e.Graphics.Clear(System.Drawing.SystemColors.Control);
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Yellow, new System.Drawing.Rectangle(0, 0, 40, 40));
                    switch (way)
                    {
                        case MovementWay.Right:
                            e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(40, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 40) });
                            e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 10, 5, 5));
                            break;
                        case MovementWay.Left:
                            e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(0, 40) });
                            e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(20, 10, 5, 5));
                            break;

                        case MovementWay.Up:
                            e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 0) });
                            e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 20, 5, 5));
                            break;

                        case MovementWay.Down:
                            e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 40), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 40) });
                            e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 10, 5, 5));
                            break;

                    }
                    break;

                case CharacterType.Enemy:
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Blue, new System.Drawing.Rectangle(0, 0, 40, 50));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(10, 10, 5, 5));
                    e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(25, 10, 5, 5));
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control,
                                            new System.Drawing.Point[] {
                                                    new System.Drawing.Point(0, 40),
                                                    new System.Drawing.Point(5, 30),
                                                    new System.Drawing.Point(10, 40),
                                                    new System.Drawing.Point(15, 30),
                                                    new System.Drawing.Point(20, 40),
                                                    new System.Drawing.Point(25, 30),
                                                    new System.Drawing.Point(30, 40),
                                                    new System.Drawing.Point(35, 30),
                                                    new System.Drawing.Point(40, 40),});

                    break;
            }
        }
Exemple #11
0
        public new void Move(MovementWay way)
        {
            if (_catched)
            {
                return;
            }
            _movement = way;
            OnPaint(new System.Windows.Forms.PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
            switch (way)
            {
            case MovementWay.Up:
                if (!IsBlock(_movement))
                {
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                }
                break;

            case MovementWay.Down:
                if (!IsBlock(_movement))
                {
                    this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                }
                break;

            case MovementWay.Left:
                if (!IsBlock(_movement))
                {
                    this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                }
                break;

            case MovementWay.Right:
                if (!IsBlock(_movement))
                {
                    this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                }
                break;
            }
            if (_dots != null)
            {
                Pacman_Movement(this, this.Location);
                return;
            }
            if (Pacman_Movement != null)
            {
                Pacman_Movement(this, this.Location);
            }
        }
        public static string ToText(this Point point, MovementWay direction)
        {
            switch (direction)
            {
            case MovementWay.Up:
                return($"Output : {(point.X / 20) - 1}, {(point.Y / 20) - 1}, North");

            case MovementWay.Down:
                return($"Output : {(point.X / 20) - 1}, {(point.Y / 20) - 1}, South");

            case MovementWay.Right:
                return($"Output : {(point.X / 20) - 1}, {(point.Y / 20) - 1}, East");

            case MovementWay.Left:
                return($"Output : {(point.X / 20) - 1}, {(point.Y / 20) - 1}, West");
            }
            return(string.Empty);
        }
Exemple #13
0
        Point GetNewLocation(MovementWay way)
        {
            switch (way)
            {
            case MovementWay.Up:
                return(new System.Drawing.Point(this.Location.X, this.Location.Y - Speed));

            case MovementWay.Down:
                return(new System.Drawing.Point(this.Location.X, this.Location.Y + Speed));

            case MovementWay.Left:
                return(new System.Drawing.Point(this.Location.X - Speed, this.Location.Y));

            case MovementWay.Right:
                return(new System.Drawing.Point(this.Location.X + Speed, this.Location.Y));
            }
            return(new Point());
        }
Exemple #14
0
        public new void Move(MovementWay way)
        {
            if (_Catched)
            {
                return;
            }

            _Movement = way;

            OnPaint(new PaintEventArgs(CreateGraphics(), ClientRectangle));

            if (!IsBlock())
            {
                switch (way)
                {
                case MovementWay.Up:
                    Location = new Point(Location.X, Location.Y - Speed);
                    break;

                case MovementWay.Down:
                    Location = new Point(Location.X, Location.Y + Speed);
                    break;

                case MovementWay.Left:
                    Location = new Point(Location.X - Speed, Location.Y);
                    break;

                case MovementWay.Right:
                    Location = new Point(Location.X + Speed, Location.Y);
                    break;
                }
            }

            if (_Dots != null)
            {
                Pacman_Movement(this, Location);
                return;
            }

            Pacman_Movement?.Invoke(this, Location);
        }
Exemple #15
0
        public new virtual void Move(MovementWay way)
        {
            switch (way)
            {
                case MovementWay.Up:
                    this.Location = new Point(this.Location.X, this.Location.Y - Speed);
                    break;

                case MovementWay.Down:
                    this.Location = new Point(this.Location.X, this.Location.Y + Speed);
                    break;

                case MovementWay.Left:
                    this.Location = new Point(this.Location.X - Speed, this.Location.Y);
                    break;

                case MovementWay.Right:
                    this.Location = new Point(this.Location.X + Speed, this.Location.Y);
                    break;
            }
        }
Exemple #16
0
        public new void Move(MovementWay way)
        {
            switch (way)
            {
            case MovementWay.Up:
                this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                break;

            case MovementWay.Down:
                this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                break;

            case MovementWay.Left:
                this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                break;

            case MovementWay.Right:
                this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                break;
            }
            return;
        }
Exemple #17
0
        public override void Move(MovementWay way)
        {
            if (IsCatched)
                return;

            _movement = way;

            if (!IsAllowed(_movement))
            {
                return;
            }

            base.Move(way);

            if (_dots != null)
            {
                PacmanMovement(this, this.Location);
                return;
            }

            if (PacmanMovement != null)
                PacmanMovement(this, this.Location);
        }
Exemple #18
0
        //Methods
        public bool IsBlock(MovementWay _Movement)
        {
            bool result = false;

            Point loc = new Point();

            loc.X = this.Location.X;
            loc.Y = this.Location.Y;

            if (_Movement == MovementWay.Right)
            {
                loc.X += this.Width;
            }

            for (int i = 0; i <= _blocks.Length - 1; i++)
            {
                if (_blocks[i] == null)
                {
                    continue;
                }

                switch (_Movement)
                {
                case MovementWay.Right:
                    if (loc.X == _blocks[i].Location.X)
                    {
                        if (loc.Y >= (_blocks[i].Location.Y - Speed) && loc.Y <= (_blocks[i].Location.Y + _blocks[i].Height - Speed))
                        {
                            result = true;
                            break;
                        }
                    }
                    break;

                case MovementWay.Left:
                    if (loc.X == (_blocks[i].Location.X + _blocks[i].Width))
                    {
                        if (loc.Y >= (_blocks[i].Location.Y - Speed) && loc.Y <= (_blocks[i].Location.Y + _blocks[i].Height - Speed))
                        {
                            result = true;
                            break;
                        }
                    }
                    break;

                case MovementWay.Up:
                    if (loc.Y == (_blocks[i].Location.Y + _blocks[i].Height))
                    {
                        if (loc.X >= (_blocks[i].Location.X - Speed) && loc.X <= (_blocks[i].Location.X + _blocks[i].Width - Speed))
                        {
                            result = true;
                            break;
                        }
                    }
                    break;

                case MovementWay.Down:
                    if ((loc.Y + this.Height) == _blocks[i].Location.Y)
                    {
                        if (loc.X >= (_blocks[i].Location.X - Speed) && loc.X <= (_blocks[i].Location.X + _blocks[i].Width - Speed))
                        {
                            result = true;
                            break;
                        }
                    }
                    break;
                }
            }
            return(result);
        }
Exemple #19
0
        /// <summary>
        /// Is place blocked or not blocked
        /// </summary>
        /// <param name="move"></param>
        /// <returns></returns>
        private bool IsAllowed(MovementWay move)
        {
            bool result = true;

            Point loc = new Point();
            loc.X = this.Location.X / Step;
            loc.Y = this.Location.Y / Step - 1;

            switch (move)
            {
                case MovementWay.Right:
                    {
                        loc.X += 1;
                        break;
                    }
                case MovementWay.Left:
                    {
                        loc.X -= 1;
                        break;
                    }

                case MovementWay.Up:
                    {
                        loc.Y -= 1;
                        break;
                    }
                case MovementWay.Down:
                    {
                        loc.Y += 1;
                        break;
                    }
            }
            if (loc.X >= 29 || loc.X < 0 || loc.Y >= 29 || loc.Y < 0)
            {
                return false;
            }

            if (this.AllowedLocationsMap[loc.X, loc.Y])
            {
                result = false;
            }

            return result;
        }
Exemple #20
0
        public new void Move(MovementWay way)
        {
            if (_Catched)
                return;

            _Movement = way;

            OnPaint(new System.Windows.Forms.PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));

            if (!IsBlock())
                switch (way)
                {
                    case MovementWay.Up:
                        this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y - Speed);
                        break;

                    case MovementWay.Down:
                        this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + Speed);
                        break;

                    case MovementWay.Left:
                        this.Location = new System.Drawing.Point(this.Location.X - Speed, this.Location.Y);
                        break;

                    case MovementWay.Right:
                        this.Location = new System.Drawing.Point(this.Location.X + Speed, this.Location.Y);
                        break;
                }

            if (_Dots != null)
            {
                Pacman_Movement(this, this.Location);
                return;
            }

            if (Pacman_Movement != null)
                Pacman_Movement(this, this.Location);
        }
Exemple #21
0
 private void btnRight_Click(object sender, EventArgs e)
 {
     _direction = MovementWay.Right;
     PlacePackman();
 }
Exemple #22
0
        private MovementWay GenerateRandomWay()
        {
            Point e = EnemyLocation;

            List<MovementWay> possibleDirections = GetPossibleDirections(e);
            AvoidRevirsingDir(ref possibleDirections);

            int rnd = _random.Next(0, possibleDirections.Count);
            _movement = possibleDirections[rnd];

            if (IsAllowed(_movement))
            {
                return possibleDirections[rnd];
            }
            else
            {
                return GenerateRandomWay();
            }
        }
Exemple #23
0
        public override void Move(MovementWay way)
        {
            if (_pacman.IsCatched || _pacman.Location==_pacman.Exit)
            {
                EnemyMovement -= Enemy_Enemy_Movement;
                return;
            }
            // swich ememy type. Chase or random way
            switch (EnemyType)
            {
                case EnemyType.Chasing:
                {
                    way = ChasingMode();
                    break;
                }
                case EnemyType.Scatter:
                {
                    _prevDir = way;

                    way = GenerateRandomWay();
                    break;
                }
            }

            base.Move(way);

            //if (EnemyMovement != null)
            //	EnemyMovement(this, this.Location);
        }
Exemple #24
0
        private MovementWay ChasingMode()
        {
            Point e = EnemyLocation;

            List<MovementWay> possibleDirections = GetPossibleDirections(e);
            e.X = e.X * Step;
            e.Y = e.Y * Step + Step;

            MovementWay way = _movement;

            //Avoids  reversing directions
            AvoidRevirsingDir(ref possibleDirections);

            // set distance as big unreal distance
            int shortestDistance = 1000;

            int targetX = _pacman.Location.X;
            int targetY = _pacman.Location.Y;

            // select shortest distance
            if (possibleDirections.Contains(MovementWay.Up) && _prevDir != MovementWay.Down)
            {
                int z = GetManhattanDistance(targetX, targetY, e.X, e.Y-1);
                if (z < shortestDistance)
                {
                    shortestDistance = z;
                    way = MovementWay.Up;
                }
            }

            if (possibleDirections.Contains(MovementWay.Down) && _prevDir != MovementWay.Up)
            {
                int z = GetManhattanDistance(targetX, targetY, e.X , e.Y+1);
                if (z < shortestDistance)
                {
                    shortestDistance = z;
                    way = MovementWay.Down;
                }
            }

            if (possibleDirections.Contains(MovementWay.Left) && _prevDir != MovementWay.Right)
            {
                int z = GetManhattanDistance(targetX, targetY, e.X-1, e.Y );
                if (z < shortestDistance)
                {
                    shortestDistance = z;
                    way = MovementWay.Left;
                }
            }

            if (possibleDirections.Contains(MovementWay.Right) && _prevDir != MovementWay.Left)
            {
                int z = GetManhattanDistance(targetX, targetY, e.X+1, e.Y );
                if (z < shortestDistance)
                {
                    shortestDistance = z;
                    way = MovementWay.Right;
                }
            }
            _prevDir = way;
            return way;
        }
Exemple #25
0
        public static void Draw(ref System.Windows.Forms.PaintEventArgs e, CharacterType type, MovementWay way = MovementWay.Right)
        {
            Console.WriteLine($"DrawCharacter {type} {way}");
            switch (type)
            {
            case CharacterType.Packman:
                e.Graphics.Clear(System.Drawing.SystemColors.Control);
                e.Graphics.FillEllipse(System.Drawing.Brushes.Yellow, new System.Drawing.Rectangle(0, 0, 40, 40));
                switch (way)
                {
                case MovementWay.Right:
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(40, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 40) });
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 10, 5, 5));
                    break;

                case MovementWay.Left:
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(0, 40) });
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(20, 10, 5, 5));
                    break;

                case MovementWay.Up:
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 0) });
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 20, 5, 5));
                    break;

                case MovementWay.Down:
                    e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control, new System.Drawing.Point[] { new System.Drawing.Point(0, 40), new System.Drawing.Point(20, 20), new System.Drawing.Point(40, 40) });
                    e.Graphics.FillEllipse(System.Drawing.Brushes.Black, new System.Drawing.Rectangle(10, 10, 5, 5));
                    break;
                }
                break;

            case CharacterType.Enemy:
                e.Graphics.FillEllipse(System.Drawing.Brushes.Blue, new System.Drawing.Rectangle(0, 0, 40, 50));
                e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(10, 10, 5, 5));
                e.Graphics.FillEllipse(System.Drawing.Brushes.LightYellow, new System.Drawing.Rectangle(25, 10, 5, 5));
                e.Graphics.FillPolygon(System.Drawing.SystemBrushes.Control,
                                       new System.Drawing.Point[] {
                    new System.Drawing.Point(0, 40),
                    new System.Drawing.Point(5, 30),
                    new System.Drawing.Point(10, 40),
                    new System.Drawing.Point(15, 30),
                    new System.Drawing.Point(20, 40),
                    new System.Drawing.Point(25, 30),
                    new System.Drawing.Point(30, 40),
                    new System.Drawing.Point(35, 30),
                    new System.Drawing.Point(40, 40),
                });

                break;
            }
        }
Exemple #26
0
        // is place allowed or not
        public bool IsAllowed(MovementWay move)
        {
            bool result = true;

            Point loc = new Point();
            loc.X = this.Location.X / Step;
            loc.Y = this.Location.Y / Step - 1;

            switch (move)
            {
                case MovementWay.Right:
                    {
                        loc.X += 1;
                        break;
                    }
                case MovementWay.Left:
                    {
                        loc.X -= 1;
                        break;
                    }

                case MovementWay.Up:
                    {
                        loc.Y -= 1;
                        break;
                    }
                case MovementWay.Down:
                    {
                        loc.Y += 1;
                        break;
                    }
            }

            byte min = 0;
            byte max = 28;

            // false, if >max or <min
            if (loc.X >= max || loc.X < min || loc.Y >= max || loc.Y < min)
            {
                return false;
            }

            // if blocked - return false
            if (this.AllowedLocationsMap[loc.X, loc.Y])
            {
                result = false;
            }

            return result;
        }