CreationClasse #8

Merged
victor_perez.ngounou merged 32 commits from CreationClasse into master 3 years ago

@ -16,7 +16,7 @@
Welcome on the BowlingScoreApp project!
_Generated with a_ **Code#0** _template_
<img src="Documentation/doc_images/CodeFirst.png" height=40/>

@ -1,11 +0,0 @@
using System;
namespace HelloWorldLib
{
///<summary>
///a sample class
///</summary>
public class Class1
{
}
}

@ -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<Joueur> joueurs;
public string Nom
{
get { return nom; }
set { nom = value; }
}
public List<Joueur> Joueurs
{
get { return joueurs; }
set { joueurs = value; }
}
public Equipe(string nom)
{
this.nom = nom;
joueurs = new List<Joueur>();
}
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<Joueur> GetJoueurs()
{
return joueurs.AsReadOnly().ToList();
}
}
}

@ -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
{
}
}

@ -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;
}
}
}
}

@ -0,0 +1,6 @@
using System;
public interface Iloader
{
}

@ -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; }
}
}
}

@ -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;
}
}
}

@ -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<Frame> Frames { get; set; }
public Partie(Joueur joueur)
{
this.Joueur = joueur;
Frames = new List<Frame>();
}
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;
}
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BowlingLib\BowlingLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,26 @@
using BowlingLib.Model;
using System;
public class StubEquipe
{
private List<Equipe> listEquipes = new List<Equipe>();
public StubEquipe()
{
}
public List<Equipe> 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;
}
}

@ -0,0 +1,20 @@
using BowlingLib.Model;
using System;
public class StubJoueur
{
private List<Joueur> listJoueurs = new List<Joueur>();
public StubJoueur()
{
}
public List<Joueur> ListJoueurs(int n = 10)
{
for (int i = 0; i < n; i++)
{
listJoueurs.Add(new Joueur("Joueur " + i + 1));
}
return listJoueurs;
}
}

@ -0,0 +1,8 @@
namespace BowlingStub
{
public class StubPartie
{
}
}

@ -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

@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BowlingLib\BowlingLib.csproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BowlingLib\BowlingLib.csproj" />
</ItemGroup>
</Project>

@ -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);
}
}
}

@ -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<ArgumentException>(() => 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<ArgumentException>(
() => new Joueur(pseudo)
);
return;
}
Joueur j = new Joueur(pseudo);
Assert.Equal(expectedPseudo, j.Pseudo);
}
}
}

@ -0,0 +1,7 @@
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
}
Loading…
Cancel
Save