/// <summary> /// The method checks the availability of the next cell /// </summary> /// <param name="coords">Coordinates</param> /// <returns>Returns true or false</returns> public bool IsPositionAvailable(Coords coords) { if (this[coords.Row, coords.Col] == BlockedCellSymbol) { return false; } return true; }
/// <summary> /// The method removes the last position of the player /// </summary> /// <param name="coords">Coordinates</param> public void RemoveObject(Coords coords) { this.matrix[coords.Row, coords.Col] = '-'; }
/// <summary> /// The method reads and executes the commands from the user /// </summary> /// <param name="cmd">input string</param> private void ExecuteCommand(string cmd) { switch (cmd.ToUpper()) { case "L": case "R": case "U": case "D": { Coords oldCoords = new Coords(this.Player.Row, this.Player.Col); Coords playerDirection = this.Controller.ProcessInput(cmd); Coords newPlayerPosition = new Coords(this.Player.Row + playerDirection.Row, this.Player.Col + playerDirection.Col); if (!this.Labyrinth.IsPositionAvailable(newPlayerPosition)) { Console.WriteLine("Invalid move"); } else { this.Player.Update(newPlayerPosition); this.Labyrinth.RemoveObject(oldCoords); } break; } case "RESTART": { this.Player.Reset(); this.StartGame(); break; } case "TOP": { Console.WriteLine(this.ScoreBoard); break; } case "EXIT": { //exit still not implemented corectly isGameOn = false; Console.WriteLine("Good Bye"); break; } default: { Console.WriteLine("Invalid input!"); Console.WriteLine("**Press a key to continue**"); Console.ReadKey(); break; } } }
/// <summary> /// Updates the coordinates and force the objects which use it to move left in a matrix /// </summary> /// <returns>Coordinates</returns> public Coords MoveLeft() { Coords coords = new Coords(0, -1); return coords; }
/// <summary> /// The method checks the if the coordinates are out of the labyrinth /// </summary> /// <param name="coords">Coord instance</param> /// <returns>Returns true or false</returns> private bool IsGameOver(Coords coords) { if ((coords.Col > 0 && coords.Col < this.Labyrinth.Size - 1) && (coords.Row > 0 && coords.Row < this.Labyrinth.Size - 1)) { return false; } else if (coords.Row == this.Labyrinth.Size - 1 || coords.Row == 0 || coords.Col == this.Labyrinth.Size - 1 || coords.Col == 0) { return true; } return true; }
/// <summary> /// Updates the coordinates and every time when the method is called it updates the players moves /// </summary> /// <param name="coords">Coordinates</param> public void Update(Coords coords) { this.Row = coords.Row; this.Col = coords.Col; this.Points++; }
/// <summary> /// Constructor /// </summary> /// <param name="symbol">char symbol</param> /// <param name="row">row</param> /// <param name="col">col</param> public Player(char symbol, int row, int col) : base(symbol, row, col) { Coords initCoords = new Coords(row, col); this.InitCoords = initCoords; }
/// <summary> /// Updates the coordinates and force the objects which use it to move left in a matrix /// </summary> /// <returns>Coordinates</returns> public Coords MoveLeft() { Coords coords = new Coords(0, -1); return(coords); }