Beispiel #1
0
 public Block()
     : base(Static.game)
 {
     if (gridPosition == null)
     {
         gridPosition = new Tuple();
     }
     rectangle = new Rectangle(gridPosition.X, gridPosition.Y, 20, 20);
     color = Color.DarkRed;
 }
Beispiel #2
0
 public Transition(Tetris tetrisState, Tuple<int, int> finalBlockTargetPosition, float time, bool noAdd = false)
 {
     this.TetrisState = tetrisState;
     this.FinalBlockTargetPosition = finalBlockTargetPosition;
     this.TransitionTime = time;
     if (!noAdd)
     {
         Register();
     }
 }
Beispiel #3
0
 private Step CollisionWork()
 {
     var pointsNCells = GetPointsFromClearing(UsedCells.Union(RunningCells));
     if (!CanAddNextPiece(pointsNCells.Item1))
     {
         pointsNCells = new Tuple<IEnumerable<Cell>, int>(ImmutableHashSet<Cell>.Empty, pointsNCells.Item2 - 10);
     }
     PrintScore(pointsNCells.Item2);
     return new Step(this, pointsNCells);
 }
Beispiel #4
0
        private Step(Step step, Tuple<IEnumerable<Cell>, int> pointsNCells)
        {
            height = step.height;
            width = step.width;
            commandIndex = step.commandIndex + 1;
            points = step.points + pointsNCells.Item2;

            Pieces = step.Pieces;
            CurrentPieceCells = Pieces[step.pieceIndex].Cells;
            UsedCells = pointsNCells.Item1.ToImmutableHashSet();
            Center = GetShift(CurrentPieceCells);
            RunningCells = CurrentPieceCells.Select(c => new Cell(c + Center)).ToImmutableHashSet();
            pieceIndex = (step.pieceIndex + 1) % step.Pieces.Count;
        }
Beispiel #5
0
 private bool uGranicama(Tuple<int, int> poz){
     return poz.Item1 > 0 && poz.Item2 > 0 && poz.Item1 < tip_igre.Redaka + 1 && poz.Item2 < tip_igre.Stupaca + 1;
 }
Beispiel #6
0
        public virtual void Update()
        {
            //Add time
            timeSinceMove += GameManager.GameTime.ElapsedGameTime.Milliseconds;

            //Set moveSpeedDown based on level
            moveSpeedDown = startMoveSpeedDown + 0.5 * GameManager.Level;

            //Controlled by player
            if (controlMode == ControlMode.Player)
            {
                //Add time
                if (InputState.isKeyDown(down))
                {
                    //Complete boost for keypress
                    timeSinceMove += GameManager.GameTime.ElapsedGameTime.Milliseconds * (moveSpeedBoost - 1);
                    slow = false;
                }

                //Move left
                if (InputState.isKeyPressed(left))
                {
                    if (CanMove(new Point(-1, 0), grid))
                    {
                        location.X -= 1;
                    }
                }

                //Move right
                if (InputState.isKeyPressed(right))
                {
                    if (CanMove(new Point(1, 0), grid))
                    {
                        location.X += 1;
                    }
                }

                //Rotate
                if (InputState.isKeyPressed(rotateLeft))
                {
                    RotateLeft();
                    //Check for helicopter rotation (aka infinity lock) withing 250 ms
                    if (timeSinceMove < 250)
                        helicopterMoves++;
                    else
                        helicopterMoves = 0;
                    //Do 10 rotations for the achievement
                    if (helicopterMoves >= 10)
                        GameManager.roflcopter.GetAchievement();
                    //Infinity lock
                    timeSinceMove = 0;
                }
                //Hard drop
                if (InputState.isKeyPressed(drop))
                {
                    Harddrop();
                }
            }

            //Controlled by AI
            if (controlMode == ControlMode.AI)
            {
                //If the AI hasn't thought yet, think
                if (!AIthought)
                {
                    moves = AI.Think(world, this);
                    xMoves = moves.Item1;
                    rotations = moves.Item2;
                    AIthought = true;
                }
                //Move horizontally
                if (xMoves > 0)
                {
                    //Move right
                    if (CanMove(new Point(1, 0), grid))
                    {
                        location.X++;
                    }
                    xMoves--;
                }
                if (xMoves < 0)
                {
                    //Move left
                    if (CanMove(new Point(-1, 0), grid))
                    {
                        location.X--;
                    }
                    xMoves++;
                }
                //Rotate
                if (rotations > 0)
                {
                    RotateLeft();
                    rotations--;
                }
                //Move down
                if (rotations == 0 && xMoves == 0)
                {
                    //Speed boost
                    timeSinceMove += GameManager.GameTime.ElapsedGameTime.Milliseconds * (moveSpeedBoost - 1);
                }
            }

            //Move down
            if (timeSinceMove >= 1000 / moveSpeedDown)
            {
                if (CanMove(new Point(0, 1), grid))
                {
                    location.Y += 1;
                }
                else
                {
                    //Can't move down
                    MoveToWorld();
                    //Reset AI
                    if (controlMode == ControlMode.AI)
                        AIthought = false;
                    //If hard drop and boost down weren't used, get the slow achievement (SP only)
                    if (slow && GameManager.CurrentGameMode == GameMode.Singleplayer)
                        GameManager.slow.GetAchievement();
                }
                timeSinceMove = 0;
            }
        }
Beispiel #7
0
 public Block(int x, int y)
     : this()
 {
     gridPosition = new Tuple(x, y);
     rectangle = new Rectangle(gridPosition.X, gridPosition.Y, 20, 20);
 }
Beispiel #8
0
 public static Tuple<int, int> RotationTransform(Tuple<int, int> pos, int n)
 {
     if (n == 0) return pos;
     if (n == 1) return Tuple.Create(pos.Item2, 3 - pos.Item1);
     if (n == 2) return Tuple.Create(3 - pos.Item1, 3 - pos.Item2);
     if (n == 3) return Tuple.Create(3 - pos.Item2, pos.Item1);
     else throw new ArgumentOutOfRangeException();
 }