Ejemplo n.º 1
0
 /// <summary>
 /// Raises the CreateNewGame()-method with the game image in a new replay manager.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void GameContinued(object sender, GameImageEventArgs e)
 {
     ReplayManager manager = new ReplayManager();
     manager.Image = e.Image;
     CreateNewGame(e.Image.Settings, true, manager);
     currentGame.SetRoundImage(manager.SearchImageAtRound(manager.SearchLastRoundNumber()), false);
     currentGame.SetCorrectGoals(currentGame.Round);
     currentGame.SetCorrectGoalsCount(currentGame.Round);
     CurrentMpHandler.MultiplayerGame = currentGame;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the received game image.
        /// It's last roundimage will be used if the "Use"-checkbox in the multiplayer lobby is selected.
        /// That will continue the saved multiplayer game.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CurrentClient_GameImageReceived(object sender, GameImageEventArgs e)
        {
            CachedSavefile = e.Image;
            CurrentLobby.CurrentFieldSettingsPanel.IsBlocked = true;

            CurrentLobby.BeginInvoke((MethodInvoker)(() =>
            {
                CurrentLobby.UseSavefileBox.CheckedChanged -= UseSavefileBox_CheckedChanged;
                CurrentLobby.UseSavefileBox.Checked = true;
                CurrentLobby.UseSavefileBox.CheckedChanged += UseSavefileBox_CheckedChanged;
            }));
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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<>:");
        }