Modification de la structure du jeu ENTIER
continuous-integration/drone/push Build is failing Details

pull/61/head
Lucas DUFLOT 12 months ago
parent f73549b0d5
commit 3e19e6ba55

@ -35,10 +35,6 @@ namespace Models
_score = value; _score = value;
} }
} }
public override string ToString()
{
return $"Ce joueur a joué {GamesPlayed} parties et à pour meilleur score {Score}";
}
public void IncrGamesPlayed() public void IncrGamesPlayed()
{ {

@ -17,11 +17,12 @@ public class Cell
private bool IsDangerous { get; set; } private bool IsDangerous { get; set; }
public string? Background { get; set; } private bool Penalty { get; set; }
public Cell(bool isDangerous = false) public Cell(bool isDangerous = false)
{ {
IsDangerous = isDangerous; IsDangerous = isDangerous;
Penalty = false;
} }
public bool GetCellType() => IsDangerous; public bool GetCellType() => IsDangerous;

@ -33,7 +33,7 @@ namespace Models.Game
return $"Ce dé a pour valeur {Value} et est entre {NbMin} et {NbMax}"; return $"Ce dé a pour valeur {Value} et est entre {NbMin} et {NbMax}";
} }
public void Lancer() public void Roll()
{ {
Value = new Random().Next(NbMin, NbMax + 1); Value = new Random().Next(NbMin, NbMax + 1);
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Models.Events;
namespace Models.Game namespace Models.Game
{ {
@ -17,12 +18,13 @@ namespace Models.Game
private int Turn { get; set; } private int Turn { get; set; }
private Rules.Rules GameRules { get; } private IRules GameRules { get; }
private HashSet<RopePath> ropePaths { get; } // == Events ==
public event GameStartedEventArgs OnGameStarted;
public Game(Player player, Map map) public event GameStartedEventArgs GameStarted; public Game(Player player, Map map)
{ {
UsedMap = map; UsedMap = map;
CurrentPlayer = player; CurrentPlayer = player;
@ -35,8 +37,8 @@ namespace Models.Game
public void RollAllDice() public void RollAllDice()
{ {
Dice1.Lancer(); Dice1.Roll();
Dice2.Lancer(); Dice2.Roll();
} }
public int ResultOperation(Operation o) public int ResultOperation(Operation o)

@ -2,12 +2,22 @@
public class Map public class Map
{ {
public SortedDictionary<Position, Cell> Cells { get; private set; } public List<Cell> Boards { get; private set; };
public string Background { get; private set; } public string Background { get; private set; }
public List<OperationCell> OperationGrid { get; private set; }
public List<List<Cell>> RopePaths { get; private set; }
public List<List<Cell>> Zones { get; private set; }
public Map(string background) public Map(string background)
{ {
Cells = new SortedDictionary<Position, Cell>(); Boards = new List<Cell>();
Background = background; Background = background;
OperationGrid = new List<OperationCell>();
RopePaths = new List<List<Cell>>();
Zones = new List<List<Cell>>();
} }
} }

@ -0,0 +1,6 @@
namespace Models;
public class OperationCell : Position
{
public bool IsChecked { get ; private set}
}

@ -6,6 +6,10 @@ public class Player
public string ProfilePicture { get; private set; } public string ProfilePicture { get; private set; }
public string CreationDate { get; private set; }
public string LastPlayed { get; private set; }
public Player() public Player()
{ {
Pseudo = "Player"; Pseudo = "Player";

@ -1,6 +0,0 @@
namespace Models.Game;
public class RopePath
{
public HashSet<Cell> Cells { get; } = new HashSet<Cell>();
}

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.Game
{
public class RopesZones
{
public List<List<Cell>>? RopeZone { get; set; }
}
}

@ -1,6 +0,0 @@
namespace Models.Interfaces;
public interface ICell
{
string GetCellType();
}

@ -0,0 +1,20 @@
namespace Models.Interfaces;
public interface IRules
{
public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells);
public bool IsCellEmpty(Cell playerChoice);
public bool IsCellValid(Position playerChoicePosition, List<Position, Cell> cells);
public bool IsZone(Cell playerChoice, List<Position, Cell> cells);
public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths);
public bool IsAdjacent(Cell cell1, Cell cell2, List<Position, Cell> cells);
public int HowMany(Cell playerChoice, List<Position, Cell> cells);
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Position, Cell> cells);
}

@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
public class OperationsGrid
{
public bool[,] Tiles;
public OperationsGrid()
{
Tiles = new bool[5,4];
}
public void ResultGrid(Operation p)
{
switch (p)
{
case Operation.LOWER:
for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[0, i] == false) { Tiles[0, i] = true; return; } }
break;
case Operation.HIGHER:
for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[1, i] == false) { Tiles[1, i] = true; return; } }
break;
case Operation.SUBTRACTION:
for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[2, i] == false) { Tiles[2, i] = true; return; } }
break;
case Operation.ADDITION:
for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[3, i] == false) { Tiles[3, i] = true; return; } }
break;
case Operation.MULTIPLICATION:
for (int i = 0; i < Tiles.GetLength(1); i++) { if (Tiles[4, i] == false) { Tiles[4, i] = true; return; } }
break;
default:
return;
}
}
}
}

