示例#1
0
 public void GetSpeedFails(int level)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var speed = TetrisLevel.GetFramesPerRow(level);
     });
 }
示例#2
0
 private void Start()
 {
     tetrisLevel           = GetComponent <TetrisLevel>();
     scoreText.text        = "Score: " + totalScore;
     levelText.text        = "Level: " + curLevel;
     totalAmountForNextLvl = amountForNextLvl;
 }
示例#3
0
        public void GetFallDistance(int level, double seconds, int expectedDistance)
        {
            var duration = TimeSpan.FromSeconds(seconds);
            int distance = (int)Math.Ceiling(TetrisLevel.GetFallDistance(level, duration));

            Assert.AreEqual(expectedDistance, distance);
        }
示例#4
0
    //

    void Start()
    {
        //Mobile
        dragDistance = Screen.height * 5 / 100; //dragDistance is 5% height of the screen
        //

        scoreAndLevel = GameObject.FindGameObjectWithTag("Level").GetComponent <ScoreAndLevel>();
        level         = GameObject.FindGameObjectWithTag("Level").GetComponent <TetrisLevel>();
        spawn         = transform.parent.GetComponent <SpawnBlocks>();

        moveSpeed = level.moveTime;
    }
示例#5
0
    void ITetrisStateObserver.HandleLevelUp(int newLevel)
    {
        _stepInterval = TetrisLevel.CalculateSecondsPerCell(newLevel);

        var music = GetNode <AudioStreamPlayer>("../bakgrundsmusik");

        music.PitchScale = (float)Math.Pow(2d, -newLevel / 2d);
        music.VolumeDb  += 4;

        GetNode <AudioStreamPlayer>("../yowza").Play();
        _willPlayScoreSound           = false;
        _willPlayTetrominoUpdateSound = false;
    }
示例#6
0
        private int CalulateSearchHeight(Tetrimino?tetrimino)
        {
            // this is the time that passed since the next piece became visible
            var passedTime = Screenshot.Timestamp
                             - _beginTime
                             + Agent.MoreTimeToAnalyze;

            int searchHeightTime = (int)Math.Ceiling(TetrisLevel.GetFallDistance(Agent.GameState.Level, passedTime, Agent.GameState.HeartMode));

            if (tetrimino.HasValue)
            {
                // we know which tetrimino we are looking for
                // we maximally search to the distance that this tetrimino could possibly fall (drop distance)
                int dropDistance = Agent.GameState.Board.DropDistance(new Piece(tetrimino.Value));
                return(Math.Min(searchHeightTime, dropDistance));
            }

            // this case only happens once (in the beginning of a new game)
            // we don't know which tetrimino we are looking for, so we take the maximum drop distance of every possible tetrimino
            int maxDropDistance = Agent.GameState.Board.MaximumDropDistanceForSpawnedPiece();

            return(Math.Min(searchHeightTime, maxDropDistance));
        }
示例#7
0
        public void SimulateRealtime(IList <Move> moves, int msPerAction)
        {
            if (!moves.Any())
            {
                return;
            }

            var movesParallel = GetMovesParallel(moves);
            var msTimePassed  = 0;
            int fallen        = 0;

            foreach (var moveParallel in movesParallel)
            {
                foreach (var move in moveParallel)
                {
                    Simulate(move);
                }

                if (moveParallel.Any(x => x != Move.Drop))
                {
                    msTimePassed += msPerAction;

                    var distance      = TetrisLevel.GetFallDistance(GameState.Level, TimeSpan.FromMilliseconds(msTimePassed), GameState.HeartMode);
                    int deltaDistance = (int)Math.Floor(distance) - fallen;
                    if (deltaDistance > 0)
                    {
                        // time passed, fall
                        for (int i = 0; i < deltaDistance; i++)
                        {
                            Simulate(Move.Fall);
                        }

                        fallen += deltaDistance;
                    }
                }
            }
        }
示例#8
0
        private void ExecuteDrop()
        {
            // when we were executing button presses, the piece has fallen some rows
            // this is especially relevant in higher levels when speed is higher
            // we let the piece fall
            var alreadyPastTime       = Agent.GetExecutionDuration(_pendingMoves.Count) + Agent.LessFallTimeBeforeDrop;
            var alreadyFallenDistance = TetrisLevel.GetFallDistance(Agent.GameState.Level, alreadyPastTime, Agent.GameState.HeartMode);

            // calculates drop distance, score and new level
            var linesBefore  = Agent.GameState.Lines;
            int linesRemoved = 0;
            // we add one because the current line needs also to be dropped
            var dropDistance = Math.Max(1.0 + Agent.GameState.Drop() - alreadyFallenDistance, 0.0);
            var dropDuration = TetrisTiming.GetDropDuration(dropDistance);
            var waitDuration = TetrisTiming.EntryDelayDuration;

            if (Agent.GameState.Lines > linesBefore)
            {
                // lines were removed
                linesRemoved = Agent.GameState.Lines - linesBefore;

                // additinally wait the line clear duration
                waitDuration += TetrisTiming.LineClearDuration;
            }

            _logger.Info($"Execute Drop (new score {Agent.GameState.Score}, {linesRemoved} lines removed, drop lasts {dropDuration.Milliseconds} ms)");

            // execute the drop blocking
            // we must wait until the drop is ended before we can continue
            // TODO: here we could do some precalculations for the next search (and execute the drop asynchronous)???
            Agent.Executor.Hold(Button.Down, dropDuration);
            _logger.Info("Drop executed");

            // sleep and wait until the lines are cleared
            WaitDrop(waitDuration);
        }
示例#9
0
 public void EnterState()
 {
     Level = new TetrisLevel(new Size(15, 30));
     Level.InitializeLevel();
     Controller.InitializeController();
 }
示例#10
0
        public void GetLevelAType(int startLevel, int clearedLines, int expectedLevel)
        {
            int level = TetrisLevel.GetLevel(startLevel, clearedLines);

            Assert.AreEqual(expectedLevel, level);
        }
示例#11
0
        public void GetDuration(int level, int rows, double expected)
        {
            var duration = TetrisLevel.GetDuration(level, rows);

            Assert.True(Math.Abs(duration.TotalSeconds - expected) < 0.01);
        }
示例#12
0
        public void GetSpeed(int level, int expected)
        {
            var speed = TetrisLevel.GetFramesPerRow(level);

            Assert.AreEqual(expected, speed);
        }