示例#1
0
        public char[,] SpawnWeapon(char[,] mat, List <Position> positionsLibres, int index)
        {
            char[,] matchar = mat;
            Cell[,] cells   = CharToCell(matchar);
            Position       rdmPosWeapon  = positionsLibres[index];
            WeaponsFactory factoryWeapon = new WeaponsFactory();
            Weapons        weaponStore   = new Weapons(factoryWeapon);
            Weapon         weapon        = weaponStore.AskForWeapon(rdmPosWeapon);

            positionsLibres.Remove(weapon.pos);
            if (weapon is Epee)
            {
                matchar[rdmPosWeapon.coord_X, rdmPosWeapon.coord_Y] = 'E';
            }
            if (weapon is Dague)
            {
                matchar[rdmPosWeapon.coord_X, rdmPosWeapon.coord_Y] = 'D';
            }
            if (weapon is Hache)
            {
                matchar[rdmPosWeapon.coord_X, rdmPosWeapon.coord_Y] = 'H';
            }
            if (weapon is Lance)
            {
                matchar[rdmPosWeapon.coord_X, rdmPosWeapon.coord_Y] = 'L';
            }
            return(matchar);
        }
示例#2
0
        public void TestRépartionWeapon()
        {
            Labyrinthe maze = new Labyrinthe();

            char[,] matchar = TestInitialisation(maze, "..\\..\\mazeGenerator.txt");
            Cell[,] cells   = maze.CharToCell(matchar);
            List <Position> positionsLibres = maze.PositionLibres(cells);
            WeaponsFactory  factory         = new WeaponsFactory();
            Weapons         weaponsStore    = new Weapons(factory);

            maze.Displaychar(matchar);
            Console.WriteLine();
            maze.RepartitionWeapon(matchar, positionsLibres, weaponsStore);
            maze.Displaychar(matchar);
        }
示例#3
0
 public Weapons(WeaponsFactory Factory)
 {
     InitDictionary();
     this.factory = Factory;
 }
