Merge remote-tracking branch 'origin/master'
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
commit cb8ef11c0e

@ -0,0 +1,12 @@
namespace QwirkleClassLibrary
{
public class AddPlayerNotifiedEventArgs : EventArgs
{
public string returnedNotified { get; private set; }
public AddPlayerNotifiedEventArgs(string returnedNotified)
{
this.returnedNotified = returnedNotified;
}
}
}

@ -22,27 +22,43 @@ namespace QwirkleClassLibrary
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
private readonly List<Player> players = new();
public ReadOnlyCollection<Score> ScoreList => scores.AsReadOnly();
private readonly List<Score> scores = new();
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
private readonly List<Cell> cellUsed = new();
public event EventHandler<AddPlayerNotifiedEventArgs>? PlayerAddNotified;
protected virtual void OnPlayerNotified(AddPlayerNotifiedEventArgs args)
=> PlayerAddNotified?.Invoke(this, args);
public event EventHandler<NextPlayerNotifiedEventArgs>? NextPlayerNotified;
protected virtual void OnNextPlayer(NextPlayerNotifiedEventArgs args)
=> NextPlayerNotified?.Invoke(this, args);
public Game()
{
bag = CreateTileBag(3);
board = CreateBoard();
}
public bool AddPlayerInGame(string? playerTag)
{
if (string.IsNullOrWhiteSpace(playerTag) == true || this.GameRunning == true)
if (string.IsNullOrWhiteSpace(playerTag) == true)
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The name is null or white space."));
return false;
}
if(this.GameRunning == true)
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running."));
return false;
}
if (players.Count >= 4)
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is full."));
return false;
}
@ -50,19 +66,22 @@ namespace QwirkleClassLibrary
{
if (p.NameTag == playerTag)
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : Name alreay taken"));
return false;
}
}
players.Add(CreatePlayer(playerTag));
scores.Add(new Score(players[players.Count - 1]));
//scores.Add(new Score(players[players.Count-1]));
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Player was correctly added"));
return true;
}
public Player CreatePlayer(string playerTag)
{
var player = new Player(playerTag);
return player;
}
@ -142,6 +161,7 @@ namespace QwirkleClassLibrary
if (GameRunning == true)
{
players[0].IsPlaying = true;
//OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
return players[0].NameTag;
}
else
@ -162,6 +182,7 @@ namespace QwirkleClassLibrary
players[i].IsPlaying = false;
players[(i + 1) % players.Count].IsPlaying = true;
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[i]));
return players[GetPlayingPlayerPosition()].NameTag;
}

@ -0,0 +1,12 @@
namespace QwirkleClassLibrary
{
public class NextPlayerNotifiedEventArgs : EventArgs
{
public Player player { get; set; }
public NextPlayerNotifiedEventArgs(Player player)
{
this.player = player;
}
}
}

@ -0,0 +1,22 @@
using QwirkleClassLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QwirkleConsoleApp
{
class NotificationClass
{
public void NotificationPlayerAdd(object? sender, AddPlayerNotifiedEventArgs args)
{
Console.WriteLine(args.returnedNotified);
}
public void NotificationNextPlayer(object? sender, NextPlayerNotifiedEventArgs args)
{
Console.WriteLine(args.player.NameTag + "'s turn");
}
}
}

@ -1,24 +1,23 @@
using QwirkleClassLibrary;
using QwirkleConsoleApp;
using System.Net.Quic;
using System.Text;
using System.Transactions;
using static System.Console;
static void AddPlayers(Game game)
{
NotificationClass nc = new NotificationClass();
game.PlayerAddNotified += nc.NotificationPlayerAdd;
while (game.PlayerList.Count < 4)
{
Write("Enter player tag : ");
string? playerTag = ReadLine();
if (game.AddPlayerInGame(playerTag) == false)
{
WriteLine("ERROR : Player already exist or game is running !");
}
else
{
WriteLine("Player " + playerTag + " added !");
}
game.AddPlayerInGame(playerTag);
Write("Do you want to add another player ? (y/n) : ");
string? answer = ReadLine();
@ -138,7 +137,14 @@ static void MenuSwitch(Game game)
WriteLine("[2] Swap your tiles");
WriteLine("[3] End your turn / Skip your turn");
try
{
enter = Convert.ToInt32(ReadLine());
}
catch {
WriteLine("ERROR : You must type (1 / 2 / 3). Please retry : ");
}
switch (enter)
{
@ -188,12 +194,14 @@ static void MainMenu(Game game)
WriteLine("Game is starting !");
Console.ResetColor();
NotificationClass nc = new NotificationClass();
game.NextPlayerNotified += nc.NotificationNextPlayer;
do
{
string tagPlayerPlay = game.SetNextPlayer();
game.SetNextPlayer();
WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
game.DrawTiles(game.GetPlayingPlayer());
MenuSwitch(game);

Loading…
Cancel
Save