示例#1
0
        /// <summary>
        /// Removes the current Player from its Team
        /// </summary>
        /// <param name="player">Player to remove</param>
        private void RemovePlayer(Player player)
        {
            // Little verification : we ask the user to validate his action
            if (Choice_Prefabs.CHOICE_REMOVEPLAYER.GetChoice() == 0)
            {
                // Asking to remove the Player
                Instructions instruction = Instructions.Team_RemovePlayer;
                Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, player));

                // We receive whether it work or not
                if (Net.BOOL.Receive(comm.GetStream()))
                {
                    // We remove the Player from its Team
                    player.team.players.Remove(player);

                    // We display a message accordingly
                    CONSOLE.WriteLine(ConsoleColor.Green, "Player " + player.name + " removed !");
                }
                else
                {
                    // We display a message accordingly
                    CONSOLE.WriteLine(ConsoleColor.Red, "Player " + player.name + "was not removed...");
                }
                CONSOLE.WaitForInput();
            }
        }
示例#2
0
        /// <summary>
        /// Manage a given Player
        /// </summary>
        /// <param name="player">Player we are managing</param>
        private void ManagePlayer(Player player)
        {
            bool continuingPlayer = true;

            while (continuingPlayer)
            {
                // CHOICE
                // We dynamically create a List containing all the players names
                List <string> choiceString = new List <string>();
                choiceString.Add("See Data");

                if (player.hasNewLevel)
                {
                    choiceString.Add("New Level !");
                }

                // We add another choice : "Remove Player"
                choiceString.Add("Remove Player");

                // We add a last choice: "Go Back"
                choiceString.Add("Go Back");

                // We create the Choice
                Choice c     = new Choice("please Select an action for " + player.name + " (last one = leave) : ", choiceString);
                int    index = c.GetChoice();


                // Since we have a dynamic attribution of choices, the on-going program is quite... messy

                // If it is the first choice : SEE DATA
                if (index == 0)
                {
                    Console.WriteLine(player);
                    CONSOLE.WaitForInput();
                }
                // If it is the second choice AND the player has a new level : NEW LEVEL
                else if (index == 1 && player.hasNewLevel)
                {
                    PlayerLevelsUp(player);
                }
                // If it is the last choice : GO BACK
                else if (index == choiceString.Count - 1)
                {
                    continuingPlayer = false;
                }
                // Otherwise : REMOVE PLAYER
                else
                {
                    RemovePlayer(player);
                }
            }
        }
示例#3
0
        /// <summary>
        /// A panel displaying all options a user can perform while logged to the program (Topic / Chat)
        /// </summary>
        private void PanelConnected()
        {
            bool continuingConnection = true;

            while (continuingConnection)
            {
                int choice = Choice_Prefabs.CHOICE_CONNECTED.GetChoice();
                switch (choice)
                {
                // COACH
                case 0:
                    DisplayCoach(userData);
                    break;

                // LEAGUE
                case 1:
                    CONSOLE.WriteLine(ConsoleColor.Magenta, "Not yet implemented !");
                    break;

                case 2:
                    CONSOLE.WriteLine(ConsoleColor.Magenta, "Not yet implemented !");
                    break;

                // TEAM
                case 3:
                    PanelTeams();
                    break;

                case 4:
                    NewTeam();
                    break;

                // LOG OUT
                case 5:
                    LogOut();
                    continuingConnection = false;
                    break;

                default:
                    Console.WriteLine("Error at the Main menu");
                    break;
                }

                CONSOLE.WaitForInput();
            }
        }
示例#4
0
        /// <summary>
        /// A panel displaying all options a user can perform while logged to the program (Topic / Chat)
        /// </summary>
        private void PanelTeam(Team team)
        {
            bool continuingTeam = true;

            while (continuingTeam)
            {
                int choice = Choice_Prefabs.CHOICE_TEAM.GetChoice();
                switch (choice)
                {
                // display data
                case 0:
                    DisplayTeam(team);
                    break;

                // manage Players
                case 1:
                    ManagePlayers(team);
                    break;

                // buy Players
                case 2:
                    NewPlayer(team);
                    break;

                // Go Back
                case 3:
                    continuingTeam = false;
                    break;

                default:
                    Console.WriteLine("Error at the detailled Team menu");
                    break;
                }

                CONSOLE.WaitForInput();
            }
        }
