Пример #1
0
        private SubUnit[] subunits; //the subunits

        #endregion Fields

        #region Constructors

        public Unit( GameGrid g )
        {
            rnd = new System.Random();
            grid = g;

            //create SubUnits
            subunits = new SubUnit[4];
            for (int i=0; i<subunits.Length; i++)
                subunits[i] = new SubUnit( grid );
        }
Пример #2
0
 ///<summary>
 //Fills a space in the grid
 ///</summary>
 public void FillSpace( int oc, SubUnit.SubUnitType s, int x, int y )
 {
     grid[y][x] = s;
     orbtimer[y][x] = oc;
 }
Пример #3
0
        //rotates the SubUnit and all attached SubUnits clockwise around their axis
        public void RotateRight()
        {
            SubUnit temp = this.top;

            //rotate pointers and adjust locations of attached SubUnits
            this.top = this.left;
            if (this.top != null) {
                this.top.Location.Y = this.Location.Y - 1;
                this.top.Location.X = this.Location.X;
                this.top.RotateRight();
            }
            this.left = this.bottom;
            if (this.left != null) {
                this.left.Location.X = this.Location.X - 1;
                this.left.Location.Y = this.Location.Y;
                this.left.RotateRight();
            }
            this.bottom = this.right;
            if (this.bottom != null) {
                this.bottom.Location.Y = this.Location.Y + 1;
                this.bottom.Location.X = this.Location.X;
                this.bottom.RotateRight();
            }
            this.right = temp;
            if (this.right != null) {
                this.right.Location.X = this.Location.X + 1;
                this.right.Location.Y = this.Location.Y;
                this.right.RotateRight();
            }
        }
Пример #4
0
 //clears all pointers to other SubUnits
 public void Clear()
 {
     this.top = null;
     this.bottom = null;
     this.left = null;
     this.right = null;
 }
Пример #5
0
        //determines what image to draw from the image collection
        //based on a SubUnit type
        private int GetIlIndex( SubUnit.SubUnitType s )
        {
            int index;

            switch(s)
            {
                case SubUnit.SubUnitType.bSq:
                    index = 0;
                    break;
                case SubUnit.SubUnitType.gSq:
                    index = 1;
                    break;
                case SubUnit.SubUnitType.pSq:
                    index = 2;
                    break;
                case SubUnit.SubUnitType.rSq:
                    index = 3;
                    break;
                case SubUnit.SubUnitType.ySq:
                    index = 4;
                    break;
                case SubUnit.SubUnitType.clearing:
                    index = 5;
                    break;
                case SubUnit.SubUnitType.bCr:
                    index = 6;
                    break;
                case SubUnit.SubUnitType.gCr:
                    index = 7;
                    break;
                case SubUnit.SubUnitType.pCr:
                    index = 8;
                    break;
                case SubUnit.SubUnitType.rCr:
                    index = 9;
                    break;
                case SubUnit.SubUnitType.yCr:
                    index = 10;
                    break;
                default:
                    index = -1;
                    break;
            }

            return index;
        }
Пример #6
0
        //blow a block in the grid and all bordering blocks that are of the specified
        //type return the amount of points racked up in process
        private void Blow( int x, int y, SubUnit.SubUnitType t, ref int blowcount, ref int pts )
        {
            //for scoring
            pts += (++blowcount)*GameState.BasePoints;

            //clear the current space
            //the update/invalidate and sleep calls make the "flash" occur
            //adjusting the time the thread sleeps speeds up/slows down the "flash"
            gameArea.FillSpace( -1, SubUnit.SubUnitType.clearing, x, y );
            this.isDirty = true;
            srfGrid.Invalidate();
            srfGrid.Update();
            Thread.Sleep(25);

            //check and blow surrounding spaces
            if ((y!=0) && ((gameArea.GetSpace(x,y-1)==t) || (gameArea.GetSpace(x,y-1)==t+5)))
                this.Blow(x,y-1,t, ref blowcount, ref pts);
            if ((x!=0) && ((gameArea.GetSpace(x-1,y)==t) || (gameArea.GetSpace(x-1,y)==t+5)))
                this.Blow(x-1,y,t, ref blowcount, ref pts);
            if ((y!=gameArea.Size.Height-1) && ((gameArea.GetSpace(x,y+1)==t) || (gameArea.GetSpace(x,y+1)==t+5)))
                this.Blow(x,y+1,t, ref blowcount, ref pts);
            if ((x!=gameArea.Size.Width-1) && ((gameArea.GetSpace(x+1,y)==t) || (gameArea.GetSpace(x+1,y)==t+5)))
                this.Blow(x+1,y,t, ref blowcount, ref pts);
        }
Пример #7
0
 //sets the pointers in a to reference Subunit b, and then
 //changes b's location to reflect the change
 private void PlaceSubUnits( SubUnit a, SubUnit b, String s)
 {
     switch(s)
     {
         case "Top":
             a.Top = b;
             b.Location.X = a.Location.X;
             b.Location.Y = a.Location.Y - 1;
             break;
         case "Bottom":
             a.Bottom = b;
             b.Location.X = a.Location.X;
             b.Location.Y = a.Location.Y + 1;
             break;
         case "Left":
             a.Left = b;
             b.Location.X = a.Location.X - 1;
             b.Location.Y = a.Location.Y;
             break;
         case "Right":
             a.Right = b;
             b.Location.X = a.Location.X + 1;
             b.Location.Y = a.Location.Y;
             break;
     }//end switch
 }