示例#1
1
文件: Board.cs 项目: GodLesZ/svn-dump
		public Board(Game game, int posX = 224, int posY = 64, int width = 384, int height = 384)
			: base(game) {
			State = EBoardState.Initialize;
			Score = 0;

			Bounds = new Rectangle(posX, posY, width, height);
		}
示例#2
0
    public void RequestEndSwapMoveAnimationFromJewel(GameObject jewel, bool bReverse)
    {
        swapJewelCount--;
        swapJewelTempList.Add(jewel);

        if (swapJewelCount != 0)
        {
            return;
        }

        if (bReverse == true)
        {
            if (bGameOver == true)
            {
                boardState = EBoardState.gameOver;
                return;
            }

            boardState = EBoardState.canInput;
            return;
        }

        bool threeMatchMainJewel = CheckThreeMatchAfterSwap(swapJewelTempList[0]);
        bool threeMatchSubJewel  = CheckThreeMatchAfterSwap(swapJewelTempList[1]);

        if (threeMatchMainJewel || threeMatchSubJewel)
        {
            DestroyJewel();
        }
        else
        {
            ReverseSwapJewel(swapJewelTempList[0], swapJewelTempList[1], swapPrevDir);
        }
    }
示例#3
0
    public void RequestEndMoveAnimationFromJewel()
    {
        swapJewelCount--;

        if (swapJewelCount != 0)
        {
            return;
        }

        if (CheckThreeMatchAfterDestroyed() == false)
        {
            if (bGameOver == true)
            {
                boardState = EBoardState.gameOver;
                return;
            }

            curAddScore   = baseAddScore;
            curComboBonus = baseComboBonus;
            boardState    = EBoardState.canInput;
        }
        else
        {
            ChangeColorWillDestroyJewel();
            Invoke("DestroyJewel", destroyInvokeTime);
        }
    }
示例#4
0
        private void InitializeBoard()
        {
            Debug.WriteLine("[Board] Initialized");

            do
            {
                for (var col = 0; col < NumberOfColumns; col++)
                {
                    for (var row = 0; row < NumberOfRows; row++)
                    {
                        Table[col, row] = new Gem(Game, (EGemType)mRandom.Next(0, 7), new Vector2(Bounds.X + (col * 48), Bounds.Y + (row * 48)));
                    }
                }
            } while (CheckBoard().Count != 0 || CheckMovable() == false);

            for (var col = 0; col < NumberOfColumns; col++)
            {
                for (var row = 0; row < NumberOfRows; row++)
                {
                    Table[col, row].Scale  = 0f;
                    Table[col, row].ZoomIn = true;
                }
            }

            State = EBoardState.Input;
        }
示例#5
0
        protected void Input(Point point)
        {
            if (State != EBoardState.Input)
            {
                return;
            }

            if (Bounds.Contains(point) == false)
            {
                return;
            }

            var point2 = new Point((point.X - Bounds.X) / 48, (point.Y - Bounds.Y) / 48);

            if (Focus.X < 0 || Focus.Y < 0)
            {
                Focus = point2;
            }
            else if ((((Focus.X - point2.X) * (Focus.X - point2.X)) + ((Focus.Y - point2.Y) * (Focus.Y - point2.Y))) == 1)
            {
                mDesfocus = point2;
                State     = EBoardState.Swap;
            }
            else
            {
                Focus = new Point(-1, -1);
            }

            Debug.WriteLine("[Board] New focus: {0}", Focus);
        }
示例#6
0
 // Update is called once per frame
 void Update()
 {
     if (bGameOver && boardState != EBoardState.movingJewel && boardState != EBoardState.gameOvered)
     {
         boardState = EBoardState.gameOvered;
         Invoke("OnGameOverPopUp", 0.5f);
     }
 }
示例#7
0
        public Board(Game game, int posX = 224, int posY = 64, int width = 384, int height = 384)
            : base(game)
        {
            State = EBoardState.Initialize;
            Score = 0;

            Bounds = new Rectangle(posX, posY, width, height);
        }
示例#8
0
    // Start is called before the first frame update
    void Start()
    {
        bGameOver         = false;
        curAddScore       = baseAddScore;
        curComboBonus     = baseComboBonus;
        destroyInvokeTime = 0.3f;

        swapJewelTempList    = new List <GameObject>();
        willDestroyJewelList = new List <GameObject>();
        destroyedJewelQueue  = new Queue <GameObject>();
        jewelArray           = new GameObject[arraySize * (reservJewelSetCount + 1), arraySize];

        GameObject tempJewel;
        Jewel      tempJewelScript;

        jewelPivot.y = jewelPivot.y + (jewelPivot.y * 2 + padding) * reservJewelSetCount;

        swapJewelCount = 0;
        gameBoardMinX  = 0;
        gameBoardMaxX  = arraySize;
        gameBoardMinY  = arraySize * reservJewelSetCount;
        gameBoardMaxY  = arraySize * (reservJewelSetCount + 1);

        for (int x = 0; x < gameBoardMaxX; x++)
        {
            for (int y = 0; y < gameBoardMaxY; y++)
            {
                tempJewel       = Instantiate(jewelPrefab);
                tempJewelScript = tempJewel.GetComponent <Jewel>();
                tempJewelScript.SetJewel();
                tempJewelScript.SetIdxOnBoard(x, y);
                tempJewelScript.SetBoard(this);
                tempJewel.transform.parent        = panelTrans;
                tempJewel.transform.localScale    = Vector3.one;
                tempJewel.transform.localPosition = new Vector3(jewelPivot.x + padding * x, jewelPivot.y - padding * y, 0);
                jewelArray[y, x] = tempJewel;
            }
        }

        CheckBoardAfterFirstCreate();
        boardState = EBoardState.ready;
    }
