public void CalculatesLettersAfterIndex()
            {
                var hiddenWord = new HiddenWord()
                {
                    Word     = "holder",
                    KeyIndex = 3,
                };

                Assert.AreEqual(2, hiddenWord.LettersAfterIndex);
            }
예제 #2
0
 public HiddenWordManager(LTName lTName, LTCity lTCity, Country country, Furniture furniture)
 {
     LTName     = lTName;
     LTCity     = lTCity;
     Country    = country;
     Furniture  = furniture;
     HiddenWord = new HiddenWord(LTName.Text.Length);
     HiddenWord = new HiddenWord(LTCity.Text.Length);
     HiddenWord = new HiddenWord(Country.Text.Length);
     HiddenWord = new HiddenWord(Furniture.Text.Length);
 }
예제 #3
0
        // GET Controller
        public async Task OnGetAsync()
        {
            // Create a new Game record
            Game        = new Game();
            Game.Phrase = new PhraseGenerator(_env).GetPhrase();

            // Save Game record
            _db.Games.Add(Game);
            await _db.SaveChangesAsync();

            // Generate Phrase
            HiddenWord hiddenWord = new HiddenWord(Game.Phrase);

            Phrase = hiddenWord.ToString();
        }
예제 #4
0
        public KremalaGame(string selectedWord, List <Player> players)
        {
            Players       = new List <Player>();
            NumberOfTries = 5;

            if (string.IsNullOrWhiteSpace(selectedWord) && players != null && players.Count > 0)
            {
                _selectedWord.AddRange(selectedWord);
                HiddenWord.AddRange(new string('*', selectedWord.Length));
                Players = players;
            }
            else
            {
                throw new Exception("Wrong Arguments!");
            }
        }
        [InlineData(20, 1, "abcdefghijklmnopqrst", DirectionFlagsEnum.UpRight, true)]  // Max size word fits in DownRight
        public void IsPlacementValid_MaxWordSize_Various(int row,
                                                         int column,
                                                         string word,
                                                         DirectionFlagsEnum direction,
                                                         bool expectedResult)
        {
            var grid       = new char[20, 20];
            var hiddenWord = new HiddenWord()
            {
                Start     = new GridLocation(row, column),
                Word      = word,
                Direction = direction
            };
            var result = PlacementValidator.IsWordPlacementValid(grid, hiddenWord);

            Assert.Equal(result, expectedResult);
        }
        public void IsPlacementValid_WordCrossesAnotherWord_Various(char[,] grid,
                                                                    int row,
                                                                    int column,
                                                                    string word,
                                                                    DirectionFlagsEnum direction,
                                                                    bool expectedResult)
        {
            var hiddenWord = new HiddenWord()
            {
                Start     = new GridLocation(row, column),
                Word      = word,
                Direction = direction
            };
            var result = PlacementValidator.IsWordPlacementValid(grid, hiddenWord);

            Assert.Equal(result, expectedResult);
        }
        /// <summary>
        /// IsWordPlacementValid
        /// Given a hidden word, check that it can fit into the grid given its length
        /// and starting position within the grid
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="hiddenWord"></param>
        /// <returns></returns>
        public static bool IsWordPlacementValid(char[,] grid, HiddenWord hiddenWord)
        {
            if (hiddenWord != null)
            {
                var gridLocation = new GridLocation(hiddenWord.Start);
                foreach (var letter in hiddenWord.Word)
                {
                    if (!CanLetterBePlaced(letter, gridLocation, grid))
                    {
                        return(false);
                    }
                    gridLocation = GridLocation.GetNextLetterGridLocation(gridLocation, hiddenWord.Direction);
                }
            }

            return(true);
        }
        /// <summary>
        /// PlaceWordInGrid
        /// Places the given word in the grid
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="hiddenWord"></param>
        /// <returns></returns>
        public bool PlaceWordInGrid(char[,] grid, HiddenWord hiddenWord)
        {
            var placed = false;

            if (placed = PlacementValidator.IsWordPlacementValid(grid, hiddenWord))
            {
                var gridLocation = new GridLocation(hiddenWord.Start);
                foreach (var letter in hiddenWord.Word)
                {
                    grid[gridLocation.Row - 1, gridLocation.Column - 1] = letter;
                    gridLocation = GridLocation.GetNextLetterGridLocation(gridLocation, hiddenWord.Direction);
                }

                //                return true;
            }

            return(placed);
        }
