コード例 #1
0
        public void RotateCCW()
        {
            if (this.game_end)
            {
                return;
            }
            Tetromino f    = this.minos.First();
            int       left = f.GetLeft();

            f.RotateCW();
            bool revert = false;

            foreach (System.Drawing.Rectangle r in this.minos.First().GetRectangles(0, 0))
            {
                int x = r.X / this.scale;
                int y = r.Y / this.scale;
                if (x >= 0 && x < 10 && y >= 0 && y < 20)
                {
                    revert |= this.grid[x, y].Color != System.Drawing.Color.FromArgb(128, 255, 255, 255);
                }
            }
            if (revert)
            {
                f.RotateCCW();
                int displacement = left - f.GetLeft();
                f.SetStart(displacement, 0);
            }
        }
コード例 #2
0
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startAngle, float time)
        {
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple <int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition       t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                        {
#if diagnose
                            Debug.WriteLine("({0},{1}) reused for rotation", XY.Item1, XY.Item2);
#endif
                            t = tetrisState.Transitions[XY];
                        }
                        else
                        {
#if diagnose
                            Debug.WriteLine("({0},{1}) Created for rotation", XY.Item1, XY.Item2);
#endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddRotation(startAngle, new Vector2(tetromino.X + 2, tetromino.Y + 2));
                    }
                }
            }
        }
コード例 #3
0
ファイル: Transitions.cs プロジェクト: mattsains/PoVtris
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startAngle, float time)
        {
            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple<int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) reused for rotation", XY.Item1, XY.Item2);
            #endif
                            t = tetrisState.Transitions[XY];
                        }
                        else
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) Created for rotation", XY.Item1, XY.Item2);
            #endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddRotation(startAngle, new Vector2(tetromino.X + 2, tetromino.Y + 2));
                    }
                }
        }
コード例 #4
0
 /// <summary>
 /// 領域を更新
 /// </summary>
 public GameState UpdateField(Tetromino nextTetromino, Point nextPos)
 {
     Point[] sqs, nextSqs;
     // 今のテトロミノを消す
     TetrominoPos(CurTetromino, CurPos, out sqs);
     PutBlock(BlockColor.Black, sqs);
     if (TetrominoPos(nextTetromino, nextPos, out nextSqs))
     {
         PutBlock(nextTetromino.Color, nextSqs);
         CurTetromino = nextTetromino;
         CurPos       = nextPos;
     }
     else
     {
         // 現状維持
         PutBlock(CurTetromino.Color, sqs);
         if (nextPos.Y == CurPos.Y + 1)
         {
             DeleteLine();
             PutStartPos();
             if (!TetrominoPos(CurTetromino, CurPos, out sqs))
             {
                 PutBlock(CurTetromino.Color, sqs);
                 GameOver();
                 return(GameState.GameOver);
             }
         }
     }
     return(GameState.Continuable);
 }
コード例 #5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Wysokość i szerokość tablicy gry.
            int         width       = 16;
            int         height      = 22;
            TetrisBoard tetrisBoard = new TetrisBoard(width, height);

            //Stworzenie wszystkich tetromino
            Tetromino[] tetrominos = new Tetromino[] {
                new Tetromino(TetrominoType.I, Color.Red),
                new Tetromino(TetrominoType.T, Color.SaddleBrown),
                new Tetromino(TetrominoType.O, Color.DarkGoldenrod),
                new Tetromino(TetrominoType.L, Color.Green),
                new Tetromino(TetrominoType.J, Color.Blue),
                new Tetromino(TetrominoType.S, Color.Brown),
                new Tetromino(TetrominoType.Z, Color.DarkCyan)
            };

            //utworzenie gracza
            Player player = new Player();
            //utworzenei silnika
            IGameEngine gameEngine = new GameEngine(tetrisBoard, player, tetrominos, 500);

            //utworzenie widoku
            IView view = new Form();

            //utworzenie presentera
            Presenter presenter = new Presenter(view, gameEngine);

            Application.Run((Form)view);
        }
