private void RedetectBlocks() { var viableBlocks = InfinoListo().Skip(cur).Take(6).ToList(); curBlockWithPos = new TetriminoWithPosition(viableBlocks.First(), 0, 4); nextBlocks = viableBlocks.Skip(1).ToList(); }
public GameState(Board board, TetriminoWithPosition fallingTetrimino, List <Tetrimino> nextTetriminoes, Tetrimino tetriminoInStash, bool thereIsDanger) { Board = board; NextTetriminoes = nextTetriminoes; FallingTetrimino = fallingTetrimino; TetriminoInStash = tetriminoInStash; ThereIsDanger = thereIsDanger; }
private void RedetectBlocks() { while (nextBlocksCaptured.Count == cur) { Console.WriteLine("Waiting for new blocks, should only happen in fake game mode"); //wait for new blocks Thread.Sleep(500); } lock (nextBlocksCaptured) { var viableBlocks = nextBlocksCaptured.Skip(cur).ToList(); var theNewBlock = viableBlocks.First(); Console.WriteLine($"New cur block ({cur}):{Environment.NewLine}{theNewBlock.ToStringRotateable()}"); curBlockWithPos = new TetriminoWithPosition(theNewBlock, 2, 3 + (theNewBlock.Width == 2 ? 1 : 0)); nextBlocks = viableBlocks.Skip(1).ToList(); } }
public void MakeMove(List <Move> moves) { foreach (var move in moves) { switch (move) { case Move.Left: curBlockWithPos.LeftCol--; break; case Move.Right: curBlockWithPos.LeftCol++; break; case Move.Drop: var previousBord = board; var result = board.drop(curBlockWithPos.Tetrimino, curBlockWithPos.LeftCol); board = result.Board; linesCleared += result.LinesCleared; linesClearedLabel.Invoke(new Action(() => { linesClearedLabel.Text = linesCleared.ToString(); })); if (result.LinesCleared != 0) { RedrawComplete(); //DrawDifferences(result.Board, previousBord); } else { //RedrawComplete(); DrawDifferences(result.Board, previousBord); } cur++; RedetectBlocks(); break; case Move.Stash: var tmp = inStash; inStash = curBlockWithPos.Tetrimino; if (tmp == null) { cur++; RedetectBlocks(); } else { curBlockWithPos = new TetriminoWithPosition(tmp, 0, 4); } break; case Move.Rotate_CW: curBlockWithPos.Tetrimino = curBlockWithPos.Tetrimino.RotateCW(); break; case Move.Rotate_CWW: curBlockWithPos.Tetrimino = curBlockWithPos.Tetrimino.RotateCW(); curBlockWithPos.Tetrimino = curBlockWithPos.Tetrimino.RotateCW(); curBlockWithPos.Tetrimino = curBlockWithPos.Tetrimino.RotateCW(); break; case Move.Enter: break; default: break; } } }
public void MakeMove(List <Move> moves) { foreach (var move in moves.Take(1)) { int linesClearedNow = 0; string keyToPress = null; switch (move) { case Move.Left: //tetris99Form.CurrentSerialConnection.SendButtonPress("LH"); keyToPress = "LH"; curBlockWithPos.LeftCol--; break; case Move.Right: //tetris99Form.CurrentSerialConnection.SendButtonPress("RH"); keyToPress = "RH"; curBlockWithPos.LeftCol++; break; case Move.Drop: var previousBord = board; var result = board.drop(curBlockWithPos.Tetrimino, curBlockWithPos.LeftCol); board = result.Board; linesCleared += result.LinesCleared; linesClearedNow = result.LinesCleared; linesClearedLabel.Invoke(new Action(() => { linesClearedLabel.Text = linesCleared.ToString(); })); if (result.LinesCleared != 0) { //RedrawComplete(); //DrawDifferences(result.Board, previousBord); } else { //RedrawComplete(); //DrawDifferences(result.Board, previousBord); } keyToPress = "UH"; //tetris99Form.CurrentSerialConnection.SendButtonPress("UH"); cur++; RedetectBlocks(); //DrawCurrentBlock(); //Thread.Sleep(500); break; case Move.Stash: var tmp = inStash; inStash = curBlockWithPos.Tetrimino; keyToPress = "7"; //tetris99Form.CurrentSerialConnection.SendButtonPress("7"); if (tmp == null) { cur++; RedetectBlocks(); //Thread.Sleep(500); } else { curBlockWithPos = new TetriminoWithPosition(tmp, 2, 3 + (tmp.Width == 2 ? 1 : 0)); } break; case Move.Rotate_CW: keyToPress = "2"; //tetris99Form.CurrentSerialConnection.SendButtonPress("2"); Rotate(); break; case Move.Rotate_CWW: keyToPress = "1"; //tetris99Form.CurrentSerialConnection.SendButtonPress("1"); Rotate(); Rotate(); Rotate(); break; case Move.Enter: break; default: break; } RedrawComplete(); DrawCurrentBlock(); DrawNextBlocks(); bool thereWasDanger = DetectIfThereIsDanger(); if (thereWasDanger) { gDanger.Clear(Color.Red); dangerCountLabel.Invoke(new Action(() => { dangerCountLabel.Text = _lastDetectedDanger.ToString(); })); } else { gDanger.Clear(Color.Green); } if (!string.IsNullOrWhiteSpace(keyToPress)) { var timeToWait = (int)Math.Max(0, minTimeToWait - _timeSinceLastKeyPress.Elapsed.TotalMilliseconds); if (timeToWait > 0) { Thread.Sleep(timeToWait); } minTimeToWait = FrameDurationHelper.ToFrameDuration(3); tetris99Form.CurrentSerialConnection.SendButtonPress(keyToPress, false); _timeSinceLastKeyPress.Restart(); if (keyToPress == "UH") { //If other players spawn shit, we need to wait for the animation if (thereWasDanger) { minTimeToWait = FrameDurationHelper.ToFrameDuration(33 + _lastDetectedDanger * 4); } else { minTimeToWait = FrameDurationHelper.ToFrameDuration(8); } } if (linesClearedNow > 0) { //Theres no more danger now _lastDanger = DateTime.MinValue; _lastNoDanger = DateTime.Now; minTimeToWait = FrameDurationHelper.ToFrameDuration(48); } } } }