From 9e8677edcce263619499cd8518cc567ce06b16ee Mon Sep 17 00:00:00 2001 From: rportet Date: Sat, 13 Apr 2024 08:58:13 +0200 Subject: [PATCH] valide chgts --- Qwirkle/QwirkleClassLibrary/Board.cs | 2 + Qwirkle/QwirkleClassLibrary/Game.cs | 28 +++++++++++++- Qwirkle/QwirkleClassLibrary/IRules.cs | 16 ++++++++ Qwirkle/QwirkleClassLibrary/Tile.cs | 5 ++- Qwirkle/TestBase/TestTile.cs | 56 +++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 Qwirkle/QwirkleClassLibrary/IRules.cs create mode 100644 Qwirkle/TestBase/TestTile.cs diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Board.cs index 55af03d..4a208d6 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Board.cs @@ -10,6 +10,8 @@ namespace QwirkleClassLibrary public class Board { private List Cells; + public IReadOnlyCollection ReadCells { get; private set; } + ReadCells = Cells.AsReadOnly; public Board() { diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 35b479d..e5ee1f8 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -8,17 +8,41 @@ using System.Xml.Linq; namespace QwirkleClassLibrary { - public class Game + public class Game : IRules { private TileBag bag; private List players; private bool gameRunning; private Board board; + Board CreateBoard() + { + Board board = new Board(); + return board; + } + + bool isMoveCorrect(Tile t, Cell c) + { + Shape shape = t.GetShape; + Color color = t.GetColor; + + int x = c.GetX; + int y = c.GetY; + + for (int i = 0; i < n; i++) + { + if (board.Cells[i].GetX == x && board.Cells[i].GetY == y) + { + + } + } + + } + public Game() { this.players = new List(); - board = new Board(); + Board board = CreateBoard(); bag = new TileBag(3); gameRunning = false; } diff --git a/Qwirkle/QwirkleClassLibrary/IRules.cs b/Qwirkle/QwirkleClassLibrary/IRules.cs new file mode 100644 index 0000000..83180f4 --- /dev/null +++ b/Qwirkle/QwirkleClassLibrary/IRules.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QwirkleClassLibrary +{ + public interface IRules + { + Board CreateBoard(); + bool isMoveCorrect(Tile t, Cell c); + bool isGameOver(); + + } +} diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tile.cs index a2510a0..ea9c895 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tile.cs @@ -1,4 +1,5 @@ -using System; +using QwirkleClassLibrary; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -32,4 +33,4 @@ namespace QwirkleClassLibrary get { return this.color; } } } -} +} \ No newline at end of file diff --git a/Qwirkle/TestBase/TestTile.cs b/Qwirkle/TestBase/TestTile.cs new file mode 100644 index 0000000..29b3f30 --- /dev/null +++ b/Qwirkle/TestBase/TestTile.cs @@ -0,0 +1,56 @@ +using QwirkleClassLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestBase +{ + internal class TestTile + { + public class TestCorrect // test with correct Shape and Color + { + [Fact] + public void TestCreateCorrect() + { + Tile t = new Tile(Shape.Star, Color.Blue); + Assert.NotNull(t); + Assert.Equal(Shape.Star, t.GetShape); + Assert.Equal(Color.Blue, t.GetColor); + } + // Modifier plus tard avec [Theory] à la place de [Fact] pour tester avec toutes les Shape et Color possibles (voir vidéo) + } + + public class TestWrongColor // test with correct Shape but wrong Color + { + [Fact] + public void TestCreateWrongColor() + { + Tile t = new Tile(Shape.Rhombus, Color.Rainbow); + Assert.Fail(t); + } + } + public class TestWrongShape // test with wrong Shape but correct Color + { + [Fact] + public void TestCreateWrongShape() + { + bool result = new Tile(Shape.Hexagon, Color.Green); + Assert.False(result); + } + } + + public class TestWrongShapeWrongColor // test with wrong Sape and wrong Color + { + [Fact] + public void TestCreateWrongShapeWrongColor() + { + bool result = new Tile(Shape.Triangle, Color.Grey); + Assert.False(result); + } + } + + } +} +