예제 #1
0
        private void ProcessState()
        {
            switch (currentState)
            {
            case GameRoundState.STARTING:
                timeRemaining = waitTime;
                currentState  = GameRoundState.WAITING;
                break;

            case GameRoundState.WAITING:
                timeRemaining = roundLength;

                currentRound++;
                OnRoundChange?.Invoke(currentRound);

                currentState = GameRoundState.RUNNING;
                OnRoundStart?.Invoke(currentRound);
                break;

            case GameRoundState.RUNNING:
                timeRemaining = waitTime;

                currentState = GameRoundState.WAITING;
                OnRoundFinished?.Invoke(currentRound);
                break;
            }
        }
예제 #2
0
    private void OnRoundEnd()
    {
        if (_redTeamCurrentRoundPoints > _blueTeamCurrentRoundPoints)
        {
            _redTeamWonRounds += 1;
        }
        if (_blueTeamCurrentRoundPoints > _redTeamCurrentRoundPoints)
        {
            _blueTeamWonRounds += 1;
        }
        if (_blueTeamCurrentRoundPoints == _redTeamCurrentRoundPoints)
        {
            _blueTeamWonRounds++; _redTeamWonRounds++;
        }

        _redTeamAllPoints  += _redTeamCurrentRoundPoints;
        _blueTeamAllPoints += _blueTeamCurrentRoundPoints;

        _redTeamCurrentRoundPoints  = 0;
        _blueTeamCurrentRoundPoints = 0;

        _uIManager.SetWonRoundText(_redTeamWonRounds, _blueTeamWonRounds);

        OnRoundFinished?.Invoke();
        _animationController.OpenChooseMenu();
        _round++;
        if (_round > 3)
        {
            _round = 3;
            _uIManager.OnAllRoundsEnd(_redTeamAllPoints, _blueTeamAllPoints, _redTeamWonRounds, _blueTeamWonRounds);
            _animationController.OpenFinallPanel();
        }

        _animationController.CloseGameMenu();
        _uIManager.OpenRounds(_round);
    }
예제 #3
0
        public void StartNextRound(bool piManual, bool sendRoundFinished = true)
        {
            if (ivRounds.Any())
            {
                ivAllMatches.AddRange(ivRounds.Last().Matches);

                if (ivRounds.Last().IsEmpty())
                {
                    ivRounds.RemoveAt(ivRounds.Count - 1);
                }
            }

            if (sendRoundFinished)
            {
                OnRoundFinished?.Invoke(this, new EventArgs());
            }

            ivRounds.Add(new Round(ivAllMatches, ivPlayers.ToList(), ivRounds.Count + 1, !piManual));

            if (!piManual)
            {
                OnNewRoundStart?.Invoke(this, new EventArgs());
            }
        }
예제 #4
0
 public void FinishDraft()
 {
     Done = true;
     ivAllMatches.AddRange(ivRounds.Last().Matches);
     OnRoundFinished?.Invoke(this, new EventArgs());
 }
예제 #5
0
        /// <summary>
        /// Try to move the currently selected piece to the given board tile.
        /// </summary>
        /// <param name="tile"></param>
        /// <returns>Returns true if movement was successfull.</returns>
        private bool MoveSelectedPieceTo(BoardTile tile, Player player)
        {
            if (SelectedTile.CanMoveTo(this, tile))
            {
                // Check if current move is a castling move
                if (SelectedTile.OccupyingPiece != null && SelectedTile.OccupyingPiece.GetType() == typeof(King) &&
                    tile.OccupyingPiece != null && tile.OccupyingPiece.GetType() == typeof(Rook) &&
                    tile.OccupyingPiece.IsWhite == SelectedTile.OccupyingPiece.IsWhite)
                {
                    var rookDestination = ((Rook)tile.OccupyingPiece).GetCastleLocation(this, tile);
                    rookDestination.OccupyingPiece = tile.OccupyingPiece;
                    tile.OccupyingPiece            = null;

                    tile = ((King)SelectedTile.OccupyingPiece).GetCastleLocation(this, SelectedTile, tile);
                }

                currentRountData.AddMove(new PlayerMove(player, SelectedTile, tile));

                latestTiles.Clear();
                latestTiles.Add(tile);
                latestTiles.Add(SelectedTile);

                if (tile.OccupyingPiece == null && SelectedTile.OccupyingPiece.GetType() != typeof(Pawn))
                {
                    movesMadeWithoutProgress++;
                }
                else
                {
                    movesMadeWithoutProgress = 0;
                }

                tile.OccupyingPiece = SelectedTile.OccupyingPiece;
                SelectedTile.OccupyingPiece.PostMovementEvent(tile);
                SelectedTile.OccupyingPiece = null;

                if (IsCheckmate(player))
                {
                    OnGameFinished?.Invoke(this, new GameFinishedEvent(player, GameFinishedReason.CheckMate));
                }
                else if (!EnoughMaterialOnBoard())
                {
                    OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.InsufficientMaterial));
                }
                else if (IsStalemate(player.IsWhite))
                {
                    OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Stalemate));
                }
                else if (movesMadeWithoutProgress >= 75)
                {
                    OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Move75));
                }

                if (currentRountData.IsDone)
                {
                    OnRoundFinished?.Invoke(this, currentRountData);
                    currentRountData = new RoundFinishedEvent(currentRountData.Round + 1);
                }

                return(true);
            }

            return(false);
        }