コード例 #1
0
ファイル: GameBoard.cs プロジェクト: kepo4ka/Diplom-CGC
        public object Clone()
        {
            GameBoard nGameBoard = new GameBoard();

            nGameBoard = (GameBoard)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++)
                {
                    nGameBoard.Cells[i, j]      = new Cell();
                    nGameBoard.Cells[i, j].X    = i;
                    nGameBoard.Cells[i, j].Y    = j;
                    nGameBoard.cells[i, j].Type = Cells[i, j].Type;
                }
            }

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

            for (int i = 0; i < Bonuses.Count; i++)
            {
                if (Bonuses[i].Visible == false)
                {
                    continue;
                }
                Bonus nbonus = new Bonus(Bonuses[i]);
                nGameBoard.Bonuses.Add(nbonus);
            }

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

            for (int i = 0; i < Bombs.Count; i++)
            {
                Bomb nbomb = new Bomb(Bombs[i]);
                nGameBoard.Bombs.Add(nbomb);
            }

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

            for (int i = 0; i < Lavas.Count; i++)
            {
                Lava nlava = new Lava(Lavas[i]);
                nGameBoard.Lavas.Add(nlava);
            }

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

            for (int i = 0; i < Players.Count; i++)
            {
                Player nplayer = new Player(Players[i]);
                nGameBoard.Players.Add(nplayer);
            }

            nGameBoard.XYinfo = new XYInfo[15, 15];

            for (int i = 0; i < nGameBoard.XYinfo.GetLength(0); i++)
            {
                for (int j = 0; j < nGameBoard.XYinfo.GetLength(1); j++)
                {
                    nGameBoard.XYinfo[i, j] = new XYInfo(XYinfo[i, j]);
                }
            }

            return(nGameBoard);
        }
コード例 #2
0
ファイル: GameBoard.cs プロジェクト: kepo4ka/Diplom-CGC
        public GameBoard(int[,] pole)
        {
            int size = 15;

            W = size;
            H = size;


            Cells   = new Cell[size, size];
            Bonuses = new List <Bonus>();
            Bombs   = new List <Bomb>();
            Lavas   = new List <Lava>();
            Players = new List <Player>();

            for (int i = 0; i < XYinfo.GetLength(0); i++)
            {
                for (int j = 0; j < XYinfo.GetLength(1); j++)
                {
                    XYinfo[i, j] = new XYInfo();
                }
            }

            for (int i = 0; i < Cells.GetLength(0); i++)
            {
                for (int j = 0; j < Cells.GetLength(1); j++)
                {
                    Cells[i, j] = new Cell()
                    {
                        X    = i,
                        Y    = j,
                        Type = CellType.None
                    };
                }
            }

            for (int i = 0; i < pole.GetLength(1); i++)
            {
                for (int j = pole.GetLength(1) - 1; j >= 0; j--)
                {
                    switch (pole[j, i])
                    {
                    case 0:
                        break;

                    case 1:
                        Cells[i, j].Type = CellType.Indestructible;
                        break;

                    case 2:
                        Cells[i, j].Type = CellType.Destructible;
                        break;

                    case 3:
                        Cells[i, j].Type = CellType.Destructible;
                        Bonus bonus = new Bonus();
                        bonus.X    = i;
                        bonus.Y    = j;
                        bonus.Type = BonusType.Ammunition;
                        Bonuses.Add(bonus);
                        break;

                    case 4:
                        Cells[i, j].Type = CellType.Destructible;
                        Bonus tbonus = new Bonus();
                        tbonus.X    = i;
                        tbonus.Y    = j;
                        tbonus.Type = BonusType.Radius;
                        Bonuses.Add(tbonus);
                        break;

                    case 5:
                        Player player = new Player();
                        player.X = i;
                        player.Y = j;
                        Players.Add(player);
                        break;

                    case 6:
                        Bonus ttbonus = new Bonus();
                        ttbonus.X       = i;
                        ttbonus.Y       = j;
                        ttbonus.Type    = BonusType.Ammunition;
                        ttbonus.Visible = true;
                        Bonuses.Add(ttbonus);
                        break;

                    case 7:
                        Bonus tttbonus = new Bonus();
                        tttbonus.X       = i;
                        tttbonus.Y       = j;
                        tttbonus.Type    = BonusType.Radius;
                        tttbonus.Visible = true;
                        Bonuses.Add(tttbonus);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: GameBoard.cs プロジェクト: kepo4ka/Diplom-CGC
        /// <summary>
        /// Сгенерировать бонусы внутри разрушаемых стен
        /// </summary>
        /// <param name="bonuses_count">Количество бонусов (будет умножено в 4 раза)</param>
        private void GenerateBonuses(int bonuses_count)
        {
            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].Type == CellType.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();
                    tbonus.X    = cells_dest[rpoint].X;
                    tbonus.Y    = cells_dest[rpoint].Y;
                    tbonus.Type = BonusType.Ammunition;
                    Bonuses.Add(tbonus);

                    tbonus      = new Bonus();
                    tbonus.X    = W - cells_dest[rpoint].X - 1;
                    tbonus.Y    = cells_dest[rpoint].Y;
                    tbonus.Type = BonusType.Ammunition;
                    Bonuses.Add(tbonus);

                    tbonus      = new Bonus();
                    tbonus.X    = cells_dest[rpoint].X;
                    tbonus.Y    = H - cells_dest[rpoint].Y - 1;
                    tbonus.Type = BonusType.Ammunition;
                    Bonuses.Add(tbonus);

                    tbonus      = new Bonus();
                    tbonus.X    = W - cells_dest[rpoint].X - 1;
                    tbonus.Y    = H - cells_dest[rpoint].Y - 1;
                    tbonus.Type = BonusType.Ammunition;
                    Bonuses.Add(tbonus);
                }
                else
                {
                    tbonus      = new Bonus();
                    tbonus.X    = cells_dest[rpoint].X;
                    tbonus.Y    = cells_dest[rpoint].Y;
                    tbonus.Type = BonusType.Radius;
                    Bonuses.Add(tbonus);

                    tbonus      = new Bonus();
                    tbonus.X    = W - cells_dest[rpoint].X - 1;
                    tbonus.Y    = cells_dest[rpoint].Y;
                    tbonus.Type = BonusType.Radius;
                    Bonuses.Add(tbonus);

                    tbonus      = new Bonus();
                    tbonus.X    = cells_dest[rpoint].X;
                    tbonus.Y    = H - cells_dest[rpoint].Y - 1;
                    tbonus.Type = BonusType.Radius;
                    Bonuses.Add(tbonus);

                    tbonus   = new Bonus();
                    tbonus.X = W - cells_dest[rpoint].X - 1;
                    tbonus.Y = H - cells_dest[rpoint].Y - 1;
                    Bonuses.Add(tbonus);
                }
            }
        }