🚧 Console App
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details

pull/108/head
Lucas DUFLOT 11 months ago
parent 462e8dc744
commit d516b5898d

@ -14,6 +14,9 @@ namespace ConsoleApp;
class Program class Program
{ {
static Game Game { get; set; }
/// <summary> /// <summary>
/// Main function of the console app /// Main function of the console app
/// </summary> /// </summary>
@ -28,21 +31,21 @@ class Program
Player player = new Player(pseudo, "test.png"); Player player = new Player(pseudo, "test.png");
Map map = new Map("Dunai","background"); Map map = new Map("Dunai","background");
Game game = new Game(persistence); Game = new Game(persistence);
// Abonnement aux événements // Abonnement aux événements
game.GameStarted += OnGameStarted!; Game.GameStarted += OnGameStarted!;
game.GameEnded += OnGameEnded!; Game.GameEnded += OnGameEnded!;
game.BoardUpdated += OnBoardUpdated!; Game.BoardUpdated += OnBoardUpdated!;
game.DiceRolled += OnDiceRolled!; Game.DiceRolled += OnDiceRolled!;
game.OperationChosen += OnOperationChosen!; Game.OperationChosen += OnOperationChosen!;
game.CellChosen += OnCellChosen!; Game.CellChosen += OnCellChosen!;
game.PlayerChooseOp += OnPlayerSelectionOp!; Game.PlayerChooseOp += OnPlayerSelectionOp!;
game.PlayerOption += OnPlayerOption!; Game.PlayerOption += OnPlayerOption!;
game.PlayerChooseCell += OnPlayerSelectionCell!; Game.PlayerChooseCell += OnPlayerSelectionCell!;
// Initialisation // Initialisation
game.InitializeGame(map, player); Game.InitializeGame(map, player);
} }
@ -75,7 +78,7 @@ class Program
continue; continue;
} }
e.Cell = new Cell(row, column); Game.PlayerCell = new Cell(row, column);
break; break;
} }
} }
@ -87,10 +90,13 @@ class Program
{ {
IEnumerable<Cell> PlayedCellsQuery = IEnumerable<Cell> PlayedCellsQuery =
from cell in e.Board from cell in e.Board
where cell.Valid == true
where cell.Value != null where cell.Value != null
select cell; select cell;
foreach (var item in e.Board) foreach (var item in e.Board)
{ {
if (item.X == 6)
Console.WriteLine();
if (!item.Valid) if (!item.Valid)
Console.Write(" "); Console.Write(" ");
else if (item.Value != null) else if (item.Value != null)
@ -108,6 +114,7 @@ class Program
} }
} }
} }
return;
} }
foreach (var item in e.Board) foreach (var item in e.Board)
{ {
@ -134,16 +141,18 @@ class Program
Console.WriteLine(); Console.WriteLine();
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList()); DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList());
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("1. Lower | 2. Higher | 3. Substraction | 4. Addition | 5. Multiplication"); Console.WriteLine("0. Lower | 1. Higher | 2. Substraction | 3. Addition | 4. Multiplication");
string? op = Console.ReadLine(); string? op = Console.ReadLine();
while (op != "1" && op != "2" && op != "3" && op != "4" && op != "5") while (op != "0" && op != "1" && op != "2" && op != "3" && op != "4")
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid operation. Please choose again."); Console.WriteLine("Invalid operation. Please choose again.");
Console.ResetColor(); Console.ResetColor();
op = Console.ReadLine(); op = Console.ReadLine();
} }
e.Operation = 3; int test = Convert.ToInt32(op);
Game.PlayerOperation = (Operation)test;
} }
@ -179,11 +188,9 @@ class Program
{ {
if (!item.Valid) if (!item.Valid)
Console.Write(" "); Console.Write(" ");
else else if (item.Value != null)
{
Console.Write($"{item.Value}"); Console.Write($"{item.Value}");
else Console.Write("O");
}
if (item.X == 6) if (item.X == 6)
Console.WriteLine(); Console.WriteLine();
} }

@ -9,11 +9,11 @@ namespace Models.Events
{ {
public class PlayerChooseOperationEventArgs : EventArgs public class PlayerChooseOperationEventArgs : EventArgs
{ {
public int Operation { get; set; } public Operation PlayerOp { get; set; }
public PlayerChooseOperationEventArgs(int op) public PlayerChooseOperationEventArgs(Operation op)
{ {
Operation = op; PlayerOp = op;
} }
} }
} }

@ -105,6 +105,10 @@ namespace Models.Game
[DataMember] [DataMember]
public int Turn { get; private set; } public int Turn { get; private set; }
public Operation PlayerOperation { get; set; }
public Cell PlayerCell { get; set; }
public Rules.Rules GameRules { get; } public Rules.Rules GameRules { get; }
@ -378,35 +382,31 @@ namespace Models.Game
RollAllDice(); RollAllDice();
res = PlayerChooseOperation(); res = PlayerChooseOperation();
PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn)); PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn));
cell = PlayerCell(); PlayerSelectionCell();
PlaceResult(cell,res); PlaceResult(PlayerCell,res);
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList()));
turn++;
} }
} }
public int PlayerChooseOperation() public int PlayerChooseOperation()
{ {
int operation=0; PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation));
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); while(!GameRules.OperationAvailable(PlayerOperation,UsedMap.OperationGrid.ToList()))
while(!GameRules.OperationAvailable(operation,UsedMap.OperationGrid.ToList()))
{ {
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation)); PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation));
} }
MarkOperationAsChecked((Operation)operation); return ResultOperation(PlayerOperation);
return ResultOperation((Operation)operation);
} }
public Cell PlayerCell() public void PlayerSelectionCell()
{ {
Cell ?playerCell = new Cell(1,0); PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(PlayerCell));
playerCell.Valid = true; while(!GameRules.NearCellIsValid(PlayerCell,UsedMap.Boards.ToList()))
PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(playerCell));
while(!GameRules.NearCellIsValid(playerCell,UsedMap.Boards.ToList()))
{ {
PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(playerCell)); PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(PlayerCell));
} }
return playerCell; MarkOperationAsChecked(PlayerOperation);
} }
/// <summary> /// <summary>

@ -54,10 +54,7 @@ namespace Models.Rules
{ {
if (Math.Abs(choosenCell.X - targetCell.X) <= 1 && Math.Abs(choosenCell.Y - targetCell.Y) <= 1) if (Math.Abs(choosenCell.X - targetCell.X) <= 1 && Math.Abs(choosenCell.Y - targetCell.Y) <= 1)
{ {
if (choosenCell.X != targetCell.X || choosenCell.Y != targetCell.Y)
{
return true; return true;
}
} }
return false; return false;
@ -118,9 +115,8 @@ namespace Models.Rules
if (choosenCell.X == cell.X && choosenCell.Y == cell.Y && cell.Value == null) if (choosenCell.X == cell.X && choosenCell.Y == cell.Y && cell.Value == null)
return true; return true;
if (IsCellAdjacent(choosenCell, cell)) if (IsCellAdjacent(choosenCell, cell))
{
return true; return true;
}
} }
return false; return false;
@ -258,11 +254,11 @@ namespace Models.Rules
return score; return score;
} }
public bool OperationAvailable(int operation,List<OperationCell> operationGrid) public bool OperationAvailable(Operation operation,List<OperationCell> operationGrid)
{ {
IEnumerable<OperationCell> row = IEnumerable<OperationCell> row =
from cell in operationGrid from cell in operationGrid
where cell.Y == operation where cell.Y == (int)operation
select cell; select cell;
foreach (var item in row) foreach (var item in row)
{ {

Loading…
Cancel
Save