@ -7,105 +7,40 @@ using Models.Game;
namespace Models.Rules namespace Models.Rules
{ {
public class Rules public class Rules : IRules
{ {
public bool IsCellExist(Position playerChoicePosition, SortedDictionary<Position, Cell> cells) public bool IsCellAdjacent(Cell choosenCell, Cell targetCell)
{ {
return cells.ContainsKey(playerChoicePosition); if (Math.Abs(choosenCell.Pos.X - targetCell.Cell.X) > 1 || Math.Abs(choosenCell.Pos.Y - targetCell.Cell.Y) > 1)
} return false;
public bool NearCellIsValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells)
{
if (!IsCellExist(playerChoicePosition, cells)) return false;
foreach (var cell in cells)
{
if (Math.Abs(playerChoicePosition.X - cell.Key.X) > 1 || Math.Abs(playerChoicePosition.Y - cell.Key.Y) > 1) continue;
if (!IsCellEmpty(cell.Value))
{
return true; return true;
} }
}
return false;
}
public bool IsCellEmpty(Cell playerChoice) public bool NearCellIsValid(Cell choosenCell, List<List<Cell>> cells)
{ {
return !playerChoice.Value.HasValue; if (choosenCell == null) return false;
}
public bool IsCellValid(Position playerChoicePosition, SortedDictionary<Position, Cell> cells) IEnumerable<Cellule> PlayedCellsQuery =
{ from cell in cells
return NearCellIsValid(playerChoicePosition, cells) && IsCellEmpty(cells. where cell.Value != null
} select cell;
public bool IsZone(Cell playerChoice, SortedDictionary<Position, Cell> cells) foreach (var cell in PlayedCellsQuery)
{
foreach (var k,v in cells)
{ {
if (playerChoice.X != item.X + 1 && playerChoice.X != item.Pos.X - 1 if(!IsCellAdjacent(choosenCell, cell)) continue;
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
if (playerChoice.Value == item.Value)
{
return true;
}
}
return false;
}
/// <summary>
/// Determines if a given cell is part of any rope path.
/// </summary>
/// <param name="playerChoice">The cell to check.</param>
/// <param name="ropePaths">A collection of rope paths to check against.</param>
/// <returns>True if the cell is part of any rope path, false otherwise.</returns>
public bool IsRopePath(Cell playerChoice, HashSet<RopePath> ropePaths)
{
foreach (var path in ropePaths)
{
if (path.Cells.Contains(playerChoice))
{
return true; return true;
} }
} }
return false;
}
public bool IsAdjacent(Cell cell1, Cell cell2, SortedDictionary<Position, Cell> cells)
{
bool isSequence = cell1.Value.HasValue && cell2.Value.HasValue && Math.Abs(cell1.Value.Value - cell2.Value.Value) == 1;
return IsCellValid(cell1, cells) && isSequence;
}
public int HowMany(Cell playerChoice, SortedDictionary<Position, Cell> cells) public bool IsZone(Cell choosen, List<List<Cell>> cells)
{
foreach(var pos in cells)
{
if (pos.Equals(playerChoice))
{ {
return pos.GetCellType() ? 6 : 12; IEnumerable<Cellule> PlayedCellsQuery =
from cell in cells
where cell.Value != null
select cell;
} }
}
return 0;
}
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, SortedDictionary<Position, Cell> cells)
{
int val = HowMany(playerChoice, cells);
foreach (var pos in cells)
{
if (!pos.Equals(playerChoice)) continue;
if (valueChoice > val)
{
playerChoice.Background = "penalty";
}
playerChoice.Value = valueChoice;
}
}
} }
} }
Loading…
Cancel
Save