コード例 #1
0
ファイル: GameEventHandler.cs プロジェクト: Jecral/Football
        private void HandleCornerOrGoalKick(Point ballLocation, Point exactBallLocation)
        {
            Team actionTeam = currentGame.FirstTeam;
            Status gameStatus;
            bool isCornerKick = false;
            Point actionPoint = ballLocation;

            Team leftTeam = (currentGame.FirstTeam.HasLeftSide) ? currentGame.FirstTeam : currentGame.SecondTeam;
            Team rightTeam = currentGame.GameAI.GetEnemyTeam(leftTeam);

            //check whether it is a corner kick or a goal kick
            if (ballLocation.X <= 0)
            {

                if (leftTeam.Players.Contains(currentGame.GameBall.LastPlayer))
                {
                    isCornerKick = true;
                    actionTeam = rightTeam;
                    actionPoint = (ballLocation.Y < leftTeam.TeamGoal.Location.Y) ? new Point(1, 1) : new Point(1, rows - 2);
                }
                else
                {
                    actionTeam = leftTeam;
                }
            }
            else if (ballLocation.X >= columns - 2)
            {
                if (rightTeam.Players.Contains(currentGame.GameBall.LastPlayer))
                {
                    isCornerKick = true;
                    actionTeam = leftTeam;
                    actionPoint = (ballLocation.Y < rightTeam.TeamGoal.Location.Y) ? new Point(columns - 2, 1) : new Point(columns - 2, rows - 2);
                }
                else
                {
                    actionTeam = rightTeam;
                }
            }

            TakeBallFromCurrentPlayer();

            //create and BallEventImage and informs the other users if this is a multiplayer game.
            BallEventImage image = new BallEventImage(currentGame.Round, actionTeam.TeamId, exactBallLocation);
            if (currentGame.IsHost && currentGame.IsMultiplayer)
            {
                currentGame.InformAboutGoal(image);
            }

            currentGame.RefreshField();
            MessageBoxIcon icon = MessageBoxIcon.Information;
            MessageBox.Show("Outside of the field!", "Information", MessageBoxButtons.OK, icon);

            if (isCornerKick)
            {
                gameStatus = Status.CornerKick;
                SetBallToPoint(actionPoint);
                BlockRoomAndTeam(actionPoint, actionTeam, gameStatus);
            }
            else
            {
                gameStatus = Status.GoalKick;
                GiveBallToPlayer(actionTeam.Goalkeeper);
            }

            currentGame.CurrentAction = new GameAction(gameStatus, actionTeam, ballLocation);
        }
コード例 #2
0
ファイル: GameEventHandler.cs プロジェクト: Jecral/Football
        /// <summary>
        /// Checks which team shot the goal, increases their goals count and changes the game status to KickOff.
        /// </summary>
        /// <param name="gridLocation"></param>
        /// <param name="exactLocation"></param>
        private void HandleGoal(Point gridLocation, Point exactLocation)
        {
            //Informs the last player that he does not control the ball anymore.
            //We have to do it now because otherwise the player would raise his LosesBall()-event,
            //which would set the Status to Normal.
            if (currentGame.GameBall.LastPlayer != null)
            {
                gameAI.AllPlayers.ToList().ForEach(x => x.HasBall = false);
            }

            currentGame.GameBall.TargetPoint = null;
            currentGame.GameBall.Speed = 0;
            currentGame.GameBall.HasPlayerContact = false;
            currentGame.GameBall.ExactLocation = exactLocation;
            currentGame.GameBall.Location = gridLocation;
            currentGame.GameBall.IsInShootState = false;
            Team goalTeam = (currentGame.SecondTeam.TeamGoal.Contains(gridLocation)) ? currentGame.FirstTeam : currentGame.SecondTeam;
            goalTeam.GoalsCount++;

            currentGame.CurrentAction = new GameAction(Status.KickOff, gameAI.GetEnemyTeam(goalTeam), gridLocation);
            currentGame.SetKickOff = true;

            BallEventImage image = new BallEventImage(currentGame.Round, goalTeam.TeamId, exactLocation);
            currentGame.CurrentReplayManager.Image.GoalImages.Add(image);
            if (currentGame.IsHost && currentGame.IsMultiplayer)
            {
                currentGame.InformAboutGoal(image);
            }

            currentGame.RefreshField();
            //GoalInformationBox.ShowBox();
            MessageBoxIcon icon = MessageBoxIcon.Information;
            MessageBox.Show("Goal!", "Information", MessageBoxButtons.OK, icon);
        }
コード例 #3
0
ファイル: GoalEventArgs.cs プロジェクト: Jecral/Football
 public BallEventArgs(BallEventImage image)
 {
     Image = image;
 }