示例#4
0
        static void Main(string[] args)
        {
            //Initialisation
            string        file       = "..\\..\\theMaze.txt";
            Labyrinthe    maze       = new Labyrinthe();
            List <string> liststring = maze.ReadFile(file);

            char[,] matchar = maze.ConvertListStringToMatChar(liststring);
            Cell[,] cells   = maze.CharToCell(matchar);
            List <Position> positionsLibres = maze.PositionLibres(cells);


            //Répartion Combatants
            FightersFactory factoryFighter = new FightersFactory();
            Fighters        fighterStore   = new Fighters(factoryFighter);

            maze.RepartitionCombatants(matchar, positionsLibres, fighterStore);

            maze.fighterList = fighterStore.fightersList;

            //Répartion Weapons
            WeaponsFactory factoryWeapons = new WeaponsFactory();
            Weapons        weaponStore    = new Weapons(factoryWeapons);

            maze.RepartitionWeapon(matchar, positionsLibres, weaponStore);

            //Stockage des Combatants
            Fighter fighter1 = fighterStore.fightersList[0]; //Bleu
            Fighter fighter2 = fighterStore.fightersList[1]; //Vert
            Fighter fighter3 = fighterStore.fightersList[2]; //Blanc



            //Stockage des Armes
            Weapon weapon1 = weaponStore.ListWeapons[0];
            Weapon weapon2 = weaponStore.ListWeapons[1];
            Weapon weapon3 = weaponStore.ListWeapons[2];
            Weapon weapon4 = weaponStore.ListWeapons[3];
            Weapon weapon5 = weaponStore.ListWeapons[4];
            Weapon weapon6 = weaponStore.ListWeapons[5];
            Weapon weapon7 = weaponStore.ListWeapons[6];
            Weapon weapon8 = weaponStore.ListWeapons[7];
            Weapon weapon9 = weaponStore.ListWeapons[8];


            //Boucle du jeu
            while (matchar[fighter1.Est().coord_X, fighter1.Est().coord_Y] != '2' && matchar[fighter2.Est().coord_X, fighter2.Est().coord_Y] != '2' && matchar[fighter3.Est().coord_X, fighter3.Est().coord_Y] != '2')
            {
                Weapon weap1 = maze.ChercheWeapon(weaponStore.ListWeapons, fighter1);
                Weapon weap2 = maze.ChercheWeapon(weaponStore.ListWeapons, fighter2);
                Weapon weap3 = maze.ChercheWeapon(weaponStore.ListWeapons, fighter3);

                if (weap1.pos.coord_X != 0 && weap1.pos.coord_Y != 0)
                {
                    fighter1.weapons.Add(weap1);
                    fighter1.Dégats  += weap1.dégats;
                    weap1.pos.coord_X = 0;
                    weap1.pos.coord_Y = 0;
                }
                if (weap2.pos.coord_X != 0 && weap2.pos.coord_Y != 0)
                {
                    fighter2.weapons.Add(weap2);
                    fighter2.Dégats  += weap2.dégats;
                    weap2.pos.coord_X = 0;
                    weap2.pos.coord_Y = 0;
                }
                if (weap3.pos.coord_X != 0 && weap3.pos.coord_Y != 0)
                {
                    fighter3.weapons.Add(weap3);
                    fighter3.Dégats  += weap3.dégats;
                    weap3.pos.coord_X = 0;
                    weap3.pos.coord_Y = 0;
                }

                matchar = CheckFight(matchar, fighterStore, fighter1, fighter2);
                matchar = CheckFight(matchar, fighterStore, fighter1, fighter3);
                if (fighter1.Hp > 0)
                {
                    matchar = maze.Deplacement(matchar, fighter1);
                }

                matchar = CheckFight(matchar, fighterStore, fighter2, fighter1);
                matchar = CheckFight(matchar, fighterStore, fighter2, fighter3);
                if (fighter2.Hp > 0)
                {
                    matchar = maze.Deplacement(matchar, fighter2);
                }


                matchar = CheckFight(matchar, fighterStore, fighter3, fighter1);
                matchar = CheckFight(matchar, fighterStore, fighter3, fighter2);
                if (fighter3.Hp > 0)
                {
                    matchar = maze.Deplacement(matchar, fighter3);
                }

                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Nombre de fighter: " + fighterStore.fightersList.Count());
                Console.WriteLine("Position du fighter 1 : " + fighter1.pos);
                Console.WriteLine("Arme du fighter 1: " + fighter1.weapons.Count());
                Console.WriteLine("Dégat du fighter1 : " + fighter1.Dégats);
                Console.WriteLine("PV du fighter1 : " + fighter1.Hp);
                Console.ResetColor();

                Console.WriteLine();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Position du fighter 2 : " + fighter2.pos);
                Console.WriteLine("Arme du fighter 2: " + fighter2.weapons.Count());
                Console.WriteLine("Dégat du fighter2 : " + fighter2.Dégats);
                Console.WriteLine("PV du fighter2 : " + fighter2.Hp);
                Console.ResetColor();

                Console.WriteLine();

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Position du fighter 3 : " + fighter3.pos);
                Console.WriteLine("Arme du fighter 3: " + fighter3.weapons.Count());
                Console.WriteLine("Dégat du fighter3 : " + fighter3.Dégats);
                Console.WriteLine("PV du fighter3 : " + fighter3.Hp);
                Console.ResetColor();

                Console.WriteLine();
                maze.Displaychar(matchar);
                //Console.ReadKey();
                Console.WriteLine();
                Console.Clear();
            }

            //Condition pour finir la partie
            if (matchar[fighter1.Est().coord_X, fighter1.Est().coord_Y] == '2')
            {
                matchar[fighter1.pos.coord_X, fighter1.pos.coord_Y] = '0';
                fighter1.pos = fighter1.Est();
                matchar[fighter1.pos.coord_X, fighter1.pos.coord_Y] = 'X';
                Console.Clear();
                maze.Displaychar(matchar);
                Console.WriteLine("End of the game");
                Console.WriteLine("Combatant 1 a gagné");
            }
            if (matchar[fighter2.Est().coord_X, fighter2.Est().coord_Y] == '2')
            {
                matchar[fighter2.pos.coord_X, fighter2.pos.coord_Y] = '0';
                fighter2.pos = fighter2.Est();
                matchar[fighter2.pos.coord_X, fighter2.pos.coord_Y] = 'X';
                Console.Clear();
                maze.Displaychar(matchar);
                Console.WriteLine("End of the game");
                Console.WriteLine("Combatant 2 a gagné");
            }
            if (matchar[fighter3.Est().coord_X, fighter3.Est().coord_Y] == '2')
            {
                matchar[fighter3.pos.coord_X, fighter3.pos.coord_Y] = '0';
                fighter3.pos = fighter3.Est();
                matchar[fighter3.pos.coord_X, fighter3.pos.coord_Y] = 'X';
                Console.Clear();
                maze.Displaychar(matchar);
                Console.WriteLine("End of the game");
                Console.WriteLine("Combatant 3 a gagné");
            }



            Console.ReadKey();
        }
