private void InitiateBoard(string aBoard) { m_StartingCamels.Clear(); m_Traps.Clear(); string[] subPattern = aBoard.Split(GameRules.CASE_SEPARATOR); for (int pos = 0; pos < subPattern.Length; pos++) { Camel lastCamel = null; string line = subPattern[pos]; for (int j = line.Length - 1; j >= 0; j--) { if (line[j] == GameRules.TRAP_PLUS || line[j] == GameRules.TRAP_MINUS) { m_Traps.Add(new Trap(line[j], pos)); } else { Camel newCamel = new Camel(line[j], pos, lastCamel); m_StartingCamels.Add(newCamel); lastCamel = newCamel; } } } }
private void CheckCamelLandOnAnotherCamel(Camel aCamel, bool aFromMinusTrap) { if (!aFromMinusTrap) { for (int i = 0; i < m_Camels.Count; i++) { if (m_Camels[i] != aCamel && m_Camels[i].Pos == aCamel.Pos && m_Camels[i].CamelOnTop == null) { m_Camels[i].CamelOnTop = aCamel; } } } else { //TODO faire des tests string camelsOnTop = aCamel.Id.ToString(); string camelsOnPos = string.Empty; List <Camel> orderedStartingCamel = SortCamelInOrderPos(m_Camels); Camel tempCamel = aCamel.CamelOnTop; while (tempCamel != null) { camelsOnTop += tempCamel.Id; tempCamel = tempCamel.CamelOnTop; } foreach (Camel camel in orderedStartingCamel) { if (!camelsOnTop.Contains(camel.Id.ToString()) && camel.Pos == aCamel.Pos && !GetCurrentCamel(camel.Id).IsMoving) { camelsOnPos += camel.Id; } } if (!string.IsNullOrEmpty(camelsOnPos)) { Camel toppestCamel = aCamel; while (toppestCamel.CamelOnTop != null) { toppestCamel = toppestCamel.CamelOnTop; } toppestCamel.CamelOnTop = GetCurrentCamel(camelsOnPos[camelsOnPos.Length - 1]); if (aCamel.CamelOnTop == null || aCamel.CamelOnTop == aCamel) { GameRules.Log("Peut etre un bug...."); } } } }
private void RemoveCamelOnTop(Camel aCamel) { foreach (Camel camel in m_Camels) { if (camel.CamelOnTop != null && camel.CamelOnTop.Id == aCamel.Id) { camel.CamelOnTop = null; } } }
private void IsLandingOnTrap(Camel aCamel) { foreach (Trap trap in m_Traps) { if (trap.Pos == aCamel.Pos) { int modifMovement = trap.IsPlusTrap ? GameRules.TRAP_PLUS_MODIFIER : GameRules.TRAP_MINUS_MODIFIER; aCamel.Pos += modifMovement; CheckCamelLandOnAnotherCamel(aCamel, modifMovement < 0); } } }
private List <Camel> SortCamelInOrderPos(List <Camel> aCamel) { List <Camel> newList = new List <Camel>(); List <Camel> remainingCamels = (List <Camel>)Extensions.Clone(aCamel); for (int j = 0; j < aCamel.Count; j++) { char tempCamelName = 'x'; Camel higherCamel = new Camel(tempCamelName, -1, null); foreach (Camel currentCamel in remainingCamels) { if (newList.Count > 0 && currentCamel.CamelOnTop != null && currentCamel.CamelOnTop.Id == newList[newList.Count - 1].Id) { //prend le camelOnTop du dernier camel entrer higherCamel = currentCamel; break; } else { //Prend le plus grosse pos + sans camel on top if (currentCamel.CamelOnTop == null && currentCamel.Pos > higherCamel.Pos) { higherCamel = currentCamel; } } } for (int k = 0; k < remainingCamels.Count; k++) { if (remainingCamels[k].Id == higherCamel.Id) { remainingCamels.Remove(remainingCamels[k]); } } if (higherCamel.Id == tempCamelName) { GameRules.Log("Didnt find higherCamel"); } newList.Add(higherCamel); } if (remainingCamels.Count != 0) { GameRules.Log("We miss a Camel"); } return(newList); }
private void MoveCamel(Camel aCamel, int aDice, bool aIsFirstCamel) { aCamel.IsMoving = true; aCamel.Pos += aDice; if (aIsFirstCamel) { RemoveCamelOnTop(aCamel); } IsLandingOnTrap(aCamel); Camel camelOnTop = aCamel.CamelOnTop; while (camelOnTop != null) { camelOnTop.Pos = aCamel.Pos; camelOnTop = camelOnTop.CamelOnTop; } aCamel.IsMoving = false; }
public Camel(char aId, int aPos, Camel aCamelOnTop) : this(aId) { this.Pos = aPos; this.CamelOnTop = aCamelOnTop; }