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

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

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

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

Loading…
Cancel
Save