示例#1
0
        public void BoardDataSwap(Gem dst)
        {
            lock(board.board) {
            Gem temp = this;
            //Swap the pointers' values, while maintaining their positions in the board
            board.board[this.index.X][this.index.Y] = board.board[dst.index.X][dst.index.Y];
            board.board[dst.index.X][dst.index.Y] = temp;

            temp = this.Clone();
            this.index = dst.index;
            dst.index = temp.index;
            }
        }
示例#2
0
 public void MouseClicked(MouseEventArgs e)
 {
     if (!IsAbleToClick)
     {
         return;
     }
     switch (e.Button)
     {
     case System.Windows.Forms.MouseButtons.Left:
         Gemstones.Board.Gem gem = gameBoard.GetCurrentGem();
         if (gem == null)
         {
             return;
         }
         //main.sm.PlaySound(SoundName.Click);
         if (!gem.isSelected)
         {
             if (gameBoard.currentlySelectedGem != null)
             {
                 if (SwitchGem(gem, gameBoard.currentlySelectedGem))
                 {
                     gameBoard.currentlySelectedGem.isSelected = false;
                     gameBoard.currentlySelectedGem            = null;
                     break;
                 }
                 gameBoard.currentlySelectedGem.isSelected = false;
             }
             gem.isSelected = true;
             gameBoard.currentlySelectedGem = gem;
         }
         else
         {
             gem.isSelected = false;
             gameBoard.currentlySelectedGem = null;
         }
         break;
     }
 }
示例#3
0
 public void SwitchWithAnimation(Gem dst)
 {
     Thread thread = new Thread(ThreadSwitchUpdate);
     thread.Name = "SwitchGem";
     thread.Start(dst);
 }
示例#4
0
        public void SwitchPlaceWith(Gem dst)
        {
            if (Thread.CurrentThread.Name != "SwitchGem" || dst == null)
                return;

            int skewX = this.bounds.X - ((Gem)dst).bounds.X;
            int PixelJump = skewX >= 0 ? 5 : -5;
            if (skewX != 0)
                for (int i = 0; i < Math.Abs(skewX); i += Math.Abs(PixelJump))
                {
                    this.bounds = new Rectangle(this.bounds.X - PixelJump, this.bounds.Y, size, size);
                    dst.bounds = new Rectangle(dst.bounds.X + PixelJump, dst.bounds.Y, size, size);
                    Thread.Sleep(GameMain.frameRate);
                }

            int skewY = this.bounds.Y - ((Gem)dst).bounds.Y;
            PixelJump = skewY >= 0 ? 5 : -5;
            if (skewY != 0)
                for (int i = 0; i < Math.Abs(skewY); i += Math.Abs(PixelJump))
                {
                    this.bounds = new Rectangle(this.bounds.X, this.bounds.Y - PixelJump, size, size);
                    dst.bounds = new Rectangle(dst.bounds.X, dst.bounds.Y + PixelJump, size, size);
                    Thread.Sleep(GameMain.frameRate);
                }
            BoardDataSwap((Gem)dst);
        }
示例#5
0
 private bool SwitchGem(Gem src, Gem dst)
 {
     if ((src.index.X == dst.index.X && (src.index.Y == dst.index.Y + 1 || src.index.Y == dst.index.Y - 1))
         || (src.index.Y == dst.index.Y && (src.index.X == dst.index.X + 1 || src.index.X == dst.index.X - 1)))
     {
         src.SwitchWithAnimation(dst);
         return true;
     }
     return false;
 }
示例#6
0
        public void InitializeBoard()
        {
            board = new List<List<Gem>>();

            for (int i = 0; i < size; i++)
            {
                List<Gem> rowList = new List<Gem>();
                for (int j = 0; j < size; j++)
                {
                    Rectangle bounds = new Rectangle(playField.X + Gem.size * j, playField.Y + Gem.size * i, Gem.size, Gem.size);
                    Point index = new Point(i, j);
                    GemName tempRand;
                    //Create a gem that does not create a triplet with adjacent gems
                    do
                    {
                        tempRand = (GemName)random.Next(6);
                        if (i < 2 && j < 2)
                            break;
                    } while ((j >= 2 && tempRand.Equals(rowList[j - 1].name) && tempRand.Equals(rowList[j - 2].name))
                         || (i >= 2 && tempRand.Equals(board[i - 1][j].name) && tempRand.Equals(board[i - 2][j].name)));
                    Gem gem = new Gem(this, tempRand, bounds, index);
                    rowList.Add(gem);
                }
                board.Add(rowList);
            }
        }