Ejemplo n.º 1
0
        //drop method
        public void Drop(List <block> sBlocks)//the floor
        {
            //if not fall rt
            if (!isFalling)
            {
                return;
            }

            shape colision = new shape(downOffdet, this);

            //if can't fall set falling to fasle and add to list
            if (colision.blocks.Any(block.cantfall))
            {
                isFalling = false;
                blocks.ForEach(blk => sBlocks.Add(blk));//TODO chage dis to foreach of blocks normal way if i choose to
            }

            if (colision.blocks.Intersect(sBlocks).Count() > 0) //fix with not origin
            {
                isFalling = false;
                //add shapes toblocks floor
                blocks.ForEach(blk => sBlocks.Add(blk));
            }
            else//if no overlap move down
            {
                move(downOffdet);
            }
        }
Ejemplo n.º 2
0
 //predicate rt true if shpae is falling
 public static bool Falling(shape shape)
 {
     if (!(shape is shape arg))
     {
         return(false);
     }
     return(shape.isFalling);
 }
Ejemplo n.º 3
0
 //copy ctor args of shape and point
 //Initialize all member fields to the Shape argument
 public shape(Point bOffset, shape spe)
 {
     //initalize all member fields to shape arg
     isFalling = spe.isFalling;
     _sLocal   = spe._sLocal;
     sahpeType = spe.sahpeType;
     spe.blocks.ForEach(mem => blocks.Add(new block(mem)));
     //invoke Move() with the offset to shift the Shape to the desired location
     move(bOffset);
 }
Ejemplo n.º 4
0
        //shift left merthod
        public void shiftLeft(List <block> sBlocks)//the floor
        {
            if (!isFalling)
            {
                return;
            }

            shape colision = new shape(leftOffdet, this);

            if (colision.blocks.Exists(block.CantShiftLeft) || colision.blocks.Exists(block.CantShiftRight))
            {
                Drop(sBlocks);
                return;
            }

            if (colision.blocks.Intersect(sBlocks).Count() > 0)
            {
                //isFalling = false;
                //add shapes toblocks floor
                //blocks.ForEach(blk => sBlocks.Add(blk));
                Drop(sBlocks);
                return;
            }
            move(leftOffdet);

            //if can't fall or go left  set falling to fasle and add to list
            //if (colision.blocks.Any(block.CantShiftLeft))
            //{
            //    isFalling = true;
            //    move(leftOffdet);//was right
            //}

            //if (colision.blocks.Intersect(sBlocks).Count() > 0)
            //{
            //    isFalling = false;
            //    //add shapes toblocks floor
            //    blocks.ForEach(blk => sBlocks.Add(blk));
            //}
            ////not need this?
            //else
            //{
            //    move(leftOffdet);
            //}
        }
Ejemplo n.º 5
0
        private void playGame_Click(object sender, EventArgs e)
        {
            //adjust based on scale
            block.drawer                = new CDrawer(500, 1000);
            block.drawer.Position       = new Point(Width, Height - 449);
            block.drawer.KeyboardEvent += Drawer_KeyboardEvent;
            block.drawer.Scale          = (int)numUpDownCol.Value;
            //timer1.Interval = 300;
            timer1.Enabled = true;
            timer1.Start();

            Qshapes = new Queue <shape>();
            for (int i = 0; i < 20; i++)
            {
                //get rdm shape in queue
                Qshapes.Enqueue(new shape(new Point(block.drawer.ScaledWidth / 2, 0)));
            }
            floor.Clear();

            pickShape = Qshapes.Dequeue();
        }
Ejemplo n.º 6
0
        //lots of checking here
        private void Timer_Tick(object sender, EventArgs e)
        {
            shape nextShape = null;

            if (block.drawer == null)
            {
                return;
            }

            // down is pressed or 1000ms has pased, drop
            if (sw.ElapsedMilliseconds >= 1000 || downState == true)
            {
                if (pickShape.isFalling == false && Qshapes.Count > 0)
                {
                    pickShape = Qshapes.Dequeue();
                    next.Clear();
                    if (Qshapes.Count() > 1)
                    {
                        nextShape = new shape(Point.Empty, Qshapes.Peek());
                    }
                    else
                    {
                        level  *= 2;
                        Qshapes = new Queue <shape>();
                        for (int i = 0; i < 20; i++)
                        {
                            //get rdm shape in queue
                            Qshapes.Enqueue(new shape(new Point(block.drawer.ScaledWidth / 2, 0)));
                        }
                        floor.Clear();

                        pickShape = Qshapes.Dequeue();
                    }
                }
                pickShape.Drop(floor);

                //crashes games adter first block hits bottom
                //if shape done falling set to null
                //if(pickShape.isFalling==false)
                //    pickShape = null;

                sw.Reset();
                sw.Start();
            }

            //not working for me idk why
            //preform key processing
            if (upState == true)
            {
                pickShape.Rotate(); upState = false;
            }
            if (leftState == true)
            {
                pickShape.shiftLeft(floor); leftState = false;
            }
            if (rightState == true)
            {
                pickShape.shiftRight(floor); rightState = false;
            }
            if (downState == true)
            {
                pickShape.Drop(floor); downState = false;
            }

            block.drawer.Clear();

            if (pickShape != null)
            {
                pickShape.ShowShape();
            }
            floor.ForEach(show => show.ShowBlock());
            nextShape?.blocks.ForEach(nxt => nxt.ShowBlock(next));
            block.drawer.Render();
        }