Beispiel #1
0
 // The four squares this block consists of
 public Block(Square[] squares, Shape shape, Texture2D texture)
 {
     Squares = squares;
     BlockShape = shape;
     BlockTexture = texture;
     NextDirection = Directions.East;
     PreviousDirection = Directions.North;
 }
Beispiel #2
0
 private GameBoard()
 {
     Board = new Square[10, 20];
     for (int i1 = 0; i1 < 10; i1++)
     {
         for (int i2 = 0; i2 < 20; i2++)
         {
             Board[i1, i2] = null;
         }
     }
     GameOver = false;
 }
Beispiel #3
0
 /// <summary>
 /// Creates the squares which make up the visible portion of the board
 /// </summary>
 private void createSquares()
 {
     for (int row = 0; row < numberOfRows; row++)
     {
         for (int col = 0; col < numberOfColumns; col++)
         {
             Square square = new Square(row, col);
             square.Width = squareDimensions;
             square.Height = squareDimensions;
             square.Parent = gameWindow;
             square.Top = row * squareDimensions;
             square.Left = col * squareDimensions;
             string key = row.ToString() + col.ToString();
             squares.Add(key, square);
         }
     }
 }
Beispiel #4
0
        public void Reflect(Object sender, BoxEventArgs e)
        {
            Box box = e.box;
            if (box == null)
                return;
            List<Square> temp = entity;
            //entity = new List<Square>(box.Entity);
            entity = new List<Square>();
            for (int i = 0; i < 4; i++)
            {
                Square s = new Square(new Position(box.Entity[i].pos.x, box.Entity[i].pos.y), BoxShape.SHADOW);
                entity.Add(s);
            }

            int tx, ty;
            int k = 0;
            bool b = true, over = false;
            while (b)
            {
                for (int i = 0; i < 4; i++)
                {
                    tx = entity[i].pos.x + 1;
                    if (tx >= gFrame.Row)
                    {
                        over = true;
                        break;
                    }
                    ty = entity[i].pos.y;
                    if (!gFrame.UnitAvilible(tx, ty))
                    {
                        b = false; break;
                    }
                }
                if (over)
                    break;
                if (b)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        entity[i].pos.x++;
                    }
                    k++;
                }
            }
            if (k > 4)
            {
                if (reflect != null)
                {
                    for (int i = 0; i < entity.Count; i++)
                    {
                        while (i < entity.Count && box.UnitInBox(entity[i].pos.x, entity[i].pos.y))
                            entity.Remove(entity[i]);
                    }
                    if (temp != null)
                        for (int i = 0; i < temp.Count; i++)
                        {
                            while (i < temp.Count && !gFrame.UnitAvilible(temp[i].pos.x,temp[i].pos.y))
                                temp.Remove(temp[i]);
                        }
                    reflect(this, new MoveEventArgs(temp, entity));
                }
            }
            else
            {
                if (reflect != null)
                {
                    if (temp != null)
                        for (int i = 0; i < temp.Count; i++)
                        {
                            while (i < temp.Count && (box.UnitInBox(temp[i].pos.x, temp[i].pos.y) || !gFrame.UnitAvilible(temp[i].pos.x,temp[i].pos.y) ))
                                temp.Remove(temp[i]);
                        }
                    reflect(this, new MoveEventArgs(temp, null));
                    entity = null;
                }
            }
        }
