public void PlayGame() { step.Show(); border.Show(); show.Show(); cursor.Show(); Console.SetCursorPosition(0, field.Rows + offSet); List <IKey> keys = new List <IKey>(); keys.Add(new ChangeState(cursor, field)); keys.Add(new InsertSourceWater(cursor, field)); var key = ConsoleKey.Pause; Moves pressKey = new Moves(cursor, field); while (key != ConsoleKey.Spacebar) { key = Console.ReadKey().Key; foreach (IKey canKey in keys) { if (canKey.Key == key) { canKey.Action(); } } pressKey.Move(key); show.Show(); cursor.Show(); Console.SetCursorPosition(0, field.Rows + offSet); } StartGame start = new StartGame(field, step); start.PlayGame(); }
public void PlayGame() { int sleep = 400; bool gameOver = false; int offSet = 1; int offSetCursor = 3; while (!gameOver) { for (int rows = 0; rows < field.Rows; ++rows) { for (int columns = 0; columns < field.Columns; ++columns) { if (field[rows, columns].State == CellState.FilledPipe || field[rows, columns].State == CellState.SourceWater) { if (rows > 0) { if (field[rows - offSet, columns].State == CellState.EmptyPipe) { field[rows - offSet, columns].State = CellState.FilledPipe; } } if (columns > 0) { if (field[rows, columns - offSet].State == CellState.EmptyPipe) { field[rows, columns - offSet].State = CellState.FilledPipe; } } } } } for (int rows = field.Rows - 1; rows >= 0; --rows) { for (int columns = field.Columns - 1; columns >= 0; --columns) { if (field[rows, columns].State == CellState.FilledPipe || field[rows, columns].State == CellState.SourceWater) { if (rows < field.Rows - 1) { if (field[rows + offSet, columns].State == CellState.EmptyPipe) { field[rows + offSet, columns].State = CellState.FilledPipe; } } if (columns < field.Columns - 1) { if (field[rows, columns + offSet].State == CellState.EmptyPipe) { field[rows, columns + offSet].State = CellState.FilledPipe; } } } } } gameOver = true; for (int i = 0; i < field.Rows; ++i) { for (int j = 0; j < field.Columns; ++j) { if (field[i, j].State == CellState.EmptyPipe) { gameOver = false; } } } step.AddStep(); Console.SetCursorPosition(0, 0); step.Show(); show.Show(); Console.SetCursorPosition(0, field.Rows + offSetCursor); System.Threading.Thread.Sleep(sleep); } }