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; } }
public override int animate() { animateCount++; int moveCount = 0; if (_State.isEye()) { moveCount = 2; } else if (_State.isFlee()) { if ((animateCount & 1) == 1) { // Déplace 1 fois sur 2 moveCount = 1; } } else { moveCount = 1; } while (moveCount > 0) { spriteCount = 1 - spriteCount; // sauvegarde la direction courante avant toute modification _DesiredDirection = CurrentDirection; // détermine la nouvelle direction en fonction de la stratégie courante CurrentDirection = strategy.move(this, X, Y, xpac, ypac); // gestion des timers timers(); // déplacement à l'écran moveGhost(); moveCount--; } return(0); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { GhostState state = value as GhostState; if (state != null) { if (state.isFlee()) { return(Application.Current.Resources["ghostFuite"]); } if (state.isEye()) { return(Application.Current.Resources["ghostEye"]); } return(parameter); } return(parameter); }