Exception application console
continuous-integration/drone/push Build is passing Details

master
Camille TURPIN-ETIENNE 12 months ago
parent f96fe5ab9f
commit 1211235cd3

@ -10,8 +10,36 @@ ReglesClassiques partie = new ReglesClassiques();
Utils.AfficherTitre();
Utils.AfficherTitre("Joueurs");
string joueur1 = Utils.SaisirNom();
string joueur2 = Utils.SaisirNom();
string joueur1;
string joueur2;
while (true)
{
try
{
joueur1 = Utils.SaisirNom();
break;
}
catch(UtilsNomJoueurNullException)
{
Console.WriteLine("Nom invalide pour le joueur ! Ressaisir le nom");
}
}
while (true)
{
try
{
joueur2 = Utils.SaisirNom();
break;
}
catch (UtilsNomJoueurNullException)
{
Console.WriteLine("Nom invalide pour le joueur 2 ! Ressaisir le nom");
}
}
Utils.AfficherSeparateur();
partie.AjouterJoueur(joueur1);

@ -62,8 +62,13 @@ namespace ConsoleApp
Console.WriteLine(nom);
Console.Write(">>> ");
nom = Console.ReadLine() ?? nom;
if (nom == "")
{
--nombreJoueurs;
throw new UtilsNomJoueurNullException();
}
Console.WriteLine();
return nom;
}
@ -218,7 +223,15 @@ namespace ConsoleApp
else
{
Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b");
code.SupprimerDernierJeton();
try
{
code.SupprimerDernierJeton();
}
catch(CodeTableauLesJetonsVideException)
{
Console.WriteLine("Il n'y a pas de jetons! Impossible de supprimer");
}
}
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
public class UtilsNomJoueurNullException : Exception
{
public UtilsNomJoueurNullException() : base("Le nom du joueur est null")
{ }
}
}

@ -35,7 +35,7 @@
public Jeton RecupererJeton(int indice)
{
if(indice < 0 || indice > TailleMaximale())
throw new CodeIndiceHorsDePortéeException();
throw new CodeIndiceHorsDePorteeException();
Jeton? jeton = lesJetons[indice];

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace CoreLibrary
{
public class CodeIndiceHorsDePortéeException : Exception
public class CodeIndiceHorsDePorteeException : Exception
{
public CodeIndiceHorsDePortéeException() : base("L'indice pointe en dehors du tableau")
public CodeIndiceHorsDePorteeException() : base("L'indice pointe en dehors du tableau")
{ }
}
}
Loading…
Cancel
Save