示例#5
0
        public void TestCombat()
        {
            Labyrinthe maze = new Labyrinthe();

            char[,] matchar = TestInitialisation(maze, "..\\..\\mazeJoute.txt");
            Cell[,] cells   = maze.CharToCell(matchar);

            FightersFactory factory         = new FightersFactory();
            Fighters        fighterStore    = new Fighters(factory);
            List <Position> positionsLibres = maze.PositionLibres(cells);
            Random          rand            = new Random();
            int             index           = rand.Next(positionsLibres.Count);

            maze.SpawnCombatant(matchar, positionsLibres, index);
            Position rdmPosFighter1 = positionsLibres[index];
            Fighter  fighter1       = fighterStore.AskForAFighter(rdmPosFighter1);

            positionsLibres.Remove(fighter1.pos);
            maze.Displaychar(matchar);
            Random rand1  = new Random();
            int    index1 = rand1.Next(positionsLibres.Count);

            maze.SpawnCombatant(matchar, positionsLibres, index1);
            Position rdmPosFighter2 = positionsLibres[index1];
            Fighter  fighter2       = fighterStore.AskForAFighter(rdmPosFighter2);

            positionsLibres.Remove(fighter2.pos);
            maze.Displaychar(matchar);

            WeaponsFactory factory2    = new WeaponsFactory();
            Weapons        weaponStore = new Weapons(factory2);
            Random         rand2       = new Random();
            int            index2      = rand2.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index2);
            Position rdmPosWeapon = positionsLibres[index2];
            Weapon   weapon       = weaponStore.AskForWeapon(rdmPosWeapon);

            positionsLibres.Remove(weapon.pos);
            maze.Displaychar(matchar);

            Random rand3  = new Random();
            int    index3 = rand3.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index3);
            Position rdmPosWeapon2 = positionsLibres[index3];
            Weapon   weapon2       = weaponStore.AskForWeapon(rdmPosWeapon2);

            positionsLibres.Remove(weapon2.pos);

            Random rand4  = new Random();
            int    index4 = rand4.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index4);
            Position rdmPosWeapon3 = positionsLibres[index4];
            Weapon   weapon3       = weaponStore.AskForWeapon(rdmPosWeapon3);

            positionsLibres.Remove(weapon3.pos);

            Random rand5  = new Random();
            int    index5 = rand5.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index5);
            Position rdmPosWeapon4 = positionsLibres[index5];
            Weapon   weapon4       = weaponStore.AskForWeapon(rdmPosWeapon4);

            positionsLibres.Remove(weapon4.pos);

            Random rand6  = new Random();
            int    index6 = rand6.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index6);
            Position rdmPosWeapon5 = positionsLibres[index6];
            Weapon   weapon5       = weaponStore.AskForWeapon(rdmPosWeapon5);

            positionsLibres.Remove(weapon5.pos);

            Random rand7  = new Random();
            int    index7 = rand7.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index7);
            Position rdmPosWeapon6 = positionsLibres[index7];
            Weapon   weapon6       = weaponStore.AskForWeapon(rdmPosWeapon6);

            positionsLibres.Remove(weapon6.pos);

            Random rand8  = new Random();
            int    index8 = rand8.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index8);
            Position rdmPosWeapon7 = positionsLibres[index8];
            Weapon   weapon7       = weaponStore.AskForWeapon(rdmPosWeapon7);

            positionsLibres.Remove(weapon7.pos);

            Random rand9  = new Random();
            int    index9 = rand9.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index9);
            Position rdmPosWeapon8 = positionsLibres[index9];
            Weapon   weapon8       = weaponStore.AskForWeapon(rdmPosWeapon8);

            positionsLibres.Remove(weapon8.pos);

            Random rand10  = new Random();
            int    index10 = rand10.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index10);
            Position rdmPosWeapon9 = positionsLibres[index10];
            Weapon   weapon9       = weaponStore.AskForWeapon(rdmPosWeapon9);

            positionsLibres.Remove(weapon9.pos);



            maze.Displaychar(matchar);
            Console.WriteLine("Position du fighter 1: " + fighter1.pos);
            Console.WriteLine("Position du fighter 2: " + fighter2.pos);
            Console.WriteLine("Nombre de fighter" + fighterStore.fightersList.Count());

            while (matchar[fighter1.Sud().coord_X, fighter1.Sud().coord_Y] != '2' && matchar[fighter2.Sud().coord_X, fighter2.Sud().coord_Y] != '2')
            {
                Weapon weap1 = maze.ChercheWeapon(weaponStore.ListWeapons, fighter1);
                Weapon weap2 = maze.ChercheWeapon(weaponStore.ListWeapons, fighter2);

                if (weap1.pos.coord_X != 0 && weap1.pos.coord_Y != 0)
                {
                    fighter1.weapons.Add(weap1);
                    fighter1.Dégats  += weap1.dégats;
                    weap1.pos.coord_X = 0;
                    weap1.pos.coord_Y = 0;
                }
                if (weap2.pos.coord_X != 0 && weap2.pos.coord_Y != 0)
                {
                    fighter2.weapons.Add(weap2);
                    fighter2.Dégats  += weap2.dégats;
                    weap2.pos.coord_X = 0;
                    weap2.pos.coord_Y = 0;
                }

                matchar = CheckFight(matchar, fighterStore, fighter1, fighter2);

                if (fighter1.Hp > 0)
                {
                    matchar = maze.Deplacement(matchar, fighter1);
                }

                matchar = CheckFight(matchar, fighterStore, fighter1, fighter2);

                if (fighter2.Hp > 0)
                {
                    matchar = maze.Deplacement(matchar, fighter2);
                }

                matchar = CheckFight(matchar, fighterStore, fighter1, fighter2);

                Console.WriteLine("Nombre de fighter" + fighterStore.fightersList.Count());
                maze.Displaychar(matchar);


                Console.WriteLine("Position du fighter 1: " + fighter1.pos);
                Console.WriteLine("Dégat du fighter 1: " + fighter1.Dégats);
                Console.WriteLine("PV du fighter 1: " + fighter1.Hp);
                Console.WriteLine("Position du fighter 2: " + fighter2.pos);
                Console.WriteLine("Dégat du fighter 2: " + fighter2.Dégats);
                Console.WriteLine("PV du fighter 2: " + fighter2.Hp);
                Console.WriteLine("rdmposweapon:" + rdmPosWeapon);

                Console.ReadKey();
                Console.Clear();
            }
            if (matchar[fighter1.Sud().coord_X, fighter1.Sud().coord_Y] == '2')
            {
                maze.Displaychar(matchar);
                matchar[fighter1.pos.coord_X, fighter1.pos.coord_Y] = '0';
                fighter1.pos = fighter1.Sud();
                matchar[fighter1.pos.coord_X, fighter1.pos.coord_Y] = 'X';
                Console.ReadKey();
                Console.Clear();
                maze.Displaychar(matchar);
                Console.ReadKey();
                Console.Clear();
                Console.WriteLine();
                Console.Write("Arme du fighter: ");
                Console.WriteLine(fighter1.weapons.Count());
                Console.Write("Arme dans la liste: ");
                Console.WriteLine(weaponStore.ListWeapons.Count());
                Console.Write("End of the game");
            }
        }