示例#9
0
文件: Board.cs 项目: GodLesZ/svn-dump
		private void InitializeBoard() {
			Debug.WriteLine("[Board] Initialized");

			do {
				for (var col = 0; col < NumberOfColumns; col++) {
					for (var row = 0; row < NumberOfRows; row++) {
						Table[col, row] = new Gem(Game, (EGemType)mRandom.Next(0, 7), new Vector2(Bounds.X + (col * 48), Bounds.Y + (row * 48)));
					}
				}
			} while (CheckBoard().Count != 0 || CheckMovable() == false);

			for (var col = 0; col < NumberOfColumns; col++) {
				for (var row = 0; row < NumberOfRows; row++) {
					Table[col, row].Scale = 0f;
					Table[col, row].ZoomIn = true;
				}
			}

			State = EBoardState.Input;
		}
示例#10
0
文件: Board.cs 项目: GodLesZ/svn-dump
		public override void Update(GameTime gameTime) {
			base.Update(gameTime);

			if (mInputState.IsNewLeftPressed()) {
				Input(new Point(Mouse.GetState().X, Mouse.GetState().Y));
			}

			bool bCountScore;
			switch (State) {
				case EBoardState.Initialize:
					InitializeBoard();
					break;

				case EBoardState.Process:
					State = CheckBoard().Count >= 1 ? EBoardState.Destroy : EBoardState.Revert;
					break;

				case EBoardState.Swap:
					Swap();
					State = EBoardState.Process;
					break;

				case EBoardState.Revert:
					if (!Table[Focus.X, Focus.Y].IsMoving() && !Table[mDesfocus.X, mDesfocus.Y].IsMoving()) {
						Swap();
						State = EBoardState.Input;
						Focus = new Point(-1, -1);
						MissSound.Play();
					}

					break;

				case EBoardState.Destroy:
					bCountScore = true;
					for (var col = 0; col < NumberOfColumns && bCountScore; col++) {
						for (var row = 0; row < NumberOfRows; row++) {
							if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut) {
								continue;
							}

							bCountScore = false;
							break;
						}
					}

					if (bCountScore) {
						var list = CheckBoard();
						foreach (var g in list) {
							g.ZoomOut = true;
						}

						State = EBoardState.Refresh;
						Score += list.Count * list.Count;
						WinSound.Play();
					}

					break;

				case EBoardState.Refresh:
					bCountScore = true;
					for (var col = 0; col < NumberOfColumns && bCountScore; col++) {
						for (var row = 0; row < NumberOfRows; row++) {
							if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut) {
								continue;
							}

							bCountScore = false;
							break;
						}

					}

					if (bCountScore) {
						Focus = new Point(-1, -1);

						for (var col = 0; col < NumberOfColumns; col++) {
							for (var row = 0; row < NumberOfRows; row++) {
								if (Table[col, row].Scale <= 0f) {
									Table[col, row] = null;
								}
							}
						}

						for (var row = NumberOfRows - 1; row >= 0; row--) {
							for (var col = 0; col < NumberOfColumns; col++) {
								if (Table[col, row] != null) {
									continue;
								}

								for (var i = row - 1; i >= -1; i--) {
									if (i == -1) {
										Table[col, row] = new Gem(Game, (EGemType)mRandom.Next(0, 7), Mapping(new Point(col, -1)));
										Table[col, row].SetMove(Mapping(new Point(col, row)));
									} else if (Table[col, i] != null) {
										Table[col, row] = Table[col, i];
										Table[col, i] = null;
										Table[col, row].SetMove(Mapping(new Point(col, row)));
										break;
									}
								}
							}
						}

						if (CheckBoard().Count == 0) {
							State = CheckMovable() ? EBoardState.Input : EBoardState.Initialize;
						} else {
							State = EBoardState.Destroy;
						}
					}

					break;
			}

			UpdateTable(gameTime);
		}
示例#11
0
文件: Board.cs 项目: GodLesZ/svn-dump
		protected void Input(Point point) {
			if (State != EBoardState.Input) {
				return;
			}

			if (Bounds.Contains(point) == false) {
				return;
			}

			var point2 = new Point((point.X - Bounds.X) / 48, (point.Y - Bounds.Y) / 48);
			if (Focus.X < 0 || Focus.Y < 0) {
				Focus = point2;
			} else if ((((Focus.X - point2.X) * (Focus.X - point2.X)) + ((Focus.Y - point2.Y) * (Focus.Y - point2.Y))) == 1) {
				mDesfocus = point2;
				State = EBoardState.Swap;
			} else {
				Focus = new Point(-1, -1);
			}

			Debug.WriteLine("[Board] New focus: {0}", Focus);
		}
