Example #1
0
        public static void SetupGame()
        {
            string[] lines = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "DataFiles\\GameSettings.txt"));

            Board = new MineField();

            string[] BoardDimensions = lines[0].Split(',');

            Board.SetupBoard(int.Parse(BoardDimensions[0]), int.Parse(BoardDimensions[1]));

            Console.WriteLine("Board Setup with dimensions " + lines[0] + "!");

            Turtle GameTurtle = new Turtle();

            GameTurtle.Direction = lines[2];
            GameTurtle.Location  = lines[1];

            string[] TurtleLocation = lines[1].Split(',');

            Board.SetupTurtle(int.Parse(TurtleLocation[0]), int.Parse(TurtleLocation[1]));

            Board.GameTurtle = GameTurtle;

            Console.WriteLine("Turtle Setup at location " + lines[1] + " in direction " + lines[2] + "!");

            string[] BoardExit = lines[3].Split(',');

            Board.SetupExit(int.Parse(BoardExit[0]), int.Parse(BoardExit[1]));

            Console.WriteLine("Board exit at " + lines[3] + "!");

            string[] MineLocations = lines[4].Split(',');

            Board.SetupMines(MineLocations);

            Console.WriteLine("Mine(s) setup at " + lines[4] + "!");

            Board.PrintBoard();

            Console.WriteLine("Game Setup!");
        }
Example #2
0
        /// <summary>
        /// Process sequence of moves represented as binary array. If turtle moves, check for terminal result or continue until all moves processed. Return incomplete if moves list exhausted.
        /// </summary>
        /// <param name="args">Sequence of moves to complete, board to complete them on</param>

        public static string ProcessMoveSequence(int[] moves, Board board)
        {
            Turtle.Pos = (int[])board.StartPos.Clone();
            Turtle.Dir = board.StartDir;

            for (int i = 0; i < moves.Length; i++)
            {
                if (moves[i] == MOVE)
                {
                    Turtle.MoveTurtle();

                    int x = Turtle.Pos[0];
                    int y = Turtle.Pos[1];

                    bool isOutOfBounds = ((x < 0 || board.N <= x) || (y < 0 || board.M <= y));

                    if (isOutOfBounds)
                    {
                        return(OUTOFBOUNDS);
                    }
                    else if (board.Tiles[x, y] == Board.EXIT)
                    {
                        return(SUCCESS);
                    }
                    else if (board.Tiles[x, y] == Board.MINE)
                    {
                        return(FAILURE);
                    }
                }
                else if (moves[i] == ROTATE)
                {
                    Turtle.RotateTurtle();
                }
            }

            return(INCOMPLETE);
        }
Example #3
0
 private void InitiliazeTurtleForSequence()
 {
     _turtle           = Turtle.GetInstance();
     _turtle.Direction = GameSetting.InitialDirection;
     _turtle.InitializeVector(GameSetting.InitialPosition.GetLength(0), GameSetting.InitialPosition.GetLength(1));
 }
Example #4
0
        static void Main(string[] args)
        {
            string    setUpFilepath    = @".\instructions\setup.txt";
            string    directionsFolder = @".\instructions";
            ArrayList lines            = Utils.getFileAsList(setUpFilepath);

            Nullable <bool>[,] grid = Utils.getMap(lines);
            if (null == grid)
            {
                Console.WriteLine("Error Loading Grid");
                Console.Read();
                Environment.Exit(1);
            }


            DirectoryInfo d = new DirectoryInfo(@directionsFolder);

            FileInfo[] files = d.GetFiles("*.txt");
            int        i     = 0;

            foreach (FileInfo file in files)
            {
                if (file.Name.StartsWith("directions"))
                {
                    i++;
                    lines = Utils.getFileAsList(directionsFolder + @"\" + file.Name);
                    ArrayList instructions = Utils.getTurtleInstructions(lines);
                    if (instructions.Count == 0)
                    {
                        Console.WriteLine("Error Loading Turtle instructions");
                        Console.Read();
                        Environment.Exit(1);
                    }

                    Turtle turtle         = new Turtle(instructions);
                    bool   isActionsBreak = false;
                    foreach (Action action in turtle.Actions)
                    {
                        if (action.Equals(Action.Rotate))
                        {
                            turtle.rotate();
                        }
                        else
                        {
                            turtle.move(grid.GetLength(0), grid.GetLength(1));
                        }
                        if (grid[turtle.X, turtle.Y] == true)
                        {
                            isActionsBreak = true;
                            Console.WriteLine("Sequence " + i + " We have Reached Our Goal !");
                            break;
                        }
                        if (grid[turtle.X, turtle.Y] == false)
                        {
                            isActionsBreak = true;
                            Console.WriteLine("Sequence " + i + " We have Struck a Mine!!");
                            break;
                        }
                    }

                    if (!isActionsBreak)
                    {
                        Console.WriteLine("Sequence " + i + " Still in Danger!!");
                    }
                }
            }


            Console.Read();
        }