private void loose() { currentPiece = null; stop_timer(); drawing.playSound("stop"); drawing.playSound("gameover"); MessageBox.Show("You are f*****g bad at TETRIS"); }
public Game(ImmutableArray<ImmutableSortedSet<Cell>> gameField, Pieces pieces, Piece movingPiece, int score, int width, bool pieceFixed = false) { this.gameField = gameField; this.pieces = pieces; this.score = score; this.movingPiece = movingPiece; this.width = width; this.pieceFixed = pieceFixed; }
public Game(int width, int height, ImmutableArray<Piece> pieces, bool pieceFixed = false) { this.width = width; this.pieces = CentralizedPieces(pieces, width); movingPiece = this.pieces.GetCurrentPiece(); this.pieces = new Pieces(this.pieces.PiecesArray,this.pieces.CurrentPiece + 1); gameField = CreateGameField(height); score = 0; this.pieceFixed = pieceFixed; }
public Game(Form1 form) { drawing = form; //initialize game timer Game_Timer.Interval = (Convert.ToInt32(1000 / FPS)); Game_Timer.Tick += new EventHandler(Game_Tick); nextPiece = new Pieces(util.colors[rand.Next(7)]); Generate_Board(); Score = 0; Level = 10; LinestoClear = 10; }
private void Game_Tick(Object myObject, EventArgs myEventArgs) { //piece got killed last tick if (currentPiece == null) { currentPiece = nextPiece; nextPiece = new Pieces(util.colors[rand.Next(7)]); drawing.Invalidate(); return; } //user input char input = drawing.get_Input(); bool changed = true; //resets to false if the switch defaults switch (input) { case 'L': move(-1); break; case 'R': move(1); break; case 'U': //TODO add handler, rotates are not always valid Rotate(); break; case 'D': gravity(); break; default: changed = false; break; } tickCount++; if (currentPiece == null) { drawing.Invalidate(); return; } //only apply natural gravity every x ticks if (tickCount >= FramesPerGrid(Level)) { gravity(); tickCount = 0; changed = true; Console.WriteLine(Level); Console.WriteLine(FramesPerGrid(Level)); Console.WriteLine(LinestoClear); } if (changed) { drawing.Invalidate(); } }
//handles gravity, setting blocks as final, Tetris check and removing the current piece private void gravity() { bool Kill = false; Piece[] old = currentPiece.Blocks(); currentPiece.gravity(); //mark piece for kill based on the position after update foreach (Piece check in currentPiece.Blocks()) { //floor collision if (check.Item2 < 0) { Kill = true; break; } //collision with another piece if (check.Item2 > 19) { continue; } if (board[check] != '.') { Kill = true; break; } } //kills the piece, applying its last valid coordinates as stable blocks if (Kill) { //set blocks as final foreach (Piece block in old) { if (block.Item2 > 19) { loose(); return; } board[block] = currentPiece.getColor(); } currentPiece = null; check_lines(); } }
public virtual IPiece GetRandomPiece() { var p = Pieces.ElementAt(Random.Next(0, Pieces.Count())); return(p.Rotate(RandomAngle())); }