Beispiel #1
0
 private bool IsSameStone(ElementClass El1, ElementClass El2)
 {
     if ((El1 != null) && (El1.elType == El2.elType))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
        //check one element and find same elements around
        //finds the direction to move in
        private bool ElementCheck(ElementClass El)
        {
            bool theReturnState = false;
            int  Xind           = 0;
            int  Yind           = 0;

            for (int i = 0; i < 3; ++i)
            {
                if ((El.Loc.X != row - 1) && ((El.Loc.Y - 1 + i) < column) && ((El.Loc.Y - 1 + i) >= 0))
                {
                    //not the bottom
                    if (IsSameStone(Board[El.Loc.X + 1, El.Loc.Y - 1 + i], El))
                    {
                        Xind            = 1;
                        Yind            = i - 1;
                        theReturnState |= CheckHelperMethod(Board[El.Loc.X, El.Loc.Y], Xind, Yind);
                    }
                }

                if ((El.Loc.X != 0) && ((El.Loc.Y - 1 + i) < column) && ((El.Loc.Y - 1 + i) >= 0))
                {
                    //not the top
                    if (IsSameStone(Board[El.Loc.X - 1, El.Loc.Y - 1 + i], El))
                    {
                        Xind            = -1;
                        Yind            = i - 1;
                        theReturnState |= CheckHelperMethod(Board[El.Loc.X, El.Loc.Y], Xind, Yind);
                    }
                }
            }
            // not to the left
            if ((El.Loc.Y != 0) && (El.Loc.Y - 1 >= 0))
            {
                if (IsSameStone(Board[El.Loc.X, El.Loc.Y - 1], El))
                {
                    Xind            = 0;
                    Yind            = -1;
                    theReturnState |= CheckHelperMethod(Board[El.Loc.X, El.Loc.Y], Xind, Yind);
                }
            }
            //not to the right
            if ((El.Loc.Y != column - 1) && (El.Loc.Y + 1 >= 0))
            {
                if (IsSameStone(Board[El.Loc.X, El.Loc.Y + 1], El))
                {
                    Xind            = 0;
                    Yind            = 1;
                    theReturnState |= CheckHelperMethod(Board[El.Loc.X, El.Loc.Y], Xind, Yind);
                }
            }

            return(theReturnState);
        }
Beispiel #3
0
        private void GenerateStack()
        {
            El = new ElementClass[3];
            Random R = new Random();
            Stone  St;

            for (int i = 0; i < 3; ++i)
            {
                int r = R.Next(0, 6);
                St    = (Stone)r;
                El[i] = new ElementClass(St, new Point(i, 3));
                ImageBoard[El[i].Loc].Source = ChosePicture(El[i].elType);
            }
        }
Beispiel #4
0
 //checks all the elements in one direction
 //i,j parameters set the direction
 private bool CheckStraight(ElementClass El, int i, int j)
 {
     if (((El.Loc.X + i) >= row) || ((El.Loc.Y + j) >= column) ||
         ((El.Loc.X + i) < 0) || ((El.Loc.Y + j) < 0))
     {
         return(false);
     }
     if ((Board[El.Loc.X + i, El.Loc.Y + j] != null) && (IsSameStone(El, Board[El.Loc.X + i, El.Loc.Y + j])))
     {
         El.toBeDeleted = true;
         Board[El.Loc.X + i, El.Loc.Y + j].toBeDeleted = true;
         return(true);
     }
     return(false);
 }
Beispiel #5
0
        //helper
        private void Swap(ref ElementClass El1, ref ElementClass El2)
        {
            ImageSource I;

            I = ImageBoard[El1.Loc].Source;
            ImageBoard[El1.Loc].Source = ImageBoard[El2.Loc].Source;
            ImageBoard[El2.Loc].Source = I;

            Point temp = El1.Loc;

            El1.Loc = El2.Loc;
            El2.Loc = temp;
            ElementClass El = El1;

            El1 = El2;
            El2 = El;
        }
Beispiel #6
0
        private bool CheckHelperMethod(ElementClass El, int Xind, int Yind)
        {
            bool theReturnState = false;
            int  Xplus          = Xind;
            int  Yplus          = Yind;

            if ((Xind != 0) || (Yind != 0))
            {
                while ((CheckStraight(Board[El.Loc.X + Xplus, El.Loc.Y + Yplus], Xind, Yind)) && (El != null))
                {
                    El.toBeDeleted = true;
                    Xplus         += Xind;
                    Yplus         += Yind;
                    theReturnState = true;
                }
            }
            //if (theReturnState) score+=1;
            return(theReturnState);
        }