Пример #1
0
        /// <summary>
        /// Manage the selection of a new Effect for a Player that is leveling up
        /// </summary>
        /// <param name="player">Player that is leveling up</param>
        /// <returns>Effect chosen for the Player leveling up (if invalid, returns null)</returns>
        public Effect?PlayerLevelsUp(Player player)
        {
            // We define the dices
            int dice1 = Dice.Roll6();
            int dice2 = Dice.Roll6();

            // We send their results
            Net.INT.Send(comm.GetStream(), dice1);
            Net.INT.Send(comm.GetStream(), dice2);

            // While we wait for the result...
            // Select the Effect Types the player can level up in
            List <EffectType>     types   = EffectStuff.GetEffectTypesForLevelUp(player.role, dice1, dice2);
            List <List <Effect> > effects = EffectStuff.GetEffectsForLevelUp(types);

            // We receive the Effect chosen
            Effect?effectReceived = Net.EFFECT.Receive(comm.GetStream());



            // We check if the Effect received is valid
            // By default, we think it is false, so we search to find the Effect in the valid one. If we find it, then it is valid !
            bool isValid = false;

            foreach (List <Effect> currentList in effects)
            {
                foreach (Effect effect in currentList)
                {
                    // if we find the Effect : good !
                    if (effect == effectReceived)
                    {
                        isValid = true;
                        break;
                    }
                }

                // We stop itirating once it is found
                if (isValid)
                {
                    break;
                }
            }

            // We return to the user whether the Effect was accepted or not
            Net.BOOL.Send(comm.GetStream(), isValid);

            // If reached, return the effect received
            return((isValid) ? effectReceived : null);
        }
Пример #2
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();
        }