Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
 public void timers()
 {
     if (strategy.isHouse())
     {
         houseTime--;
         if (houseTime <= 0 && X == (Labyrinth.HOUSE_X * Constants.GRID_WIDTH) - Constants.GRID_WIDTH_2)
         {
             // en position pour sortir de la maison
             if (Y == (Labyrinth.HOUSE_Y - 3) * Constants.GRID_HEIGHT)
             {
                 // ok la sortie est atteinte
                 if (!_State.isFlee())
                 {
                     setState(GhostState.RANDOM);
                 }
                 // en sortant de la maison certains partent à doite, d'autres à gauche
                 if (color <= 1)
                 {
                     CurrentDirection = Direction.Right;
                 }
                 else
                 {
                     CurrentDirection = Direction.Left;
                 }
             }
             else if (Y == Labyrinth.HOUSE_Y * Constants.GRID_HEIGHT)
             {
                 // dans la maison, en face de la sortie
                 CurrentDirection = Direction.Up;
             }
         }
     }
     if (strategy.isRandom())
     {
         randomTime--;
         if (randomTime <= 0)
         {
             setState(GhostState.HUNT);
         }
     }
     if (_State.isRest())
     {
         fleeTime--;
         if (fleeTime <= 0)
         {
             setState(GhostState.RANDOM);
         }
     }
     if (_State.isFlee())
     {
         fleeTime--;
         if (fleeTime <= (Constants.TIME_FLEE / 2))
         {
             blink = true;
             if (fleeTime <= 0)
             {
                 setState(GhostState.HUNT);
                 blink = false;
             }
         }
     }
 }
Exemplo n.º 3
0
        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;
                }
        }