예제 #1
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;
		}
예제 #2
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);
		}
예제 #3
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);
        }