//создает и возвращает новую фигуру public static Figure Get(ITetris tetris, int num) { switch (num) { case 0: return(new fI(tetris)); case 1: return(new fQ(tetris)); case 2: return(new fT(tetris)); case 3: return(new fZ(tetris)); case 4: return(new fJ(tetris)); case 5: return(new fS(tetris)); case 6: return(new fL(tetris)); } return(new fT(tetris)); }
// c'tor public TetrisViewPageModel(INavigationService navigationService) { if (navigationService == null) { throw new ArgumentNullException("NavigationService not provided"); } Debug.WriteLine("==============================> TetrisViewModel c'tor"); this.navigationService = navigationService; // empty function to prevent any null exceptions ... this.GameOverDialog = (n) => { return(Task.Delay(0)); }; this.GamePausedDialog = () => { return(Task.Delay(0)); }; this.model = new TetrisModelImpl(); // initialize view model data repository this.board = new List <BoardCellModel>(); for (int row = 0; row < this.model.NumRows; row++) { for (int col = 0; col < this.model.NumColumns; col++) { BoardCellModel cell = new BoardCellModel(this, Color.Gray); this.board.Add(cell); } } this.level = this.model.Level; this.lines = this.model.Lines; this.score = this.model.Score; // listen to changes of underlying model this.model.PropertyChanged += this.PropertyChangedEventHandler; }
//получить новую фигуру public Figure GetNext(ITetris field) { n = rand.Next(0, 7); queue.Enqueue(n); Figure f = GenerateNextFigure.Get(field, queue.Dequeue()); PaintSmallFigure(n); return f; }
//получить новую фигуру public Figure GetNext(ITetris field) { n = rand.Next(0, 7); queue.Enqueue(n); Figure f = GenerateNextFigure.Get(field, queue.Dequeue()); PaintSmallFigure(n); return(f); }
public fQ(ITetris parent) : base(parent) { brush = QueueBrushes.GetBrush(); a.X = 0; a.Y = 4; b.X = 0; b.Y = 5; c.X = 1; c.Y = 4; d.X = 1; d.Y = 5; InitFigure(); }
public fZ(ITetris parent) : base(parent) { rotation = Rotation.rotation0; brush = QueueBrushes.GetBrush(); a.X = 0; a.Y = 4; b.X = 0; b.Y = 5; c.X = 1; c.Y = 5; d.X = 1; d.Y = 6; InitFigure(); }
public fJ(ITetris parent) : base(parent) { rotation = Rotation.rotation0; brush = QueueBrushes.GetBrush(); a.X = 0; a.Y = 5; b.X = 1; b.Y = 5; c.X = 2; c.Y = 4; d.X = 2; d.Y = 5; InitFigure(); }
public fI(ITetris parent) : base(parent) { rotation = Rotation.rotation0; brush = QueueBrushes.GetBrush(); a.X = 0; a.Y = 3; b.X = 0; b.Y = 4; c.X = 0; c.Y = 5; d.X = 0; d.Y = 6; InitFigure(); }
public Form1(ITetris tetris) { InitializeComponent(); tetrisBL = tetris; this.Paint += Form1_Paint; this.KeyDown += Form1_KeyDown; tetrisBL.ShapeMove += TetrisBL_ShapeMove; tetrisBL.CreateShape += TetrisBL_CreateShape; tetrisBL.SlicedLine += TetrisBL_SlicedLine; tetrisBL.GameOver += TetrisBL_GameOver; this.DoubleBuffered = true; this.Width = widthOfForm; this.Height = heightthOfForm; this.lbl_show_score.Text = "0"; Init(); }
//создает и возвращает новую фигуру public static Figure Get(ITetris tetris, int num) { switch (num) { case 0: return new fI(tetris); case 1: return new fQ(tetris); case 2: return new fT(tetris); case 3: return new fZ(tetris); case 4: return new fJ(tetris); case 5: return new fS(tetris); case 6: return new fL(tetris); } return new fT(tetris); }
protected Figure(ITetris parent) { this.parent = parent; }
/// <summary> /// Метод отображает главное меню. /// </summary> /// <param name="tetris"></param> public void MainMenuShow(ITetris tetris) { Console.Clear(); Console.Title = "Тетрис"; Console.CursorVisible = false; Console.WindowWidth = 50; Console.BufferWidth = Console.WindowWidth; Console.WindowHeight = 17; Console.BufferHeight = Console.WindowHeight; string[] menu = new string[3] { "Начать игру", "Рекорды", "Выход" }; int[] stringLength = new int[3] { 11, 7, 5 }; int[] rowPos = new int[3] { ((Console.WindowHeight - 3) / 2), ((Console.WindowHeight - 3) / 2) + 1, ((Console.WindowHeight - 3) / 2) + 2 }; int curPos = 0; while (true) { Console.SetCursorPosition(15, rowPos[curPos]); Console.Write("*"); Console.SetCursorPosition(2, 15); Console.Write("Для выбора нажмите Пробел"); for (int i = 0; i < 3; i++) { Console.SetCursorPosition(((Console.WindowWidth - stringLength[i]) / 2) - 1, rowPos[i]); Console.Write(menu[i]); } if (Console.KeyAvailable) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.DownArrow) { for (int i = 0; i < 3; i++) { Console.SetCursorPosition(15, rowPos[i]); Console.Write(" "); } if (curPos + 1 > 2) { curPos = 0; } else { curPos++; } Console.SetCursorPosition(15, rowPos[curPos]); Console.Write("*"); } else if (key.Key == ConsoleKey.UpArrow) { for (int i = 0; i < 3; i++) { Console.SetCursorPosition(15, rowPos[i]); Console.Write(" "); } if (curPos - 1 < 0) { curPos = 2; } else { curPos--; } Console.SetCursorPosition(15, rowPos[curPos]); Console.Write("*"); } else if (key.Key == ConsoleKey.Spacebar) { if (curPos == 2) { Environment.Exit(0); } else if (curPos == 1) { ShowRecordTable(tetris); break; } else if (curPos == 0) { Play(); break; } } else if (key.Key == ConsoleKey.Escape) { Environment.Exit(0); } } Thread.Sleep(100); } }
/// <summary> /// Метод отображает таблицу рекордов (данные считываются из БД). /// </summary> /// <param name="tetris"></param> public void ShowRecordTable(ITetris tetris) { Console.Clear(); Console.WindowWidth = 50; Console.BufferWidth = Console.WindowWidth; Console.WindowHeight = 17; Console.BufferHeight = Console.WindowHeight; ResultsDAL results = new ResultsDAL(); List <TetrisResults> recordList = results.GetTopFive(); // Если записи в БД отсутствуют, то сообщаем, что запией нет. if (recordList == null) { Console.WriteLine(" Записи отсутствуют."); Console.SetCursorPosition(2, 15); Console.Write("Нажмите пробел, чтобы вернуться в главное меню"); while (true) { if (Console.KeyAvailable) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.Spacebar) { break; } else { Console.SetCursorPosition(0, 14); Console.WriteLine(" "); } } Thread.Sleep(100); } tetris.MainMenuShow(tetris); } else { string heading = "Пять лучших результатов"; int indexOfCentralPosition = (Console.WindowWidth - heading.Length) / 2; Console.SetCursorPosition(indexOfCentralPosition, 1); Console.Write(heading); string table = String.Format("| {0, 1} | {1,-3} | {2,-4} | {3,-3} | {4,-10} |", "№", "Очки", "Время", "Линии", "Имя"); indexOfCentralPosition = (Console.WindowWidth - table.Length) / 2; Console.SetCursorPosition(indexOfCentralPosition, 3); Console.Write(table); Console.SetCursorPosition(indexOfCentralPosition, 4); Console.Write(String.Format("| {0, 1} | {1,-3} | {2,-4} | {3,-3} | {4,-10} |", "-", "----", "-----", "-----", "----------")); for (int i = 0; i < recordList.Count; i++) { Console.SetCursorPosition(indexOfCentralPosition, i + 5); Console.WriteLine(String.Format("| {0, 1} | {1,-4} | {2:00}:{3:00} | {4,-5} | {5,-10} |", i + 1, recordList[i].Points, TimeSpan.Parse(recordList[i].Time).Minutes, TimeSpan.Parse(recordList[i].Time).Seconds, recordList[i].Lines, recordList[i].Name)); Console.SetCursorPosition(indexOfCentralPosition, i + 6); } Console.WriteLine("| {0, 1} | {1,-3} | {2,-4} | {3,-3} | {4,-10} |", "-", "----", "-----", "-----", "----------"); Console.WriteLine(); Console.WriteLine("Нажмите пробел, чтобы вернуться в главное меню"); while (true) { if (Console.KeyAvailable) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.Spacebar) { tetris.MainMenuShow(tetris); break; } else { Console.SetCursorPosition(0, 14); Console.WriteLine(" "); } } Thread.Sleep(100); } } }