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

@ -9,11 +9,11 @@ namespace Models.Events
{
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]
public int Turn { get; private set; }
public Operation PlayerOperation { get; set; }
public Cell PlayerCell { get; set; }
public Rules.Rules GameRules { get; }
@ -285,10 +289,10 @@ namespace Models.Game
where cell.Value == null
where cell.Valid == true
select cell;
foreach (var item in ValidCell)
{
if(item.X == playerChoice.X && item.Y == playerChoice.Y)
item.Value = result;
foreach (var item in ValidCell)
{
if(item.X == playerChoice.X && item.Y == playerChoice.Y)
item.Value = result;
}
}
@ -378,35 +382,31 @@ namespace Models.Game
RollAllDice();
res = PlayerChooseOperation();
PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn));
cell = PlayerCell();
PlaceResult(cell,res);
PlayerSelectionCell();
PlaceResult(PlayerCell,res);
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList()));
turn++;
}
}
public int PlayerChooseOperation()
{
int operation=0;
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation));
while(!GameRules.OperationAvailable(operation,UsedMap.OperationGrid.ToList()))
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation));
while(!GameRules.OperationAvailable(PlayerOperation,UsedMap.OperationGrid.ToList()))
{
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(operation));
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation));
}
MarkOperationAsChecked((Operation)operation);
return ResultOperation((Operation)operation);
return ResultOperation(PlayerOperation);
}
public Cell PlayerCell()
public void PlayerSelectionCell()
{
Cell ?playerCell = new Cell(1,0);
playerCell.Valid = true;
PlayerChooseCell?.Invoke(this,new PlayerChooseCellEventArgs(playerCell));
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>

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

Loading…
Cancel
Save