void createButton_Click(object sender, EventArgs e)
        {
            GameSettings settings = fieldSettings.CurrentSettings;
            settings.RoundsPerHalf = Int32.Parse(gameSettingsPanel.GameRoundsBox.Text);
            settings.SecondsPerRound = Int32.Parse(gameSettingsPanel.RoundSecondsBox.Text);
            settings.FirstTeamUsesKI = gameSettingsPanel.FirstKiBox.SelectedIndex == 1;
            settings.SecondTeamUsesKI = gameSettingsPanel.SecondKiBox.SelectedIndex == 1;

            FieldSettingsEventArgs args = new FieldSettingsEventArgs(settings);
            GameCreated(this, args);
            Close();
        }
Beispiel #2
0
        /// <summary>
        /// Raises the FieldSetingsChanged()-event with the current Settings saved in the FieldSettingsEventArgs
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FieldGrid_MouseUp(object sender, MouseEventArgs e)
        {
            if (settingsChanged && !IsBlocked)
            {
                if (FieldSettingsChanged != null)
                {
                    GameSettings settings = CurrentSettings;
                    FieldSettingsEventArgs args = new FieldSettingsEventArgs(settings);

                    if (FieldSettingsChanged != null)
                    {
                        FieldSettingsChanged(this, args);
                    }
                }
                settingsChanged = false;
            }

            if (!IsBlocked)
            {
                FieldGrid.Cursor = GetFittingCursor(currentFieldComponent);
            }
        }
        /// <summary>
        /// Creates the current game Settings and raises the RaiseSettingsEvent()-method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FieldSettingsChanged(object sender, FieldSettingsEventArgs e)
        {
            GameSettings settings = e.Settings;
            settings.RoundsPerHalf = Int32.Parse(gameSettingsPanel.GameRoundsBox.Text);
            settings.SecondsPerRound = Int32.Parse(gameSettingsPanel.RoundSecondsBox.Text);
            settings.FirstTeamUsesKI = gameSettingsPanel.FirstKiBox.SelectedIndex == 1;
            settings.SecondTeamUsesKI = gameSettingsPanel.SecondKiBox.SelectedIndex == 1;

            RaiseSettingsEvent(settings);
        }
 /// <summary>
 /// Raises the GameSettingsChanged()-event with the Settings in the parameter as the argument.
 /// </summary>
 /// <param name="Settings"></param>
 private void RaiseSettingsEvent(GameSettings settings)
 {
     FieldSettingsEventArgs args = new FieldSettingsEventArgs(settings);
     GameSettingsChanged(this, args);
 }
Beispiel #5
0
 /// <summary>
 /// Raises the CreateNewGame()-method
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void MultiplayerGameCreated(object sender, FieldSettingsEventArgs e)
 {
     CreateNewGame(e.Settings, true, null);
     CurrentMpHandler.MultiplayerGame = currentGame;
 }
Beispiel #6
0
 /// <summary>
 /// Raises the CreateNewGame()-method
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void SingleplayerGameCreated(object sender, FieldSettingsEventArgs e)
 {
     CreateNewGame(e.Settings, false, null);
 }