Beispiel #5
0
 public Block GenerateBlock()
 {
     Block block = null;
     Shape randomShape = ChooseShape();
     var squares = new Square[4];
     Texture2D blockTexture;
     switch (randomShape)
     {
         case Shape.Square:
             blockTexture = GameContent.Load<Texture2D>("square");
             squares[0] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[1] = new Square(new Vector2(160.0f, 32.0f), blockTexture);
             squares[2] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(192.0f, 32.0f), blockTexture);
             block = new Block(squares, Shape.Square, blockTexture);
             break;
         case Shape.Line:
             blockTexture = GameContent.Load<Texture2D>("line");
             squares[0] = new Square(new Vector2(96.0f, 0.0f), blockTexture);
             squares[1] = new Square(new Vector2(128.0f, 0.0f), blockTexture);
             squares[2] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             block = new Block(squares, Shape.Line, blockTexture);
             break;
         case Shape.L:
             blockTexture = GameContent.Load<Texture2D>("lblock");
             squares[0] = new Square(new Vector2(160.0f, 32.0f), blockTexture);
             squares[1] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[2] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(224.0f, 0.0f), blockTexture);
             block = new Block(squares, Shape.L, blockTexture);
             break;
         case Shape.J:
             blockTexture = GameContent.Load<Texture2D>("jblock");
             squares[0] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[1] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[2] = new Square(new Vector2(224.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(224.0f, 32.0f), blockTexture);
             block = new Block(squares, Shape.J, blockTexture);
             break;
         case Shape.S:
             blockTexture = GameContent.Load<Texture2D>("sblock");
             squares[0] = new Square(new Vector2(160.0f, 32.0f), blockTexture);
             squares[1] = new Square(new Vector2(192.0f, 32.0f), blockTexture);
             squares[2] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(224.0f, 0.0f), blockTexture);
             block = new Block(squares, Shape.S, blockTexture);
             break;
         case Shape.Z:
             blockTexture = GameContent.Load<Texture2D>("zblock");
             squares[0] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[1] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[2] = new Square(new Vector2(192.0f, 32.0f), blockTexture);
             squares[3] = new Square(new Vector2(224.0f, 32.0f), blockTexture);
             block = new Block(squares, Shape.Z, blockTexture);
             break;
         case Shape.T:
             blockTexture = GameContent.Load<Texture2D>("tblock");
             squares[0] = new Square(new Vector2(128.0f, 0.0f), blockTexture);
             squares[1] = new Square(new Vector2(160.0f, 0.0f), blockTexture);
             squares[2] = new Square(new Vector2(192.0f, 0.0f), blockTexture);
             squares[3] = new Square(new Vector2(160.0f, 32.0f), blockTexture);
             block = new Block(squares, Shape.T, blockTexture);
             break;
     }
     return block;
 }
Beispiel #6
0
 private bool CheckRotation(Square[] newSquares)
 {
     return newSquares[0].CheckSquare() && newSquares[1].CheckSquare() && newSquares[2].CheckSquare() &&
            newSquares[3].CheckSquare();
 }
Beispiel #7
0
        public override void Rotate(ref int actual, World world, Platform platform)
        {
            if (actual == 1)
            {
                int x;
                int y;

                x = squares[0].dots[0].x;
                y = squares[0].dots[0].y;

                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x, y, sym);
                Square s2 = new Square(x - 2, y + 2, sym);
                Square s3 = new Square(x, y - 2, sym);
                Square s4 = new Square(x - 2, y, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);


                actual = 2;
            }
            else if (actual == 2)
            {
                int x;
                int y;

                x = squares[0].dots[0].x;
                y = squares[0].dots[0].y;

                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x, y, sym);
                Square s2 = new Square(x, y + 2, sym);
                Square s3 = new Square(x - 2, y, sym);
                Square s4 = new Square(x + 2, y + 2, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);

                actual = 1;
            }

            if (IsHit(squares, world.wallsDots()) || IsHit(squares, platform.platform))
            {
                recursion = true;
                Rotate(ref actual, world, platform);
            }
            else
            {
                recursion = false;
                Draw(squares);
            }
        }
Beispiel #8
0
 // Used when rotating
 public bool CheckSquare(Square square)
 {
     int indexValueX = Convert.ToInt32(square.Position.X/32);
     int indexValueY = Convert.ToInt32(square.Position.Y/32);
     if (indexValueX >= 0 && indexValueX < 10 && indexValueY >= 0 && indexValueY < 20)
     {
         // true if unoccupied, false if occupied
         return Board[indexValueX, indexValueY] == null;
     }
     return false;
 }