コード例 #6
0
        private void DrawShadow(GameTime gameTime)
        {
            if (game.State == Tetris.Game.GameState.Clearing || game.State == Tetris.Game.GameState.GameOver || game.State == Tetris.Game.GameState.Paused)
            {
                return;
            }
            var shadow = new Tetromino(game.CurrentTetromino);

            while (game.Board.DoesTetrominoFit(shadow))
            {
                shadow.PositionX++;
            }
            shadow.PositionX--;

            float amount = 0.80f;

            /*  if ((gameTime.TotalGameTime.Ticks /  (TimeSpan.TicksPerMillisecond * 100)) % 2 == 0)
             * {
             *    amount = 0.83f;
             * }*/

            DrawTetramino(shadow, Color.Lerp(Color.White, Color.Black, amount),
                          blockSize,
                          (shadow.PositionY - shadow.NumColumns / 2) * blockSize,
                          (shadow.PositionX - game.NumHiddenRows - shadow.NumRows / 2) * blockSize);
        }
コード例 #7
0
ファイル: Board.cs プロジェクト: destbg/Tetris
 private void PreviewFalse()
 {
     board[prv[0]][cB[1]] = new Tetromino();
     board[prv[1]][cB[3]] = new Tetromino();
     board[prv[2]][cB[5]] = new Tetromino();
     board[prv[3]][cB[7]] = new Tetromino();
 }
コード例 #8
0
        private Tetromino[] CreateRandomizedPieceSet()
        {
            var pieces = new Tetromino[] {
                Tetromino.IPiece,
                Tetromino.JPiece,
                Tetromino.LPiece,
                Tetromino.SPiece,
                Tetromino.ZPiece,
                Tetromino.OPiece,
                Tetromino.TPiece
            };

            // Randomize sequence
            for (var i = 0; i < pieces.Length; i++)
            {
                //
                var j = Random.Next(pieces.Length);

                // Swap ith and jth pieces
                var temp = pieces[i];
                pieces[i] = pieces[j];
                pieces[j] = temp;
            }

            return(pieces);
        }
コード例 #9
0
        public static Tetromino GenerateRandomTetromino(PositionInfo initialPosition)
        {
            TetrominoShapeType shapeType = shapeTypes[randomNumberGenerator.Next(0, shapeTypes.Length)];
            var tetromino = new Tetromino(initialPosition, shapeType);

            return(tetromino);
        }
コード例 #10
0
 void GameOver()
 {
     timer1.Stop();
     next = null;
     MessageBox.Show("GAME OVER");
     isGameOver = true;
 }
コード例 #11
0
        static void Main(string[] args)
        {
            Initialize();
            _currentTetromino = GetRandomTetromino();

            ReadKey();
        }
コード例 #12
0
ファイル: TretisField.cs プロジェクト: ZnqbuZ/Tetris
        public override void Clear()
        {
            base.Clear();

            current            = Tetromino.Zero;
            IsTetrominoFalling = false;
        }
コード例 #13
0
        private void Awake()
        {
            List <ComponentPool <Tetromino> > createdPools = new List <ComponentPool <Tetromino> >();

            for (int i = 0; i < _tetrominoPrefabs.Length; ++i)
            {
                Tetromino prefabToPool = _tetrominoPrefabs[i];
                ComponentPool <Tetromino> dedicatedPool = new ComponentPool <Tetromino>(
                    1,
                    () =>
                {
                    Tetromino tetromino = Instantiate(prefabToPool);
                    tetromino.gameObject.SetActive(false);
                    return(tetromino);
                },
                    (tetromino) =>
                {
                    tetromino.gameObject.SetActive(true);
                    tetromino.transform.rotation = Quaternion.identity;
                    tetromino.AdjustTetrominoChildBlocksRotation();
                },
                    (tetromino) =>
                {
                    tetromino.gameObject.SetActive(false);
                });
                createdPools.Add(dedicatedPool);
            }

            _pools = createdPools.ToArray();
        }
