Exemple #1
0
        public void SetWord(SearchWord word, Vector2 position, List <WordDirection> directionList, SearchLetter[,] currentLetterArray)
        {
            Random rand   = new Random();
            int    option = rand.Next(0, directionList.Count);

            word.SetWordPosition(word, position, directionList[option], currentLetterArray);
        }
Exemple #2
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);
            }
        }