diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs
index 7638e41..96a2700 100644
--- a/Sources/BowlingLib/Model/Frame.cs
+++ b/Sources/BowlingLib/Model/Frame.cs
@@ -36,6 +36,11 @@ namespace BowlingLib.Model
this.IsSpare = false;
}
+ ///
+ /// Lance une quille
+ ///
+ /// le nombre de quilles tombés
+ ///
public void Lancer(int quillesTombees)
{
if (quillesTombees > QuillesRestantes)
@@ -80,6 +85,7 @@ namespace BowlingLib.Model
if (quillesTombees + this.Lancer1.QuillesTombees == 10)
{
this.IsSpare = true;
+ QuillesRestantes = 10;
}
}
}
@@ -148,7 +154,7 @@ namespace BowlingLib.Model
this.IsSpare = true;
}
}
- if (this.QuillesRestantes == 0 || this.Lancer2 != null)
+ if (this.QuillesRestantes == 0 || (this.Lancer2 != null && this.Numero != 10))
{
this.IsFinished = true;
}
diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs
index 9c78293..d591c9a 100644
--- a/Sources/BowlingLib/Model/Partie.cs
+++ b/Sources/BowlingLib/Model/Partie.cs
@@ -13,24 +13,37 @@ namespace BowlingLib.Model
public List Frames { get; set; }
+ ///
+ /// Constructeur
+ ///
+ ///
public Partie(Joueur joueur)
{
this.Joueur = joueur;
Frames = new List();
}
+ ///
+ /// Ajoute un frame à la partie
+ ///
+ ///
public void AddFrame(Frame frame)
{
Frames.Add(frame);
}
+
+ ///
+ /// Calcule le score de la partie
+ ///
+ /// le Score d'une partie
public int? GetScore()
{
int? score = 0;
for (int i = 0; i < Frames.Count; i++)
{
score += Frames[i].QuillesTombees;
- if (Frames[i].IsStrike)
+ if (Frames[i].IsStrike && i < Frames.Count - 1)
{
score += Frames[i + 1].QuillesTombees;
if (Frames[i + 1].IsStrike && i < Frames.Count - 2)
@@ -38,7 +51,7 @@ namespace BowlingLib.Model
score += Frames[i + 2].QuillesTombees;
}
}
- else if (Frames[i].IsSpare)
+ else if (Frames[i].IsSpare && i < Frames.Count - 1)
{
score += Frames[i + 1].Lancer1.QuillesTombees;
}
diff --git a/Sources/BowlingStub/StubPartie.cs b/Sources/BowlingStub/StubPartie.cs
index 228b370..574254f 100644
--- a/Sources/BowlingStub/StubPartie.cs
+++ b/Sources/BowlingStub/StubPartie.cs
@@ -1,8 +1,28 @@
-namespace BowlingStub
+using BowlingLib.Model;
+
+namespace BowlingStub
{
public class StubPartie
{
+ List listParties = new List();
+ public StubPartie()
+ {
+
+
+ }
+
+ //Fonction permettant de créer une partie pour chaque joueur
+ public List ListParties(int n = 10)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ listParties.Add(new Partie(new Joueur("Joueur " + i + 1)));
+ }
+ return listParties;
+ }
+
+
}
}
\ No newline at end of file
diff --git a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs
new file mode 100644
index 0000000..da4505b
--- /dev/null
+++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs
@@ -0,0 +1,164 @@
+using BowlingLib.Model;
+using BowlingStub;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace BowlingAppUnitTest
+{
+ public class UTPartie
+ {
+ //le cas ou le joueur ne fait que des strikes
+ [Fact]
+ public void TestGetScore()
+ {
+ //Arrange
+ StubPartie stubPartie = new StubPartie();
+ List listParties = stubPartie.ListParties();
+ Partie partie = listParties[0];
+ partie.AddFrame(new Frame(1));
+ partie.AddFrame(new Frame(2));
+ partie.AddFrame(new Frame(3));
+ partie.AddFrame(new Frame(4));
+ partie.AddFrame(new Frame(5));
+ partie.AddFrame(new Frame(6));
+ partie.AddFrame(new Frame(7));
+ partie.AddFrame(new Frame(8));
+ partie.AddFrame(new Frame(9));
+ partie.AddFrame(new Frame(10));
+ partie.AddFrame(new Frame(11));
+
+ for (int i = 0; i < partie.Frames.Count; i++)
+ {
+ partie.Frames[i].Lancer(10);
+ }
+
+ //Act
+ int? score = partie.GetScore();
+
+ //Assert
+ Assert.Equal(300, score);
+ }
+
+ //le cas ou le joueur fait que des spares
+
+ [Fact]
+
+ public void TestGetScore2()
+ {
+ //Arrange
+ StubPartie stubPartie = new StubPartie();
+ List listParties = stubPartie.ListParties();
+ Partie partie = listParties[0];
+ partie.AddFrame(new Frame(1));
+ partie.AddFrame(new Frame(2));
+ partie.AddFrame(new Frame(3));
+ partie.AddFrame(new Frame(4));
+ partie.AddFrame(new Frame(5));
+ partie.AddFrame(new Frame(6));
+ partie.AddFrame(new Frame(7));
+ partie.AddFrame(new Frame(8));
+ partie.AddFrame(new Frame(9));
+ partie.AddFrame(new Frame(10));
+
+ for (int i = 0; i < partie.Frames.Count; i++)
+ {
+ partie.Frames[i].Lancer(5);
+ partie.Frames[i].Lancer(5);
+ if (i == 9)
+ {
+ partie.Frames[i].Lancer(5);
+ }
+
+ }
+
+ //Act
+ int? score = partie.GetScore();
+
+ //Assert
+ Assert.Equal(150, score);
+ }
+
+ //le cas ou le joueur fait que des spares et des strikes
+
+ [Fact]
+
+ public void TestGetScore3()
+ {
+ //Arrange
+ StubPartie stubPartie = new StubPartie();
+ List listParties = stubPartie.ListParties();
+ Partie partie = listParties[0];
+ partie.AddFrame(new Frame(1));
+ partie.AddFrame(new Frame(2));
+ partie.AddFrame(new Frame(3));
+ partie.AddFrame(new Frame(4));
+ partie.AddFrame(new Frame(5));
+ partie.AddFrame(new Frame(6));
+ partie.AddFrame(new Frame(7));
+ partie.AddFrame(new Frame(8));
+ partie.AddFrame(new Frame(9));
+ partie.AddFrame(new Frame(10));
+
+ for (int i = 0; i < partie.Frames.Count; i++)
+ {
+ if (i % 2 == 0)
+ {
+ partie.Frames[i].Lancer(10);
+ }
+ else
+ {
+ partie.Frames[i].Lancer(5);
+ partie.Frames[i].Lancer(5);
+ if (i==9)
+ {
+ partie.Frames[i].Lancer(5);
+ }
+ }
+ }
+
+ //Act
+ int? score = partie.GetScore();
+
+ //Assert
+ Assert.Equal(200, score);
+ }
+
+ //le cas ou le joueur ne fait aucun strike ou spare
+
+ [Fact]
+
+ public void TestGetScore4()
+ {
+ //Arrange
+ StubPartie stubPartie = new StubPartie();
+ List listParties = stubPartie.ListParties();
+ Partie partie = listParties[0];
+ partie.AddFrame(new Frame(1));
+ partie.AddFrame(new Frame(2));
+ partie.AddFrame(new Frame(3));
+ partie.AddFrame(new Frame(4));
+ partie.AddFrame(new Frame(5));
+ partie.AddFrame(new Frame(6));
+ partie.AddFrame(new Frame(7));
+ partie.AddFrame(new Frame(8));
+ partie.AddFrame(new Frame(9));
+ partie.AddFrame(new Frame(10));
+
+ for (int i = 0; i < partie.Frames.Count; i++)
+ {
+ partie.Frames[i].Lancer(5);
+ partie.Frames[i].Lancer(4);
+ }
+
+ //Act
+ int? score = partie.GetScore();
+
+ //Assert
+ Assert.Equal(90, score);
+ }
+ }
+}
\ No newline at end of file