Exemplo n.º 1
0
        public gameScr(List <Texture2D> _textureLibrary, List <SoundEffect> _soundLibrary, int _level, int _w, int _l)
        {
            textureLibrary = _textureLibrary;
            soundLibrary   = _soundLibrary;

            backButton = new Button(new Rectangle(720, 20, 60, 60), new List <Texture2D> {
                textureLibrary[47], textureLibrary[48], textureLibrary[49]
            });

            pipeTextures(textureLibrary);

            waterList = new List <Pipe>();

            //INIT PIPES
            if (_level == 99)
            {
                tileGrid = new Tile[_w, _l];
                tileGrid = createPathGrid(tileGrid, _w, _l);
                tileGrid = finishPathGrid(tileGrid, _w, _l);
                pipeGrid = new Pipe[_w, _l];
                pipeGrid = createGrid(pipeGrid, tileGrid, _w, _l);
            }
            else
            {
                levelInfo gameLevel = new levelInfo();
                gameLevel = fetchFromDatabase(_level);
                pipeGrid  = new Pipe[gameLevel._xLength, gameLevel._yLength];
                pipeGrid  = infoToGrid(gameLevel);
            }
        }
Exemplo n.º 2
0
        private levelInfo fetchFromDatabase(int level)
        {
            string _path = Environment.CurrentDirectory;

            for (int i = 0; i < 6; i++)
            {
                _path = Convert.ToString(Directory.GetParent(_path));
            }
            levelInfo       thisLevel = new levelInfo();
            OleDbConnection seedConn  = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _path + @"\LevelSeeds.accdb");

            seedConn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM tableLevels WHERE Level=[_Level]", seedConn);

            cmd.Parameters.AddWithValue("_Level", level);
            OleDbDataReader reader = cmd.ExecuteReader();

            reader.Read();
            thisLevel._xLength = reader.GetInt32(1);
            thisLevel._yLength = reader.GetInt32(2);
            thisLevel._seed    = reader.GetString(3);
            seedConn.Close();
            return(thisLevel);
        }
Exemplo n.º 3
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);
        }