Updated the player's narrow gameplay with PlaceTile on Game.cs and made Program.cs acceptable
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 12 months ago
parent 825ef75557
commit 4bdc3eeb5d

@ -59,6 +59,11 @@ namespace QwirkleClassLibrary
{ {
this.GameRunning = true; this.GameRunning = true;
} }
public Player GetPlayingPlayer()
{
return players[GetPlayingPlayerPosition()];
}
public int GetPlayingPlayerPosition() public int GetPlayingPlayerPosition()
{ {
@ -91,22 +96,6 @@ namespace QwirkleClassLibrary
} }
} }
public bool PlaceTileGame(Tile tile, int x, int y)
{
bool checkremove = false;
bool checkaddcell = board.AddTileInCell(x, y, tile);
if (checkaddcell == true)
{
checkremove = players[GetPlayingPlayerPosition()].RemoveTileToPlayer(tile);
}
if (checkaddcell == checkremove)
{
return checkaddcell;
}
return false;
}
public string SetFirstPlayer() public string SetFirstPlayer()
{ {
players[0].IsPlaying = true; players[0].IsPlaying = true;
@ -128,18 +117,40 @@ namespace QwirkleClassLibrary
return players[GetPlayingPlayerPosition()].NameTag; return players[GetPlayingPlayerPosition()].NameTag;
} }
public void PlaceTile(Player player, Tile tile, int x, int y) public bool PlaceTile(Player player, Tile tile, int x, int y)
{ {
throw new NotImplementedException(); if (board.AddTileInCell(x, y, tile) == true)
{
return player.RemoveTileToPlayer(tile) == true;
}
else
{
return false;
}
} }
public bool ContinueToPlay() public bool SwapTiles(Player player)
{ {
throw new NotImplementedException(); if (bag.TilesBag.Count < 6)
} {
} return false;
}
for (int i = 0; i < player.Tiles.Count; i++)
{
Random random = new Random();
int val = random.Next(0, bag.TilesBag.Count);
player.AddTileToPlayer(bag.TilesBag[val]);
bag.RemoveTileInBag(bag.TilesBag[val]);
}
} return true;
}
public bool DrawTile(Player player)
{
return true;
}
}
}

@ -6,7 +6,9 @@ public interface IPlayer
public string SetNextPlayer(); public string SetNextPlayer();
public void PlaceTile(Player player, Tile tile, int x, int y); public bool PlaceTile(Player player, Tile tile, int x, int y);
public bool ContinueToPlay(); public bool SwapTiles(Player player);
public bool DrawTile(Player player);
} }

@ -34,48 +34,55 @@ static void AddPlayers(Game game)
} }
} }
static void MainMenu(Game game)
{
game.GiveTilesToPlayers();
Console.ForegroundColor = ConsoleColor.Green;
WriteLine("Game is starting !");
Console.ResetColor();
do
{
string tagPlayerPlay = game.SetNextPlayer();
WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
MenuSwitch(game);
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
}
static void ShowTiles(Game game) static void ShowTiles(Game game)
{ {
WriteLine("\n --------------------- YOUR TILES ------------------------"); WriteLine("\n --------------------- YOUR TILES ------------------------");
int pos = game.GetPlayingPlayerPosition(); var currentPlayer = game.GetPlayingPlayer();
StringBuilder stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++) for (int i = 0; i < currentPlayer.Tiles.Count(); i++)
{ {
stringBuilder.Append("[" + (i+1) + "] "); stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString()); stringBuilder.AppendLine(currentPlayer.Tiles[i].ToString());
} }
Write(stringBuilder); Write(stringBuilder);
}
static void AddTile(Game game)
{
Tile? tile = null;
Write("Enter the number of the tile you want to place : ");
int no = Convert.ToInt32(ReadLine());
while (no < 1 || no > 6)
{
Write("ERROR : Enter a number between 1 and 6 ! : ");
no = Convert.ToInt32(ReadLine());
}
tile = game.TileOfPlayerWithPos(no - 1);
Write("Enter the x of the cell: ");
int x = Convert.ToInt32(ReadLine());
Write("Enter the y of the cell : ");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true)
{
WriteLine("ok ! your tile is placed");
}
else
{
WriteLine("ERROR : Cell already used");
}
} }
static void MenuSwitch(Game game) static void MenuSwitch(Game game)
{ {
int enter = 0; int enter = 0;
while (enter != 3) while (enter != 3)
@ -93,48 +100,34 @@ static void MenuSwitch(Game game)
switch (enter) switch (enter)
{ {
case 1: case 1:
CaseOneAddTile(game); AddTile(game);
break; break;
case 2: case 2:
break; break;
case 3: case 3:
return; return;
} }
} }
} }
static void CaseOneAddTile(Game game) static void MainMenu(Game game)
{ {
Tile? tile = null; game.GiveTilesToPlayers();
Write("Enter no tile : ");
int no = Convert.ToInt32(ReadLine());
if (no >= 0 && no <= 5) Console.ForegroundColor = ConsoleColor.Green;
WriteLine("Game is starting !");
Console.ResetColor();
do
{ {
tile = game.TileOfPlayerWithPos(no+1); string tagPlayerPlay = game.SetNextPlayer();
Write("Enter x : ");
int x = Convert.ToInt32(ReadLine()); WriteLine(" --------------------- GAME ! ------------------------");
Write("Enter y : "); WriteLine(tagPlayerPlay + "'s turn !");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTileGame(tile, x, y) == true)
{
Write("ok ! your tile is placed \n");
} MenuSwitch(game);
else
{
Write("ERROR : Cell already use \n");
}
}
else
{
Write("No is out of range\n");
}
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
} }
static void MainGame() static void MainGame()
@ -151,7 +144,6 @@ static void MainGame()
game.StartGame(); game.StartGame();
MainMenu(game); MainMenu(game);
} }
MainGame(); MainGame();

Loading…
Cancel
Save