示例#6
0
        public void TestRamasserWeapon()
        {
            Labyrinthe maze = new Labyrinthe();

            char[,] matchar = TestInitialisation(maze, "..\\..\\theMaze.txt");
            Cell[,] cells   = maze.CharToCell(matchar);

            FightersFactory factory         = new FightersFactory();
            Fighters        fighterStore    = new Fighters(factory);
            List <Position> positionsLibres = maze.PositionLibres(cells);
            Random          rand            = new Random();
            int             index           = rand.Next(positionsLibres.Count);

            maze.SpawnCombatant(matchar, positionsLibres, index);
            Position rdmPosFighter = positionsLibres[index];
            Fighter  fighter       = fighterStore.AskForAFighter(rdmPosFighter);

            positionsLibres.Remove(fighter.pos);
            maze.Displaychar(matchar);

            WeaponsFactory factory2    = new WeaponsFactory();
            Weapons        weaponStore = new Weapons(factory2);
            Random         rand2       = new Random();
            int            index2      = rand2.Next(positionsLibres.Count);

            maze.SpawnWeapon(matchar, positionsLibres, index2);
            Position rdmPosWeapon = positionsLibres[index2 - 1];
            Weapon   weapon       = weaponStore.AskForWeapon(rdmPosWeapon);

            positionsLibres.Remove(weapon.pos);
            maze.Displaychar(matchar);
            Console.WriteLine("Position du fighter" + fighter.pos);
            Console.WriteLine("Nombre de fighter" + fighterStore.fightersList.Count());

            while (matchar[fighter.Sud().coord_X, fighter.Sud().coord_Y] != '2')
            {
                Weapon weap = maze.ChercheWeapon(weaponStore.ListWeapons, fighter);

                if (weap.pos.coord_X != 0 && weap.pos.coord_Y != 0)
                {
                    fighter.weapons.Add(weap);
                    weap.pos.coord_X = 0;
                    weap.pos.coord_Y = 0;
                }
                matchar = maze.Deplacement(matchar, fighter);
                Console.WriteLine("Nombre de fighter" + fighterStore.fightersList.Count());
                maze.Displaychar(matchar);
                Console.Clear();

                Console.WriteLine("Position du fighter" + fighter.pos);
                Console.WriteLine("rdmposweapon:" + rdmPosWeapon);
                Console.WriteLine(weap.pos);
            }
            if (matchar[fighter.Sud().coord_X, fighter.Sud().coord_Y] == '2')
            {
                maze.Displaychar(matchar);
                matchar[fighter.pos.coord_X, fighter.pos.coord_Y] = '0';
                fighter.pos = fighter.Sud();
                matchar[fighter.pos.coord_X, fighter.pos.coord_Y] = 'X';
                Console.ReadKey();
                Console.Clear();
                maze.Displaychar(matchar);
                Console.ReadKey();
                Console.Clear();
                Console.WriteLine();
                Console.Write("Arme du fighter: ");
                Console.WriteLine(fighter.weapons.Count());
                Console.Write("Arme dans la liste: ");
                Console.WriteLine(weaponStore.ListWeapons.Count());
                Console.Write("End of the game");
            }
        }