public override bool Execute() { if (game.GetCurrentY() > game.GetField().GetTopMost()) { Console.SetCursorPosition(game.GetCurrentX(), game.DecrementY()); } return(base.Execute()); }
public override bool Execute() { if (game.GetCurrentY() <= game.GetField().GetRow()) { Console.SetCursorPosition(game.GetCurrentX(), game.IncrementY()); } return(base.Execute()); }
internal static void Main(string[] parametersFromConsole) { Game game = null; Parameters parameters = new Parameters(); if (parametersFromConsole.Length != 0) { int resultOfParse; char[] inputParameters = new char[parametersFromConsole.Length]; for (int i = 0; i < parametersFromConsole.Length; i++) { if (int.TryParse(parametersFromConsole[i].Substring(1), out resultOfParse)) { inputParameters[i] = parametersFromConsole[i].First(); } } bool correctParameters = true; if (!inputParameters.Contains((char)EnumParameters.Width) && inputParameters.Contains((char)EnumParameters.Heigth)) { correctParameters = false; Console.Write("Invalid arguments: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Width of the Universe was not specified."); Console.ResetColor(); } else if (inputParameters.Contains((char)EnumParameters.Width) && !inputParameters.Contains((char)EnumParameters.Heigth)) { correctParameters = false; Console.Write("Invalid arguments: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Height of the Universe was not specified."); Console.ResetColor(); } if (correctParameters) { char symbolOfInputParametr; for (int i = 0; i < parametersFromConsole.Length; i++) { symbolOfInputParametr = parametersFromConsole[i].First(); parametersFromConsole[i] = parametersFromConsole[i].Substring(1); if (int.TryParse(parametersFromConsole[i], out resultOfParse)) { switch (symbolOfInputParametr) { case (char)EnumParameters.Width: parameters.Row = resultOfParse; break; case (char)EnumParameters.Heigth: parameters.Column = resultOfParse; break; case (char)EnumParameters.Delay: parameters.Delay = resultOfParse; break; } } } } else { Environment.Exit(0); } } game = new Game(parameters); game.GetField().Paint(); do { game.Update(); } while (!game.IsKeyPressed(Console.ReadKey(true).Key)); Console.SetCursorPosition(game.GetField().GetLeftMost(), game.GetField().GetHeight() + game.GetField().GetTopMost()); }
public override bool Execute() { game.GetField().GetCells()[game.GetCurrentY() - game.GetField().GetTopMost(), game.GetCurrentX() - game.GetField().GetLeftMost()].ChangeStatus(); return(base.Execute()); }