From eef064c3d67643b0e0ff9ea72623d61683af1dd4 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sat, 24 Sep 2022 16:59:25 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20des=20classes=20Frames,=20Lance?= =?UTF-8?q?r=20et=20Partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BowlingLib/Model/Frame.cs | 209 +++++++++++++++++++++++++++++ Sources/BowlingLib/Model/Lancer.cs | 34 +++++ Sources/BowlingLib/Model/Partie.cs | 57 ++++++++ 3 files changed, 300 insertions(+) create mode 100644 Sources/BowlingLib/Model/Frame.cs create mode 100644 Sources/BowlingLib/Model/Lancer.cs create mode 100644 Sources/BowlingLib/Model/Partie.cs diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs new file mode 100644 index 0000000..82fd0ac --- /dev/null +++ b/Sources/BowlingLib/Model/Frame.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Frame + { + private int numero; + private int score; + private int quillesRestantes; + private int quillesTombees; + private bool isStrike; + private bool isSpare; + private bool isFinished; + private Lancer lancer1; + private Lancer lancer2; + private Lancer lancer3; + + public int Numero + { + get { return numero; } + set { numero = value; } + } + + public int Score + { + get { return score; } + set { score = value; } + } + + public int QuillesRestantes + { + get { return quillesRestantes; } + set { quillesRestantes = value; } + } + + public int QuillesTombees + { + get { return quillesTombees; } + set { quillesTombees = value; } + } + + public bool IsStrike + { + get { return isStrike; } + set { isStrike = value; } + } + + public bool IsSpare + { + get { return isSpare; } + set { isSpare = value; } + } + + public bool IsFinished + { + get { return isFinished; } + set { isFinished = value; } + } + + public Lancer Lancer1 + { + get { return lancer1; } + set { lancer1 = value; } + } + + public Lancer Lancer2 + { + get { return lancer2; } + set { lancer2 = value; } + } + + public Lancer Lancer3 + { + get { return lancer3; } + set { lancer3 = value; } + } + + 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/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..c5d462e --- /dev/null +++ b/Sources/BowlingLib/Model/Partie.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Partie + { + private Joueur joueur; + private List frames; + + public Joueur Joueur + { + get { return joueur; } + set { joueur = value; } + } + + public List Frames + { + get { return frames; } + set { frames = value; } + } + + public Partie(Joueur joueur) + { + this.joueur = joueur; + frames = new List(); + } + + public void AddFrame(Frame frame) + { + frames.Add(frame); + } + + public int GetScore() + { + int score = 0; + foreach (Frame frame in frames) + { + score += frame.Score; + } + return score; + } + + public int GetScore(int frameNumber) + { + int score = 0; + for (int i = 0; i < frameNumber; i++) + { + score += frames[i].Score; + } + return score; + } + } +}