예제 #9
0
        public void PlaceWordInGrid_ValidWordDownwards_Success()
        {
            IRandomNumberService randomNumberService = new RandomNumberService();
            var wordPlacementService = new WordPlacementService(randomNumberService);
            var grid       = new char[20, 20];
            var hiddenWord = new HiddenWord()
            {
                Start     = new GridLocation(10, 10),
                Word      = "hello",
                Direction = DirectionFlagsEnum.Down
            };
            var result = wordPlacementService.PlaceWordInGrid(grid, hiddenWord);

            Assert.True(result);
            Assert.Equal('h', grid[9, 9]);  // grid id 0 based
            Assert.Equal('e', grid[10, 9]);
            Assert.Equal('l', grid[11, 9]);
            Assert.Equal('l', grid[12, 9]);
            Assert.Equal('o', grid[13, 9]);
        }
        /// <summary>
        /// GetWordPlacement
        /// Attempts to find a place in the grid for the given word
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="word"></param>
        /// <returns></returns>
        public HiddenWord GetWordPlacement(char[,] grid, string word)
        {
            var        startLocationFound  = false;
            var        entireGridSearched  = false;
            var        initialGridLocation = new GridLocation(_randomNumberService, grid);
            var        gridLocation        = new GridLocation(initialGridLocation);
            HiddenWord hiddenWord          = null;

            // Randomize direction list
            Random rnd        = new Random();
            var    directions = _directions.OrderBy(x => rnd.Next()).ToArray();

            // move right and down, checking if word can fit into any direction. if so add it
            do
            {
                // check word can be placed in any of the directions
                foreach (var direction in directions)
                {
                    hiddenWord = new HiddenWord()
                    {
                        Direction = direction,
                        Start     = gridLocation,
                        Word      = word
                    };

                    if (startLocationFound = PlacementValidator.IsWordPlacementValid(grid, hiddenWord))
                    {
                        break;
                    }
                }

                if (!startLocationFound)
                {
                    // Move to next position
                    gridLocation       = grid.GetNextGridLocation(gridLocation);
                    entireGridSearched = gridLocation.Equals(initialGridLocation);
                }
            }while (!startLocationFound && !entireGridSearched);

            return(startLocationFound ? hiddenWord : null);
        }
예제 #11
0
    public void Completed(bool success)
    {
        _active = false;
        Movable.MovementEnabled = true;
        _completed = success;
        Debug.Log("Mission ended, success: " + success);
        if (success)
        {
            Inventory.GainItem(Word);
            Destroy(_source.gameObject);
        }
        else
        {
            HiddenWord w = _source.GetComponent <HiddenWord>();
            if (w != null)
            {
                w.Hidden = true;
            }
        }

        Destroy(PuzzleUIobj.gameObject);
    }
예제 #12
0
파일: DAL.cs 프로젝트: bahilo/HiddenWord
        public Statistic insertStatistic(int userId, int wordId, int nbTry, int setupId)
        {
            XStatistic statistic = new XStatistic();
            statistic.ID = genericMethode.autoIncrementXmlDataPrimaryKey("XStatistic", "ID");
            statistic.userid = userId;
            statistic.wordid = wordId;
            statistic.setupid = setupId;
            statistic.nbtry = nbTry;

            HiddenWord hiddenWord = new HiddenWord();
            hiddenWord.Item = statistic;

            List<XStatistic> paramList = new List<XStatistic>();
            paramList.Add(genericMethode.saveXmlData<XStatistic>(hiddenWord, "XStatistic", statistic.ID.ToString()));

            List<Statistic> statisticList = bindXmlObjectToStatistic(paramList);
            Statistic result = new Statistic();
            if (statisticList.Count != 0)
            {
                result = statisticList[0];
            }

            return result;
        }
