Ejemplo n.º 1
0
        public Boolean Moving(System.Windows.Forms.KeyPressEventArgs e,
                              Soils soilList, Stones stoneList, Bombs bombList)
        {
            if ((e.KeyChar.ToString() == "p") || (e.KeyChar.ToString() == "ç"))
            {
                BombNowCreate = true;
                if ((myDirection == Direction.Left) &&
                    (Map.GetItem(this.TOP / 25, this.LEFT / 25 - 1) == ItemName.Null))//left
                {
                    Bomb currentBomb = new Bomb(left / 25 - 1, top / 25);
                    bombList.AddPlayer(currentBomb);

                    Map.SetItem(this.TOP / 25, this.LEFT / 25 - 1, ItemName.Bomb);
                    Map.SetInd(this.TOP / 25, this.LEFT / 25 - 1, bombList.IndexOf(currentBomb));
                }
                if ((myDirection == Direction.Right) &&
                    (Map.GetItem(this.TOP / 25, this.LEFT / 25 + 1) == ItemName.Null))//right
                {
                    Bomb currentBomb = new Bomb(left / 25 + 1, top / 25);
                    bombList.AddPlayer(currentBomb);

                    Map.SetItem(this.TOP / 25, this.LEFT / 25 + 1, ItemName.Bomb);
                    Map.SetInd(this.TOP / 25, this.LEFT / 25 + 1, bombList.IndexOf(currentBomb));
                }
                if ((myDirection == Direction.Up) &&
                    (Map.GetItem(this.TOP / 25 - 1, this.LEFT / 25) == ItemName.Null))//up
                {
                    Bomb currentBomb = new Bomb(left / 25, top / 25 - 1);
                    bombList.AddPlayer(currentBomb);

                    Map.SetItem(this.TOP / 25 - 1, this.LEFT / 25, ItemName.Bomb);
                    Map.SetInd(this.TOP / 25 - 1, this.LEFT / 25, bombList.IndexOf(currentBomb));
                }
                if ((myDirection == Direction.Down) &&
                    (Map.GetItem(this.TOP / 25 + 1, this.LEFT / 25) == ItemName.Null))  //down
                {
                    Bomb currentBomb = new Bomb(left / 25, top / 25 + 1);
                    bombList.AddPlayer(currentBomb);

                    Map.SetItem(this.TOP / 25 + 1, this.LEFT / 25, ItemName.Bomb);
                    Map.SetInd(this.TOP / 25 + 1, this.LEFT / 25, bombList.IndexOf(currentBomb));
                }
                return(false);
            }
            else if ((e.KeyChar.ToString() == "a") || (e.KeyChar.ToString() == "ô"))
            {
                RemoveLeftSoil(soilList);
                if ((Map.GetItem(this.TOP / 25, this.LEFT / 25 - 1) == ItemName.Stone) &&
                    (Map.GetItem(this.TOP / 25, this.LEFT / 25 - 2) == ItemName.Null))             //left stone
                {
                    foreach (Stone st in stoneList)
                    {
                        if ((st.LEFT == this.LEFT - 25) && (st.TOP == this.TOP))
                        {
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Null);
                            st.LEFT -= 25;
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Stone);
                        }
                    }
                }
                else if ((Map.GetItem(this.TOP / 25, this.LEFT / 25 - 1) == ItemName.Bomb) &&
                         (Map.GetItem(this.TOP / 25, this.LEFT / 25 - 2) == ItemName.Null))        //left bomb
                {
                    foreach (Bomb st in bombList)
                    {
                        if ((st.LEFT == this.LEFT - 25) && (st.TOP == this.TOP))
                        {
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Null);
                            st.LEFT -= 25;
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Bomb);
                        }
                    }
                }
                if (Map.GetItem(this.TOP / 25, this.LEFT / 25 - 1) == ItemName.Null)         //left
                {
                    left       -= size;
                    player      = new Bitmap("PlayerLeft.bmp");
                    myDirection = Direction.Left;
                    return(true);
                }
            }
            else if ((e.KeyChar.ToString() == "d") || (e.KeyChar.ToString() == "â"))
            {
                RemoveRightSoil(soilList);
                if ((Map.GetItem(this.TOP / 25, this.LEFT / 25 + 1) == ItemName.Stone) &&
                    (Map.GetItem(this.TOP / 25, this.LEFT / 25 + 2) == ItemName.Null))             //left stone
                {
                    foreach (Stone st in stoneList)
                    {
                        if ((st.LEFT == this.LEFT + 25) && (st.TOP == this.TOP))
                        {
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Null);
                            st.LEFT += 25;
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Stone);
                        }
                    }
                }
                else if ((Map.GetItem(this.TOP / 25, this.LEFT / 25 + 1) == ItemName.Bomb) &&
                         (Map.GetItem(this.TOP / 25, this.LEFT / 25 + 2) == ItemName.Null))        //left bomb
                {
                    foreach (Bomb st in bombList)
                    {
                        if ((st.LEFT == this.LEFT + 25) && (st.TOP == this.TOP))
                        {
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Null);
                            st.LEFT += 25;
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Bomb);
                        }
                    }
                }
                if (Map.GetItem(this.TOP / 25, this.LEFT / 25 + 1) == ItemName.Null)         //right
                {
                    left       += size;
                    player      = new Bitmap("PlayerRight.bmp");
                    myDirection = Direction.Right;
                    return(true);
                }
            }
            else if ((e.KeyChar.ToString() == "w") || (e.KeyChar.ToString() == "ö"))
            {
                RemoveUpSoil(soilList);
                if (Map.GetItem(this.TOP / 25 - 1, this.LEFT / 25) == ItemName.Null)         //up
                {
                    top        -= size;
                    player      = new Bitmap("PlayerUp.bmp");
                    myDirection = Direction.Up;
                    return(true);
                }
            }
            else if ((e.KeyChar.ToString() == "s") || (e.KeyChar.ToString() == "û"))
            {
                RemoveDownSoil(soilList);
                if (Map.GetItem(this.TOP / 25 + 1, this.LEFT / 25) == ItemName.Null)            //down
                {
                    top        += size;
                    player      = new Bitmap("PlayerDown.bmp");
                    myDirection = Direction.Down;
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void BombMove(Bombs bombList, Skiers skiList, Bricks brickList)
        {
            Int32 countSkier = 0;

            Int32 [] IndSkier  = new Int32[bombList.CountPlayer];
            Int32    countBomb = 0;

            Int32 [] IndBomb = new Int32[bombList.CountPlayer];
            foreach (Bomb st in bombList)
            {
                if (Map.GetItem(st.TOP / 25 + 1, st.LEFT / 25) == ItemName.Skier)
                {
                    foreach (Skier sk in skiList)
                    {
                        if ((st.LEFT == sk.LEFT) && (st.TOP == (sk.TOP - 25)))
                        {
                            IndSkier[countSkier] = skiList.IndexOf(sk);
                            IndBomb[countBomb]   = bombList.IndexOf(st);
                            Invalidate(new Rectangle(sk.LEFT, sk.TOP, 25, 25));
                            Invalidate(new Rectangle(st.LEFT, st.TOP, 25, 25));
                            Map.SetItem(st.TOP / 25, st.LEFT / 25, ItemName.Null);
                            Map.SetItem(sk.TOP / 25, sk.LEFT / 25, ItemName.Null);
                            countSkier++;
                            countBomb++;
                        }
                    }
                }
            }
            Array.Sort(IndSkier);
            Array.Reverse(IndSkier);

            Array.Sort(IndBomb);
            Array.Reverse(IndBomb);

            for (int i = 0; i < countBomb; i++)
            {
                bombList.RemovePlayer(IndBomb[i]);
            }
            for (int i = 0; i < countSkier; i++)
            {
                skiList.RemovePlayer(IndSkier[i]);
            }

            foreach (Bomb st in bombList)
            {
                if (st.Moving(trac) == true)
                {
                    if (st.BombDirec == Direction.Down)
                    {
                        InvalidateDown(st);
                    }
                    if (st.BombDirec == Direction.Left)
                    {
                        InvalidateLeft(st);
                    }
                    if (st.BombDirec == Direction.Right)
                    {
                        InvalidateRight(st);
                    }
                }
            }
        }