// Start is called before the first frame update void Start() { _panelRT = (RectTransform)GetComponent("RectTransform"); _smallPanelRT = (RectTransform)NextTetrominoPanel.GetComponent("RectTransform"); _refTile = (GameObject)Resources.Load("Tile"); _panelWidth = _panelRT.sizeDelta.x; _panelHeight = _panelRT.sizeDelta.y; _smallPanelWidth = _smallPanelRT.sizeDelta.x; _smallPanelHeight = _smallPanelRT.sizeDelta.y; _tileWidth = _panelWidth / 10; _tileHeight = _panelHeight / 20; _smallTileWidth = 20; _smallTileHeight = 20; _gameBoard = new TetrisGameBoard(_panelWidth, _panelHeight, _tileWidth, _tileHeight); _random = new System.Random(); _gameover = false; _nextTetrominoEnum = GetRandomTetromino(); _nextTetromino = SmallTetrominoFromEnum(_nextTetrominoEnum); _nextTetromino.UpdateTilesPositions(); SpawnNewTetromino(); }
protected Figure(TColor color, int[,] body, TetrisGameBoard board) { Color = color; _body = (int[, ])body.Clone(); Board = board; _correctionTurn = 0; }
private void startNewGame() { txtGameOver.Visibility = Visibility.Hidden; TopScores.Clear(); if (tgb != null) { tgb.Pause(); tgb = null; } List <Shape> toRemove = canvas1.Children.OfType <Shape>().ToList(); foreach (Shape e in toRemove) { canvas1.Children.Remove(e); } tgb = new TetrisGameBoard(this.canvas1, rnd, (Brush)this.Resources["BoarderBrush"]); tgb.ScoreChangedEvent += new TetrisGameBoard.ScoreChangedEventHandler(tgb_ScoreChangedEvent); //displayBoard(sender, e); //displaySetShapes(sender, e); // and download the scores from the server. displayHighScores(); if (webThread.ThreadState != System.Threading.ThreadState.Stopped) { txtHighScores.Text = "Loading Scores... " + Environment.NewLine; } }
private void InitializeGameBoard() { if (_gameBoard == null) { _gameBoard = new TetrisGameBoard(10, 20, _connString); SubscribeToEvents(); _graphicGameBoard = GBoard.CreateGraphics(); _graphicNextFigure = NFigureBoard.CreateGraphics(); } }
public ViewModel(byte width, byte height, SqlConnectionStringBuilder connS) { _connString = connS; _model = new TetrisGameBoard(width, height, _connString); _model.UpdateEvent += Update; _model.GameOverEvent += GameOver; _model.SoundEvent += Sound; _model.VelocityChangeEvent += VelocityChanged; _save = new Command(OnSave, parameter => true); _open = new Command(OnOpen, parameter => true); _start = new Command(OnStart, parameter => true); _keyDown = new Command(OnKeyDown, parameter => true); }
public bool Collision(TetrisGameBoard gameBoard) { // Create an empty collision grid of size GridSize List <List <int> > collisionGrid = new List <List <int> >(); for (int i = 0; i < GridSize; i++) { collisionGrid.Add(new List <int>()); for (int j = 0; j < GridSize; j++) { collisionGrid[i].Add(0); } } // Add collision data from wall or gameboard for (int i = Y, a = 0; i < (Y + GridSize); i++, a++) { for (int j = X, b = 0; j < (X + GridSize); j++, b++) { if (i < 0 || i > 19 || j < 0 || j > 9) { collisionGrid[a][b] = 1; } else if (gameBoard.Board[i, j] != null) { collisionGrid[a][b] = 1; } } } // Check for collision between Grid and collision grid for (int i = 0; i < GridSize; i++) { for (int j = 0; j < GridSize; j++) { if (Grid[i, j] == 1 && collisionGrid[i][j] == 1) { return(true); } } } return(false); }
/// <summary> /// Rotate tetromino clockwise /// </summary> /// <param name="gameBoard"></param> public void RotateRight(TetrisGameBoard gameBoard) { int x = X; int y = Y; int[,] wkd = WKDRight[Rotation]; switch (Rotation) { case TetrominoRotation.Initial: Rotation = TetrominoRotation.Right; break; case TetrominoRotation.Right: Rotation = TetrominoRotation.Twice; break; case TetrominoRotation.Twice: Rotation = TetrominoRotation.Left; break; case TetrominoRotation.Left: Rotation = TetrominoRotation.Initial; break; } for (int i = 0; i < 5; i++) { X = x + wkd[i, 0]; Y = y - wkd[i, 1]; if (!Collision(gameBoard)) { //Debug.Log($"success with {wkd[i, 0]}, {wkd[i, 1]}"); break; } } }
static void Main(string[] args) { SqlConnectionStringBuilder connString = new SqlConnectionStringBuilder() { DataSource = "5.248.50.32,2501", InitialCatalog = "TetrisBase", UserID = "user2", Password = "******", Pooling = true }; _board = new TetrisGameBoard(10, 20, connString); _board.GameOverEvent += GameOver; _board.SoundEvent += PlaySound; _board.UpdateEvent += Update; Timer.Elapsed += Step; _board.VelocityChangeEvent += VelocityChanged; Console.CursorVisible = false; Console.WindowWidth = 56; Console.WindowHeight = 38; Drawing.DrawInitialData(); StartKeyControl(); }
public LeftZigzag(TColor color, int[,] body, TetrisGameBoard board) : base(color, body, board) { }
public Square(TColor color, int[,] body, TetrisGameBoard board) : base(color, body, board) { }
public RightG(TColor color, int[,] body, TetrisGameBoard board) : base(color, body, board) { }
public LetterT(TColor color, int[,] body, TetrisGameBoard board) : base(color, body, board) { }
private void startNewGame() { txtGameOver.Visibility = Visibility.Hidden; TopScores.Clear(); if (tgb != null) { tgb.Pause(); tgb = null; } List<Shape> toRemove = canvas1.Children.OfType<Shape>().ToList(); foreach (Shape e in toRemove) { canvas1.Children.Remove(e); } tgb = new TetrisGameBoard(this.canvas1, rnd,(Brush) this.Resources["BoarderBrush"]); tgb.ScoreChangedEvent += new TetrisGameBoard.ScoreChangedEventHandler(tgb_ScoreChangedEvent); //displayBoard(sender, e); //displaySetShapes(sender, e); // and download the scores from the server. displayHighScores(); if (webThread.ThreadState != System.Threading.ThreadState.Stopped) { txtHighScores.Text = "Loading Scores... " + Environment.NewLine; } }