public static void ExecuteCommands(string command, Turtle turtle, List <Tile> board, ref bool comReady, ref string result, ref bool mineHit, ref bool success) { if (command == "") { return; } switch (command) { case "N": turtle.SetDefaultDirection("N"); break; case "E": turtle.SetDefaultDirection("E"); break; case "S": turtle.SetDefaultDirection("S"); break; case "W": turtle.SetDefaultDirection("W"); break; case "R": turtle.RotateRight(); break; case "L": turtle.RotateLeft(); break; case "M": turtle.Move(); comReady = turtle.CheckMine(board); if (comReady) { result = "Mine Hit!"; Console.WriteLine(result); mineHit = true; } else { comReady = turtle.CheckExit(board); if (comReady) { result = "Success!!"; Console.WriteLine(result); success = true; } } break; default: result = $"Command = '{command}' was not used"; Console.WriteLine(result); break; } }
private void DoAction(string move) { if (string.Equals(move, "M")) { _turtle.Move(); return; } _turtle.Rotate(move); }
public void StartGame() { for (int i = 4; i < textFile.Length; i++) { Console.WriteLine($"Next intructions: {textFile[i]}"); string[] line = textFile[i].Split(); foreach (var letter in line) { if (letter.Contains(Direction.Left) || letter.Contains(Direction.Right)) { turtle.Rotate(letter); } else if (letter.Contains(Action.Move)) { if (!turtle.CanMove(gameBoard.rows, gameBoard.columns)) { Console.WriteLine("Turtle hit a wall, can't move any further."); continue; } turtle.Move(); } Console.WriteLine($"Turtle current position x: {turtle.posX}, y: {turtle.posY}, facing: {turtle.facingPos}"); } } string turtlePosition = gameBoard.grids[turtle.posX, turtle.posY]; string result = $"Still in {GameObjects.Danger}. Turtle has not hit a mine or found the exit."; if (!string.IsNullOrEmpty(turtlePosition)) { if (turtlePosition.Contains(GameObjects.Mine)) { result = $"Oh! Turtle hit a {GameObjects.Mine}."; } else if (turtlePosition.Contains(GameObjects.Exit)) { result = $"Success! Turtle found the {GameObjects.Exit}."; } } Console.WriteLine($"Result: {result}"); gameResult = result; }