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;
        }
    }
예제 #2
0
 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;
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
 public void InitializeBoard(IBoard board, IScoreInfo scoreInfo, ITetromino tetromino)
 {
     this.DrawBorder(board);
     this.DrawBoard(board);
     this.DisplayInfo(board, scoreInfo);
     this.DisplayNextTetromino(board, tetromino);
 }
예제 #5
0
        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();
        }
예제 #6
0
 public Tetromino(ITetromino other)
 {
     Type   = other.Type;
     Pos    = other.Pos;
     Angle  = other.Angle;
     Locked = other.Locked;
 }
예제 #7
0
 public void DisplayNextTetromino(IBoard board, ITetromino tetromino)
 {
     Console.SetCursorPosition(board.Width * 2 + 5, 5);
     ClearArea();
     Console.SetCursorPosition(board.Width * 2 + 5, 5);
     tetromino.DrawTetromino();
 }
예제 #8
0
 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);
            }
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        public void SetBoardAndTetromino(IBoard board, ITetromino tetromino)
        {
            if (board == null)
            {
                Reset();
                return;
            }

            DoLoad((CancellationToken ct) =>
            {
                return(Renderer.RenderBoard(board, tetromino, 15, ct));
            });
        }
예제 #16
0
 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);
 }
예제 #17
0
        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();
        }
예제 #18
0
        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);
        }
예제 #19
0
 public IEnumerable <Vec2> GetTetrominoPoints(ITetromino tetromino)
 {
     return(GetTetrominoPoints(tetromino.Type, tetromino.Pos, tetromino.Angle));
 }
예제 #20
0
 public GameStep(ITetromino t, List <Input> inputs, Input input)
 {
     Tetromino = t;
     Inputs    = new List <Input>(inputs);
     Inputs.Add(input);
 }
예제 #21
0
 public CurrentTetromino(ITetromino tetromino, int tetrominoAxisX, int tetrominoAxisY)
 {
     this.Tetromino = tetromino;
     this.Row       = tetrominoAxisX;
     this.Col       = tetrominoAxisY;
 }
예제 #22
0
 public GameStep(ITetromino tetromino, List <Input> inputs)
 {
     Tetromino = tetromino;
     Inputs    = inputs;
 }
예제 #23
0
 public TetrominoWithLocation(ITetromino tetromino, int row, int column)
 {
     Tetromino = tetromino;
     Row       = row;
     Column    = column;
 }
예제 #24
0
 public IGameState Next(ITetromino tetromino, List <Input> inputs)
 {
     return(new GameState(this, tetromino, inputs));
 }
 public void AddTetromino(ITetromino tetromino)
 {
     this.Tetrominoes.Enqueue(tetromino);
 }