示例#5
0
        /// <summary>
        /// When a Player levels up
        /// </summary>
        /// <param name="player"></param>
        private void PlayerLevelsUp(Player player)
        {
            // Asking to level up a Player
            Instructions instruction = Instructions.Player_LevelUp;

            Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, player));


            // We receive / define some variables
            int dice1 = Net.INT.Receive(comm.GetStream());
            int dice2 = Net.INT.Receive(comm.GetStream());

            dice1 = 5;
            dice2 = 6;
            List <EffectType> types = EffectStuff.GetEffectTypesForLevelUp(player.role, dice1, dice2);


            // There are 2 steps :
            // PART 1 - display some useful info to the user
            // PART 2 - Wait for the user to choose a new Effect for his Player

            // PART 1 - display some useful info to the user
            Console.Clear();
            Console.WriteLine("New level !\n\n\n\nyou rolled {0} - {1} !", dice1, dice2);

            Console.WriteLine("You can level up in any category :");
            types.ForEach(type => Console.WriteLine(" - " + type));
            CONSOLE.WaitForInput();


            // PART 2 - Wait for the user to choose a new Effect for his Player
            // We initialize our variables
            List <List <Effect> > effects = EffectStuff.GetEffectsForLevelUp(types);
            bool   continuing             = true;
            Effect chosenEffect           = effects[0][0];
            int    currentType            = 0;
            int    currentEffect          = 0;



            // While the user doesn't press Enter, the loop continues
            do
            {
                // We clear the console, and display a given message
                Console.Clear();

                // We display all our Types
                for (int t = 0; t < types.Count; t++)
                {
                    // Display the current EffectType
                    Console.WriteLine("\n" + types[t]);

                    // Display all its Effects (with an arrow if it is the current one)
                    for (int e = 0; e < effects[t].Count; e++)
                    {
                        // Initialize some variables
                        Effect       effect = effects[t][e];
                        string       arrow  = (currentType == t && currentEffect == e) ? "\t --> " : "\t     ";
                        ConsoleColor color  = (player.effectsAll.Contains(effect)) ? ConsoleColor.Red : ConsoleColor.Blue;

                        // Display the result
                        CONSOLE.WriteLine(color, arrow + effect.name());
                    }
                }


                // We read the input
                ConsoleKeyInfo input          = Console.ReadKey();
                bool           goToLastEffect = false;


                // If it is an Array key (UP or DOWN), we modify our index accordingly
                if (input.Key == ConsoleKey.UpArrow)
                {
                    currentEffect--;

                    // If the index goes too low, we change type
                    if (currentEffect < 0)
                    {
                        currentType--;
                        goToLastEffect = true;
                    }
                }
                if (input.Key == ConsoleKey.DownArrow)
                {
                    currentEffect++;

                    // If the index goes too high, we change type
                    if (currentEffect > effects[currentType].Count - 1)
                    {
                        currentType++;
                        currentEffect = 0;
                    }
                }
                // If it is a LEFT Array key : go to the previous type
                if (input.Key == ConsoleKey.LeftArrow)
                {
                    currentType--;
                    currentEffect = 0;
                }
                // If it is a RIGHT Array key : go to the next type
                if (input.Key == ConsoleKey.RightArrow)
                {
                    currentType++;
                    currentEffect = 0;
                }



                // If the type is too high / too low, we change it accordingly
                if (currentType < 0)
                {
                    currentType = types.Count - 1;
                }
                if (currentType > types.Count - 1)
                {
                    currentType = 0;
                }

                // If needed : we replace the effect counter to the last index of the current list
                if (goToLastEffect)
                {
                    currentEffect = effects[currentType].Count - 1;
                }


                // We check if we end the loop
                if (input.Key == ConsoleKey.Enter)
                {
                    // We set the chosen Effect
                    chosenEffect = effects[currentType][currentEffect];

                    Console.Clear();
                    // We display a message, whether the Effect can be chosen or not
                    if (player.effectsAll.Contains(chosenEffect))
                    {
                        CONSOLE.WriteLine(ConsoleColor.Red, "You cannot choose the Effect " + chosenEffect.name() + " :\n\nyour Player already has it !!");
                        CONSOLE.WaitForInput();
                    }
                    else
                    {
                        continuing = false;
                    }
                }
            }while (continuing);

            // Small message
            CONSOLE.WriteLine(ConsoleColor.Green, "You have chosen the Effect " + chosenEffect.name() + " !!");

            // Sending the chosen Effect
            Net.EFFECT.Send(comm.GetStream(), chosenEffect);

            // If the Effect was validated : add it to the Player
            if (Net.BOOL.Receive(comm.GetStream()))
            {
                CONSOLE.WriteLine(ConsoleColor.Green, "\n\n\tEffect validated !!");
                player.effects.Add(chosenEffect);
            }
            else
            {
                CONSOLE.WriteLine(ConsoleColor.Red, "\n\n\tEffect refused...");
            }

            CONSOLE.WaitForInput();
        }
