Esempio n. 1
0
        public void Rotate(Position pos)
        {
            int rotate = 0;

            if (pos == Position.ROTATEL)
            {
                rotate--;
            }
            else
            {
                rotate++;
            }
            if (!CheckCollision(pos))
            {
                this.ClearObject();
                tObject.Rotate(rotate);
                if (tObject.Size(1) + column >= tField.Size(1))
                {
                    column = tField.Size(1) - tObject.Size(1);
                }
                this.DrawObject();
            }
        }
Esempio n. 2
0
        private bool CheckCollision(Position pos)
        {
            int          newRow       = row;
            int          newColumn    = column;
            TetrisObject tetrisObject = new TetrisObject(tObject);

            switch (pos)
            {
            case Position.UP:
                newRow--;
                if (newRow < 0)
                {
                    return(true);
                }
                break;

            case Position.DOWN:
                newRow++;
                break;

            case Position.LEFT:
                newColumn--;
                break;

            case Position.RIGHT:
                newColumn++;
                break;

            case Position.ROTATEL:
                tetrisObject.Rotate(-1);
                if (tetrisObject.Size(1) + newColumn >= tField.Size(1))
                {
                    newColumn = tField.Size(1) - tetrisObject.Size(1);
                }
                break;

            case Position.ROTATER:
                tetrisObject.Rotate(1);
                if (tetrisObject.Size(1) + newColumn >= tField.Size(1))
                {
                    newColumn = tField.Size(1) - tetrisObject.Size(1);
                }
                break;

            default:
                break;
            }
            foreach (Point p in tetrisObject)
            {
                if (p.X + newRow >= tField.Size(0) || newColumn < 0 || newColumn + p.Y >= tField.Size(1))
                {
                    return(true);
                }
                if (tField[p.X + newRow, p.Y + newColumn] == Color.Gold)
                {
                    goldenPoints += 3;
                    //tField[p.X + newRow, p.Y + newColumn] = Color.Yellow;
                }
                if (tField[p.X + newRow, p.Y + newColumn] == Color.Gray || tField[p.X + newRow, p.Y + newColumn] == Color.Black)
                {
                    return(true);
                }
            }

            return(false);
        }