rportet 1 year ago
commit a2ee132f45

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable All
namespace QwirkleClassLibrary
{
@ -21,7 +21,7 @@ namespace QwirkleClassLibrary
{
for (int j = 0; j < 12; j++)
{
var localcell = new Cell(i, j);
Cell localcell = new(i, j);
Cells.Add(localcell);
}
}
@ -38,11 +38,6 @@ namespace QwirkleClassLibrary
return Cells[i].SetTile(tile);
}
else
{
return false;
}
}
}
return false;

@ -11,6 +11,11 @@ public class Cell
public Cell(int x, int y)
{
if (x < 0 || y < 0)
{
throw new ArgumentException(x.ToString() + y.ToString());
}
this.x = x;
this.y = y;
}
@ -37,7 +42,7 @@ public class Cell
public bool SetTile(Tile addedTile)
{
if(tile == null)
if(this.tile == null)
{
tile = addedTile;
return true;

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,9 +12,10 @@ namespace QwirkleClassLibrary
public class Game : IRules
{
private TileBag bag;
private List<Player> players;
private bool gameRunning;
private Board board;
public ReadOnlyCollection<Player> PlayerList { get; private set; }
private readonly List<Player> players = new List<Player>();
Board CreateBoard()
{
@ -43,8 +45,11 @@ namespace QwirkleClassLibrary
{
this.players = new List<Player>();
Board board = CreateBoard();
board = new Board();
bag = new TileBag(3);
Console.Write(bag.TilesBag.Count);
gameRunning = false;
PlayerList = players.AsReadOnly();
}
public bool AddPlayerInGame(string? PlayerTag)
@ -104,24 +109,6 @@ namespace QwirkleClassLibrary
get { return players.Count; }
}
public List<Tile> ListTilesBag
{
get { return bag.TilesInBag(); }
}
public string ShowTileOfPlayer(int posplayer)
{
List<Tile> tiles = players[posplayer].Tiles;
string r = ("Tile of " + posplayer + " : ");
foreach (Tile tile in tiles)
{
r = (r + " " + tile.NameColorTile());
}
return r;
}
public Tile TileOfPlayerWithPos(int postile)
{
@ -145,7 +132,9 @@ namespace QwirkleClassLibrary
{
for (int j = 0; j < 6; j++)
{
Tile tile = ListTilesBag[j];
Random random = new Random();
int val = random.Next(0, bag.TilesBag.Count);
Tile tile = bag.TilesBag[val];
players[i].AddTilePlayer(tile);
bag.RemoveTileInBag(tile);
}
@ -158,7 +147,7 @@ namespace QwirkleClassLibrary
int posPlayerNextPlay = GetPlayingPlayerPosition() + 1;
if (posPlayerNextPlay >= GetNbPlayers)
if (posPlayerNextPlay > GetNbPlayers)
{
posPlayerNextPlay = 0;
}
@ -175,9 +164,18 @@ namespace QwirkleClassLibrary
public bool PlaceTileGame(Tile tile, int x, int y)
{
bool r = board.AddTileInCell(x, y, tile);
players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile);
return r;
bool checkremove=false;
bool checkaddcell = board.AddTileInCell(x, y, tile);
if (checkaddcell == true)
{
checkremove = players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile);
}
if (checkaddcell == checkremove)
{
return checkaddcell;
}
return false;
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -9,12 +10,18 @@ namespace QwirkleClassLibrary
public class Player
{
private string nameTag;
private List<Tile> playerTiles;
public ReadOnlyCollection<Tile> Tiles { get; private set; }
private readonly List<Tile> playerTiles = new List<Tile>();
public Player(string name)
{
if(name==null || string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name");
}
nameTag = name;
Tiles = new List<Tile>();
playerTiles = new List<Tile>();
Tiles = playerTiles.AsReadOnly();
}
public string GetNameTag
@ -27,17 +34,13 @@ namespace QwirkleClassLibrary
public void AddTilePlayer(Tile tile)
{
Tiles.Add(tile);
playerTiles.Add(tile);
}
public bool RemoveTilePlayer(Tile tile)
{
return Tiles.Remove(tile);
return playerTiles.Remove(tile);
}
public List<Tile> Tiles
{
get;
}
}
}

@ -32,5 +32,10 @@ namespace QwirkleClassLibrary
{
get { return this.color; }
}
public override string ToString()
{
return shape.ToString() + color.ToString();
}
}
}

@ -9,7 +9,7 @@ namespace QwirkleClassLibrary
{
public class TileBag
{
public ReadOnlyCollection<Tile> Tiles { get ; private set; }
public ReadOnlyCollection<Tile> TilesBag { get ; private set; }
private readonly List<Tile> tiles = new List<Tile>();
public TileBag(int nbSet)
@ -25,6 +25,7 @@ namespace QwirkleClassLibrary
}
}
}
TilesBag = tiles.AsReadOnly();
}
public void RemoveTileInBag(Tile tile)
@ -37,11 +38,6 @@ namespace QwirkleClassLibrary
}
}
}
public List<Tile> TilesInBag()
{
return tiles;
}
}
}