示例#6
0
        /// <summary>
        /// Creates a new Player
        /// </summary>
        /// <param name="team">Team the Player is in</param>
        private void NewPlayer(Team team)
        {
            bool   continueNewPlayer       = true;
            bool   continueNewPlayerInputs = true;
            string errorMessage            = "";

            do
            {
                // CHOICE
                // We dynamically create a List containing all the roles names
                List <string> choiceString = new List <string>();
                team.race.roles().ForEach(role => choiceString.Add(role.ToStringCustom()));

                // We add as a last choice the option to "Cancel"
                choiceString.Add("Cancel");

                // We create the Choice
                Choice c     = new Choice("please Select a Role (last one = cancel) : ", choiceString);
                int    index = c.GetChoice();

                if (index != choiceString.Count - 1)
                {
                    // We save the Role
                    Role role = team.race.roles()[index];

                    // if the role chosen is too cost-expensive
                    if (role.price() > team.money)
                    {
                        CONSOLE.WriteLine(ConsoleColor.Red, PrefabMessages.NOT_ENOUGH_MONEY);
                        CONSOLE.WaitForInput();
                    }
                    // if the player can afford it : continue
                    else
                    {
                        // Inputs
                        do
                        {
                            Console.Clear();

                            // Displays a message if the credentials are incorrect
                            CONSOLE.WriteLine(ConsoleColor.Red, errorMessage);

                            // NAME
                            Console.Write("\n Please enter the {0}'s name (empty = go back) : ", role.name());
                            string name = Console.ReadLine();


                            // All the fields are empty : go back to the menu
                            if (name.Length == 0)
                            {
                                continueNewPlayerInputs = false;
                            }
                            // If at least one field is too long : ERROR
                            else if (name.Length > PrefabMessages.INPUT_MAXSIZE_COACH_NAME)
                            {
                                errorMessage = PrefabMessages.INCORRECT_INPUT_SIZE;
                            }
                            // If at least one field has one incorrect character : ERROR
                            else if (!Util.CorrectInput(name))
                            {
                                errorMessage = PrefabMessages.INCORRECT_INPUT_CHARACTER;
                            }
                            // Otherwise : verify with the server
                            else
                            {
                                // Sending the new Player
                                Instructions instruction = Instructions.Team_AddPlayer;
                                Player       newPlayer   = new Player(name, role, team);
                                Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, newPlayer));

                                // We receive the id of the Player from the server
                                Guid idReceived = Net.GUID.Receive(comm.GetStream());

                                // We see if the id received is valid
                                if (idReceived != Guid.Empty)
                                {
                                    // We set the received id
                                    newPlayer.id = idReceived;

                                    // We add the Player to the user's team
                                    team.players.Add(newPlayer);

                                    // We make the transaction (the team has less money now)
                                    team.money -= role.price();

                                    // We display a success message
                                    CONSOLE.WriteLine(ConsoleColor.Green, PrefabMessages.PLAYER_CREATION_SUCCESS);

                                    // Ending the loops
                                    continueNewPlayerInputs = false;
                                    continueNewPlayer       = false;
                                }
                                else
                                {
                                    errorMessage = PrefabMessages.PLAYER_CREATION_FAILURE;
                                }
                            }
                        }while (continueNewPlayerInputs);
                    }
                }
                else
                {
                    continueNewPlayer = false;
                }
            }while (continueNewPlayer);
        }