Merge pull request 'Classe "Rules": Optimisation, Sécurité et requêtes LINQ' (#57) from rules into dev
continuous-integration/drone/push Build is failing Details

Reviewed-on: #57
pull/61/head
Rémi LAVERGNE 12 months ago
commit 29b2e02116

@ -8,32 +8,32 @@ namespace Models.Game
{
public class Game
{
public Player CurentPlayer { get; set; }
public Player CurrentPlayer { get; set; }
public Map NameMap { get; set; }
private Map UsedMap { get; set; }
public De De1 { get; set; }
public De De2 { get; set; }
private De Dice1 { get; set; }
private De Dice2 { get; set; }
public int Turn { get; set; }
private int Turn { get; set; }
public Rules.Rules rules { get; set; }
private Rules.Rules Rules { get; set; }
public Game(Player player,Map map)
{
NameMap = map;
CurentPlayer = player;
De1 = new De();
De2 = new De(1);
UsedMap = map;
CurrentPlayer = player;
Dice1 = new De();
Dice2 = new De(1);
Turn = 0;
rules = new Rules.Rules();
Rules = new Rules.Rules();
}
public void ThrowDice()
{
De1.Lancer();
De2.Lancer();
Dice1.Lancer();
Dice2.Lancer();
}
public int ResultOperation(Operation o)
@ -41,31 +41,19 @@ namespace Models.Game
switch (o)
{
case Operation.LOWER:
if (De1.IsLower(De2))
{
return De1.Nb;
}
return De2.Nb;
return Dice1.IsLower(Dice2) ? Dice1.Nb : Dice2.Nb;
case Operation.HIGHER:
if (De1.IsLower(De2))
{
return De2.Nb;
}
return De1.Nb;
return Dice1.IsLower(Dice2) ? Dice2.Nb : Dice1.Nb;
case Operation.SUBTRACTION:
if (De1.IsLower(De2))
{
return De2.Nb - De1.Nb;
}
return De1.Nb - De2.Nb;
return Dice1.IsLower(Dice2) ? Dice2.Nb - Dice1.Nb : Dice1.Nb - Dice2.Nb;
case Operation.ADDITION:
return De2.Nb + De1.Nb;
return Dice2.Nb + Dice1.Nb;
case Operation.MULTIPLICATION:
return De2.Nb * De1.Nb;
return Dice2.Nb * Dice1.Nb;
default:
return 0;
}
@ -79,17 +67,15 @@ namespace Models.Game
}
else
{
if(rules.NearCell(playerChoice,NameMap.Cells))
if(Rules.NearCell(playerChoice,UsedMap.Cells))
{
playerChoice.Value = result;
}
}
return;
}
public void AddRopeZone(Cell playerChoice,RopesZones list)
{
}
}

@ -8,12 +8,29 @@ namespace Models.Rules
{
public class Rules
{
public bool NearCell(Cell playerChoice, List<Cell> cells)
public static bool NearCell(Cell playerChoice, List<Cell> cells)
{
return cells.Any(item => playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1 || playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1);
}
public static bool IsCellEmpty(Cell playerChoice)
{
return playerChoice.Value == null;
}
public static bool IsCellValid(Cell playerChoice, List<Cell> cells)
{
return NearCell(playerChoice, cells) && IsCellEmpty(playerChoice);
}
public static bool IsZone(Cell playerChoice, List<Cell> cells)
{
foreach (var item in cells)
{
if(playerChoice.Pos.X == item.Pos.X +1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y +1 || playerChoice.Pos.Y == item.Pos.Y -1 )
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
if (playerChoice.Value == item.Value)
{
return true;
}
@ -21,24 +38,54 @@ namespace Models.Rules
return false;
}
public bool IsCellEmpty(Cell playerChoice)
public static bool IsRopePath(Cell playerChoice, List<Cell> cells, List<Cell> ropePaths)
{
if (playerChoice.Value == null)
foreach (var item in cells)
{
if (playerChoice.Pos.X != item.Pos.X + 1 && playerChoice.Pos.X != item.Pos.X - 1
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
if (playerChoice.Value != item.Value + 1 && playerChoice.Value != item.Value - 1) continue;
foreach (var path in ropePaths)
{
if (path.Equals(playerChoice))
{
return true;
}
}
return IsRopePath(item, cells, ropePaths);
}
return false;
}
public bool IsCellValid(Cell playerChoice, List<Cell> cells)
public static int HowMany(Cell playerChoice, List<Cell> cells)
{
if (NearCell(playerChoice, cells) && IsCellEmpty(playerChoice))
foreach(var pos in cells)
{
return true;
if (pos.Equals(playerChoice))
{
return pos.GetCellType() ? 6 : 12;
}
}
return 0;
}
return false;
public static void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<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;
}
}
}
}

@ -1,43 +0,0 @@
namespace Models.Rules;
public class Zones
{
public bool IsZone(Cell playerChoice, List<Cell> cells)
{
foreach (var item in cells)
{
if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1)
{
if (playerChoice.Value == item.Value)
{
return true;
}
}
}
return false;
}
public bool IsCheminDeCorde(Cell playerChoice, List<Cell> cells, List<Cell> cheminsDeCorde)
{
foreach (var item in cells)
{
if (playerChoice.Pos.X == item.Pos.X + 1 || playerChoice.Pos.X == item.Pos.X - 1
|| playerChoice.Pos.Y == item.Pos.Y + 1 || playerChoice.Pos.Y == item.Pos.Y - 1)
{
if (playerChoice.Value == item.Value+1 || playerChoice.Value == item.Value-1)
{
foreach (var chemin in cheminsDeCorde)
{
if (chemin.Equals(playerChoice))
{
return true;
}
}
return IsCheminDeCorde(item, cells, cheminsDeCorde);
}
}
}
return false;
}
}

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
namespace Models.Rules
{
public class ruleBox
{
public int HowMany(Cell playerChoice, List<Cell> cells)
{
foreach(var pos in cells)
{
if (pos.Equals(playerChoice))
{
if (pos.GetCellType())
{
return 6;
}
return 12;
}
}
return 0;
}
public void SetValueAndPenalty(int valueChoice, Cell playerChoice, List<Cell> cells)
{
int val = HowMany(playerChoice, cells);
foreach (var pos in cells)
{
if (pos.Equals(playerChoice))
{
if (valueChoice > val)
{
playerChoice.Background = "notcontent";
}
playerChoice.Value = valueChoice;
}
}
}
}
}
Loading…
Cancel
Save