예제 #13
0
 public HiddenWordManager(Word word)
 {
     _word      = word;
     HiddenWord = new HiddenWord(_word.Text.Length);
 }
예제 #14
0
파일: DAL.cs 프로젝트: bahilo/HiddenWord
        public Words InsertWord(string name)
        {
            XWords word = new XWords();
            word.ID = genericMethode.autoIncrementXmlDataPrimaryKey("XWords", "ID");
            word.name = name;

            HiddenWord hiddenWord = new HiddenWord();
            hiddenWord.Item = word;

            List<XWords> paramList = new List<XWords>();
            paramList.Add(genericMethode.saveXmlData<XWords>(hiddenWord, "XWords", word.ID.ToString()));

            List<Words> wordsList = bindXmlDataToWord(paramList);
            Words result = new Words();
            if ( wordsList.Count != 0 )
            {
                result = wordsList[0];
            }
            return result;
        }
예제 #15
0
 private static void TryHiddenWord()
 {
     HiddenWord.Hide(637);
 }
예제 #16
0
 public HiddenWordManager(Word word)
 {
     _hiddenWord = new HiddenWord(word);
 }
예제 #17
0
        public void BasicTest4()
        {
            HiddenWord kata = new HiddenWord();

            Assert.AreEqual("melted", kata.hidden(942547));
        }
예제 #18
0
        public void BasicTest1()
        {
            HiddenWord kata = new HiddenWord();

            Assert.AreEqual("aid", kata.hidden(637));
        }
예제 #19
0
        public void BasicTest2()
        {
            HiddenWord kata = new HiddenWord();

            Assert.AreEqual("debt", kata.hidden(7415));
        }
예제 #20
0
        public void BasicTest3()
        {
            HiddenWord kata = new HiddenWord();

            Assert.AreEqual("email", kata.hidden(49632));
        }
예제 #21
0
파일: DAL.cs 프로젝트: bahilo/HiddenWord
        public User InsertUser(string pseudo)
        {
            XUsers user = new XUsers();
            user.ID = genericMethode.autoIncrementXmlDataPrimaryKey("XUsers", "ID");
            user.pseudo = pseudo;

            HiddenWord hiddenWord = new HiddenWord();
            hiddenWord.Item = user;

            List<XUsers> paramList = new List<XUsers>();
            paramList.Add(genericMethode.saveXmlData<XUsers>(hiddenWord, "XUsers", user.ID.ToString()));

            List<User> usersList = bindXmlDataToUser(paramList);
            User result = new User();
            if (usersList.Count != 0)
            {
                result = usersList[0];
            }
            return result;
        }
예제 #22
0
 public void AddWord(HiddenWord word)
 {
     word.AddToWordSearch(this);
     this.Words.Add(word);
 }
