Ejemplo n.º 1
0
        public WordSearchController(SpriteBatch spriteBatch, GameContent gameContent)
        {
            this.spriteBatch = spriteBatch;
            this.gameContent = gameContent;

            DB = new SqliteDB();

            HomeButton   = new MenuButton(new Vector2(16, 16), "HomeButton", gameContent.home, spriteBatch, gameContent);
            WinnerSplash = gameContent.congrats;

            WordBox    = new SearchBox(spriteBatch, gameContent);
            Drawable   = new Drawing(spriteBatch, gameContent);
            Background = gameContent.wordseachBackground;

            PlayFieldWidth  = 10;
            PlayFieldHeight = 8;

            CurrentLetter2DArray = new SearchLetter[PlayFieldWidth, PlayFieldHeight];
            PopulateNonWords(spriteBatch, gameContent);
        }
Ejemplo n.º 2
0
        public void PopulateNonWords(SpriteBatch spriteBatch, GameContent gameContent)
        {
            char[]       letterValueArray = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
                                              'p',       'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            SearchLetter letter;
            Random       random = new Random();
            int          randomIndex;
            int          positionY = 32;

            for (int ii = 0; ii < PlayFieldHeight; ii++)
            {
                int positionX = 364;
                for (int jj = 0; jj < PlayFieldWidth; jj++)
                {
                    randomIndex  = random.Next(0, 26);
                    letter       = new SearchLetter(letterValueArray[randomIndex], new Vector2(positionX, positionY), spriteBatch, gameContent);
                    letter.Value = '0';
                    CurrentLetter2DArray[jj, ii] = letter;
                    positionX += 64;
                }
                positionY += 64;
            }
        }
Ejemplo n.º 3
0
        public void CreateWordSearch(SpriteBatch spriteBatch, GameContent gameContent, GameState state)
        {
            List <int> idList = new List <int>();

            CurrentLetter2DArray = new SearchLetter[PlayFieldWidth, PlayFieldHeight];
            WordList             = new List <SearchWord>();
            WordBox   = new SearchBox(spriteBatch, gameContent);
            Drawable  = new Drawing(spriteBatch, gameContent);
            NewButton = new MenuButton();
            Missed    = false;
            Won       = false;

            PopulateNonWords(spriteBatch, gameContent);

            int IdMax = 0;

            switch (state)
            {
            case GameState.WordSearchNature:
            {
                IdMax = 24;
                break;
            }

            case GameState.WordSearchAnimal:
            {
                IdMax = 49;
                break;
            }

            case GameState.WordSearchMachines:
            {
                IdMax = 74;
                break;
            }
            }

            idList = GetRandomIDs(IdMax);

            string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Words.db3");
            var    db     = new SQLiteConnection(dbPath);
            var    table  = db.Table <WordDB>();

            SearchWord word;
            SearchWord boxWord;
            Vector2    pos = new Vector2(16, 130);

            foreach (int ii in idList)
            {
                word    = new SearchWord(table.ElementAt(ii).Word, spriteBatch, gameContent);
                boxWord = new SearchWord(table.ElementAt(ii).Word, spriteBatch, gameContent);
                WordList.Add(word);
                boxWord.SetWordPosition(boxWord, pos, WordDirection.Box, CurrentLetter2DArray);
                WordBox.DisplayList.Add(boxWord);
                pos = new Vector2(16, pos.Y += 48);
            }
            db.Close();

            foreach (SearchWord searchword in WordList)
            {
                List <WordDirection> possiblePositions = new List <WordDirection>();
                pos = GetRandomPosition();
                possiblePositions = CheckControl(searchword, pos);
                while (possiblePositions.Count < 1)
                {
                    pos = GetRandomPosition();
                    possiblePositions = CheckControl(searchword, pos);
                }
                SetWord(searchword, pos, possiblePositions, CurrentLetter2DArray);
            }
        }