コード例 #14
0
        public bool Collision(Tetromino figure)
        {
            if (this.CurrentFigureCol > this.TetrisColumns - figure.Height)
            {
                return(true);
            }

            if (this.CurrentFigureRow + figure.Width == this.TetrisRows)
            {
                return(true);
            }

            for (int row = 0; row < figure.Width; row++)
            {
                for (int col = 0; col < figure.Height; col++)
                {
                    if (figure.Body[row, col] &&
                        this.TetrisField[this.CurrentFigureRow + row + 1, this.CurrentFigureCol + col])
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #15
0
ファイル: Board.cs プロジェクト: destbg/Tetris
 private void SetFalse()
 {
     board[cB[0]][cB[1]] = new Tetromino();
     board[cB[2]][cB[3]] = new Tetromino();
     board[cB[4]][cB[5]] = new Tetromino();
     board[cB[6]][cB[7]] = new Tetromino();
 }
コード例 #16
0
        private void ApplySwapPiece()
        {
            // No existing hold piece (first use)
            if (HoldPiece == null)
            {
                // Assign the hold piece
                HoldPiece = UserPiece;

                // Get the next piece in the queue
                GiveUserNextPiece();
            }
            else
            {
                // Swap piece and hold piece
                var temp = UserPiece;
                UserPiece = HoldPiece;
                HoldPiece = temp;

                // Reset piece to top
                ResetPiecePosition();
            }

            // Mark as unable to hold again
            CanHoldSwap = false;
        }
コード例 #17
0
        // Call to paint the grid itself
        public void Paint(System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;
            System.Drawing.Pen      p = new System.Drawing.Pen(System.Drawing.Color.Black, 1); // outline
            System.Drawing.Brush    b;

            // draw the filled-in grid
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    b = new System.Drawing.SolidBrush(grid[x, y].Color);
                    System.Drawing.Rectangle rect =
                        new System.Drawing.Rectangle(grid[x, y].X + this.shift_x, grid[x, y].Y + this.shift_y,
                                                     scale, scale);

                    g.FillRectangle(b, rect);
                    g.DrawRectangle(p, rect);
                }
            }

            if (game_end)
            {
                foreach (GridBlock gb in this.overflow)
                {
                    b = new System.Drawing.SolidBrush(gb.Color);
                    System.Drawing.Rectangle rect =
                        new System.Drawing.Rectangle(gb.X + this.shift_x, gb.Y + this.shift_y,
                                                     scale, scale);

                    g.FillRectangle(b, rect);
                    g.DrawRectangle(p, rect);
                }
            }
            else
            {
                Tetromino f = this.minos.First();
                b = new System.Drawing.SolidBrush(f.Color);
                foreach (System.Drawing.Rectangle r in f.GetRectangles(this.shift_x, this.shift_y))
                {
                    g.FillRectangle(b, r);
                    g.DrawRectangle(p, r);
                }
            }

            int x_shift = this.shift_x + 12 * this.scale;
            int y_shift = this.shift_y + 3 * this.scale;

            for (int i = 1; i < 4; i++)
            {
                Tetromino t = this.minos.ElementAt(i);
                b = new System.Drawing.SolidBrush(t.Color);
                foreach (System.Drawing.Rectangle r in t.GetRectangles(x_shift, y_shift))
                {
                    g.FillRectangle(b, r);
                    g.DrawRectangle(p, r);
                }
                y_shift += 5 * this.scale;
            }
        }
コード例 #18
0
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startX, int startY, float time, bool noAdd = false)
        {
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple <int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition       t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                        {
                            t = tetrisState.Transitions[XY];
                        }
                        else
                        {
#if diagnose
                            Debug.WriteLine("({0},{1}) Created for tet translation", XY.Item1, XY.Item2);
#endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddTranslation(new Vector2((tetromino.X - startX), (tetromino.Y - startY)));
                    }
                }
            }
        }
コード例 #19
0
        // Moves current block to the left
        public void MoveLeft()
        {
            if (game_end)
            {
                return;
            }
            Tetromino f = this.minos.First();

            if (f.GetLeft() > 0)
            {
                // check if any blocks are to the right
                bool go = true;
                foreach (System.Drawing.Rectangle rect in f.GetRectangles(0, 0))
                {
                    int x = (rect.X - this.scale) / this.scale;
                    int y = rect.Y / this.scale;
                    if (y < 0)
                    {
                        continue;
                    }
                    go &= (grid[x, y].Color == System.Drawing.Color.FromArgb(128, 255, 255, 255));
                    if (y < 20)
                    {
                        go &= (grid[x, y + 1].Color == System.Drawing.Color.FromArgb(128, 255, 255, 255));
                    }
                }

                if (go)
                {
                    f.Shift(false);
                }
            }
        }