예제 #23
0
        // POST Controller
        public async Task <IActionResult> OnPostAsync(int id)
        {
            // Retrieve Game record
            Game = await _db.Games.FindAsync(id);

            // Generate Phrase
            HiddenWord hiddenWord = new HiddenWord(Game.Phrase, Game.Guesses);

            Phrase = hiddenWord.ToString();

            if (ModelState.IsValid &&
                !hiddenWord.IsRevealed() &&
                Game.IncorrectGuesses < 7)
            {
                // Enforce lower case
                Guess = char.ToLower(Guess);

                // Get previous guesses
                List <char> guesses = Game.Guesses;

                // Guess must be a letter
                Regex rgx = new Regex(@"^[a-zA-Z]$");
                if (!rgx.IsMatch(Guess.ToString()))
                {
                    Message = "You can only guess letters.";
                    return(Page());
                }

                // Guess must be new
                foreach (char prevGuess in guesses)
                {
                    if (Guess == prevGuess)
                    {
                        Message = "You already guessed '" + Guess + "'.";
                        return(Page());
                    }
                }

                // Add Guess to Game record
                guesses.Add(Guess);
                Game.Guesses = guesses;

                if (hiddenWord.Reveal(Guess))   // Correct Guess...
                {
                    // ...update Phrase
                    Phrase = hiddenWord.ToString();
                }
                else                            // Incorrect Guess...
                {
                    // ...update Game record
                    Game.IncorrectGuesses++;
                }

                // Save Game record
                try
                {
                    await _db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw new System.Exception($"Game {Game.Id} not found!");
                }
            }

            if (hiddenWord.IsRevealed())            // Check win condition
            {
                Message = "Congratulations, you've won!";
            }
            else if (Game.IncorrectGuesses >= 7)    // Check lose condition
            {
                Game.IncorrectGuesses = 7;
                Message = "You've run out of guesses.";
            }

            return(Page());
        }
예제 #24
0
            public static WordSearch CreateNew(int width, int height, string[] words)
            {
                var ws = new WordSearch {
                    Width = width, Height = height, WordSearchLetters = new char[width, height]
                };
                var maxAttempts = ws.Width * ws.Height * 10;

                foreach (var word in words)
                {
                    var hiddenWord = new HiddenWord
                    {
                        Word = word.ToUpper()
                    };

                    int attempts = 0;
                    do
                    {
                        hiddenWord.Direction = (WordDirection)_random.Next(3);

                        switch (hiddenWord.Direction)
                        {
                        case WordDirection.HORIZONTAL:
                            hiddenWord.X = _random.Next(ws.Width - word.Length);
                            hiddenWord.Y = _random.Next(ws.Height);
                            break;

                        case WordDirection.VERTICAL:
                            hiddenWord.X = _random.Next(ws.Width);
                            hiddenWord.Y = _random.Next(ws.Height - word.Length);
                            break;

                        case WordDirection.DIAGONAL:
                            hiddenWord.X = _random.Next(ws.Width - word.Length);
                            hiddenWord.Y = _random.Next(ws.Height - word.Length);
                            break;
                        }
                        attempts++;
                    } while (!hiddenWord.FitsInWordSearch(ws) && attempts < maxAttempts);

                    if (attempts >= maxAttempts)
                    {
                        throw new Exception("SORRY! This ain't going to work.");
                    }
                    else
                    {
                        ws.AddWord(hiddenWord);
                    }
                }

                for (var y = 0; y < ws.WordSearchLetters.GetLength(1); y++)
                {
                    for (var x = 0; x < ws.WordSearchLetters.GetLength(0); x++)
                    {
                        if (ws.WordSearchLetters[x, y] == '\0')
                        {
                            ws.WordSearchLetters[x, y] = (char)('A' + _random.Next(0, 26));
                        }
                    }
                }

                return(ws);
            }
예제 #25
0
파일: DAL.cs 프로젝트: bahilo/HiddenWord
        public Setup InsertSetup(int maxTry, int status)
        {
            XSetups setup = new XSetups();
            setup.ID = genericMethode.autoIncrementXmlDataPrimaryKey("XSetups", "ID");
            setup.maxtry = maxTry;
            setup.status = status;

            HiddenWord hiddenWord = new HiddenWord();
            hiddenWord.Item = setup;

            List<XSetups> paramList = new List<XSetups>();
            paramList.Add(genericMethode.saveXmlData<XSetups>(hiddenWord, "XSetups", setup.ID.ToString()));

            List<Setup> setupsList = bindXmlDataToSetup(paramList);
            Setup result = new Setup();
            if (setupsList.Count != 0)
            {
                result = setupsList[0];
            }
            return result;
        }