public override String ToString() { StringBuilder sb = new StringBuilder(); sb.Append(color); sb.Append(", state="); if (_State.isEye()) { sb.Append("e"); } else if (_State.isFlee()) { sb.Append("f"); } else if (_State.isHouse()) { sb.Append("ho"); } else if (_State.isHunt()) { sb.Append("hu"); } else if (_State.isRandom()) { sb.Append("r"); } sb.Append(", strategy="); if (strategy.isEye()) { sb.Append("e"); } else if (strategy.isFlee()) { sb.Append("f"); } else if (strategy.isHouse()) { sb.Append("ho"); } else if (strategy.isHunt()) { sb.Append("hu"); } else if (strategy.isRandom()) { sb.Append("r"); } sb.Append(", x="); sb.Append(xLaby); sb.Append(", y="); sb.Append(yLaby); sb.Append(", d="); sb.Append(CurrentDirection); sb.Append(", od="); sb.Append(_DesiredDirection); return(sb.ToString()); }
public void setState(GhostState newState) { if (newState.isEye()) { // état demandé : yeux avec déplacement yeux State = GhostState.EYE; strategy = Strategy.EYE; } else if (newState.isFlee()) { // état demandé : fuite if (!State.isEye()) { // fuit seulement si pas en état yeux fleeTime = Constants.TIME_FLEE; blink = false; if (!strategy.isHouse()) { strategy = Strategy.FLEE; _DesiredDirection = CurrentDirection; CurrentDirection = CurrentDirection.Opposite; } State = GhostState.FLEE; } } else if (newState.isRest()) { fleeTime = Constants.TIME_REST; strategy = Strategy.FLEE; _DesiredDirection = CurrentDirection; CurrentDirection = CurrentDirection.Opposite; State = GhostState.REST; } else if (newState.isHouse()) { // état demandé : chasse avec déplacement maison strategy = Strategy.HOUSE; houseTime = color * Constants.TIME_HOUSE; State = GhostState.HOUSE; } else if (newState.isHunt()) { // état demandé : chasse avec déplacement chasse strategy = Strategy.HUNT; State = GhostState.HUNT; } else if (newState.isRandom()) { // état demandé : chasse avec déplacement aléatoire strategy = Strategy.RANDOM; randomTime = Constants.TIME_RANDOM_OFFSET + color * Constants.TIME_RANDOM_K; State = GhostState.HUNT; } }