コード例 #20
0
 /// <summary>
 /// Sets the next tetromino.
 /// </summary>
 public void SetNextTetromino(Tetromino nextTetromino)
 {
     if (nextTetromino is I)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/I.png");
     }
     else if (nextTetromino is J)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/J.png");
     }
     else if (nextTetromino is L)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/L.png");
     }
     else if (nextTetromino is O)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/O.png");
     }
     else if (nextTetromino is S)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/S.png");
     }
     else if (nextTetromino is T)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/T.png");
     }
     else if (nextTetromino is Z)
     {
         NextBlock.Image = Image.FromFile("../../Tetrominos/Z.png");
     }
 }
コード例 #21
0
 public static bool sideCollisionCheck(int side, Tetromino currTetronimo, Board board)
 {
     if (side == 0)
     {
         for (int i = currTetronimo.thisTetromino.GetLength(0) - 1; i >= 0; i--)
         {
             for (int j = 0; j < currTetronimo.thisTetromino.GetLength(1); j++)
             {
                 if ((currTetronimo.thisTetromino[i, j] != null && board.Grid[currTetronimo.thisTetromino[i, j].y, currTetronimo.thisTetromino[i, j].x - 1].color != 0 && !board.Grid[currTetronimo.thisTetromino[i, j].y, currTetronimo.thisTetromino[i, j].x - 1].isCurrent) ||
                     currTetronimo.y + currTetronimo.thisTetromino.GetLength(0) == board.Grid.GetLength(0) - 1)
                 {
                     return(true);
                 }
             }
         }
     }
     if (side == 1)
     {
         for (int i = currTetronimo.thisTetromino.GetLength(0) - 1; i >= 0; i--)
         {
             for (int j = 0; j < currTetronimo.thisTetromino.GetLength(1); j++)
             {
                 if ((currTetronimo.thisTetromino[i, j] != null && board.Grid[currTetronimo.thisTetromino[i, j].y, currTetronimo.thisTetromino[i, j].x + 1].color != 0 && !board.Grid[currTetronimo.thisTetromino[i, j].y, currTetronimo.thisTetromino[i, j].x + 1].isCurrent) ||
                     currTetronimo.y + currTetronimo.thisTetromino.GetLength(0) == board.Grid.GetLength(0) - 1)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
コード例 #22
0
 public TetrisGame()
 {
     Score             = 0;
     TetrominosDropped = 0;
     NextTetromino     = Tetromino.RandomTetromino();
     GameOver          = Paused = TetrominoChanged = false;
     GameStarted       = DateTime.Now;
 }
コード例 #23
0
 public void Stop()
 {
     if (ActiveTetromino != null)
     {
         _tetrominoSpawner.DiscardTetromino(ActiveTetromino);
     }
     ActiveTetromino = null;
 }
コード例 #24
0
 private static void RemoveTetrominoFromFieldMatrix(Tetromino tetromino, Brush[,] matrix)
 {
     for (int i = 0; i < tetromino.BodyPositions.Count; i++)
     {
         var position = tetromino.BodyPositions[i];
         matrix[position.Y, position.X] = null;
     }
 }
コード例 #25
0
 internal static void UpdateField(Tetromino tetromino, Brush[,] fieldMatrix)
 {
     for (int i = 0; i < tetromino.BodyPositions.Count; i++)
     {
         var position = tetromino.BodyPositions[i];
         fieldMatrix[position.Y, position.X] = tetromino.Brush;
     }
 }
コード例 #26
0
ファイル: TretisField.cs プロジェクト: ZnqbuZ/Tetris
        public Tetromino Rotate()
        {
            Tetromino res = Clone();

            res.X1 = RotateRow(Y1); res.Y1 = RotateCol(X1);
            res.X2 = RotateRow(Y2); res.Y2 = RotateCol(X2);
            res.X3 = RotateRow(Y3); res.Y3 = RotateCol(X3);
            return(res);
        }
コード例 #27
0
 void PlayNext()
 {
     current = next;
     next    = NewTetromino();
     foreach (var item in current.Original)
     {
         matrix.Rows[item.RowIndex][item.ColIndex] = CellStatus.FALL;
     }
 }
コード例 #28
0
ファイル: Board.cs プロジェクト: destbg/Tetris
        private void SetTrue()
        {
            var b = cB[8];

            board[cB[0]][cB[1]] = new Tetromino(true, b);
            board[cB[2]][cB[3]] = new Tetromino(true, b);
            board[cB[4]][cB[5]] = new Tetromino(true, b);
            board[cB[6]][cB[7]] = new Tetromino(true, b);
        }
コード例 #29
0
ファイル: Tetromino.cs プロジェクト: andreivancea/MonoTetris
 public Tetromino(Tetromino other)
 {
     this.blocks            = other.blocks;
     this.Color             = other.Color;
     this.PositionX         = other.PositionX;
     this.PositionY         = other.PositionY;
     this.rotation          = other.rotation;
     this.SrsRotationOffset = other.SrsRotationOffset;
 }
コード例 #30
0
ファイル: Renderer.cs プロジェクト: Chamberlain91/Tetris
 public void Draw(int x, int y, Tetromino data, int orientation, char chr = '█')
 {
     //
     Draw(x, y, data.Width, data.Height, (int xc, int yc, out ConsoleColor color) =>
     {
         color = data.Color;
         return(data.IsSolid(xc, yc, orientation));
     }, chr);
 }
コード例 #31
0
ファイル: PlayingGrid.cs プロジェクト: janbaas/Torie
        //Constructor initialiseert objecten en geeft ze juiste posities.
        public PlayingGrid(Vector2 position, int width, int height)
            : base(position, width, height)
        {
            Current = new Tetromino();

            Next = new Tetromino().GenerateRandom();
            Next.GenerateRandom();
            Score = new ScoreGameObject(new Vector2(10, 10), "Comic Sans");
            resetTetromino();
        }
コード例 #32
0
ファイル: Board.cs プロジェクト: AntonProtasov/Tetris
        public void MoveTetromino(MoveDirection direction)
        {
            HideTetromino();
            switch (direction)
            {
            case MoveDirection.Down:
                if (!CanMoveDown(1))
                {
                    PlaceTetromino(instantly: false);
                }
                else
                {
                    for (int i = 0; i < currentTetromino.Units.Length; i++)
                    {
                        currentTetromino.Units[i].Row += 1;
                    }
                }
                break;

            case MoveDirection.InstantlyDown:
                PlaceTetromino(instantly: true);
                break;

            case MoveDirection.Right:
            case MoveDirection.Left:
                bool rigth  = direction == MoveDirection.Right;
                int  offset = rigth ? 1 : -1;

                if (ClashWithBlocksOrBorders(currentTetromino, offset))
                {
                    break;
                }

                for (int i = 0; i < currentTetromino.Units.Length; i++)
                {
                    currentTetromino.Units[i].Column = currentTetromino.Units[i].Column + offset;
                }
                break;

            case MoveDirection.Rotate:
                if (currentTetromino.Kind == TetrominoKind.O)
                {
                    break;
                }

                Tetromino rotated = manager.Rotate(currentTetromino);

                if (!ClashWithBlocksOrBorders(rotated))
                {
                    currentTetromino = rotated;
                }
                break;
            }
            AddTetrominoToBoard();
        }
コード例 #33
0
ファイル: Tetris.cs プロジェクト: mattsains/PoVtris
        public bool Update()
        {
            if (!GameOver)
            {
                if (current == null)
                {
                    current = new Tetromino(this);
                    List<Tetromino.Shapes> shapeNames = Tetromino.Structures.Keys.ToList();
                    Tetromino.Shapes newShape = shapeNames[r.Next(shapeNames.Count)];
                    current.Spawn(newShape, 3, 0, r.Next(4));
                }
                else
                {
                    bool done = current.MoveDown();
                    if (done)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < Width; j++)
                            {
                                if (Grid[j, i] != Color.Transparent)
                                {
                                    GameOver = true;
                                    break;
                                }
                            }
                            if (GameOver)
                                break;
                        }

                        ClearFullLines();

                        current = new Tetromino(this);
                        List<Tetromino.Shapes> shapeNames = Tetromino.Structures.Keys.ToList();
                        Tetromino.Shapes newShape = shapeNames[r.Next(shapeNames.Count)];
                        current.Spawn(newShape, 3, 0, r.Next(4));
                    }
                }
            }
            return GameOver;
        }
コード例 #34
0
ファイル: PlayingGrid.cs プロジェクト: janbaas/Torie
        //Zet de huidge Tetromino bovenaan en genereer een nieuwe Tetromino.
        public void resetTetromino()
        {
            Current = Next;
            Current.Position = new Point(Width / 2 - 1, 0);

            Next = new Tetromino().GenerateRandom();
            Next.Position = new Point(Width + 1, 1);
            Next.GenerateRandom();

            Score.blockCount++;
        }
コード例 #35
0
ファイル: PlayingGrid.cs プロジェクト: janbaas/Torie
        //Kijk of de positie van de Tetromino geldig is.
        bool isTetrominoValid(Tetromino Tetromino)
        {
            Point pos = Tetromino.Position;

            if (pos.X < 0 || pos.X > Width - Tetromino.Width || pos.Y > Height - Tetromino.Height)
                return false; //De Tetromino bevindt zich buiten het grid.

            for (int x = 0; x < Tetromino.Width; x++)
                for (int y = 0; y < Tetromino.Height; y++)
                    if (Tetromino.blocks[x, y] != null && blocks[pos.X + x, pos.Y + y] != null)
                        return false; //Een van de blokken van de Tetromino bevindt zich op een positie waar ook al een blok uit het grid is.

            return true; //De positie is geldig.
        }
コード例 #36
0
ファイル: Tetromino.cs プロジェクト: janbaas/Torie
        //Roteer de huidige tetromino
        public Tetromino Rotate()
        {
            Tetromino result = new Tetromino();
            result.blocks = new Block[Height, Width];
            result.position = position;

            for (int x = 0; x < Height; x++)
                for (int y = 0; y < Width; y++)
                    result.blocks[x, y] = blocks[y, x]; //Spiegelen in de lijn y = x

            result = result.Mirror(); //Verticaal spiegelen

            return result;
        }
コード例 #37
0
ファイル: Transitions.cs プロジェクト: mattsains/PoVtris
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startX, int startY, float time, bool noAdd = false)
        {
            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple<int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                            t = tetrisState.Transitions[XY];
                        else
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) Created for tet translation", XY.Item1, XY.Item2);
            #endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddTranslation(new Vector2((tetromino.X - startX), (tetromino.Y - startY)));
                    }
                }
        }
コード例 #38
0
ファイル: Tetromino.cs プロジェクト: janbaas/Torie
        //Functie die een verticaal gespiegelde Tetromino teruggeeft, nodig bij roteren
        Tetromino Mirror()
        {
            Tetromino result = new Tetromino();
            result.blocks = new Block[Width, Height];
            result.position = position;

            for (int x = 0; x < Width; x++)
                for (int y = 0; y < Height; y++)
                    result.blocks[x, y] = blocks[Width - x - 1, y];

            return result;
        }
コード例 #39
0
ファイル: PlayingGrid.cs プロジェクト: janbaas/Torie
        //Roteer, indien dit een geldige zet is.
        public void RotateTetromino()
        {
            Tetromino rotated = Current.Rotate();

            //Als de geroteerde Tetromino zich buiten het scherm bevindt na het draaien, corrigeren.
            while (rotated.Position.X > Width - rotated.Width && !isTetrominoValid(rotated))
                rotated.Position = new Point(rotated.Position.X - 1, rotated.Position.Y);

            if (isTetrominoValid(rotated))
                Current = rotated;
        }