Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if we're advancing to a new phase, false otherwise
        /// </summary>
        /// <param name="performedAction"></param>
        /// <returns></returns>
        public bool AdvanceDay(StackEggAction performedAction)
        {
            if (!ActionIsLegal(performedAction))
            {
                throw new InvalidOperationException(performedAction + " is not a legal action at this time");
            }

            var critical = CriticalStats().ToList();

            switch (performedAction)
            {
            case StackEggAction.Ask:
            case StackEggAction.Answer:
            case StackEggAction.Upvote:
            case StackEggAction.Downvote:
            case StackEggAction.Close:
            case StackEggAction.Nothing:
                PerformBaseAction(performedAction);
                break;

            case StackEggAction.FlagForModerator:
                FlagForModerator();
                break;
            }

            foreach (var stat in CurrentPhase.AvailableStats)
            {
                AccumulatedStats[stat] += HeartRound(Stats[stat]);
            }

            DaysElapsed++;

            var stillCritical = critical.Intersect(CriticalStats()).ToList();

            if (stillCritical.Count > 0)
            {
                if (!IsFailing && ModeratorFlags > 0)
                {
                    IsFailing = true;
                    return(false);
                }
                else
                {
                    CurrentPhaseId = StackEggPhase.Id.Failed;
                    return(true);
                }
            }

            IsFailing = false;

            if (GetPhaseProgress() >= 1.0)
            {
                AdvanceToNextPhase();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public bool ActionIsLegal(StackEggAction action)
 {
     if (CurrentPhase == null)
         return false;
     switch (action)
     {
         case StackEggAction.Nothing: return true;
         case StackEggAction.FlagForModerator: return ModeratorFlags > 0;
         default: return !IsFailing && CurrentPhase.AvailableActions.Contains(action);
     }
 }
Ejemplo n.º 3
0
        private void PerformBaseAction(StackEggAction action)
        {
            var phase     = CurrentPhase;
            var newValues = new Dictionary <StackEggStat, double>();

            foreach (var influencedStat in phase.AvailableStats)
            {
                var  oldValue     = Stats[influencedStat];
                var  newValue     = oldValue;
                bool anyInfluence = false,
                     anyPositiveActionInfluence = false;
                var statInfluence = phase.StatInfluences[influencedStat];
                if (statInfluence.ActionInfluences != null && statInfluence.ActionInfluences.ContainsKey(action))
                {
                    var change = statInfluence.ActionInfluences[action];
                    newValue = oldValue + change;
                    if (change > 0)
                    {
                        // see the guarantee in the description of StackEggStatInfluence.ActionInfluences
                        newValue = Math.Max(newValue, HeartRound(oldValue) + 1);
                        anyPositiveActionInfluence = true;
                    }
                    anyInfluence = true;
                }

                if (statInfluence.StatInfluences != null && !anyPositiveActionInfluence)
                {
                    foreach (var kvp in statInfluence.StatInfluences)
                    {
                        var influencingStat = kvp.Key;
                        var arrayIndex      = HeartRoundExtended(Stats[influencingStat]) + 1;
                        var change          = kvp.Value[arrayIndex];
                        if (change.HasValue)
                        {
                            newValue    += change.Value;
                            anyInfluence = true;
                        }
                    }
                }

                if (!anyInfluence)
                {
                    newValue = oldValue + statInfluence.IdleInfluence;
                }

                newValues[influencedStat] = CapStat(newValue, statInfluence.CapAtZero);
            }

            foreach (var stat in phase.AvailableStats)
            {
                Stats[stat] = newValues[stat];
            }
        }
Ejemplo n.º 4
0
        public bool ActionIsLegal(StackEggAction action)
        {
            if (CurrentPhase == null)
            {
                return(false);
            }
            switch (action)
            {
            case StackEggAction.Nothing: return(true);

            case StackEggAction.FlagForModerator: return(ModeratorFlags > 0);

            default: return(!IsFailing && CurrentPhase.AvailableActions.Contains(action));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if we're advancing to a new phase, false otherwise
        /// </summary>
        /// <param name="performedAction"></param>
        /// <returns></returns>
        public bool AdvanceDay(StackEggAction performedAction)
        {
            if (!ActionIsLegal(performedAction))
                throw new InvalidOperationException(performedAction + " is not a legal action at this time");

            var critical = CriticalStats().ToList();

            switch (performedAction)
            {
                case StackEggAction.Ask:
                case StackEggAction.Answer:
                case StackEggAction.Upvote:
                case StackEggAction.Downvote:
                case StackEggAction.Close:
                case StackEggAction.Nothing:
                    PerformBaseAction(performedAction);
                    break;
                case StackEggAction.FlagForModerator:
                    FlagForModerator();
                    break;
            }

            foreach (var stat in CurrentPhase.AvailableStats)
            {
                AccumulatedStats[stat] += HeartRound(Stats[stat]);
            }

            DaysElapsed++;

            var stillCritical = critical.Intersect(CriticalStats()).ToList();
            if (stillCritical.Count > 0)
            {
                if (!IsFailing && ModeratorFlags > 0)
                {
                    IsFailing = true;
                    return false;
                }
                else
                {
                    CurrentPhaseId = StackEggPhase.Id.Failed;
                    return true;
                }
            }

            IsFailing = false;

            if (GetPhaseProgress() >= 1.0)
            {
                AdvanceToNextPhase();
                return true;
            }
            return false;
        }
Ejemplo n.º 6
0
        private void PerformBaseAction(StackEggAction action)
        {
            var phase = CurrentPhase;
            var newValues = new Dictionary<StackEggStat, double>();
            foreach (var influencedStat in phase.AvailableStats)
            {
                var oldValue = Stats[influencedStat];
                var newValue = oldValue;
                bool anyInfluence = false,
                     anyPositiveActionInfluence = false;
                var statInfluence = phase.StatInfluences[influencedStat];
                if (statInfluence.ActionInfluences != null && statInfluence.ActionInfluences.ContainsKey(action))
                {
                    var change = statInfluence.ActionInfluences[action];
                    newValue = oldValue + change;
                    if (change > 0)
                    {
                        // see the guarantee in the description of StackEggStatInfluence.ActionInfluences
                        newValue = Math.Max(newValue, HeartRound(oldValue) + 1);
                        anyPositiveActionInfluence = true;
                    }
                    anyInfluence = true;
                }

                if (statInfluence.StatInfluences != null && !anyPositiveActionInfluence)
                {
                    foreach (var kvp in statInfluence.StatInfluences)
                    {
                        var influencingStat = kvp.Key;
                        var arrayIndex = HeartRoundExtended(Stats[influencingStat]) + 1;
                        var change = kvp.Value[arrayIndex];
                        if (change.HasValue)
                        {
                            newValue += change.Value;
                            anyInfluence = true;
                        }
                    }
                }

                if (!anyInfluence)
                {
                    newValue = oldValue + statInfluence.IdleInfluence;
                }

                newValues[influencedStat] = CapStat(newValue, statInfluence.CapAtZero);
            }

            foreach (var stat in phase.AvailableStats)
            {
                Stats[stat] = newValues[stat];
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var game = new StackEggGame().Initialize();

            while (true)
            {
                if (game.CurrentPhase == null)
                {
                    switch (game.CurrentPhaseId)
                    {
                    case StackEggPhase.Id.WonTheInternet:
                        Console.WriteLine("Congratulations, your site has won the internet!");
                        break;

                    case StackEggPhase.Id.Failed:
                        Console.WriteLine("Oops, your site was shut down.");
                        break;
                    }
                    return;
                }

                var sb = new StringBuilder();
                sb.AppendFormat("{0} day{1} elapsed, your Site is ", game.DaysElapsed, game.DaysElapsed == 1 ? "" : "s");
                switch (game.CurrentPhaseId)
                {
                case StackEggPhase.Id.PrivateBeta:
                    sb.Append("in private beta");
                    break;

                case StackEggPhase.Id.PublicBeta:
                    sb.Append("in public beta");
                    break;

                case StackEggPhase.Id.Launched:
                    sb.Append("fully graduated");
                    break;
                }
                sb.AppendFormat(", phase progress: {0}%", (int)(game.GetPhaseProgress() * 100));
                sb.AppendLine();
                sb.AppendLine("Site stats:");
                foreach (var stat in game.CurrentPhase.AvailableStats)
                {
                    var exact  = game.Stats[stat];
                    var hearts = StackEggGame.HeartRound(exact);
                    sb.AppendFormat("  {0, -10} {1}{2}", stat, new String('#', hearts), new String('.', 4 - hearts));
                    if (StackEggGame.HeartRoundExtended(exact) < 0)
                    {
                        sb.Append(" (dangerously low!)");
                    }
                    sb.AppendLine();
                }
                if (game.ModeratorFlags > 0)
                {
                    sb.AppendLine();
                    sb.AppendLine("  Mod flags  " + game.ModeratorFlags);
                }

                sb.AppendLine();
                if (game.IsFailing)
                {
                    sb.AppendLine("Your Site is on the verge of being shut down!");
                    sb.AppendLine("Only flagging for moderator attention can save it now.");
                    sb.AppendLine();
                }

                sb.AppendLine("Choose your action:");

                foreach (var action in game.AvailableActions())
                {
                    sb.AppendFormat("{0}: {1}", (int)action, action);
                    sb.AppendLine();
                }
                sb.AppendLine("q: Quit");

                Console.Write(sb.ToString());

                var            validAction  = false;
                StackEggAction chosenAction = StackEggAction.Nothing;

                while (!validAction)
                {
                    var s = Console.ReadLine();
                    if (s == "q" || s == "Q")
                    {
                        Console.WriteLine("Good bye.");
                        return;
                    }
                    else
                    {
                        int num;
                        if (int.TryParse(s, out num))
                        {
                            chosenAction = (StackEggAction)num;
                            if (game.ActionIsLegal(chosenAction))
                            {
                                validAction = true;
                            }
                        }
                    }
                    if (!validAction)
                    {
                        Console.WriteLine("That's not a valid action, choose again:");
                    }
                }
                Console.WriteLine();
                Console.WriteLine();
                game.AdvanceDay(chosenAction);
            }
        }