ProjectCow.Cow.MoveRandomly C# (CSharp) Method

MoveRandomly() private method

private MoveRandomly ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void
        private void MoveRandomly(GameTime gameTime)
        {
            if (Position.Y == OriginalY)
            {
                // Subtract the elapsed time
                actionDuration = actionDuration.Subtract(gameTime.ElapsedGameTime);

                // If action duration runs out
                if (actionDuration.Ticks <= 0)
                {
                    moveLeft = false;
                    moveRight = false;
                    int nextAction;

                    // Always move if frightened
                    if (frightened)
                        nextAction = random.Next(2);
                    else
                        nextAction = random.Next(4);

                    if (nextAction == 0)
                    {
                        moveLeft = true;
                        spriteEffect = SpriteEffects.None;
                    }
                    else if (nextAction == 1)
                    {
                        moveRight = true;
                        spriteEffect = SpriteEffects.FlipHorizontally;
                    }
                    // If nextAction > 1 then stay still

                    int milliseconds = random.Next(500, 1000);
                    actionDuration = actionDuration.Add(new TimeSpan(0, 0, 0, 0, milliseconds));
                }
            }
            else
            {
                // Object is being lifted so be frightened and don't move
                moveLeft = false;
                moveRight = false;
                frightened = true;
                currentMoveSpeed = MOVE_SPEED * 3;
                currentImage = frightenedImage;
                actionDuration = TimeSpan.Zero;

                if (isMooing == false && cowmoo != null)
                {
                    cowmoo.Play();
                }

                isMooing = true;
            }
        }