|
|
|
@ -1,134 +1,246 @@
|
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Models;
|
|
|
|
|
using Models.Events;
|
|
|
|
|
using Models.Exceptions;
|
|
|
|
|
using Models.Game;
|
|
|
|
|
using Models.Rules;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cell pos01 = new Cell(0,0);
|
|
|
|
|
Cell pos02 = new Cell(1,0);
|
|
|
|
|
Cell pos03 = new Cell(2,0);
|
|
|
|
|
Cell pos04 = new Cell(3,0);
|
|
|
|
|
Cell pos05 = new Cell(4,0); //4
|
|
|
|
|
|
|
|
|
|
Cell pos11 = new Cell(0, 1);
|
|
|
|
|
Cell pos12 = new Cell(1, 1);
|
|
|
|
|
Cell pos13 = new Cell(2, 1); //8
|
|
|
|
|
Cell pos14 = new Cell(3, 1);
|
|
|
|
|
Cell pos15 = new Cell(4, 1); //4
|
|
|
|
|
|
|
|
|
|
Cell pos21 = new Cell(0, 2); //8
|
|
|
|
|
Cell pos22 = new Cell(1, 2);
|
|
|
|
|
Cell pos23 = new Cell(2, 2);
|
|
|
|
|
Cell pos24 = new Cell(3, 2);
|
|
|
|
|
Cell pos25 = new Cell(4, 2); //4
|
|
|
|
|
|
|
|
|
|
Cell pos31 = new Cell(0, 3); //8
|
|
|
|
|
Cell pos32 = new Cell(1, 3);
|
|
|
|
|
Cell pos33 = new Cell(2, 3);
|
|
|
|
|
Cell pos34 = new Cell(3, 3);
|
|
|
|
|
Cell pos35 = new Cell(4, 3); //4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Cell> list = new List<Cell>();
|
|
|
|
|
list.Add(pos01);
|
|
|
|
|
list.Add(pos02);
|
|
|
|
|
list.Add(pos03);
|
|
|
|
|
list.Add(pos04);
|
|
|
|
|
list.Add(pos05);
|
|
|
|
|
|
|
|
|
|
list.Add(pos11);
|
|
|
|
|
list.Add(pos12);
|
|
|
|
|
list.Add(pos13);
|
|
|
|
|
list.Add(pos14);
|
|
|
|
|
list.Add(pos15);
|
|
|
|
|
|
|
|
|
|
list.Add(pos21);
|
|
|
|
|
list.Add(pos22);
|
|
|
|
|
list.Add(pos23);
|
|
|
|
|
list.Add(pos24);
|
|
|
|
|
list.Add(pos25);
|
|
|
|
|
|
|
|
|
|
list.Add(pos31);
|
|
|
|
|
list.Add(pos32);
|
|
|
|
|
list.Add(pos33);
|
|
|
|
|
list.Add(pos34);
|
|
|
|
|
list.Add(pos35);
|
|
|
|
|
|
|
|
|
|
Player p2 = new Player("Luka");
|
|
|
|
|
|
|
|
|
|
Game game = new Game(p2, new Map("background"));
|
|
|
|
|
|
|
|
|
|
game.UsedMap.Boards = list;
|
|
|
|
|
|
|
|
|
|
game.PlaceResult(pos02, 5);
|
|
|
|
|
game.PlaceResult(pos03, 5);
|
|
|
|
|
game.PlaceResult(pos32, 5);
|
|
|
|
|
|
|
|
|
|
game.PlaceResult(pos31, 8);
|
|
|
|
|
game.PlaceResult(pos21, 8);
|
|
|
|
|
game.PlaceResult(pos21, 8);
|
|
|
|
|
game.PlaceResult(pos13, 8);
|
|
|
|
|
|
|
|
|
|
game.PlaceResult(pos05, 4);
|
|
|
|
|
game.PlaceResult(pos15, 4);
|
|
|
|
|
game.PlaceResult(pos25, 4);
|
|
|
|
|
game.PlaceResult(pos35, 4);
|
|
|
|
|
|
|
|
|
|
int cpt = 0;
|
|
|
|
|
/*
|
|
|
|
|
foreach (var item in game.UsedMap.Boards)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" | ");
|
|
|
|
|
Console.Write(item.Value);
|
|
|
|
|
cpt++;
|
|
|
|
|
if (cpt % 4 == 0) Console.Write(" |\n");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i<game.UsedMap.Boards.Count; i++)
|
|
|
|
|
|
|
|
|
|
namespace ConsoleApp;
|
|
|
|
|
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" | ");
|
|
|
|
|
Console.Write(game.UsedMap.Boards[i].Value);
|
|
|
|
|
cpt++;
|
|
|
|
|
if (cpt % 5 == 0) Console.Write(" |\n");
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Main function of the console app
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args"></param>
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Enter your pseudo:");
|
|
|
|
|
string? pseudo = Console.ReadLine();
|
|
|
|
|
if (pseudo != null)
|
|
|
|
|
{
|
|
|
|
|
Player player = new Player(pseudo);
|
|
|
|
|
|
|
|
|
|
Map map = new Map("background");
|
|
|
|
|
Game game = new Game(player, map);
|
|
|
|
|
|
|
|
|
|
// Abonnement aux événements
|
|
|
|
|
game.GameStarted += OnGameStarted!;
|
|
|
|
|
game.GameEnded += OnGameEnded!;
|
|
|
|
|
game.BoardUpdated += OnBoardUpdated!;
|
|
|
|
|
game.DiceRolled += OnDiceRolled!;
|
|
|
|
|
game.OperationChosen += OnOperationChosen!;
|
|
|
|
|
game.CellChosen += OnCellChosen!;
|
|
|
|
|
|
|
|
|
|
// Initialisation
|
|
|
|
|
game.InitializeGame();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos02, game.UsedMap);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when the game has started.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnGameStarted(object sender, GameStartedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"The game has started! Player: {e.CurrentPlayer.Pseudo}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos31, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when the game has ended.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnGameEnded(object sender, GameEndedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"The game has ended! Player: {e.CurrentPlayer.Pseudo}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//foreach(var oui in game.GameRules.EveryAdjacentCells(pos13, game.UsedMap.Boards)) //du débug
|
|
|
|
|
//{
|
|
|
|
|
// Console.WriteLine(oui.Value);
|
|
|
|
|
//}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when the board is updated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnBoardUpdated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DisplayBoard(((Game)sender).UsedMap);
|
|
|
|
|
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos32, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos33, game.UsedMap);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when the dice are rolled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnDiceRolled(object sender, DiceRolledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Dice 1: {e.Dice1Value} | Dice 2: {e.Dice2Value}");
|
|
|
|
|
Operation playerOperation = GetPlayerOperation();
|
|
|
|
|
((Game)sender).HandlePlayerOperation(playerOperation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos05, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos15, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos25, game.UsedMap);
|
|
|
|
|
game.GameRules.IsZoneValidAndAddToZones(pos35, game.UsedMap);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when an operation is chosen by the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnOperationChosen(object sender, OperationChosenEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}");
|
|
|
|
|
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid);
|
|
|
|
|
Cell playerChoice = GetPlayerChoice();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidCellCoordinatesException err)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(err.Message);
|
|
|
|
|
playerChoice = GetPlayerChoice();
|
|
|
|
|
((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidCellException err)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(err.Message);
|
|
|
|
|
playerChoice = GetPlayerChoice();
|
|
|
|
|
((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event when a cell is chosen by the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
static void OnCellChosen(object sender, CellChosenEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Cell chosen: ({e.Cell.X}, {e.Cell.Y}) with result: {e.Result}");
|
|
|
|
|
DisplayBoard(((Game)sender).UsedMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//affichage des zones
|
|
|
|
|
foreach (var item in game.UsedMap.Zones)
|
|
|
|
|
{
|
|
|
|
|
foreach (var cell in item)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays the game board.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="map">Used map to display</param>
|
|
|
|
|
static void DisplayBoard(Map map)
|
|
|
|
|
{
|
|
|
|
|
int cpt = 0;
|
|
|
|
|
for (int i = 0; i < map.Boards.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (cpt % 6 == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("| ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (map.Boards[i].Value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(map.Boards[i].Value?.ToString().PadLeft(2));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" O");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cpt++;
|
|
|
|
|
if (cpt % 6 == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" |");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays the operation table.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="operationTable">The operation table to display.</param>
|
|
|
|
|
static void DisplayOperationTable(List<OperationCell> operationTable)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(cell.Value);
|
|
|
|
|
Console.WriteLine("Operation Table:");
|
|
|
|
|
string[] operations = { "Addition (+)", "Subtraction (-)", "Multiplication (*)", "Lower Dice (less)", "Higher Dice (high)" };
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < operations.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(operations[i].PadRight(18));
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
|
{
|
|
|
|
|
int index = i * 4 + j;
|
|
|
|
|
if (index < operationTable.Count)
|
|
|
|
|
{
|
|
|
|
|
string status = operationTable[index].IsChecked ? "X" : " ";
|
|
|
|
|
Console.Write($" | {status}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.Write(" |\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(game.GameRules.FinalCalculusOfZones(game.UsedMap.Zones));
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the cell chosen by the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The cell chosen by the player.</returns>
|
|
|
|
|
static Cell GetPlayerChoice()
|
|
|
|
|
{
|
|
|
|
|
int row, column;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Enter the position of the cell you want to play");
|
|
|
|
|
Console.WriteLine("Enter the row number (0-5)");
|
|
|
|
|
if (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 6)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid row number. Please enter a number between 0 and 5.");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Enter the column number (0-5)");
|
|
|
|
|
if (!int.TryParse(Console.ReadLine(), out column) || column < 0 || column >= 6)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid column number. Please enter a number between 0 and 5.");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Cell(row, column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map maaaap = new Map("background");
|
|
|
|
|
Game Gaaame = new(new Player("Luka"), maaaap);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the operation chosen by the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
|
|
|
|
static Operation GetPlayerOperation()
|
|
|
|
|
{
|
|
|
|
|
DisplayOperationOptions();
|
|
|
|
|
string? op = Console.ReadLine();
|
|
|
|
|
while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5")
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid operation. Please choose again.");
|
|
|
|
|
op = Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return op switch
|
|
|
|
|
{
|
|
|
|
|
"1" => Operation.ADDITION,
|
|
|
|
|
"2" => Operation.SUBTRACTION,
|
|
|
|
|
"3" => Operation.MULTIPLICATION,
|
|
|
|
|
"4" => Operation.LOWER,
|
|
|
|
|
"5" => Operation.HIGHER,
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gaaame.InitializeGame();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays the operation options for the player to choose from.
|
|
|
|
|
/// </summary>
|
|
|
|
|
static void DisplayOperationOptions()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Choose an operation:");
|
|
|
|
|
Console.WriteLine("1: Addition (+)");
|
|
|
|
|
Console.WriteLine("2: Subtraction (-)");
|
|
|
|
|
Console.WriteLine("3: Multiplication (*)");
|
|
|
|
|
Console.WriteLine("4: Lower Dice (less)");
|
|
|
|
|
Console.WriteLine("5: Higher Dice (high)");
|
|
|
|
|
}
|
|
|
|
|
}
|