Exemplo n.º 1
0
        private bool ValidMove(direction dir)
        {
            Globals.coords tempcoord = currPiece.location;
            int[,] shape = new int[4, 4];
            bool valid = false;

            //setup phase:  change coordinates or piece for checkPiece
            switch(dir)
            {
                //modify x/y values for pieces if necessary
                case direction.LEFT:
                    tempcoord.x = currPiece.location.x - 1;
                    shape = currPiece.shape;
                    break;
                case direction.RIGHT:
                    tempcoord.x = currPiece.location.x + 1;
                    shape = currPiece.shape;
                    break;
                case direction.TICK_DOWN:
                case direction.DOWN:
                    tempcoord.y = currPiece.location.y + 1;
                    shape = currPiece.shape;
                    break;
                case direction.RotateCW:
                    shape = currPiece.getRotation(rotType.CW);
                    break;
                case direction.HARD_DROP:
                    tempcoord = hardDropLocation;
                    shape = currPiece.shape;
                    newPiece = true;
                    break;
                case direction.NEW_PIECE:
                    tempcoord.x = 5;
                    tempcoord.y = 0;
                    shape = currPiece.shape;
                    break;
            }

            //hack:  if an I tetrionimo is positioned at X = -1, checking
            //bounds results in an IndexOutofRangeException (since we're checking L to R).
            //should enable a temporary x-offset property that's generated
            //when the temporary piece is rotated.
            int temp = shape[0,0] + shape[1,0] + shape[2,0] + shape[3,0];

            //action phase:  checkPiece
            if(tempcoord.x > -1 || temp == 0)
            {
                if (field.checkPiece(shape, tempcoord))
                {
                    currPiece.location = tempcoord;
                    valid = true;
                }
            }

            //finishing phase: move is valid, set the rotations.
            if (valid == true)
            {
                switch (dir)
                {
                    case direction.RotateCW:
                        currPiece.setRotation(rotType.CW);
                        break;
                    case direction.RotateCCW:
                        currPiece.setRotation(rotType.CCW);
                        break;
                }

                hardDropLocation = field.getHardDrop(currPiece.shape, currPiece.location);
            }
            else
            {
                if (dir == direction.TICK_DOWN)
                    newPiece = true;
            }

            return valid;
        }
Exemplo n.º 2
0
 public Tetronimo(Tetronimo oldPiece)
 {
     _shape = new int[4, 4];
     shapeArray = allshapes[oldPiece._type];
     rotation = oldPiece.rotation;
     this._shape = shapeArray[rotation];
     location = oldPiece.location;
     _width = oldPiece.width;
     _height = oldPiece.height;
     GetDimensions();
 }
Exemplo n.º 3
0
        //Maybe separate out Holding stuff to another function?
        public void DispatchPiece(bool holding = false)
        {
            if (state == gameState.COUNTDOWN)
                nextPiece = random.Next(0, 7);

            if (holding)
            {
                if (heldPiece > -1)
                {
                    int temp = currPiece.type;
                    currPiece = new Tetronimo(heldPiece);
                    heldPiece = temp;
                }
                else
                {
                    heldPiece = currPiece.type;
                    currPiece = new Tetronimo(nextPiece);
                    nextPiece = random.Next(0, 7);
                }
                //don't want them to spam the hold key, let another piece go first.
                justHeld = true;
            }
            else
            {
                currPiece = new Tetronimo(nextPiece);
                nextPiece = random.Next(0, 7);
                //reset justHeld, we got a new piece
                justHeld = false;
            }
            //if the piece can't be drawn, it's blocked, game ends.
            if (!ValidMove(direction.NEW_PIECE))
            {
                menu = new Menu(gameOverItems);
                state = gameState.GAME_OVER;
            }
            else
            {
                hardDropLocation = field.getHardDrop(currPiece.shape, currPiece.location);
            }
        }