push of edit by jules
continuous-integration/drone/push Build is failing Details

test_old_branch
Jérémy Mouyon 12 months ago
commit 3d31a17ae3

@ -6,17 +6,16 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary
{ {
public class Game public class Game : IPlayer
{ {
private TileBag bag; private TileBag bag;
private bool gameRunning; public bool GameRunning { get; private set; }
private Board board; private Board board;
public ReadOnlyCollection<Player> PlayerList { get; private set; } public ReadOnlyCollection<Player> PlayerList { get; }
private readonly List<Player> players = new List<Player>(); private readonly List<Player> players;
public Game() public Game()
{ {
@ -27,11 +26,9 @@ namespace QwirkleClassLibrary
PlayerList = players.AsReadOnly(); PlayerList = players.AsReadOnly();
} }
public bool AddPlayerInGame(string? PlayerTag) public bool AddPlayerInGame(string? playerTag)
{ {
bool nameInvalid = string.IsNullOrWhiteSpace(PlayerTag); if (string.IsNullOrWhiteSpace(playerTag) == true || this.GameRunning == true)
if (nameInvalid == true || this.gameRunning == true || PlayerTag == null)
{ {
return false; return false;
} }
@ -41,32 +38,30 @@ namespace QwirkleClassLibrary
return false; return false;
} }
for (int i = 0; i < players.Count; i++) foreach (var p in players)
{ {
if (players[i].NameTag == PlayerTag) if (p.NameTag == playerTag)
{ {
return false; return false;
} }
} }
Player p = new Player(PlayerTag); players.Add(CreatePlayer(playerTag));
players.Add(p);
return true; return true;
} }
public bool StartGame() public Player CreatePlayer(string playerTag)
{ {
if (players.Count < 2) var player = new Player(playerTag);
{ return player;
return false;
} }
this.gameRunning = true; public void StartGame()
return true; {
this.GameRunning = true;
} }
public int GetPlayingPlayerPosition() public int GetPlayingPlayerPosition()
{ {
for (int i = 0; i < players.Count; i++) for (int i = 0; i < players.Count; i++)
@ -79,80 +74,72 @@ namespace QwirkleClassLibrary
return -1; return -1;
} }
public int GetNbPlayers
{
get { return players.Count; }
}
public Tile TileOfPlayerWithPos(int postile) public Tile TileOfPlayerWithPos(int postile)
{ {
return players[GetPlayingPlayerPosition()].Tiles[postile]; return players[GetPlayingPlayerPosition()].Tiles[postile];
} }
public void SetNextPlayer(int old, int neew) public void GiveTilesToPlayers()
{ {
foreach (var p in players)
if (old >= 0 || old != -1)
{
players[old].IsPlaying = false;
}
players[neew].IsPlaying = true;
}
public void TilsBagPlayer()
{
for (int i = 0; i < players.Count; i++)
{ {
for (int j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
{ {
Random random = new Random(); Random random = new Random();
int val = random.Next(0, bag.TilesBag.Count); int val = random.Next(0, bag.TilesBag.Count);
Tile tile = bag.TilesBag[val];
players[i].AddTilePlayer(tile); p.AddTileToPlayer(bag.TilesBag[val]);
bag.RemoveTileInBag(tile); bag.RemoveTileInBag(bag.TilesBag[val]);
} }
} }
} }
public string NextPlayer() public bool PlaceTileGame(Tile tile, int x, int y)
{ {
int posPlayerPlay = GetPlayingPlayerPosition(); bool checkremove = false;
bool checkaddcell = board.AddTileInCell(x, y, tile);
int posPlayerNextPlay = GetPlayingPlayerPosition() + 1; if (checkaddcell == true)
if (posPlayerNextPlay > GetNbPlayers)
{ {
posPlayerNextPlay = 0; checkremove = players[GetPlayingPlayerPosition()].RemoveTileToPlayer(tile);
} }
SetNextPlayer(posPlayerPlay, posPlayerNextPlay); if (checkaddcell == checkremove)
{
return (players[posPlayerNextPlay].NameTag); return checkaddcell;
}
return false;
} }
public bool GameRunning public string SetFirstPlayer()
{ {
get { return gameRunning; } players[0].IsPlaying = true;
return players[0].NameTag;
} }
public bool PlaceTileGame(Tile tile, int x, int y) public string SetNextPlayer()
{ {
bool checkremove=false; int i = GetPlayingPlayerPosition();
bool checkaddcell = board.AddTileInCell(x, y, tile);
if (checkaddcell == true) if (i == -1)
{ {
checkremove = players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile); return SetFirstPlayer();
} }
if (checkaddcell == checkremove) players[i].IsPlaying = false;
{ players[(i + 1) % players.Count].IsPlaying = true;
return checkaddcell;
return players[GetPlayingPlayerPosition()].NameTag;
} }
return false;
public void PlaceTile(Player player, Tile tile, int x, int y)
{
throw new NotImplementedException();
} }
public bool ContinueToPlay()
{
throw new NotImplementedException();
}
} }