Beispiel #7
0
        /// <summary>
        /// Interprets the mesage and raises the suitable event.
        /// 
        /// Syntax:
        /// 
        /// chat<chatId>:Player1;Player2;Player3 --> Raises NewChatCreated()-event with the received users as the UserListEventArgs.
        /// That will create a new chatroom with these users.
        /// 
        /// userlist<chatId>:serialized List<User> --> The userlist of chatroom with this chat id.
        /// info<HH:mm:ss,Username,ServermessageType>: --> The information that someone has joined/left the server or changed the team.
        /// message<chatId,Username,HH:mm:ss>:message content --> A chat message from an user in a specific chatroom
        /// name<>:name --> Raises LoginNameAssigned()-event if the name equals the own name - raises UserNameChanged()-event if not.
        /// settings<>:serialized GameSettings--> Raises HandleReceivedSettings()-method with the serialized GameSetting as the parameter.
        /// start<>:serialized GameSettings  --> Raises the GameCreated()-event with the received settings.
        /// change<>:serialized ChangeOverImage --> Raises the ChangeoverReceived()-event.
        /// useSavegame<>:bool --> Raises UseSavegameChanged()-event with the received bool as the BoolEventArgs.
        /// end<>: --> Raises GameEnded()-event.
        /// action<>:serialized CachedRoundAction --> Raises ActionReceived()-event with the received CachedRoundAction as the ReceivedActionArgs.
        /// team<username, oldTeamId, newTeamId>: --> The information that someone switched the team. Raises HandleTeamEvent()-method.
        /// </summary>
        /// <param name="message">The message from the server</param>
        private void Interpret(string message)
        {
            int paramsStart = message.IndexOf('<');
            int paramsEnd = message.IndexOf('>');

            string paramsString = message.Substring(paramsStart + 1, paramsEnd - (paramsStart + 1));
            string[] parameters = paramsString.Split(',');
            message = message.Remove(paramsStart, paramsEnd - (paramsStart - 1)); //type:content

            string[] splitted = message.Split(':');

            string type = splitted[0];
            string content = message.Substring(message.IndexOf(':') + 1, (message.Length - (message.IndexOf(':') + 1)));

            switch (type)
            {
                case "chat":
                    string[] names = content.Split(';');
                    UserListEventArgs args = new UserListEventArgs(names, Convert.ToInt32(parameters[0]), ListType.ChatRoom);
                    NewChatCreated(this, args);
                    break;

                case "userlist":
                    if (Convert.ToInt32(parameters[0]) == 1)
                    {
                        List<User> users = serializer.Deserialize<List<User>>(content);
                        UserListEventArgs userListArgs = new UserListEventArgs(users, Convert.ToInt32(parameters[0]), ListType.ChatRoom);
                        CompleteUserListReceived(this, userListArgs);
                    }
                    else
                    {
                        string[] usernames = content.Split(';');
                        UserListEventArgs userListArgs = new UserListEventArgs(usernames, Convert.ToInt32(parameters[0]), ListType.ChatRoom);
                        ChatUserListReceived(this, userListArgs);
                    }
                    break;

                case "name":
                    UsernameChangeEventArgs changeArgs;
                    if (parameters[0] == "")
                    {
                        string oldName = ClientName;
                        ClientName = content;
                        changeArgs = new UsernameChangeEventArgs(oldName, content);
                        LoginNameAssigned(this, changeArgs);
                    }
                    else
                    {
                        changeArgs = new UsernameChangeEventArgs(parameters[0], content);
                        UserNameChanged(this, changeArgs);
                        if (parameters[0] == ClientName)
                        {
                            ClientName = content;
                        }
                    }
                    break;

                case "info":
                    HandleInfo(parameters, content);
                    break;

                case "message":
                    HandleNewMessage(parameters, content);
                    break;

                case "action":
                    CachedRoundAction cachedAction = serializer.Deserialize<CachedRoundAction>(content);
                    ReceivedActionArgs actionArgs = new ReceivedActionArgs(cachedAction);
                    ActionReceived(this, actionArgs);
                    break;

                case "team":
                    HandleTeamEvent(parameters, content);
                    break;

                case "settings":
                    HandleReceivedSettings(content);
                    break;

                case "start":
                    GameSettings createSettings = serializer.Deserialize<GameSettings>(content);
                    FieldSettingsEventArgs createSettingsArgs = new FieldSettingsEventArgs(createSettings);
                    GameCreated(this, createSettingsArgs);
                    break;

                case "ready":
                    UserListEventArgs readyArgs = new UserListEventArgs(new string[] { content }, 1, ListType.Team);
                    UserIsReady(this, readyArgs);
                    break;

                case "calculate":
                    List<string> listOfActions = serializer.Deserialize<List<string>>(content);
                    List<CachedRoundAction> actions = new List<CachedRoundAction>();
                    foreach (string serializedAction in listOfActions)
                    {
                        actions.Add(serializer.Deserialize<CachedRoundAction>(serializedAction));
                    }

                    ReceivedActionArgs roundActionsArgs = new ReceivedActionArgs(actions);
                    RoundActionsReceived(this, roundActionsArgs);
                    break;

                case "round":
                    RoundImage status = serializer.Deserialize<RoundImage>(content);
                    RoundImageEventArgs statusArgs = new RoundImageEventArgs(status);
                    RoundImageReceived(this, statusArgs);
                    break;

                case "game":
                    GameImage gameImage = serializer.Deserialize<GameImage>(content);
                    GameImageEventArgs gameArgs = new GameImageEventArgs(gameImage);
                    GameImageReceived(this, gameArgs);
                    break;

                case "goal":
                    BallEventImage image = serializer.Deserialize<BallEventImage>(content);
                    BallEventArgs goalArgs = new BallEventArgs(image);
                    GoalImageReceived(this, goalArgs);
                    break;

                case "status":
                    MultiplayerStatus mpGameStatus = (MultiplayerStatus)Enum.Parse(typeof(MultiplayerStatus), content);
                    GameStatusEventArgs mpStatusArgs = new GameStatusEventArgs(mpGameStatus);
                    MultiplayerStatusReceived(this, mpStatusArgs);
                    break;

                case "useSavegame":
                    BoolEventArgs boolArgs = new BoolEventArgs(Convert.ToBoolean(content));
                    UseSavegameChanged(this, boolArgs);
                    break;

                case "changeover":
                    ChangeoverImage changeImage = serializer.Deserialize<ChangeoverImage>(content);
                    ChangeoverEventArgs changeoverArgs = new ChangeoverEventArgs(changeImage);
                    ChangeoverReceived(this, changeoverArgs);
                    break;

                case "end":
                    GameEndReceived(this, EventArgs.Empty);
                    break;

                default:
                    Console.WriteLine("There is no function for the message: " + message);
                    break;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Deserializes the received GameSettings and raises the FieldSettingsReceived()-event with the settings as the argument.
 /// </summary>
 /// <param name="content"></param>
 private void HandleReceivedSettings(string content)
 {
     GameSettings settingsObject = serializer.Deserialize<GameSettings>(content);
     FieldSettingsEventArgs settingsArgs = new FieldSettingsEventArgs(settingsObject);
     FieldSettingsReceived(this, settingsArgs);
 }
Beispiel #9
0
 /// <summary>
 /// Sends the changed game Settings to the server
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Lobby_GameSettingsChanged(object sender, FieldSettingsEventArgs e)
 {
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     CurrentClient.Send("settings<>:" + serializer.Serialize(e.Settings));
 }
Beispiel #10
0
        /// <summary>
        /// Raises the GameCreated()-event.
        /// This will create a new game, which will be set as MultiplayerGame.
        /// Adds the game's events then.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CurrentClient_GameCreated(object sender, FieldSettingsEventArgs e)
        {
            if (teamChanger != null && teamChanger.IsHandleCreated)
            {
                teamChanger.Close();
            }

            if (CurrentLobby.UseSavefileBox.Checked)
            {
                CachedSavefile.Settings = e.Settings;
                GameImageEventArgs gameArgs = new GameImageEventArgs(CachedSavefile);
                GameContinued(this, gameArgs);
            }
            else
            {
                GameCreated(this, e);
            }
            MultiplayerGame.ActionChosen += MultiplayerGame_ActionChosen;
            MultiplayerGame.GameImageChanged += MultiplayerGame_RoundImageChanged;
            MultiplayerGame.GoalsChanged += MultiplayerGame_GoalsChanged;
            CurrentClient.Send("gameLoaded<>:");
        }
Beispiel #11
0
 /// <summary>
 /// Updates the FieldSettingsPanel of the lobby.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void CurrentClient_FieldSettingsReceived(object sender, FieldSettingsEventArgs e)
 {
     if (CurrentLobby != null && CurrentLobby.Visible)
     {
         CurrentLobby.CurrentFieldSettingsPanel.UpdateSettings(e.Settings);
         CurrentLobby.UpdateSettings(e.Settings);
     }
 }