示例#12
0
 public void SetGameStart()
 {
     boardState = EBoardState.canInput;
     Timer.GetInstance().StartTimer();
 }
示例#13
0
    public void RequestSwapWithAnotherJewelFromJewel(GameObject jewel, EDir dir)
    {
        if (boardState != EBoardState.canInput)
        {
            return;
        }

        Vector2 idxOnBoardJewel = jewel.GetComponent <Jewel>().GetIdxOnBoard();
        bool    bCanSwap        = false;

        switch (dir)
        {
        case EDir.left:
            if (idxOnBoardJewel.x - 1 < gameBoardMinX)
            {
                return;
            }

            bCanSwap          = true;
            idxOnBoardJewel.x = idxOnBoardJewel.x - 1;
            break;

        case EDir.right:
            if (idxOnBoardJewel.x + 1 >= gameBoardMaxX)
            {
                return;
            }

            bCanSwap          = true;
            idxOnBoardJewel.x = idxOnBoardJewel.x + 1;
            break;

        case EDir.up:
            if (idxOnBoardJewel.y - 1 < gameBoardMinY)
            {
                return;
            }

            bCanSwap          = true;
            idxOnBoardJewel.y = idxOnBoardJewel.y - 1;
            break;

        case EDir.down:
            if (idxOnBoardJewel.y + 1 >= gameBoardMaxY)
            {
                return;
            }

            bCanSwap          = true;
            idxOnBoardJewel.y = idxOnBoardJewel.y + 1;
            break;

        default:
            break;
        }

        if (bCanSwap)
        {
            boardState = EBoardState.movingJewel;
            SwapJewel(jewel, jewelArray[(int)idxOnBoardJewel.y, (int)idxOnBoardJewel.x], dir);
        }
    }
示例#14
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (mInputState.IsNewLeftPressed())
            {
                Input(new Point(Mouse.GetState().X, Mouse.GetState().Y));
            }

            bool bCountScore;

            switch (State)
            {
            case EBoardState.Initialize:
                InitializeBoard();
                break;

            case EBoardState.Process:
                State = CheckBoard().Count >= 1 ? EBoardState.Destroy : EBoardState.Revert;
                break;

            case EBoardState.Swap:
                Swap();
                State = EBoardState.Process;
                break;

            case EBoardState.Revert:
                if (!Table[Focus.X, Focus.Y].IsMoving() && !Table[mDesfocus.X, mDesfocus.Y].IsMoving())
                {
                    Swap();
                    State = EBoardState.Input;
                    Focus = new Point(-1, -1);
                    MissSound.Play();
                }

                break;

            case EBoardState.Destroy:
                bCountScore = true;
                for (var col = 0; col < NumberOfColumns && bCountScore; col++)
                {
                    for (var row = 0; row < NumberOfRows; row++)
                    {
                        if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut)
                        {
                            continue;
                        }

                        bCountScore = false;
                        break;
                    }
                }

                if (bCountScore)
                {
                    var list = CheckBoard();
                    foreach (var g in list)
                    {
                        g.ZoomOut = true;
                    }

                    State  = EBoardState.Refresh;
                    Score += list.Count * list.Count;
                    WinSound.Play();
                }

                break;

            case EBoardState.Refresh:
                bCountScore = true;
                for (var col = 0; col < NumberOfColumns && bCountScore; col++)
                {
                    for (var row = 0; row < NumberOfRows; row++)
                    {
                        if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut)
                        {
                            continue;
                        }

                        bCountScore = false;
                        break;
                    }
                }

                if (bCountScore)
                {
                    Focus = new Point(-1, -1);

                    for (var col = 0; col < NumberOfColumns; col++)
                    {
                        for (var row = 0; row < NumberOfRows; row++)
                        {
                            if (Table[col, row].Scale <= 0f)
                            {
                                Table[col, row] = null;
                            }
                        }
                    }

                    for (var row = NumberOfRows - 1; row >= 0; row--)
                    {
                        for (var col = 0; col < NumberOfColumns; col++)
                        {
                            if (Table[col, row] != null)
                            {
                                continue;
                            }

                            for (var i = row - 1; i >= -1; i--)
                            {
                                if (i == -1)
                                {
                                    Table[col, row] = new Gem(Game, (EGemType)mRandom.Next(0, 7), Mapping(new Point(col, -1)));
                                    Table[col, row].SetMove(Mapping(new Point(col, row)));
                                }
                                else if (Table[col, i] != null)
                                {
                                    Table[col, row] = Table[col, i];
                                    Table[col, i]   = null;
                                    Table[col, row].SetMove(Mapping(new Point(col, row)));
                                    break;
                                }
                            }
                        }
                    }

                    if (CheckBoard().Count == 0)
                    {
                        State = CheckMovable() ? EBoardState.Input : EBoardState.Initialize;
                    }
                    else
                    {
                        State = EBoardState.Destroy;
                    }
                }

                break;
            }

            UpdateTable(gameTime);
        }