Merge branch 'testDe' into dev
continuous-integration/drone/push Build is failing Details

Merge des ajouts dans la boucle de jeu et Application Console.
pull/67/head
Rémi LAVERGNE 11 months ago
commit 34c76e5602

@ -96,24 +96,24 @@ for (int i = 0; i<game.UsedMap.Boards.Count; i++)
if (cpt % 5 == 0) Console.Write(" |\n");
}
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos02, game.UsedMap));
game.GameRules.IsZoneValidAndAddToZones(pos02, game.UsedMap);
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos31, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap));
game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos31, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos13, game.UsedMap);
//foreach(var oui in game.GameRules.EveryAdjacentCells(pos13, game.UsedMap.Boards)) //du débug
//{
// Console.WriteLine(oui.Value);
//}
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos32, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos33, game.UsedMap));
game.GameRules.IsZoneValidAndAddToZones(pos32, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos33, game.UsedMap);
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos05, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos15, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos25, game.UsedMap));
Console.WriteLine(game.GameRules.IsZoneValidAndAddToZones(pos35, game.UsedMap));
game.GameRules.IsZoneValidAndAddToZones(pos05, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos15, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos25, game.UsedMap);
game.GameRules.IsZoneValidAndAddToZones(pos35, game.UsedMap);
//affichage des zones

@ -92,6 +92,7 @@ namespace Models.Game
}
}
/// <summary>
/// Places the result of a dice operation into a chosen cell on the game board.
/// The result can be placed in the chosen cell if it's the first turn or if the chosen cell is valid according to the game rules.
@ -165,18 +166,84 @@ namespace Models.Game
/// </summary>
private async void GameLoop()
{
Cell PlayerChoice = new Cell(0, 0);
string op = "";
Operation convOp = new Operation();
int valueCurrentCell = 0;
while (_isRunning)
{
if (Turn == 20) GameEnded?.Invoke(this, new GameEndedEventArgs(CurrentPlayer));
/*
if (CheckGameEnd()) //TODO Règle pour check si fin de jeu
{
_isRunning = false;
//TODO Code pour comptabiliser les points
int scoreZones = GameRules.FinalCalculusOfZones(UsedMap.Zones);
//GameEnded?.Invoke(this, new GameEndedEventArgs(player));
}
*/
await Task.Delay(1000); // 1 seconde
UsedMap.DisplayBoards();
RollAllDice();
Console.WriteLine($"Dice 1: {Dice1.Value} | Dice 2: {Dice2.Value}");
Console.WriteLine("What do you want : " +
"Addition ? ( + )" +
"Substraction ? ( - )" +
"Multiplication ? ( * )" +
"The lower dice ? ( less )" +
"The higher dice ? high )");
op = Console.ReadLine();
while (op != "+" && op != "-" && op != "*" && op != "less" && op != "high")
{
op = Console.ReadLine();
}
if (op == "less")
{
convOp = Operation.LOWER;
//incrémentation du tableau des opérations
}
else if (op == "high")
{
convOp = Operation.HIGHER;
//incrémentation du tableau des opérations
}
if (op == "+")
{
convOp = Operation.ADDITION;
//incrémentation du tableau des opérations
}
if (op == "-")
{
convOp = Operation.SUBTRACTION;
//incrémentation du tableau des opérations
}
if (op == "*")
{
convOp = Operation.MULTIPLICATION;
//incrémentation du tableau des opérations
}
valueCurrentCell = ResultOperation(convOp);
Console.WriteLine($"The value of the dice is : {valueCurrentCell}");
Console.WriteLine();
PlayerChoice = UsedMap.PlayerChoiceOfPosition();
while (!GameRules.IsCellValid(PlayerChoice, UsedMap.Boards))
{
PlayerChoice = UsedMap.PlayerChoiceOfPosition();
}
PlaceResult(PlayerChoice, valueCurrentCell);
GameRules.IsZoneValidAndAddToZones(PlayerChoice, UsedMap);
AddToRopePath(PlayerChoice, GameRules.EveryAdjacentCells(PlayerChoice, UsedMap.Boards));
Turn++;
}
}

