|
|
@ -8,12 +8,29 @@ namespace Models.Rules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class 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)
|
|
|
|
foreach (var item in cells)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(playerChoice.Pos.X == item.Pos.X +1 || playerChoice.Pos.X == item.Pos.X - 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 )
|
|
|
|
&& playerChoice.Pos.Y != item.Pos.Y + 1 &&
|
|
|
|
|
|
|
|
playerChoice.Pos.Y != item.Pos.Y - 1) continue;
|
|
|
|
|
|
|
|
if (playerChoice.Value == item.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -21,24 +38,54 @@ namespace Models.Rules
|
|
|
|
return false;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|