public Board(Grid tetrisGrid, int speed) { _rows = tetrisGrid.RowDefinitions.Count; _cols = tetrisGrid.ColumnDefinitions.Count; _score = 0; _linesFilled = 0; _speed = speed; _blockControls = new Label[_cols, _rows]; for (var i = 0; i < _cols; i++) { for (var j = 0; j < _rows; j++) { _blockControls[i, j] = new Label { Background = NoBrush, BorderBrush = GrayBrush, BorderThickness = new Thickness(1, 1, 1, 1) }; Grid.SetRow(_blockControls[i, j], j); Grid.SetColumn(_blockControls[i, j], i); tetrisGrid.Children.Add(_blockControls[i, j]); } } _currentTetramino = new Tetramino(); CurrentTetraminoDraw(); }
/// <summary> /// create new figure, /// and move it down with reading user input /// and trying to do what user wants /// </summary> void Update() { if (DoUpdate) { if (NewFigure) { glass.RemoveRows(); CurrentFig = figures.Select(); CurrentFig.x = glass.Width / 2; CurrentFig.y = 2; if (checker.Overlay(CurrentFig)) { GameOver = true; } NewFigure = false; } else { glass.PutFigure(CurrentFig, Color.white); Input = userInput.CheckUserInput(); CurrentFig.TryMove(Input); if (checker.Sides(CurrentFig, Mode) || checker.SidesY(CurrentFig) || checker.Overlay(CurrentFig)) { CurrentFig.Rollback(Input); } if (checker.Fix(CurrentFig)) { NewFigure = true; } glass.PutFigure(CurrentFig, CurrentFig.color); } } }
public void CurrentTetraminoMoveDown() { var position = _currentTetramino.GetCurrentPosition(); var shape = _currentTetramino.GetCurrentShape(); var move = true; CurrentTetraminoErase(); foreach (var point in shape) { if (((int)(point.Y + position.Y) + 2 + 1) >= _rows) { move = false; } else if ( !Equals(_blockControls[ ((int)(point.X + position.X) + ((_cols / 2) - 1)), (int)(point.Y + position.Y) + 2 + 1] .Background, NoBrush)) { move = false; } } if (move) { _currentTetramino.MoveDown(); CurrentTetraminoDraw(); } else { CurrentTetraminoDraw(); CheckRows(); _currentTetramino = new Tetramino(); } }
/// <summary> /// テトリミノが落ちたときの処理 /// </summary> public void CurrentTetriminoMoveDown() { // テトリミノの位置 Point position = _currentTetrimino.GetCurrentPosition(); Point[] Shape = _currentTetrimino.GetCurrentShape(); bool move = true; CurrentTetriminoErase(); foreach (Point s in Shape) { if ((int)(s.Y + position.Y + 2 + 1) >= Rows) { move = false; } else if (BlockControls[((int)(s.X + position.X) + ((Cols / 2) - 1)), (int)(s.Y + position.Y) + 2 + 1].Background != NoBrush) { move = false; } } if (move) { _currentTetrimino.MoveDown(); CurrentTetriminoDraw(); } else { CurrentTetriminoDraw(); CheckRows(); _currentTetrimino = new Tetramino(); } }
//Konstruktor public Board(Grid TetrisGrid) { Rows = TetrisGrid.RowDefinitions.Count; Cols = TetrisGrid.ColumnDefinitions.Count; Score = 0; LinesFilled = 0; BlockControls = new Label[Cols, Rows]; for (int i = 0; i < Cols; i++) { for (int j = 0; j < Rows; j++) { BlockControls[i, j] = new Label(); BlockControls[i, j].Background = NoBrush; BlockControls[i, j].BorderBrush = SilverBrush; BlockControls[i, j].BorderThickness = new Thickness(1, 1, 1, 1); Grid.SetRow(BlockControls[i, j], j); Grid.SetColumn(BlockControls[i, j], i); TetrisGrid.Children.Add(BlockControls[i, j]); } } //Spielstein erzeugen currTetramino = new Tetramino(); currTetraminoDraw(); }
public Tetramino GetRandomTetramino() { int index = random.Next(7); Tetramino nextTetamino = defaultTetraminos[index]; return(nextTetamino.GetCopy()); }
/// <summary> /// コンスタラクタ /// </summary> /// <param name="TetrisGrid"></param> public Board(Grid TetrisGrid) { Rows = TetrisGrid.RowDefinitions.Count; Cols = TetrisGrid.ColumnDefinitions.Count; Score = 0; LinesFilled = 0; // TODO:できたらネストを浅くする。foreachで書き直す BlockControls = new Label[Cols, Rows]; for (int ColCount = 0; ColCount < Cols; ColCount++) { for (int RowCount = 0; RowCount < Rows; RowCount++) { BlockControls[ColCount, RowCount] = new Label { Background = NoBrush, BorderBrush = SilverBrush, BorderThickness = new Thickness(1, 1, 1, 1) }; Grid.SetRow(BlockControls[ColCount, RowCount], RowCount); Grid.SetColumn(BlockControls[ColCount, RowCount], ColCount); TetrisGrid.Children.Add(BlockControls[ColCount, RowCount]); } } _currentTetrimino = new Tetramino(); CurrentTetriminoDraw(); }
public Board(Grid TetrisGrid) { rows = TetrisGrid.RowDefinitions.Count; cols = TetrisGrid.ColumnDefinitions.Count; score = 0; filledLines = 0; BlockControls = new Label[cols, rows]; for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { BlockControls[i, j] = new Label(); BlockControls[i, j].Background = NoBrush; BlockControls[i, j].BorderBrush = SilverBrush; BlockControls[i, j].BorderThickness = new Thickness(1, 1, 1, 1); Grid.SetRow(BlockControls[i, j], j); Grid.SetColumn(BlockControls[i, j], i); TetrisGrid.Children.Add(BlockControls[i, j]); } } CurrTetramino = new Tetramino(); currTetraminoDraw(); }
private void RePaintFig(char f = '0') { Tetramino t = new Tetramino(); t.MoveDown(); if (FigureParams.CellsDic.Keys.Contains(f)) { GetGridField(f).DrowField(); t = new Tetramino(f); t.MoveDown(); GetGridField(f).TetraminoDraw(t); } else { foreach (var item in FigureParams.CellsDic.Keys) { GetGridField(item).DrowField(); t = new Tetramino(item); t.MoveDown(); GetGridField(item).TetraminoDraw(t); } Main.DrowField(); Main.TetraminoDraw(MainT); } }
private void ChangeColorFig(int index) { FigureParams.SetColor(MainT.NameFig, AllFigBrushes[index]); Main.TetraminoErase(MainT); MainT = new Tetramino(MainT.NameFig); MainT.MoveDown(); Main.TetraminoDraw(MainT); }
private void FigGrid_J_MouseUp(object sender, MouseButtonEventArgs e) { CancelButton_Click(sender, e); Main.TetraminoErase(MainT); MainT = new Tetramino((sender as Grid).Name.Last()); MainT.MoveDown(); Main.TetraminoDraw(MainT); indexFig = AllFigBrushes.FindIndex(x => x == MainT.Color); FigColor = MainT.Color; }
/// <summary> /// стереть фигуру тетрамино из поля /// </summary> public void TetraminoErase(Tetramino tetramino) { Point pos = tetramino.Position; Point[] figure = tetramino.Cells; foreach (Point S in figure) { Field[(int)(S.X + pos.X) + ((columns / 2) - 1), (int)(S.Y + pos.Y)].Fill = GridField.fieldBrush; } }
public Tetramino GetCopy() { Tetramino copy = new Tetramino(); copy.Kind = this.Kind; for (int i = 0; i < Units.Length; i++) { copy.Units[i] = this.Units[i]; } return(copy); }
/// <summary> /// нарисовать на поле тетрамино /// </summary> /// <param name="tetramino"></param> public void TetraminoDraw(Tetramino tetramino) { Point pos = tetramino.Position; Point[] figure = tetramino.Cells; Brush color = tetramino.Color; foreach (Point P in figure) { Field[(int)(P.X + pos.X) + ((columns / 2) - 1), (int)(P.Y + pos.Y)].Fill = color; } }
public CustomWindow() { InitializeComponent(); AllFigBrushes = new List <Brush>(10) { Brushes.Cyan, Brushes.Orange, Brushes.Red, Brushes.Yellow, Brushes.Purple, Brushes.Blue, Brushes.Green, }; int count = AllFigBrushes.Count; for (int i = 0; i < count; i++) { AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.White, 90)); AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.White, 45)); AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.White, 0)); AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.Black, 90)); AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.Black, 45)); AllFigBrushes.Add(new LinearGradientBrush(((SolidColorBrush)AllFigBrushes[i]).Color, Colors.Black, 0)); } AllFieldBrushes = new List <Brush>(10) { Brushes.White, Brushes.Black, Brushes.DarkBlue, Brushes.Silver }; I = new GridField(FigGrid_I); J = new GridField(FigGrid_J); L = new GridField(FigGrid_L); T = new GridField(FigGrid_T); S = new GridField(FigGrid_S); Z = new GridField(FigGrid_Z); O = new GridField(FigGrid_O); Main = new GridField(MainGrid); MainT = new Tetramino('I'); indexFig = AllFigBrushes.FindIndex(x => x == MainT.Color); indexField = AllFieldBrushes.FindIndex(x => x == GridField.fieldBrush); indexGran = AllFieldBrushes.FindIndex(x => x == GridField.granBrush); FigColor = MainT.Color; MainT.MoveDown(); GranColor.Fill = GranBrush; FieldColor.Fill = FieldBrush; RePaintFig(); }
public Board() { boardHeight = 24; boardWidth = 10; cells = new Cell[boardHeight][]; manager = new TetraminoManager(); currentTetramino = manager.GetRandomTetramino(); InitFreeSpaces(); InitBorder(); AddTetrominoToBoard(); }
/// <summary> /// check for collision with the top and bottom /// </summary> /// <param name="tmino"></param> /// <returns>true if collision</returns> public bool SidesY(Tetramino tmino) { int newy; foreach (Tile tile in tmino.tiles) { newy = tile.y + tmino.y; if (newy < 0 || newy >= Height) { return(true); } } return(false); }
/// <summary> /// Создать игровое поле /// </summary> /// <param name="TetrisGrid">Grid основного игрового поля</param> /// <param name="NextFigGrid">Grid для показа следующей фигуры</param> public Table(Grid TetrisGrid, Grid NextFigGrid) { TetrisField = new GridField(TetrisGrid); this.NextFigGrid = new GridField(NextFigGrid); LvlUp = false; score = 0; linesAssembled = 0; lvl = 1; thisLevelLinesAssembled = 0; currentTetramino = new Tetramino(); TetrisField.TetraminoDraw(currentTetramino); nextTetramino = new Tetramino(); this.NextFigGrid.TetraminoDraw(nextTetramino); }
/// <summary> /// check for collision with the left and right walls /// </summary> /// <param name="tmino"></param> /// <param name="mode">if mode=2 it always false</param> /// <returns>true if collision</returns> public bool Sides(Tetramino tmino, int mode) { if (mode == 2) { return(false); } int newx; foreach (Tile tile in tmino.tiles) { newx = tile.x + tmino.x; if (newx < 0 || newx >= Width) { return(true); } } return(false); }
/// <summary> /// put provided tetramino to glass with specified color /// </summary> /// <param name="tmino"></param> /// <param name="color"></param> public void PutFigure(Tetramino tmino, Color color) { int newx, newy; foreach (Tile tile in tmino.tiles) { newx = tile.x + tmino.x; newy = tile.y + tmino.y; while (newx < 0) { newx += Width; } if (newx >= Width) { newx %= Width; } Board[newx, newy] = color; } }
private bool ClashWithBlocksOrBorder(Tetramino currentTetramino, int offset = 0) { foreach (Unit unit in currentTetramino.Units) { if (unit.Column + offset < 0) { return(true); } if (unit.Column + offset > 23) { return(true); } if (cells[unit.Row][unit.Column + offset].IsBlockOrBorder) { return(true); } } return(false); }
/// <summary> /// Фигуру вниз /// </summary> public void CurTetraminoMovDown(bool CoolGame = false) { // бонус за быструю игру (нажата кнопка вниз) if (CoolGame) { score += 1 * lvl; } Point pos = currentTetramino.Position; Point[] figure = currentTetramino.Cells; bool canMove = true; TetrisField.TetraminoErase(currentTetramino); foreach (Point S in figure) { if (((int)(S.Y + pos.Y) + 1) >= TetrisField.rows) { canMove = false; } else if (TetrisField.Field[((int)(S.X + pos.X) + ((TetrisField.columns / 2) - 1)), (int)(S.Y + pos.Y) + 1].Fill != GridField.fieldBrush) { canMove = false; } } if (canMove) { currentTetramino.MoveDown(); TetrisField.TetraminoDraw(currentTetramino); } else { TetrisField.TetraminoDraw(currentTetramino); CheckRows(); CheckGameOver(); currentTetramino = nextTetramino; NextFigGrid.TetraminoErase(nextTetramino); nextTetramino = new Tetramino(); NextFigGrid.TetraminoDraw(nextTetramino); score += lvl * 10; //бонус за новую фигуру } }
private void PlaceTetramino(bool instantly) { if (instantly) { MoveDownInstantly(); } foreach (Unit unit in currentTetramino.Units) { cells[unit.Row][unit.Column].TransformToBlock(); } if (EndGame(cells[4])) { Game.EndGame(); return; } currentTetramino = manager.GetRandomTetramino(); }
/// <summary> /// check is it ok to fix tetramino here /// </summary> /// <param name="tmino"></param> /// <returns>true if it can be fixed</returns> public bool Fix(Tetramino tmino) { int newx, newy; foreach (Tile tile in tmino.tiles) { newx = tile.x + tmino.x; newy = tile.y + tmino.y; while (newx < 0) { newx += Width; } if (newx >= Width) { newx %= Width; } if (newy == Height - 1 || newy < Height - 1 && Board[newx, newy + 1] != Color.white) { return(true); } } return(false); }
/// <summary> /// is it something under the tetramino /// </summary> /// <param name="tmino"></param> /// <returns>true if exist something under</returns> public bool Overlay(Tetramino tmino) { int newx, newy; foreach (Tile tile in tmino.tiles) { newx = tile.x + tmino.x; newy = tile.y + tmino.y; while (newx < 0) { newx += Width; } if (newx >= Width) { newx %= Width; } if (Board[newx, newy] != Color.white) { return(true); } } return(false); }
//Bewegung nach unten public void CurrTetraminoMoveDown() { Point Position = currTetramino.getCurrPosition(); Point[] Shape = currTetramino.getCurrShape(); bool move = true; currTetraminoErase(); foreach (Point S in Shape) { //Bewegung aus Spielfeld heraus? if (((int)(S.Y + Position.Y) + 3) >= Rows) { move = false; } //anderer Stein im Weg (Prüfung anhand der Farbe)? else if (BlockControls[((int)(S.X + Position.X) + ((Cols / 2) - 1)), (int)(S.Y + Position.Y) + 3].Background != NoBrush) { move = false; } } //wenn Bewegung möglich -> bewegen if (move) { currTetramino.movDown(); currTetraminoDraw(); } //ansonsten liegt Stein bereits unten else { //neuen Stein erzeugen currTetraminoDraw(); CheckRows(); currTetramino = new Tetramino(); } }
bool IsOnFieldYComponent(ref Tetramino tetramino) { bool[,] map = manager[tetramino]; for (int x = 0; x < map.GetLength(0); x++) if (tetramino.x + x >= 0 && tetramino.x + x <= 9) { FieldRenderer.Cell[] column = new FieldRenderer.Cell[20]; for (int y = 0; y < 20; y++) column[y] = field[tetramino.x + x, y, true]; for (int y = 0; y < map.GetLength(1); y++) if (!(tetramino.y + y >= 0 && tetramino.y + y <= 19 && !column[tetramino.y + y].inUse) && map[x, y]) return false; } return true; }
private void InitDefaultTetromino() { Tetramino tetraminoI = new Tetramino(); tetraminoI.Kind = TetrominoKind.I; tetraminoI.Units[0] = new Unit(0, 4); tetraminoI.Units[1] = new Unit(1, 4); tetraminoI.Units[2] = new Unit(2, 4); tetraminoI.Units[3] = new Unit(3, 4); defaultTetraminos[0] = tetraminoI; Tetramino tetraminoO = new Tetramino(); tetraminoO.Kind = TetrominoKind.O; tetraminoO.Units[0] = new Unit(0, 4); tetraminoO.Units[1] = new Unit(0, 5); tetraminoO.Units[2] = new Unit(1, 4); tetraminoO.Units[3] = new Unit(1, 5); defaultTetraminos[1] = tetraminoO; Tetramino tetraminoT = new Tetramino(); tetraminoT.Kind = TetrominoKind.T; tetraminoT.Units[0] = new Unit(0, 5); tetraminoT.Units[1] = new Unit(0, 4); tetraminoT.Units[2] = new Unit(0, 6); tetraminoT.Units[3] = new Unit(1, 5); defaultTetraminos[2] = tetraminoT; Tetramino tetraminoJ = new Tetramino(); tetraminoJ.Kind = TetrominoKind.J; tetraminoJ.Units[0] = new Unit(0, 4); tetraminoJ.Units[1] = new Unit(1, 4); tetraminoJ.Units[2] = new Unit(2, 4); tetraminoJ.Units[3] = new Unit(2, 3); defaultTetraminos[3] = tetraminoJ; Tetramino tetraminoL = new Tetramino(); tetraminoL.Kind = TetrominoKind.L; tetraminoL.Units[0] = new Unit(0, 4); tetraminoL.Units[1] = new Unit(1, 4); tetraminoL.Units[2] = new Unit(2, 4); tetraminoL.Units[3] = new Unit(2, 5); defaultTetraminos[4] = tetraminoL; Tetramino tetraminoS = new Tetramino(); tetraminoS.Kind = TetrominoKind.S; tetraminoS.Units[0] = new Unit(0, 5); tetraminoS.Units[1] = new Unit(0, 4); tetraminoS.Units[2] = new Unit(1, 4); tetraminoS.Units[3] = new Unit(1, 3); defaultTetraminos[5] = tetraminoS; Tetramino tetraminoZ = new Tetramino(); tetraminoZ.Kind = TetrominoKind.Z; tetraminoZ.Units[0] = new Unit(0, 3); tetraminoZ.Units[1] = new Unit(0, 4); tetraminoZ.Units[2] = new Unit(1, 4); tetraminoZ.Units[3] = new Unit(1, 5); defaultTetraminos[6] = tetraminoZ; }
public void currTetraminoDown() { Point position = CurrTetramino.getCurrPosition(); Point[] Shape = CurrTetramino.getCurrShape(); Boolean move = true; currTetraminErase(); // check if … // a) the tetramino is not at the bottom of the grid // b) there is no other tetramino under of the moving one foreach (Point s in Shape) { if (((int)(s.Y + position.Y) + 2 + 1) >= rows) { move = false; } else if (BlockControls[((int)(s.X + position.X) + ((cols / 2) - 1)), (int)(s.Y + position.Y) + 2 + 1].Background != NoBrush) { move = false; } } if (move) { CurrTetramino.moveDown(); currTetraminoDraw(); } else { currTetraminoDraw(); if (CurrTetramino.getCurrPosition().Y == 0) { // game over! MainWindow.instance.GameOver(); } else { checkRows(); CurrTetramino = new Tetramino(); } } }
protected override void DoUpdate(FrameEventArgs e) { if (!field.IsGameOver) { field.Clear(); dropTimer -= e.Time; if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].softDrop]) dropTimer = 0; if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].softDrop] && !prev_down) dropTimer = dropSpeed; if (dropTimer <= 0) { TryMove(0, -1, false, ref currentTetramino, true); dropTimer += dropSpeed; } if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].rotate] && !prev_up) TryMove( 0, 0, true, ref currentTetramino, true); if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].right] && !prev_right) { TryMove(-1, 0, false, ref currentTetramino, true); rightDAR = initialDAR; } if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].right]) { rightDAR -= e.Time; if (rightDAR < 0) { rightDAR += repeatDAR; TryMove(-1, 0, false, ref currentTetramino, true); } } if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].left] && !prev_left) { TryMove( 1, 0, false, ref currentTetramino, true); leftDAR = initialDAR; } if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].left]) { leftDAR -= e.Time; if (leftDAR < 0) { leftDAR += repeatDAR; TryMove( 1, 0, false, ref currentTetramino, true); } } bool result = true; hardDropTetramino = currentTetramino; do result = TryMove(0, -1, false, ref hardDropTetramino, false); while (result); if (Window.Keyboard[CoordinatedInputManager.KeyMaps[player].hardDrop] && !prev_lock) { currentTetramino = hardDropTetramino; deferredLock = true; lockTimer = 0; } bool[,] map = manager[hardDropTetramino]; for (int x = 0; x < map.GetLength(0); x++) if (hardDropTetramino.x + x >= 0 && hardDropTetramino.x + x <= 9) for (int y = 0; y < map.GetLength(1); y++) if (field[hardDropTetramino.x + x, hardDropTetramino.y + y, false] != default(FieldRenderer.Cell)) { field[hardDropTetramino.x + x, hardDropTetramino.y + y, false].inUse = map[x, y]; field[hardDropTetramino.x + x, hardDropTetramino.y + y, false].color = hardDropTetramino.color; field[hardDropTetramino.x + x, hardDropTetramino.y + y, false].ghost = true; } for (int x = 0; x < map.GetLength(0); x++) if (currentTetramino.x + x >= 0 && currentTetramino.x + x <= 9) for (int y = 0; y < map.GetLength(1); y++) if (field[currentTetramino.x + x, currentTetramino.y + y, false] != default(FieldRenderer.Cell)) { field[currentTetramino.x + x, currentTetramino.y + y, false].inUse = map[x, y] | field[currentTetramino.x + x, currentTetramino.y + y, false].inUse; field[currentTetramino.x + x, currentTetramino.y + y, false].color = currentTetramino.color; if (map[x, y]) field[currentTetramino.x + x, currentTetramino.y + y, false].ghost = false; } if (deferredLock) { lockTimer -= e.Time; if (lockTimer <= 0) LockTetramino(); } CalculateClears(); prev_up = Window.Keyboard[CoordinatedInputManager.KeyMaps[player].rotate]; prev_left = Window.Keyboard[CoordinatedInputManager.KeyMaps[player].left]; prev_down = Window.Keyboard[CoordinatedInputManager.KeyMaps[player].softDrop]; prev_right = Window.Keyboard[CoordinatedInputManager.KeyMaps[player].right]; prev_lock = Window.Keyboard[CoordinatedInputManager.KeyMaps[player].hardDrop]; } }
bool IsOnFieldXComponent(ref Tetramino tetramino) { bool[,] map = manager[tetramino]; for (int x = 0; x < map.GetLength(0); x++) for (int y = 0; y < map.GetLength(1); y++) if (!(tetramino.x + x >= 0 && tetramino.x + x <= 9) && map[x, y]) return false; return true; }
void SpawnTetramino() { RandomGenerator.TetraminoData d = rand.Generate(); currentTetramino = manager.SpawnDictionary[(TetraminoType)d.newTetramino]; field.IsGameOver = !VerifyNoOverlap(ref currentTetramino); field.NextTetramino = (TetraminoType)d.nextTetramino; field.UpdateUI = true; }
bool TryMove(int x, int y, bool rotate, ref Tetramino tetramino, bool allowGameStateChange) { Tetramino newTetramino = tetramino; newTetramino.x += x; newTetramino.y += y; if (rotate) newTetramino.rotation = (TetraminoRotation)(((ushort)newTetramino.rotation + 1) % 4) - 0; if (IsOnFieldXComponent(ref newTetramino)) // prevents IsOnFieldYComponent from crashing { bool yCheck = IsOnFieldYComponent(ref newTetramino); if (!yCheck && y != 0) if (!deferredLock && allowGameStateChange) { lockTimer = dropSpeed / 2; deferredLock = true; } if (VerifyNoOverlap(ref newTetramino) && yCheck) { tetramino = newTetramino; return true; } } else if (rotate) { //TODO: Wallkick } return false; }
bool VerifyNoOverlap(ref Tetramino tetramino) { bool[,] map = manager[tetramino]; for (int x = 0; x < map.GetLength(0); x++) if (tetramino.x + x >= 0 && tetramino.x + x <= 9) for (int y = 0; y < map.GetLength(1); y++) if (field[tetramino.x + x, tetramino.y + y, true] != default(FieldRenderer.Cell)) if (field[tetramino.x + x, tetramino.y + y, true].inUse && map[x, y]) return false; return true; }