Beispiel #9
0
        void GetRandomBlock()
        {
            int RandomPosition = rand.Next(0, 4);

            switch (RandomBlock)
            {
                case 0:
                    t_block = new T_Block(StartPoint, RandomPosition, BlockSize,board);
                    moveLeft = t_block.MoveLeft;
                    moveRight = t_block.MoveRight;
                    moveDown = t_block.MoveDown;
                    rotate = t_block.Rotate;

                    BlockColor = t_block.color;
                    returnCoordinates = t_block.returnCoordinates;

                    break;
                case 1:
                    square = new Square(StartPoint, BlockSize,board);
                    moveLeft = square.MoveLeft;
                    moveRight = square.MoveRight;
                    moveDown = square.MoveDown;
                    rotate = square.Rotate;

                    BlockColor = square.color;
                    returnCoordinates = square.returnCoordinates;

                    break;
                case 2:
                    stick = new Stick(StartPoint, RandomPosition, BlockSize,board);
                    moveLeft = stick.MoveLeft;
                    moveRight = stick.MoveRight;
                    moveDown = stick.MoveDown;
                    rotate = stick.Rotate;

                    BlockColor = stick.color;
                    returnCoordinates = stick.returnCoordinates;

                    break;
                case 3:
                    z_block = new Z_Block(StartPoint, RandomPosition, BlockSize,board);
                    moveLeft = z_block.MoveLeft;
                    moveRight = z_block.MoveRight;
                    moveDown = z_block.MoveDown;
                    rotate = z_block.Rotate;

                    BlockColor = z_block.color;
                    returnCoordinates = z_block.returnCoordinates;
                    break;
                //
                default:
                    break;

            }
        }
Beispiel #10
0
        Bitmap DrawRandomBlock()
        {
            Bitmap RandomDraft = new Bitmap(RandomBSheet.Width, RandomBSheet.Height);
            Painter @Painter = new Painter(RandomDraft, BlockSize, RandomDraft.Width, RandomDraft.Height);

            int RandomPosition = rand.Next(0, 4);

            Color RColor = Color.FromArgb(40, 40, 40);

            Point Position = new Point(2 * BlockSize, 2 * BlockSize);

            switch(RandomBlock)
            {
                case 0:
                    t_block = new T_Block(RandomDraft, Position, RandomPosition, BlockSize);
                    t_block.Draw();
                    @Painter.DrawArea(RColor);
                    return RandomDraft;
                case 1:
                    square = new Square(RandomDraft, Position, BlockSize);
                    square.Draw();
                    @Painter.DrawArea(RColor);
                    return RandomDraft;
                case 2:
                    stick = new Stick(RandomDraft, Position, RandomPosition, BlockSize);
                    stick.Draw();
                    @Painter.DrawArea(RColor);
                    return RandomDraft;
                case 3:
                    z_block = new Z_Block(RandomDraft, Position, RandomPosition, BlockSize);
                    z_block.Draw();
                    @Painter.DrawArea(RColor);
                    return RandomDraft;
                default:
                    return RandomDraft;
            }
        }
Beispiel #11
0
        public void Rotation(ref int actual, int x, int y)
        {
            if (actual == 1)
            {
                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x, y - 2, sym);
                Square s2 = new Square(x - 2, y - 2, sym);
                Square s3 = new Square(x - 2, y, sym);
                Square s4 = new Square(x - 2, y + 2, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);


                actual++;
            }
            else if (actual == 2)
            {
                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x + 2, y, sym);
                Square s2 = new Square(x - 2, y - 2, sym);
                Square s3 = new Square(x, y - 2, sym);
                Square s4 = new Square(x + 2, y - 2, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);

                actual++;
            }
            else if (actual == 3)
            {
                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x + 2, y, sym);
                Square s2 = new Square(x + 2, y + 2, sym);
                Square s3 = new Square(x + 2, y - 2, sym);
                Square s4 = new Square(x, y + 2, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);

                actual++;
            }
            else if (actual == 4)
            {
                if (!recursion)
                {
                    Clear(squares);
                }
                squares.Clear();

                Square s1 = new Square(x - 2, y, sym);
                Square s2 = new Square(x - 2, y + 2, sym);
                Square s3 = new Square(x, y + 2, sym);
                Square s4 = new Square(x + 2, y + 2, sym);

                squares.Add(s1);
                squares.Add(s3);
                squares.Add(s2);
                squares.Add(s4);

                actual = 1;
            }
            recursion = false;
        }