private IGraphicsObject CreateCuboid(IMifAtlas atlas, OpenTK.Color color) { var figureType = FigureType.Cuboid; var shapeData = _calculler.Calculate(atlas.X, atlas.Y, atlas.Z, false, 1, 1, 1, XyzConstrainsModifier.Norm); return(_factory.Create(figureType, shapeData.Item1, shapeData.Item2, shapeData.Item3, shapeData.Item4, color)); }
/// <summary> /// Функция опускания фигуры на единицу и проверка упала или еще летит /// </summary> public void MakeIteration() { IsEndGame = GetIsEndGame(); if (!IsEndGame) { if (Field.IsCanSetUpFigure(_figure, _x, _y + 1)) { Field.SetUp(_figure, _y, _x, CellType.Empty); _y++; Field.SetUp(_figure, _y, _x, CellType.Figure); } else { Field.SetUp(_figure, _y, _x, CellType.Border); _timer.Interval = _speed; PlayerScore += Field.Remove(); _figure = NextFigure; _x = (Field.M - _figure.M) / 2; _y = 1; NextFigure = FigureFactory.Create(); } FieldChanged?.Invoke(); } }
public void Play(Label ScoreLabel) { Figure = FigureFactory.Create(); NextFigure = FigureFactory.Create(); RefreshTimer.Tick += Makemove; RefreshTimer.Tick += (o, e) => { ScoreLabel.Content = Info.LinesCleared; }; RefreshTimer.IsEnabled = true; }
public void Run() { try { bool canContinue = true; _figuresViwer.ShowMessage(_insrtuction); do { string[] arguments = _figuresViwer.InputParameters(); if (!_numbericsCheker.IsNumber(arguments[1], arguments[2], arguments[3])) { string message = string.Format("{0}\n{1}", DefaultSettings.WRONG_FORMAT_ARGS, _insrtuction); _figuresViwer.ShowMessage(message); return; } double[] sides = GetNumbers(arguments[1], arguments[2], arguments[3]); if (!_figuresChecker.IsRightName(arguments[0], DefaultSettings.COMMON_NAME) || !_figuresChecker.HasRightSides(sides)) { string message = string.Format("{0}\n{1}", DefaultSettings.WRONG_FIGURES_ARGS, _insrtuction); _figuresViwer.ShowMessage(message); return; } _figuresContainer.Enqueue(_figureBuilder.Create(arguments[0], sides)); string answer = _figuresViwer.InputAnswer(DefaultSettings.ANSWER_MESSAGE); canContinue = _checker.CanContinue(answer); } while (canContinue); if (_figuresContainer.Count == 0) { _figuresViwer.ShowMessage(_insrtuction); return; } IFiguresSorter trianlgleSorter = _sorterFactory.Create(_figuresContainer, _figuresComparer); IEnumerable <IFigure> figures = trianlgleSorter.SortFigures(); _figuresViwer.ShowFigures(figures); } catch (NullReferenceException ex) { string message = string.Format("{0}\n{1}", ex.Message, _insrtuction); _figuresViwer.ShowMessage(message); } }
static void Main(string[] args) { bool collide = true; TetrisEngineGrid = CreateEngineGrid(); ConsoleKeyInfo key = new ConsoleKeyInfo(); GameInfo info = new GameInfo(); while (true) { collide = true; Figures Figure = FigureFactory.Create(); while (collide) { Console.WriteLine(LinesCleared); key = Console.ReadKey(); if (key.Key == ConsoleKey.DownArrow) { collide = CheckCollision(MoveDown, ref Figure, ref TetrisEngineGrid, info); } if (key.Key == ConsoleKey.LeftArrow) { collide = CheckCollision(MoveLeft, ref Figure, ref TetrisEngineGrid, info); } else if (key.Key == ConsoleKey.RightArrow) { collide = CheckCollision(MoveRight, ref Figure, ref TetrisEngineGrid, info); } else if (key.Key == ConsoleKey.Spacebar) { collide = CheckCollision(MoveRotate, ref Figure, ref TetrisEngineGrid, info); } if (key.Key == ConsoleKey.Escape) { collide = false; } Console.Clear(); TetrisGrid = FillConsoleGrid(TetrisEngineGrid); DrawGrid(TetrisGrid); Figures newFigure = FigureFactory.Create(); Thread.Sleep(50); } } }
/// <summary> /// Перезапуск игры /// </summary> public void Restart() { Field.Clear(); _figure = FigureFactory.Create(); NextFigure = FigureFactory.Create(); _x = (Field.M - _figure.M) / 2; _y = 1; PlayerScore = 0; FieldChanged?.Invoke(); _timer.Start(); }
public void DropFigure() { Figure = NextFigure; UI.BrushPresent = new SolidColorBrush { Color = ListOfColors[rng.Next(0, 5)] }; if (RefreshInterval > 0.1) { RefreshInterval -= 0.01; RefreshTimer.Interval = TimeSpan.FromSeconds(RefreshInterval); } NextFigure = FigureFactory.Create(); UI.DrawNextFigure(NextFigure); }