示例#1
0
        public object Clone()
        {
            GameBoard nGameBoard = new GameBoard();

            nGameBoard = (GameBoard)this.MemberwiseClone();


            nGameBoard.Cells = new Cell[nGameBoard.W, nGameBoard.H];

            for (int i = 0; i < nGameBoard.Cells.GetLength(0); i++)
            {
                for (int j = 0; j < nGameBoard.Cells.GetLength(1); j++)
                {
                    if (this.Cells[i, j] is Cell_destructible)
                    {
                        nGameBoard.Cells[i, j] = new Cell_destructible();
                    }
                    else if (this.Cells[i, j] is Cell_indestructible)
                    {
                        nGameBoard.Cells[i, j] = new Cell_indestructible();
                    }
                    else
                    {
                        nGameBoard.Cells[i, j] = new Cell_free();
                    }
                    nGameBoard.Cells[i, j].X = i;
                    nGameBoard.Cells[i, j].Y = j;
                }
            }

            nGameBoard.Bonuses = new List <Bonus>();

            for (int i = 0; i < this.Bonuses.Count; i++)
            {
                Bonus nbonus;
                if (this.Bonuses[i] is Bonus_big)
                {
                    nbonus = new Bonus_big(this.Bonuses[i].X, this.Bonuses[i].Y);
                }
                else
                {
                    nbonus = new Bonus_fast(this.Bonuses[i].X, this.Bonuses[i].Y);
                }
                nbonus.Visible = this.Bonuses[i].Visible;
                nbonus.Color   = this.Bonuses[i].Color;
                nGameBoard.Bonuses.Add(nbonus);
            }

            nGameBoard.Bombs = new List <Bomb>();

            for (int i = 0; i < this.Bombs.Count; i++)
            {
                Bomb nbomb;
                if (this.Bombs[i] is Bomb_big)
                {
                    nbomb = new Bomb_big();
                }
                else
                {
                    nbomb = new Bomb();
                }
                nbomb.X        = this.Bombs[i].X;
                nbomb.Y        = this.Bombs[i].Y;
                nbomb.Color    = this.Bombs[i].Color;
                nbomb.PlayerID = this.Bombs[i].PlayerID;
                nbomb.LiveTime = this.Bombs[i].LiveTime;

                nGameBoard.Bombs.Add(nbomb);
            }

            nGameBoard.Lavas = new List <Lava>();

            for (int i = 0; i < this.Lavas.Count; i++)
            {
                var  tlava = this.Lavas[i];
                Lava nlava = new Lava();
                nlava.Color    = tlava.Color;
                nlava.LiveTime = tlava.LiveTime;
                nlava.PlayerID = tlava.PlayerID;
                nlava.Radius   = tlava.Radius;
                nlava.X        = tlava.X;
                nlava.Y        = tlava.Y;
                nGameBoard.Lavas.Add(nlava);
            }


            nGameBoard.Players = new List <Player>();

            for (int i = 0; i < this.Players.Count; i++)
            {
                Player nplayer = new Player();

                nplayer.X          = this.Players[i].X;
                nplayer.Y          = this.Players[i].Y;
                nplayer.Health     = this.Players[i].Health;
                nplayer.ID         = this.Players[i].ID;
                nplayer.Name       = this.Players[i].Name;
                nplayer.Points     = this.Players[i].Points;
                nplayer.BombsCount = this.Players[i].BombsCount;
                nplayer.BonusType  = this.Players[i].BonusType;
                nplayer.Color      = this.Players[i].Color;
                nplayer.ACTION     = this.Players[i].ACTION;

                nGameBoard.Players.Add(nplayer);
            }

            nGameBoard.DeadPlayers = new List <Player>();

            for (int i = 0; i < this.DeadPlayers.Count; i++)
            {
                Player nplayer = new Player();
                nplayer.X          = this.DeadPlayers[i].X;
                nplayer.Y          = this.DeadPlayers[i].Y;
                nplayer.Health     = this.DeadPlayers[i].Health;
                nplayer.ID         = this.DeadPlayers[i].ID;
                nplayer.Name       = this.DeadPlayers[i].Name;
                nplayer.Points     = this.DeadPlayers[i].Points;
                nplayer.BombsCount = this.DeadPlayers[i].BombsCount;
                nplayer.BonusType  = this.DeadPlayers[i].BonusType;
                nplayer.Color      = this.DeadPlayers[i].Color;
                nplayer.ACTION     = this.DeadPlayers[i].ACTION;

                nGameBoard.DeadPlayers.Add(nplayer);
            }

            return(nGameBoard);
        }
示例#2
0
        /// <summary>
        /// Сгенерировать бонусы внутри разрушаемых стен
        /// </summary>
        /// <param name="bonuses_count">Количество бонусов (будет умножено в 4 раза)</param>
        private void GenerateBonuses(int bonuses_count)
        {
            bonuses = new List <Bonus>();

            List <Cell> cells_dest = new List <Cell>();

            for (int i = 0; i < W / 2; i++)
            {
                for (int j = 0; j < H / 2; j++)
                {
                    if (Cells[i, j] is Cell_destructible)
                    {
                        cells_dest.Add(Cells[i, j]);
                    }
                }
            }

            bonuses_count = bonuses_count % cells_dest.Count;

            List <int> cells_dest_indexes = new List <int>();

            for (int i = 0; i < cells_dest.Count; i++)
            {
                cells_dest_indexes.Add(i);
            }

            for (int i = 0; i < bonuses_count; i++)
            {
                int rpoint = cells_dest_indexes[rn.Next(0, cells_dest_indexes.Count)];
                cells_dest_indexes.Remove(rpoint);

                int   rtype = rn.Next(0, 2);
                Bonus tbonus;
                if (rtype % 2 == 0)
                {
                    tbonus = new Bonus_fast(cells_dest[rpoint].X, cells_dest[rpoint].Y);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_fast(W - cells_dest[rpoint].X - 1, cells_dest[rpoint].Y);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_fast(cells_dest[rpoint].X, H - cells_dest[rpoint].Y - 1);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_fast(W - cells_dest[rpoint].X - 1, H - cells_dest[rpoint].Y - 1);
                    bonuses.Add(tbonus);
                }
                else
                {
                    tbonus = new Bonus_big(cells_dest[rpoint].X, cells_dest[rpoint].Y);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_big(W - cells_dest[rpoint].X - 1, cells_dest[rpoint].Y);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_big(cells_dest[rpoint].X, H - cells_dest[rpoint].Y - 1);
                    bonuses.Add(tbonus);

                    tbonus = new Bonus_big(W - cells_dest[rpoint].X - 1, H - cells_dest[rpoint].Y - 1);
                    bonuses.Add(tbonus);
                }
            }
        }