/// <summary> /// Returns an index of given PawnContainer. /// When a BandController is passed, then the index will be -1 or 24 depending on which player's turn it is. /// It's made so, it'll be easier to calculate move based on starting index + amount of steps for pawn to make. /// </summary> /// <param name="InContainer">The container for which we want to know the index.</param> /// <returns>Index of a given container.</returns> public int GetIndexOf(PawnsContainer InContainer) { if (InContainer is BandController) { return(CurrentPlayer == PlayerColor.Red ? -1 : 24); } else { return(FieldsOrder.IndexOf(InContainer as FieldController)); } }
public virtual void SetParent(PawnsContainer InContainer) { if (InContainer != null) { transform.parent = InContainer.transform; Container = InContainer; Field = Container as FieldController; } else { // error } }
public Move(GameManager InGameManager, PawnsContainer InContainer, DiceController[] InDices, bool bInAreDicesTheSame) { GameManager = InGameManager; if (GameManager) { bAreDicesTheSame = bInAreDicesTheSame; Dices = InDices.ToList(); Steps = Dices.Select(d => d.GetDots()).Sum(); Start = InContainer; StartIndex = GameManager.GetIndexOf(Start); DestinationIndex = StartIndex + (GameManager.GetPlayer() == PlayerColor.Red ? Steps : -Steps); DestinationField = GameManager.GetField(DestinationIndex); } Logger.Log(this, "Move created. Start band: {0}, destination: {1}({2}), steps: {3}, dices: {4}({5}), valid: {6}", Start ? Start.name : "NULL", DestinationIndex, DestinationField ? DestinationField.name : "NULL", Steps, Dices.Count, string.Join(", ", Dices.Select(d => d.name).ToArray()), IsValid()); }
public PossibleMoves(GameManager InGameManager, PawnsContainer InContainer, List <DiceController> InDices, bool bSingleDiceMoves = false) { if (InGameManager) { Dices = InDices; // Doubling amount of moves if amount of dots on both dices are the same. bool bDicesAreTheSame = Dices[0].GetDots() == Dices[1].GetDots(); if (bDicesAreTheSame && !bSingleDiceMoves) { List <DiceController> temp = new List <DiceController>(); foreach (DiceController dice in Dices) { if (dice.GetUsageState() != DiceState.FullyUsed) { temp.Add(dice); if (dice.GetUsageState() == DiceState.NotUsed) { temp.Add(dice); } } } if (temp.Count > 1) { for (int iCombination = 1; iCombination <= temp.Count; ++iCombination) { Moves.Add(new Move(InGameManager, InContainer, temp.Take(iCombination).ToArray(), bDicesAreTheSame)); } } else { if (temp.Count == 1) { Moves.Add(new Move(InGameManager, InContainer, temp.ToArray(), bDicesAreTheSame)); } else { // error } } } else { Moves.Add(new Move(InGameManager, InContainer, new DiceController[] { Dices[0] }, bDicesAreTheSame)); Moves.Add(new Move(InGameManager, InContainer, new DiceController[] { Dices[1] }, bDicesAreTheSame)); if (!bSingleDiceMoves) { Moves.Add(new Move(InGameManager, InContainer, new DiceController[] { Dices[0], Dices[1] }, bDicesAreTheSame)); } } Logger.Log(this, "Possible moves based on dices roll [{0}-{1}] are: {2}", Dices[0].GetDots(), Dices[1].GetDots(), string.Join(", ", Moves.Select(m => m.GetSteps().ToString()).ToArray())); // Removing invalid moves for (int iMove = Moves.Count - 1; iMove >= 0; --iMove) { if (Moves[iMove].IsValid()) { Moves[iMove].Show(); } else { Moves.RemoveAt(iMove); } } Logger.Log(this, "Possible, validated moves are: {0}", string.Join(", ", Moves.Select(m => m.ToString()).ToArray())); } }
protected void MovePawn(PawnsContainer InDestination, PawnController InPawn) { RemovePawn(InPawn); InDestination.AddPawn(InPawn, true); }
public void MovePawn(PawnsContainer InDestination, PlayerColor InPawnColor) { MovePawn(InDestination, GetPawn(InPawnColor)); }
public void MovePawn(PawnsContainer InDestination) { MovePawn(InDestination, GetPawn()); }