@ -31,9 +31,87 @@ public class Map
public Map(string background)
{
Boards = new List<Cell>();
Boards = InitializeBoards();
Background = background;
OperationGrid = new List<OperationCell>();
//RopePaths = new List<List<Cell>>();
RopePaths = new List<List<Cell>>();
Zones = new List<List<Cell>>();
}
public static List<Cell> InitializeBoards()
{
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);
Cell pos11 = new Cell(0, 1);
Cell pos12 = new Cell(1, 1);
Cell pos13 = new Cell(2, 1);
Cell pos14 = new Cell(3, 1);
Cell pos15 = new Cell(4, 1);
Cell pos21 = new Cell(0, 2);
Cell pos22 = new Cell(1, 2);
Cell pos23 = new Cell(2, 2);
Cell pos24 = new Cell(3, 2);
Cell pos25 = new Cell(4, 2);
Cell pos31 = new Cell(0, 3);
Cell pos32 = new Cell(1, 3);
Cell pos33 = new Cell(2, 3);
Cell pos34 = new Cell(3, 3);
Cell pos35 = new Cell(4, 3);
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);
return list;
}
public void DisplayBoards()
{
int cpt = 0;
for (int i = 0; i < Boards.Count; i++)
{
Console.Write(" | ");
Console.Write(Boards[i].Value);
cpt++;
if (cpt % 5 == 0) Console.Write(" |\n");
}
}
public Cell PlayerChoiceOfPosition()
{
Console.WriteLine("Enter the position of the cell you want to play");
Console.WriteLine("Enter the row number");
int row = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the column number");
int column = Convert.ToInt32(Console.ReadLine());
return new Cell(row, column);
}
}

@ -6,9 +6,9 @@ public interface IRules
{
//public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells);
//public bool IsCellEmpty(Cell playerChoice);
public bool IsCellEmpty(Cell playerChoice);
//public bool IsCellValid(Position playerChoicePosition, List<Position, Cell> cells);
public bool IsCellValid(Cell playerChoicePosition, List<Cell> cells);
//public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths);

@ -10,6 +10,22 @@ namespace Models.Rules
{
public class Rules : IRules
{
public bool IsCellEmpty(Cell playerChoice)
{
if (playerChoice == null || playerChoice.Value == null) return true;
return false;
}
public bool IsCellValid(Cell playerChoicePosition, List<Cell> cells)
{
if (!IsCellEmpty(playerChoicePosition)) return false;
if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false;
return true;
}
public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
{
if (Math.Abs(choosenCell.X - targetCell.X) > 1 || Math.Abs(choosenCell.Y - targetCell.Y) > 1)
@ -72,7 +88,7 @@ namespace Models.Rules
public void IsZoneValidAndAddToZones(Cell chosenCell, Map map)
{
if (chosenCell == null ||chosenCell.Value == null) return false;
if (chosenCell == null ||chosenCell.Value == null) return;
List<Cell> adjacentCells = new List<Cell>();
@ -95,7 +111,7 @@ namespace Models.Rules
}
}
return false;
return;
}
public bool IsValueInZones(Cell chosenCell, List<List<Cell>> zones)
@ -158,6 +174,7 @@ namespace Models.Rules
foreach (var cell in cells)
{
if (choosenCell == cell) continue;
if (IsCellAdjacent(choosenCell, cell))
{
adjacentCells.Add(cell);
@ -172,7 +189,11 @@ namespace Models.Rules
int? calculus = 0;
for(int i = 0; i < zones.Count; i++)
{
calculus += zones[i].Count * zones[i][0].Value;
calculus += zones[i].Count - 1 + zones[i][0].Value;
if (zones[i].Count > 9)
{
calculus += (zones[i].Count - 9) * 5;
}
}
return calculus;
}

Loading…
Cancel
Save