@ -4,7 +4,7 @@ public interface IPlayer
{ {
public Player CreatePlayer(string playerTag); public Player CreatePlayer(string playerTag);
public void SetNextPlayer(List<Player> players); public string SetNextPlayer();
public void PlaceTile(Player player, Tile tile, int x, int y); public void PlaceTile(Player player, Tile tile, int x, int y);

@ -25,16 +25,16 @@ namespace QwirkleClassLibrary
Tiles = playerTiles.AsReadOnly(); Tiles = playerTiles.AsReadOnly();
} }
public string NameTag { get; set; } public string NameTag { get; }
public bool IsPlaying { get; set; } = false; public bool IsPlaying { get; set; } = false;
public void AddTilePlayer(Tile tile) public void AddTileToPlayer(Tile tile)
{ {
playerTiles.Add(tile); playerTiles.Add(tile);
} }
public bool RemoveTilePlayer(Tile tile) public bool RemoveTileToPlayer(Tile tile)
{ {
return playerTiles.Remove(tile); return playerTiles.Remove(tile);
} }

@ -4,55 +4,60 @@ using System.Text;
using System.Transactions; using System.Transactions;
using static System.Console; using static System.Console;
static void AddPlayers(Game game)
static void addPlayer(Game game)
{ {
string? enterline = ""; while (game.PlayerList.Count < 4)
{
Write("Enter player tag : ");
string? playerTag = ReadLine();
do if (game.AddPlayerInGame(playerTag) == false)
{ {
WriteLine("Enter name of player (enter quit to quit) : "); WriteLine("ERROR : Player already exist or game is running !");
enterline = ReadLine(); }
if (enterline != "quit") else
{
WriteLine("Player " + playerTag + " added !");
}
Write("Do you want to add another player ? (y/n) : ");
string? answer = ReadLine();
if (answer == "n" && game.PlayerList.Count >= 2)
{ {
bool r = game.AddPlayerInGame(enterline); break;
if (r == false) }
if (answer == "n" && game.PlayerList.Count < 2)
{ {
WriteLine("ERROR : Name is invalid."); WriteLine("ERROR : You must have at least 2 players !");
} }
} }
} while (game.PlayerList.Count<4 && enterline !="quit");
} }
static void MainMenu(Game game) static void MainMenu(Game game)
{ {
game.TilsBagPlayer(); game.GiveTilesToPlayers();
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Write("The loading of the game is well done! Good game :p\n"); WriteLine("Game is starting !");
Console.ResetColor(); Console.ResetColor();
do do
{ {
String TagPlayerPlay; string tagPlayerPlay = game.SetNextPlayer();
TagPlayerPlay = game.NextPlayer();
Write(" --------------------- GAME ! ------------------------ \n");
Write(TagPlayerPlay + " you have main now ! \n"); WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
MenuSwitch(game); 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 :) } while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
} }
static void ShowTiles(Game game) static void ShowTiles(Game game)
{ {
Write("\n --------------------- YOUR TILES ------------------------ \n"); WriteLine("\n --------------------- YOUR TILES ------------------------");
int pos = game.GetPlayingPlayerPosition(); int pos = game.GetPlayingPlayerPosition();
@ -72,15 +77,16 @@ static void MenuSwitch(Game game)
{ {
int enter = 0; int enter = 0;
do
while (enter != 3)
{ {
ShowTiles(game); ShowTiles(game);
Write("\n --------------------- CHOICES ------------------------ \n"); WriteLine("\n --------------------- CHOICES ------------------------");
Write("[1] Place your tiles \n"); WriteLine("[1] Place your tiles");
Write("[2] Swap your tiles \n"); WriteLine("[2] Swap your tiles");
Write("[3] Skip \n"); WriteLine("[3] Skip your turn");
enter = Convert.ToInt32(ReadLine()); enter = Convert.ToInt32(ReadLine());
@ -95,7 +101,8 @@ static void MenuSwitch(Game game)
return; return;
} }
} while (enter != 3);
}
} }
@ -134,29 +141,17 @@ static void MainGame()
{ {
Game game = new Game(); Game game = new Game();
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.BackgroundColor = ConsoleColor.DarkGreen; WriteLine(" ===================== WELCOME TO QWIRKLE ! =====================");
Write("WELCOME IN QWIRKLE GAME ! \n For start the game please enter 2 / 4 players ;) \n \n"); WriteLine("Enter the players' nametags (2 to 4 players) : ");
Console.ResetColor(); Console.ResetColor();
addPlayer(game);
game.StartGame(); AddPlayers(game);
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(); game.StartGame();
}
MainMenu(game); MainMenu(game);
} }
MainGame(); MainGame();

@ -26,7 +26,7 @@ namespace TestBase
Tile tile = new Tile(Shape.Round, Color.Orange); Tile tile = new Tile(Shape.Round, Color.Orange);
p.AddTilePlayer(tile); p.AddTileToPlayer(tile);
bool r = false; bool r = false;
@ -48,7 +48,7 @@ namespace TestBase
Tile tile = new Tile(Shape.Round, Color.Orange); Tile tile = new Tile(Shape.Round, Color.Orange);
p.RemoveTilePlayer(tile); p.RemoveTileToPlayer(tile);
bool r = true; bool r = true;

Loading…
Cancel
Save