Esempio n. 1
0
        private Pipe[,] createGrid(Pipe[,] pipeGrid, Tile[,] pathGrid, int width, int length)
        {
            int         x    = 0;
            int         y    = 0;
            int         x_   = 0;
            int         y_   = 0;
            int         _col = 0;
            int         _row = 0;
            Random      r    = new Random();
            int         rNum;
            SoundEffect _sound;

            for (x = 0; x < width; x++)
            {
                for (y = 0; y < length; y++)
                {
                    rNum = r.Next(0, 3);
                    if (rNum == 0 || rNum == 2)
                    {
                        _sound = soundLibrary[0];
                    }
                    else
                    {
                        _sound = soundLibrary[1];
                    }
                    x_ = 400 - (30 * width);
                    y_ = 300 - (30 * length);
                    Thread.Sleep(20);
                    if (pathGrid[x, y].tileType == 3)
                    {
                        rNum = r.Next(0, 3);
                        if (rNum == 0)
                        {
                            pathGrid[x, y].tileType = 0;
                        }
                        else if (rNum == 1)
                        {
                            pathGrid[x, y].tileType = 1;
                        }
                        else
                        {
                            pathGrid[x, y].tileType = 2;
                        }
                    }
                    Thread.Sleep(20);
                    if (pathGrid[x, y].tileType == 2)
                    {
                        rNum = r.Next(0, 3);
                        if (x == 0 && y == 0)
                        {
                            pipeGrid[x, y] = new cutPipe(emptyCut, fullCut, _sound, new Rectangle(x_ + (_col * 60), y_ + (_row * 60), 60, 60), rNum, true);
                        }
                        else
                        {
                            pipeGrid[x, y] = new cutPipe(emptyCut, fullCut, _sound, new Rectangle(x_ + (_col * 60), y_ + (_row * 60), 60, 60), rNum, false);
                        }
                    }
                    else if (pathGrid[x, y].tileType == 1)
                    {
                        rNum           = r.Next(0, 3);
                        pipeGrid[x, y] = new strPipe(emptyStr, fullStr, _sound, new Rectangle(x_ + (_col * 60), y_ + (_row * 60), 60, 60), rNum);
                    }
                    else if (pathGrid[x, y].tileType == 0)
                    {
                        rNum           = r.Next(0, 3);
                        pipeGrid[x, y] = new corPipe(emptyCor, fullCor, _sound, new Rectangle(x_ + (_col * 60), y_ + (_row * 60), 60, 60), rNum);
                    }
                    _row += 1;
                }
                _col += 1;
                _row  = 0;
            }
            return(pipeGrid);
        }
Esempio n. 2
0
        private Pipe[,] infoToGrid(levelInfo gameLevel)
        {
            Pipe[,] _pipeGrid;
            Random r = new Random();
            int    width, height;
            string seed;
            int    quantity;
            int    lowerBound;
            int    charCode;
            char   rawChar;
            int    rowCurrent  = 0;
            int    rowQuantity = 0;

            width     = gameLevel._xLength;
            height    = gameLevel._yLength;
            seed      = gameLevel._seed;
            _pipeGrid = new Pipe[width, height];
            string[] rawArray = new string[height];

            foreach (char a in seed)
            {
                charCode = (int)a;
                if (charCode < 75)//Straight
                {
                    lowerBound = 65;
                    rawChar    = '1';
                }
                else if (charCode > 84)//Cutoff
                {
                    lowerBound = 85;
                    rawChar    = '2';
                }
                else//Corner
                {
                    lowerBound = 75;
                    rawChar    = '0';
                }
                quantity              = (charCode - lowerBound) + 1;
                rowQuantity          += quantity;
                rawArray[rowCurrent] += new string(rawChar, quantity);
                if (rowQuantity == width)
                {
                    rowQuantity = 0;
                    rowCurrent += 1;
                }
            }
            int         _row   = 0;
            int         _col   = 0;
            int         startX = 400 - (30 * width);
            int         startY = 300 - (30 * height);
            SoundEffect _sound;

            foreach (string str in rawArray)
            {
                _col = 0;
                foreach (char c in str)
                {
                    Thread.Sleep(20);
                    int rNum = r.Next(0, 3);
                    if (rNum == 0 || rNum == 2)
                    {
                        _sound = soundLibrary[0];
                    }
                    else
                    {
                        _sound = soundLibrary[1];
                    }


                    switch (c)
                    {
                    case '0':
                    {
                        _pipeGrid[_col, _row] = new corPipe(emptyCor, fullCor, _sound, new Rectangle(startX + (_col * 60), startY + (_row * 60), 60, 60), rNum);
                        break;
                    }

                    case '1':
                    {
                        _pipeGrid[_col, _row] = new strPipe(emptyStr, fullStr, _sound, new Rectangle(startX + (_col * 60), startY + (_row * 60), 60, 60), rNum);
                        break;
                    }

                    case '2':
                    {
                        if (_col == 0 && _row == 0)
                        {
                            _pipeGrid[_col, _row] = new cutPipe(emptyCut, fullCut, _sound, new Rectangle(startX + (_col * 60), startY + (_row * 60), 60, 60), rNum, true);
                        }
                        else
                        {
                            _pipeGrid[_col, _row] = new cutPipe(emptyCut, fullCut, _sound, new Rectangle(startX + (_col * 60), startY + (_row * 60), 60, 60), rNum, false);
                        }
                        break;
                    }
                    }
                    _col += 1;
                }
                _row += 1;
            }
            return(_pipeGrid);
        }