@ -1,10 +1,12 @@
using QwirkleClassLibrary;
using System.Net.Quic;
using System.Text;
using System.Transactions;
using static System.Console;
static void testJeremy()
{
Game game = new Game();
static void addPlayer(Game game)
{
string? enterline = "";
do
@ -20,69 +22,141 @@ static void testJeremy()
}
}
} while (enterline != "quit");
} while (game.PlayerList.Count<4 && enterline !="quit");
}
game.StartGame();
static void MainMenu(Game game)
{
game.TilsBagPlayer();
Console.ForegroundColor = ConsoleColor.Green;
Write("The loading of the game is well done! Good game :p\n");
Console.ResetColor();
if (game.GameRunning == true)
do
{
game.TilsBagPlayer();
String TagPlayerPlay;
TagPlayerPlay = game.NextPlayer();
Write(" --------------------- GAME ! ------------------------ \n");
Write(TagPlayerPlay + " you have main now ! \n");
string s = game.ShowTileOfPlayer(game.GetPlayingPlayerPosition());
Write(s + "\n");
MenuSwitch(game);
} while (game.GetPlayingPlayerPosition() != 3); // cette boucle permet juste de faire un tour, quand le score fonctionnera il faudra la faire arreter quand la partie sera finis :)
}
static void ShowTiles(Game game)
{
Write("\n --------------------- YOUR TILES ------------------------ \n");
int pos = game.GetPlayingPlayerPosition();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++)
{
stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString());
}
Write(stringBuilder);
}
static void MenuSwitch(Game game)
{
int enter = 0;
do
{
ShowTiles(game);
Write("\n --------------------- CHOICES ------------------------ \n");
Write("[1] Place your tiles \n");
Write("[2] Swap your tiles \n");
Write("[3] Skip \n");
int enter = Convert.ToInt32(ReadLine());
Tile tile = null;
enter = Convert.ToInt32(ReadLine());
switch (enter)
{
case 1:
// si good faire des boucles demain
Write("Enter no tile : ");
int no = Convert.ToInt32(ReadLine());
if (no >= 0 && no <= 5)
{
tile = game.TileOfPlayerWithPos(no);
Write("Enter x : ");
int x = Convert.ToInt32(ReadLine());
Write("Enter y : ");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTileGame(tile, x, y) == true)
{
Write("ok ! your tile is placed \n");
}
else
{
Write("no no no \n");
}
}
else
{
Write("No is out of range\n");
}
CaseOneAddTile(game);
break;
case 2:
break;
case 3:
return;
}
} while (enter != 3);
}
static void CaseOneAddTile(Game game)
{
Tile? tile = null;
Write("Enter no tile : ");
int no = Convert.ToInt32(ReadLine());
if (no >= 0 && no <= 5)
{
tile = game.TileOfPlayerWithPos(no+1);
Write("Enter x : ");
int x = Convert.ToInt32(ReadLine());
Write("Enter y : ");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTileGame(tile, x, y) == true)
{
Write("ok ! your tile is placed \n");
}
else
{
Write("ERROR : Cell already use \n");
}
}
else
{
Write("No is out of range\n");
}
}
static void MainGame()
{
Game game = new Game();
Console.BackgroundColor = ConsoleColor.DarkGreen;
Write("WELCOME IN QWIRKLE GAME ! \n For start the game please enter 2 / 4 players ;) \n \n");
Console.ResetColor();
addPlayer(game);
game.StartGame();
while (game.GameRunning == false)
{
game = new Game();
Console.ForegroundColor= ConsoleColor.Red;
Write("ERROR : Please enter minimun 2 valid player ! \n");
Console.ResetColor();
addPlayer(game);
game.StartGame();
}
MainMenu(game);
}
testJeremy();
MainGame();

@ -0,0 +1,24 @@
using QwirkleClassLibrary;
namespace TestBase;
public class TestCell
{
[Theory]
[InlineData(true, 10, 20)]
[InlineData(false, -10, -10)]
[InlineData(false, 10, -10)]
[InlineData(false, -10, 10)]
public void Test_CellConstructor(bool isValid, int x, int y)
{
if (!isValid)
{
Assert.Throws<ArgumentException>(() => new Cell(x, y));
return;
}
Cell c = new Cell(x, y);
Assert.Equal(x, c.GetX);
Assert.Equal(y, c.GetY);
}
}

@ -2,14 +2,64 @@ using QwirkleClassLibrary;
namespace TestBase
{
public class UnitTest1
public class TestPlayers
{
public void Test_PlayerRemoveTile(bool expectedResult)
[Theory]
[InlineData(true, "Mathis")]
[InlineData(false, null)]
public void Test_CreatePlayer(bool isValid, string playertag)
{
Tile t = new Tile(Square, Red);
Player p = new Player("Patrick");
bool result = p.RemoveTilePlayer(t);
Assert.True(result);
if (!isValid)
{
Assert.Throws<ArgumentNullException>(() => new Player(playertag));
return;
}
Player player = new Player(playertag);
Assert.Equal(playertag, player.GetNameTag);
}
[Fact]
public void Test_AddTilePlayer()
{
Player p = new Player("cobaye");
Tile tile = new Tile(Shape.Round, Color.Orange);
p.AddTilePlayer(tile);
bool r = false;
for(int i = 0; i < p.Tiles.Count; i++)
{
if (p.Tiles[i] == tile)
{
r = true;
}
}
Assert.True(r);
}
[Fact]
public void Test_RemoveilePlayer()
{
Player p = new Player("cobaye");
Tile tile = new Tile(Shape.Round, Color.Orange);
p.RemoveTilePlayer(tile);
bool r = true;
for (int i = 0; i < p.Tiles.Count; i++)
{
if (p.Tiles[i] == tile)
{
r = false;
}
}
Assert.True(r);
}
}
}
Loading…
Cancel
Save