diff --git a/README.md b/README.md index 759a040..8d1bb87 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Welcome on the BowlingScoreApp project! - + _Generated with a_ **Code#0** _template_ \ No newline at end of file diff --git a/Sources/BowlingLib/Class1.cs b/Sources/BowlingLib/Class1.cs deleted file mode 100644 index 31eb072..0000000 --- a/Sources/BowlingLib/Class1.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace HelloWorldLib -{ - /// - ///a sample class - /// - public class Class1 - { - } -} diff --git a/Sources/BowlingLib/Model/Equipe.cs b/Sources/BowlingLib/Model/Equipe.cs new file mode 100644 index 0000000..9356838 --- /dev/null +++ b/Sources/BowlingLib/Model/Equipe.cs @@ -0,0 +1,56 @@ +<<<<<<< HEAD +using System; +======= +<<<<<<< HEAD +using System; +======= +using System; +>>>>>>> origin/CreationTest +>>>>>>> 8e1fb8c3cd98585de832d5a5d1b851f8a5f444ce +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Equipe + { + private string nom; + private List joueurs; + + public string Nom + { + get { return nom; } + set { nom = value; } + } + + public List Joueurs + { + get { return joueurs; } + set { joueurs = value; } + } + + public Equipe(string nom) + { + this.nom = nom; + joueurs = new List(); + } + + public void AjouterJoueur(Joueur joueur) + { + joueurs.Add(joueur); + } + + public void SupprimerJoueur(Joueur joueur) + { + joueurs.Remove(joueur); + } + + //retourner la liste non modifiable des joueurs de l'équipe + public List GetJoueurs() + { + return joueurs.AsReadOnly().ToList(); + } + } +} diff --git a/Sources/BowlingLib/Model/FacadeManager.cs b/Sources/BowlingLib/Model/FacadeManager.cs new file mode 100644 index 0000000..fe21397 --- /dev/null +++ b/Sources/BowlingLib/Model/FacadeManager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + internal class FacadeManager + { + } +} diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs new file mode 100644 index 0000000..7638e41 --- /dev/null +++ b/Sources/BowlingLib/Model/Frame.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Frame + { + public int Numero { get; set; } + + + public int QuillesRestantes { get; set; } + + public int QuillesTombees { get; set; } + + public bool IsStrike { get; set; } + + public bool IsSpare { get; set; } + + public bool IsFinished { get; set; } + + public Lancer Lancer1 { get; set; } + + public Lancer Lancer2 { get; set; } + + public Lancer Lancer3 { get; set; } + + public Frame(int numero) + { + this.Numero = numero; + this.QuillesRestantes = 10; + this.IsFinished = false; + this.IsStrike = false; + this.IsSpare = false; + } + + public void Lancer(int quillesTombees) + { + if (quillesTombees > QuillesRestantes) + { + throw new ArgumentException("Le nombre de quilles tombees doit etre inferieur au nombre de quilles restantes"); + } + if (quillesTombees < 0) + { + throw new ArgumentException("Le nombre de quilles tombees doit et etre positif"); + } + + if (this.Numero == 10) + { + if (this.Lancer1 == null) + { + this.Lancer1 = new Lancer(quillesTombees); + this.QuillesRestantes -= quillesTombees; + this.QuillesTombees += quillesTombees; + if (quillesTombees == 10) + { + this.IsStrike = true; + } + } + else if (this.Lancer2 == null) + { + this.Lancer2 = new Lancer(quillesTombees); + this.QuillesRestantes -= quillesTombees; + this.QuillesTombees += quillesTombees; + if (this.IsStrike) + { + if (quillesTombees == 10) + { + this.IsStrike = true; + } + else + { + this.IsStrike = false; + } + } + else + { + if (quillesTombees + this.Lancer1.QuillesTombees == 10) + { + this.IsSpare = true; + } + } + } + else if (this.Lancer3 == null) + { + this.Lancer3 = new Lancer(quillesTombees); + this.QuillesRestantes -= quillesTombees; + this.QuillesTombees += quillesTombees; + if (this.IsStrike) + { + if (quillesTombees == 10) + { + this.IsStrike = true; + } + else + { + this.IsStrike = false; + } + } + else if (this.IsSpare) + { + if (quillesTombees + this.Lancer2.QuillesTombees == 10) + { + this.IsSpare = true; + } + else + { + this.IsSpare = false; + } + } + else + { + if (quillesTombees + this.Lancer2.QuillesTombees == 10) + { + this.IsSpare = true; + } + } + } + else + { + throw new ArgumentException("Le nombre de lancers est deja atteint"); + } + } + else + { + if (this.Lancer1 == null) + { + this.Lancer1 = new Lancer(quillesTombees); + } + else if (this.Lancer2 == null) + { + this.Lancer2 = new Lancer(quillesTombees); + } + else + { + throw new ArgumentException("Le nombre de lancers est deja atteint"); + } + this.QuillesRestantes -= quillesTombees; + this.QuillesTombees += quillesTombees; + if (quillesTombees == 10) + { + this.IsStrike = true; + } + else if (this.QuillesRestantes == 0) + { + this.IsSpare = true; + } + } + if (this.QuillesRestantes == 0 || this.Lancer2 != null) + { + this.IsFinished = true; + } + } + } +} diff --git a/Sources/BowlingLib/Model/Iloader.cs b/Sources/BowlingLib/Model/Iloader.cs new file mode 100644 index 0000000..93593be --- /dev/null +++ b/Sources/BowlingLib/Model/Iloader.cs @@ -0,0 +1,6 @@ +using System; + +public interface Iloader +{ + +} diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs new file mode 100644 index 0000000..cf10721 --- /dev/null +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Joueur + { + private string pseudo; + + public Joueur(string pseudo) + { + this.pseudo = pseudo; + + if (pseudo == null || pseudo == "" || pseudo.Length < 3) + { + throw new ArgumentException("Le pseudo ne peut pas être vide"); + } + } + + public string Pseudo + { + get { return pseudo; } + private set { pseudo = value; } + } + + } +} diff --git a/Sources/BowlingLib/Model/Lancer.cs b/Sources/BowlingLib/Model/Lancer.cs new file mode 100644 index 0000000..ad447ce --- /dev/null +++ b/Sources/BowlingLib/Model/Lancer.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Lancer + { + private int quillesTombees; + + public int QuillesTombees + { + get { return quillesTombees; } + set + { + if (value < 0 || value > 10) + { + throw new ArgumentException("Le nombre de quilles tombees doit etre compris entre 0 et 10"); + } + quillesTombees = value; + } + } + + public Lancer(int quillesTombees) + { + this.quillesTombees = quillesTombees; + } + + + + } +} diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs new file mode 100644 index 0000000..9c78293 --- /dev/null +++ b/Sources/BowlingLib/Model/Partie.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Partie + { + + public Joueur Joueur { get; set; } + + public List Frames { get; set; } + + public Partie(Joueur joueur) + { + this.Joueur = joueur; + Frames = new List(); + } + + public void AddFrame(Frame frame) + { + Frames.Add(frame); + } + + public int? GetScore() + { + int? score = 0; + for (int i = 0; i < Frames.Count; i++) + { + score += Frames[i].QuillesTombees; + if (Frames[i].IsStrike) + { + score += Frames[i + 1].QuillesTombees; + if (Frames[i + 1].IsStrike && i < Frames.Count - 2) + { + score += Frames[i + 2].QuillesTombees; + } + } + else if (Frames[i].IsSpare) + { + score += Frames[i + 1].Lancer1.QuillesTombees; + } + } + return score; + } + } +} diff --git a/Sources/BowlingStub/BowlingStub.csproj b/Sources/BowlingStub/BowlingStub.csproj new file mode 100644 index 0000000..88ad13a --- /dev/null +++ b/Sources/BowlingStub/BowlingStub.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Sources/BowlingStub/StubEquipe.cs b/Sources/BowlingStub/StubEquipe.cs new file mode 100644 index 0000000..4a76c4e --- /dev/null +++ b/Sources/BowlingStub/StubEquipe.cs @@ -0,0 +1,26 @@ +using BowlingLib.Model; +using System; + +public class StubEquipe +{ + private List listEquipes = new List(); + public StubEquipe() + { + } + + public List ListEquipes(int n = 10, int j = 2) + { + for (int i = 0; i < n; i++) + { + listEquipes.Add(new Equipe("Equipe " + i + 1)); + + for(int k = 0; k < j; k++) + { + listEquipes.ElementAt(i).AjouterJoueur(new Joueur("Joueur " + i + 1 + "-" + k + 1)); + + } + } + return listEquipes; + } + +} diff --git a/Sources/BowlingStub/StubJoueur.cs b/Sources/BowlingStub/StubJoueur.cs new file mode 100644 index 0000000..5fc7ec1 --- /dev/null +++ b/Sources/BowlingStub/StubJoueur.cs @@ -0,0 +1,20 @@ +using BowlingLib.Model; +using System; + +public class StubJoueur +{ +private List listJoueurs = new List(); + public StubJoueur() + { + } + + public List ListJoueurs(int n = 10) + { + for (int i = 0; i < n; i++) + { + listJoueurs.Add(new Joueur("Joueur " + i + 1)); + } + return listJoueurs; + } + +} diff --git a/Sources/BowlingStub/StubPartie.cs b/Sources/BowlingStub/StubPartie.cs new file mode 100644 index 0000000..228b370 --- /dev/null +++ b/Sources/BowlingStub/StubPartie.cs @@ -0,0 +1,8 @@ +namespace BowlingStub +{ + public class StubPartie + { + + + } +} \ No newline at end of file diff --git a/Sources/Solution.sln b/Sources/Solution.sln index 4105d6d..5078181 100644 --- a/Sources/Solution.sln +++ b/Sources/Solution.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BowlingApp", "BowlingApp\Bo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BowlingAppUnitTest", "Tests\BowlingAppUnitTest\BowlingAppUnitTest.csproj", "{F9B12DFD-EF58-429F-9344-70DFC10EC6E5}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BowlingStub", "BowlingStub\BowlingStub.csproj", "{B50615A5-ABFD-4A9C-B236-DBAEDE62AB2E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +31,10 @@ Global {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.Build.0 = Release|Any CPU + {B50615A5-ABFD-4A9C-B236-DBAEDE62AB2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B50615A5-ABFD-4A9C-B236-DBAEDE62AB2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B50615A5-ABFD-4A9C-B236-DBAEDE62AB2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B50615A5-ABFD-4A9C-B236-DBAEDE62AB2E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.csproj b/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.csproj index 73961d6..13f9b25 100644 --- a/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.csproj +++ b/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.csproj @@ -1,25 +1,25 @@ - - - - net6.0 - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - + + + + net6.0 + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + diff --git a/Sources/Tests/BowlingAppUnitTest/UnitTest1.cs b/Sources/Tests/BowlingAppUnitTest/UnitTest1.cs deleted file mode 100644 index 69d7a2a..0000000 --- a/Sources/Tests/BowlingAppUnitTest/UnitTest1.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using HelloWorldLib; -using Xunit; - -namespace HelloWordLib_UnitTests -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - Class1 c = new Class1(); - Assert.NotNull(c); - } - } -} diff --git a/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs new file mode 100644 index 0000000..3d735d3 --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs @@ -0,0 +1,50 @@ +using System; +using BowlingLib.Model; +using Xunit; + +namespace Test.BowlingAppUnitTest +{ + public class UnitTestJoueur + { + Joueur j = new Joueur("Paul"); + [Fact] + public void TestConstructeur() + { + Assert.NotNull(j); + Assert.Equal( "Paul",j.Pseudo); + Assert.NotEqual("joel",j.Pseudo ); + } + + [Fact] + public void TestInvalidJoueur() + { + Assert.Throws(() => new Joueur(null)); + } + + [Theory] + // [InlineData(false,"Augustin","Augustinn")] + [InlineData(true,"Amir","Amir")] + [InlineData(false,"Amir","")] + [InlineData(false,"Amir",null)] + [InlineData(false,null,null)] + [InlineData(false,null,"")] + [InlineData(false,"",null)] + [InlineData(false,"","")] + [InlineData(false,"f2","f2")] + + public void TestContructeur(bool isValid, string expectedPseudo, String pseudo ) + { + if (!isValid) + { + Assert.Throws( + () => new Joueur(pseudo) + ); + return; + } + Joueur j = new Joueur(pseudo); + Assert.Equal(expectedPseudo, j.Pseudo); + + + } + } +} diff --git a/Sources/global.json b/Sources/global.json new file mode 100644 index 0000000..87aef9f --- /dev/null +++ b/Sources/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.0", + "rollForward": "latestMajor", + "allowPrerelease": false + } +} \ No newline at end of file