public string generateCommand()
        {
            openConnection();
            StringBuilder sb = new StringBuilder();

            sb.Append("generate ");
            sb.Append(mazeName.ToString());
            sb.Append(" " + MazeRows.ToString());
            sb.Append(" " + MazeCols.ToString());
            myMission = sb.ToString();
            writer.WriteLine(myMission);
            writer.Flush();

            // read all result
            string result = reader.ReadLine();

            //string resultAllData;
            while (true)
            {
                // we add '@' char for each string that we want to print, and stop the printing
                // when we arrive this char.
                if (reader.Peek() == '@')
                {
                    result.TrimEnd('\n');
                    break;
                }
                result += reader.ReadLine();
            }
            reader.DiscardBufferedData();

            //close the connection
            CloseConnection();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// update the source.
        /// </summary>
        public void BindingUpdateSource()
        {
            BindingExpression be = ServerIP.GetBindingExpression(UCTextField.ValueProperty);

            be.UpdateSource();
            be = ServerPort.GetBindingExpression(UCTextField.ValueProperty);
            be.UpdateSource();
            be = MazeRows.GetBindingExpression(UCTextField.ValueProperty);
            be.UpdateSource();
            be = MazeCols.GetBindingExpression(UCTextField.ValueProperty);
            be.UpdateSource();
        }
        public void CreateMaze()
        {
            if (MazeRows.Count != 0)
            {
                Maze = new char[MazeRows.Count, MazeRows.Peek().Length];
                int length = MazeRows.Count;

                for (int x = 0; x < length; x++)
                {
                    for (int y = 0; y < MazeRows.Peek().Length; y++)
                    {
                        Maze[x, y] = MazeRows.Peek()[y];
                    }

                    MazeRows.Dequeue();
                }
            }
        }
Exemplo n.º 4
0
        public void StartGame()
        {
            string strMaze = model.startCommand("start " + MazeNames.ToString() + " " + MazeRows.ToString() + " " + MazeCols.ToString());

            // convert the json to maze object
            // string strMaze = model.generateCommand();
            MyMaze = Maze.FromJSON(strMaze);
            // update properties
            MazeRows        = MyMaze.Rows;
            MazeCols        = MyMaze.Cols;
            MazeNames       = MyMaze.Name;
            InitialPosition = MyMaze.InitialPos;
            // update current position to the start point in maze
            CurrentPosition = MyMaze.InitialPos;
            EndPosition     = MyMaze.GoalPos;
        }
        public void InitializeMaze()
        {
            Console.Write("Enter the width(cells per row) of the maze: ");
            int mazeRowLength = Convert.ToInt32(Console.ReadLine());

            bool addRow      = true;
            int  numRowAdded = 1;

            //Determines length of protective walls
            string endWalls = "";

            for (int x = 0; x < mazeRowLength + 2; x++)
            {
                endWalls += '1';
            }

            //Enqueues the upper protective wall
            MazeRows.Enqueue(endWalls);

            while (addRow == true)
            {
                string inputRow = "1";
                Console.Write("\nEnter layout for row " + numRowAdded + " (Passage = \"0\" Wall = \"1\" Exit = \"e\" Initial Position = \"m\"): ");
                inputRow += Console.ReadLine() + "1";

                if (inputRow.Length > mazeRowLength + 2)
                {
                    Console.WriteLine("\nRow entered is too long! Enter another Row.");
                    continue;
                }

                if (inputRow.Length < mazeRowLength + 2)
                {
                    Console.WriteLine("\nRow entered is too short! Enter another Row.");
                    continue;
                }

                if (CheckInputRow(inputRow) == false)
                {
                    Console.WriteLine("\nRow entered contains illegal characters! Enter another Row.");
                    continue;
                }

                //Enqueues the entered Row
                MazeRows.Enqueue(inputRow);
                numRowAdded++;

                //Asks if the user would like to add another row
                string response = "";
                while (response != "Y" && response != "N")
                {
                    Console.Write("\nWould you like to add another Row? ('Y' / 'N')");
                    response = Console.ReadLine().ToUpper();
                }

                if (response == "N")
                {
                    addRow = false;
                }
            }

            MazeRows.Enqueue(endWalls);
        }