private void TetrominoFactory(int id) { switch (id) { case 1: nextTetromino = new ITetromino(); break; case 2: nextTetromino = new TTetromino(); break; case 3: nextTetromino = new LTetromino(); break; case 4: nextTetromino = new JTetromino(); break; case 5: nextTetromino = new ZTetromino(); break; case 6: nextTetromino = new STetromino(); break; default: nextTetromino = new OTetromino(); break; } }
public static void BindTetrominoToSound(this ITetromino tetromino, SoundManager soundManager) { tetromino.MoveSucceed += soundManager.PlayTetrominoMoveSound; tetromino.MoveFailed += soundManager.PlayTetrominoMoveFailedSound; tetromino.Rotated += soundManager.PlayTetrominoRotateSound; tetromino.Landed += soundManager.PlayTetrominoLandSound; }
public IEnumerable <int> GetAllowedKicks(IBoard board, ITetromino tetromino, int targetAngle) { if (tetromino.Type == TetrominoType.I) { yield break; } bool canKick = false; foreach (var p in s_Def[tetromino.Type][targetAngle]) { if (p.x == -2) { if (board.Get(tetromino.Pos.x + p.x, tetromino.Pos.y + p.y) != TetrominoType.Empty) { canKick = true; } } else if (p.x == 0) { if (board.Get(tetromino.Pos.x + p.x, tetromino.Pos.y + p.y) != TetrominoType.Empty) { canKick = true; } } } // always try kick right first if (canKick) { yield return(1); yield return(-1); } }
public void InitializeBoard(IBoard board, IScoreInfo scoreInfo, ITetromino tetromino) { this.DrawBorder(board); this.DrawBoard(board); this.DisplayInfo(board, scoreInfo); this.DisplayNextTetromino(board, tetromino); }
private void Start() { _gameState.ResetData(); _grid = new TetrisGrid(_gridHeight, _gridWidth); _grid.GridOverflowed += GridOnGridOverflowed; _soundManager = GetComponent <SoundManager>(); _spawner = GetComponent <RandomPrefabsSpawner>(); _inputManager = new InputManagersWrapper(new List <IInputManager>() { GetComponent <InputManager>(), GetComponent <TouchInputManager>() }); _scoreCalculator = new ScoreCalculator(_gameState, _scoreData); _levelManager = new LevelManager(_gameState, 10, _maxLevel); _preview = new GameObject("Preview", new Type[] { typeof(SpriteRenderer) }); _preview.transform.position = _previewPosition; _currentTetromino = CreateTetromino(); InitializeCurrentTetromino(); _nextTetromino = CreateTetromino(); SetUpPreview(); }
public Tetromino(ITetromino other) { Type = other.Type; Pos = other.Pos; Angle = other.Angle; Locked = other.Locked; }
public void DisplayNextTetromino(IBoard board, ITetromino tetromino) { Console.SetCursorPosition(board.Width * 2 + 5, 5); ClearArea(); Console.SetCursorPosition(board.Width * 2 + 5, 5); tetromino.DrawTetromino(); }
public GameStep(ITetromino tetromino, Input input) { Tetromino = tetromino; Inputs = new List <Input>() { input }; }
public void RefillTetrominoes(ITetrominoRepository tetrominoRepository, ITetrominoFactory tetrominoFactory) { for (int i = 0; i < Constants.TetrominoRefillCount; i++) { ITetromino tetromino = tetrominoFactory.CreateTetromino(); tetrominoRepository.AddTetromino(tetromino); } }
public static Bitmap RenderBoard(IBoard board, ITetromino tetromino, int blockSize, CancellationToken cancel) { var bitmaps = s_Bitmaps.Value; cancel.ThrowIfCancellationRequested(); Bitmap bitmap = new Bitmap(board.Width * blockSize, board.HeightVisible * blockSize, PixelFormat.Format24bppRgb); using (var g = Graphics.FromImage(bitmap)) { g.CompositingMode = CompositingMode.SourceCopy; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; cancel.ThrowIfCancellationRequested(); { float scale = (float)blockSize / bitmaps.EmptyBrush.Image.Width; bitmaps.EmptyBrush.ResetTransform(); bitmaps.EmptyBrush.ScaleTransform(scale, scale); g.FillRectangle(bitmaps.EmptyBrush, 0, 0, blockSize * board.Width, blockSize * board.HeightVisible); } board.ForEachVisible((int x, int y, TetrominoType tetrominoType) => { if (tetrominoType != TetrominoType.Empty) { cancel.ThrowIfCancellationRequested(); PaintBlock(g, x, board.HeightVisible - y - 1, blockSize, bitmaps.White, 1.0f); } }); board.ForEachVisible((int x, int y, TetrominoType tetrominoType) => { if (tetrominoType != TetrominoType.Empty) { cancel.ThrowIfCancellationRequested(); PaintBlock(g, x, board.HeightVisible - y - 1, blockSize, bitmaps.Locked[tetrominoType]); } }); if (tetromino != null) { foreach (var p in board.GameRules.GetTetrominoPoints(tetromino)) { cancel.ThrowIfCancellationRequested(); PaintBlock(g, p.x, board.HeightVisible - p.y - 1, blockSize, bitmaps.Active[tetromino.Type]); } } } return(bitmap); }
public GameState(IGameState o, ITetromino tetromino, List <Input> inputs) { NextTetromino = o.Rng.Peek().First(); GameRules = o.GameRules; Rng = o.Rng.Next(); int linesCleared; Board = o.Board.LockTetromino(tetromino, out linesCleared); Time = GameRules.GetNextTime(o.Time, o.Level, inputs, linesCleared); Level = GameRules.GetNextLevel(o.Level, linesCleared); }
public ITetromino CreateTetromino() { TetrominoType type = this.GenerateRandomTetrominoType(); var typeOfTetromino = Assembly.GetExecutingAssembly().GetTypes() .FirstOrDefault(v => v.Name == type.ToString()); ITetromino tetromino = (ITetromino)Activator.CreateInstance(typeOfTetromino); return(tetromino); }
public ITetromino StepTetromino(ITetromino prevTetromino, Input input) { var t = new Tetromino(prevTetromino); ApplyRotate(t, input.Rotate, true); ApplyMove(t, input.Move); ApplyGravity(t); ApplyLock(t, input.Move); return(t); }
public IBoard LockTetromino(ITetromino tetromino, out int clearedLines) { MutableBoard board = new MutableBoard(this); foreach (var p in GameRules.GetTetrominoPoints(tetromino)) { board.Set(p.x, p.y, tetromino.Type); } clearedLines = board.ClearCompletedLines(); return(board); }
public void SetBoardAndTetromino(IBoard board, ITetromino tetromino) { if (board == null) { Reset(); return; } DoLoad((CancellationToken ct) => { return(Renderer.RenderBoard(board, tetromino, 15, ct)); }); }
private bool IsSpawnPossible(ITetromino tetromino, IBoard board, int tetrominoSpawnPoint) { for (int i = 0; i < tetromino.Blocks.GetLength(0); i++) { for (int j = tetrominoSpawnPoint; j < tetrominoSpawnPoint + tetromino.Blocks.GetLength(1); j++) { if (board.Blocks[i, j] == 1 && tetromino.Blocks[i, j - tetrominoSpawnPoint] == 1) { return(false); } } } return(true); }
private void CurrentTetrominoOnLanded(int numOfMoves) { int linesCleard = _grid.ClearFullLines(); if (linesCleard > 0) { _gameState.LinesCleared += linesCleard; _gameState.Level = _levelManager.GetCurrentLevel(); _soundManager.PlayLineClearedSound(); } _gameState.Score += _scoreCalculator.GetScoreForClearedLines(linesCleard) + _scoreCalculator.GetScoreForTetromino(numOfMoves); UnbindCurrentTetromino(); _currentTetromino = _nextTetromino; InitializeCurrentTetromino(); _nextTetromino = CreateTetromino(); SetUpPreview(); }
public ICurrentTetromino SpawnTetromino(ITetromino tetromino, IBoard board, ICurrentTetromino currentTetromino) { int tetrominoSpawnPoint = (int)(board.Width / 2 - Math.Ceiling((double)tetromino.Blocks.GetLength(1) / 2)); if (this.IsSpawnPossible(tetromino, board, tetrominoSpawnPoint)) { for (int i = 0; i < tetromino.Blocks.GetLength(0); i++) { for (int j = tetrominoSpawnPoint; j < tetrominoSpawnPoint + tetromino.Blocks.GetLength(1); j++) { if (tetromino.Blocks[i, j - tetrominoSpawnPoint] == 1) { board.Blocks[i, j] = 1; } } } return(new CurrentTetromino(tetromino, 0, tetrominoSpawnPoint)); } return(currentTetromino); }
public IEnumerable <Vec2> GetTetrominoPoints(ITetromino tetromino) { return(GetTetrominoPoints(tetromino.Type, tetromino.Pos, tetromino.Angle)); }
public GameStep(ITetromino t, List <Input> inputs, Input input) { Tetromino = t; Inputs = new List <Input>(inputs); Inputs.Add(input); }
public CurrentTetromino(ITetromino tetromino, int tetrominoAxisX, int tetrominoAxisY) { this.Tetromino = tetromino; this.Row = tetrominoAxisX; this.Col = tetrominoAxisY; }
public GameStep(ITetromino tetromino, List <Input> inputs) { Tetromino = tetromino; Inputs = inputs; }
public TetrominoWithLocation(ITetromino tetromino, int row, int column) { Tetromino = tetromino; Row = row; Column = column; }
public IGameState Next(ITetromino tetromino, List <Input> inputs) { return(new GameState(this, tetromino, inputs)); }
public void AddTetromino(ITetromino tetromino) { this.Tetrominoes.Enqueue(tetromino); }