コード例 #1
0
ファイル: VolcanoGame.cs プロジェクト: skotz/volcanoes
        private void BackgroundWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!e.Cancelled)
            {
                _lastSearch = (SearchResult)e.Result;

                if (_lastSearch.BestMove >= 0 && CurrentState.IsValidMove(_lastSearch.BestMove))
                {
                    bool growthHappened = CurrentState.MakeMove(_lastSearch.BestMove);

                    MoveHistory.Add(_lastSearch.BestMove);
                    if (growthHappened)
                    {
                        MoveHistory.Add(Constants.AllGrowMove);
                    }
                    OnMoveMade?.Invoke(growthHappened);

                    if (CurrentState.State == GameState.GameOver)
                    {
                        OnGameOver?.Invoke(CurrentState.Winner, CurrentState.Winner == Player.Draw ? VictoryType.InfiniteEruption : VictoryType.AntipodePathCreation);
                    }
                    else
                    {
                        ComputerPlay();
                    }
                }
                else
                {
                    // If an engine doesn't find a move, then he adjourns the game
                    CurrentState.Winner = CurrentState.Player == Player.One ? Player.Two : Player.One;
                    OnGameOver?.Invoke(CurrentState.Winner, _lastSearch.Timeout ? VictoryType.OpponentTimeout : VictoryType.ArenaAdjudication);
                }
            }
        }
コード例 #2
0
    /// <summary>
    /// Updates the hexagons.
    /// </summary>
    public IEnumerator UpdateHexagons()
    {
        // Disable the player input while updating.
        InputManager.Instance.DisableInput();

        var hexagonsToFallDown = HexagonControllers.Where(controller =>
                                                          !controller.DoesHaveHexagonBelow()).ToList();

        while (hexagonsToFallDown.Count > 0)
        {
            hexagonsToFallDown.ForEach(hexagon =>
            {
                if (hexagon)
                {
                    hexagon.MoveHexagonDown();
                }
            });

            hexagonsToFallDown = HexagonControllers.Where(controller =>
                                                          !controller.DoesHaveHexagonBelow()).ToList();

            yield return(null);
        }

        yield return(new WaitForSeconds(0.25f));

        var hexagonsToDestroy = GetHexagonsToDestroy(HexagonControllers);

        if (hexagonsToDestroy.Count > 0)
        {
            DestroyHexagons(hexagonsToDestroy);
            StartCoroutine(UpdateHexagons());
        }
        else
        {
            OnMoveMade?.Invoke();

            var emptyIdentifiers = FindEmptyIdentifiers();
            //ScoreManager.Instance.AddScore(emptyIdentifiers.Count);
            foreach (var emptyIdentifier in emptyIdentifiers)
            {
                if (ScoreManager.Instance.ShouldSpawnBomb)
                {
                    SpawnPrefab(emptyIdentifier, bombPrefab);
                    ScoreManager.Instance.DisableBombSpawn();
                }
                else
                {
                    SpawnPrefab(emptyIdentifier, hexagonPrefab);
                }
                yield return(new WaitForSeconds(0.10f));
            }

            // Enable player input after update.
            InputManager.Instance.EnableInput();
        }
    }
コード例 #3
0
        /// <summary>
        /// Lets the board know that this player has made a move.
        /// </summary>
        /// <param name="boardPieceMove"></param>
        /// <returns></returns>
        protected bool MovePiece(BoardPieceMove boardPieceMove)
        {
            // Make sure it is our turn
            if (Board.PlayerTurn != Player)
            {
                return(false);
            }

            // Apply move to the core data structure
            return(OnMoveMade != null && OnMoveMade.Invoke(boardPieceMove));
        }
コード例 #4
0
        public void Move(object sender, MoveArgs e)
        {
            if (e.playerId != Turn)
            {
                return;                         // not players turn Return
            }
            int col      = e.col;
            int playerId = e.playerId;
            int row;

            //check a place is available in Coloum
            if (!Move_Available(col))
            {
                return;                       // Move Not Avaliable Return
            }
            //annoyouns Move to network if it was made by local player
            if (e.playerId == Properties.Settings.Default.userId)
            {
                OnMoveMade?.Invoke(this, new MoveArgs(col, Properties.Settings.Default.userId));
            }
            row = GetRow(col, playerId);
            lock (board)                                 // Lock Board while in use
            {
                board.boardState[col, row] = e.playerId; //update Boardstate With move
                OnUpdate(this, board);
            }
            Turn *= -1;   // use
                          // use  reference types that point to player / players peices ------------------------------------------------------
                          // dont repeat your selfs

            // Ai Takes over moves

            if (win(e.playerId, col, row))
            {
                gameActive = false;
                OnWin?.Invoke(this, e.playerId.ToString()); // Publish Win Event
            }
            if (Ai && gameActive && Turn == Properties.Settings.Default.userId)
            {
                AiPlayer();
            }
        }
コード例 #5
0
        public void MakeMove(ActionOption actionOption)
        {
            MoveState = MoveState.MakingMove;
            OnMoveMade?.Invoke(this, actionOption);

            if (actionOption == null)
            {
                FinishMove(null);
                return;
            }

            Direction direction = Direction.GetDirection(CellEntity.Cell.StagePosition, actionOption.Target.StagePosition);

            if (direction != null && CellEntity.Cell.BorderEntities[direction])
            {
                CellEntity.Cell.BorderEntities[direction].GetComponent <IInteractableThrough>()?.Interact(CellEntity, direction);
            }

            actionOption.EntityAction.OnMoveFinish += FinishMove;
            actionOption.EntityAction.Interact(actionOption.Target);

            DeselectAction();
        }
コード例 #6
0
ファイル: VolcanoGame.cs プロジェクト: skotz/volcanoes
        public void MakeMove(int move)
        {
            if (CurrentState.IsValidMove(move))
            {
                bool growthHappened = CurrentState.MakeMove(move);

                MoveHistory.Add(move);
                if (growthHappened)
                {
                    MoveHistory.Add(Constants.AllGrowMove);
                }
                OnMoveMade?.Invoke(growthHappened);

                if (CurrentState.State == GameState.GameOver)
                {
                    OnGameOver?.Invoke(CurrentState.Winner, CurrentState.Winner == Player.Draw ? VictoryType.InfiniteEruption : VictoryType.AntipodePathCreation);
                }
                else
                {
                    ComputerPlay();
                }
            }
        }
コード例 #7
0
 private void canvas_Click(object sender, EventArgs e)
 {
     OnMoveMade?.Invoke(this, new CanvasClickedArgs(x, y, Properties.Settings.Default.userId));
     //Properties.Settings.Default.userId *= -1;
 }