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

@ -60,6 +60,11 @@ namespace QwirkleClassLibrary
this.GameRunning = true;
}
public Player GetPlayingPlayer()
{
return players[GetPlayingPlayerPosition()];
}
public int GetPlayingPlayerPosition()
{
for (int i = 0; i < players.Count; i++)
@ -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()
{
players[0].IsPlaying = true;
@ -128,18 +117,40 @@ namespace QwirkleClassLibrary
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;
}
public bool ContinueToPlay()
else
{
throw new NotImplementedException();
return false;
}
}
public bool SwapTiles(Player player)
{
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 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
static void ShowTiles(Game game)
{
string tagPlayerPlay = game.SetNextPlayer();
WriteLine("\n --------------------- YOUR TILES ------------------------");
WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
var currentPlayer = game.GetPlayingPlayer();
MenuSwitch(game);
var stringBuilder = new StringBuilder();
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
for (int i = 0; i < currentPlayer.Tiles.Count(); i++)
{
stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(currentPlayer.Tiles[i].ToString());
}
Write(stringBuilder);
}
static void ShowTiles(Game game)
static void AddTile(Game game)
{
WriteLine("\n --------------------- YOUR TILES ------------------------");
int pos = game.GetPlayingPlayerPosition();
StringBuilder stringBuilder = new StringBuilder();
Tile? tile = null;
Write("Enter the number of the tile you want to place : ");
int no = Convert.ToInt32(ReadLine());
for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++)
while (no < 1 || no > 6)
{
stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString());
Write("ERROR : Enter a number between 1 and 6 ! : ");
no = Convert.ToInt32(ReadLine());
}
Write(stringBuilder);
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)
{
int enter = 0;
while (enter != 3)
@ -93,48 +100,34 @@ static void MenuSwitch(Game game)
switch (enter)
{
case 1:
CaseOneAddTile(game);
AddTile(game);
break;
case 2:
break;
case 3:
return;
}
}
}
static void CaseOneAddTile(Game game)
static void MainMenu(Game game)
{
Tile? tile = null;
Write("Enter no tile : ");
int no = Convert.ToInt32(ReadLine());
game.GiveTilesToPlayers();
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");
Console.ForegroundColor = ConsoleColor.Green;
WriteLine("Game is starting !");
Console.ResetColor();
}
else
{
Write("ERROR : Cell already use \n");
}
}
else
do
{
Write("No is out of range\n");
}
string tagPlayerPlay = game.SetNextPlayer();
WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
MenuSwitch(game);
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
}
static void MainGame()
@ -151,7 +144,6 @@ static void MainGame()
game.StartGame();
MainMenu(game);
}
MainGame();
Loading…
Cancel
Save