Exemplo n.º 1
0
        /// <summary>
        /// Searches East for a given word on a given board starting at a given origin point. If it finds the word,
        /// it returns a list of all of the coordinates that make up the word. Otherwise, it returns null
        /// </summary>
        /// <param name="board">WordSearchBoard to search on</param>
        /// <param name="origin">Coordinate point to begin searching</param>
        /// <param name="word">Word to search for</param>
        /// <returns>If it finds the word, returns a list of all of the coordinates that make up the word. Otherwise, it returns null</returns>
        public List <Coordinate> CheckEast(WordSearchBoard board, Coordinate origin, string word)
        {
            _output = new List <Coordinate>();

            Coordinate tempCoordinate = new Coordinate(origin.X, origin.Y);

            foreach (char letter in word)
            {
                try
                {
                    if (board.GetCharAt(tempCoordinate) == letter)
                    {
                        _output.Add(tempCoordinate);
                        tempCoordinate = new Coordinate(tempCoordinate.X + 1, tempCoordinate.Y);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (ArgumentException)
                {
                    //ArgumentException here means that the tempCoordinate is pointed to an invalid coordinate off the board
                    //Return null because we know words cannot wrap around to another part of the board
                    return(null);
                }
            }

            return(_output);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches North-West for a given word on a given board starting at a given origin point. If it finds the word,
        /// it returns a list of all of the coordinates that make up the word. Otherwise, it returns null
        /// </summary>
        /// <param name="board">WordSearchBoard to search on</param>
        /// <param name="origin">Coordinate point to begin searching</param>
        /// <param name="word">Word to search for</param>
        /// <returns>If it finds the word, returns a list of all of the coordinates that make up the word. Otherwise, it returns null</returns>
        public List <Coordinate> CheckNorthWest(WordSearchBoard board, Coordinate origin, string word)
        {
            _output = new List <Coordinate>();

            Coordinate tempCoordinate = new Coordinate(origin.X, origin.Y);

            foreach (char letter in word)
            {
                try
                {
                    if (board.GetCharAt(tempCoordinate) == letter)
                    {
                        _output.Add(tempCoordinate);
                        tempCoordinate = new Coordinate(tempCoordinate.X - 1, tempCoordinate.Y - 1);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (ArgumentException)
                {
                    //ArgumentException here means that the tempCoordinate is pointed to an invalid coordinate off the board
                    return(null);
                }
            }

            return(_output);
        }
        public void TestWith1CharBoard()
        {
            List <string> lines = new List <string>();

            lines.Add("A");

            _board = new WordSearchBoard(lines);

            Assert.AreEqual(1, _board.GetLength());
        }
        public void TestListWithValidStrings()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);
        }
        public void TestListWithBlankStringsThrowsException()
        {
            List <string> lines = new List <string>();

            lines.Add("");
            lines.Add("");
            lines.Add("");

            _board = new WordSearchBoard(lines);
        }
        public void Setup()
        {
            _results = new List <Coordinate>();

            _lines = new List <string>();
            _lines.Add("A,B,C");
            _lines.Add("D,E,F");
            _lines.Add("G,H,I");

            _board = new WordSearchBoard(_lines);
        }
        public void TestWithInvalidY()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);
            _board.GetCharAt(0, 3);
        }
        public void TestWithNegativeX()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);
            _board.GetCharAt(-1, 0);
        }
Exemplo n.º 9
0
        public void TestWithNegativeY()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);
            _board.GetCharAt(new Coordinate(0, -1));
        }
Exemplo n.º 10
0
        public void TestToString()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);

            Assert.AreEqual("A,B,C\nD,E,F\nG,H,I", _board.ToString());
        }
        public void TestWithSmallBoard()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);

            Assert.AreEqual(3, _board.GetLength());
        }
        /// <summary>
        /// Accepts list of all of the lines given to the application and sets up the game
        /// </summary>
        /// <param name="inputLines">List of all of the lines in the input file</param>
        /// <exception cref="ArgumentException">Exception thrown if there are 0 lines in the input file or if the list of words (first line) is null or empty</exception>
        public WordSearchGame(List<string> inputLines)
        {
            _words = new List<string>();

            if (inputLines.Count == 0) throw new ArgumentException("Board cannot have 0 lines");
            if (inputLines[0] == null) throw new ArgumentException("List of words cannot be null");
            
            if (inputLines[0].Length > 0)
                _words.AddRange(inputLines[0].Split(","));

            inputLines.RemoveAt(0);
            
            _board = new WordSearchBoard(inputLines);
        }
        public void TestWithValidXY()
        {
            List <string> lines = new List <string>();

            lines.Add("A,B,C");
            lines.Add("D,E,F");
            lines.Add("G,H,I");

            _board = new WordSearchBoard(lines);

            Assert.AreEqual('A', _board.GetCharAt(0, 0));
            Assert.AreEqual('B', _board.GetCharAt(1, 0));
            Assert.AreEqual('C', _board.GetCharAt(2, 0));

            Assert.AreEqual('D', _board.GetCharAt(0, 1));
            Assert.AreEqual('E', _board.GetCharAt(1, 1));
            Assert.AreEqual('F', _board.GetCharAt(2, 1));

            Assert.AreEqual('G', _board.GetCharAt(0, 2));
            Assert.AreEqual('H', _board.GetCharAt(1, 2));
            Assert.AreEqual('I', _board.GetCharAt(2, 2));
        }
 public void TestNullInputThrowsException()
 {
     _board = new WordSearchBoard(null);
 }