Exemplo n.º 1
0
 void WriteTamagotchiStatus(TamagotchiContract tama)
 {
     WriteLine($"Viewing Tamagotchi: {tama.Name} [Status: {tama.Status}]");
     if (!tama.HasDied)
     {
         WriteLine($"[Bordedom: {tama.Boredom}] [Health: {tama.Health}] [Hunger: {tama.Hungriness}] [Sleep: {tama.Sleepiness}]");
     }
 }
Exemplo n.º 2
0
        string StartRulesView(TamagotchiContract tama)
        {
            var rules = tama.Rules;
            var index = 0;

            Func <RuleContract> current = () => rules.ElementAt(index);
            Action next    = () => index = (index + 1) % rules.Count();
            Action refresh = () =>
            {
                tama  = _repo.Get(tama.ID);
                rules = tama.Rules;
            };

            while (true)
            {
                var rule = current.Invoke();

                System.Console.Clear();
                WriteHeader();

                WriteTamagotchiStatus(tama);

                WriteLine("Type [quit] to close the application.");
                WriteLine("Type [back] to go back to the start.");
                WriteLine("Type [next] to go to the next rule");

                if (rule.IsActive)
                {
                    WriteLine("Type [off] to deactivate the rule");
                }
                else
                {
                    WriteLine("Type [on] to activate the rule");
                }

                WriteLine();
                Write($"[Name: {rule.Name}] [Active: ", ConsoleColor.Gray);

                ConsoleColor color = ConsoleColor.Green;

                if (!rule.IsActive)
                {
                    color = ConsoleColor.Red;
                }

                Write($"{rule.IsActive}", color);
                Write("]", ConsoleColor.Gray);
                WriteLine();

                WriteLine($"Discription:{NewLine}[{rule.Discription}]");
                WriteLine();

                try { _repo.HasData(); }
                catch (Exception) { ShowConnectionError(); }

                var input = AskForInput();

                if (input == "off")
                {
                    _repo.SetRule(tama.Name, rule.Name, false);
                    refresh.Invoke();
                    continue;
                }

                if (input == "on")
                {
                    _repo.SetRule(tama.Name, rule.Name, true);
                    refresh.Invoke();
                    continue;
                }

                if (input == "next")
                {
                    next.Invoke();
                    continue;
                }

                if (input == "quit" || input == "back")
                {
                    return(input);
                }
            }
        }
Exemplo n.º 3
0
        string StartDetailView(TamagotchiContract tama)
        {
            if (tama == null)
            {
                return("");
            }

            while (true)
            {
                System.Console.Clear();
                WriteHeader();

                WriteTamagotchiStatus(tama);

                if (tama.IsInCoolDown)
                {
                    WriteLine();
                    WriteLine($"Cooldown in effect until {tama.CoolDownUntilUtc.ToLocalTime()}.");
                    if (tama.CoolDownLeft.Hours > 0)
                    {
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Hours} hours {tama.CoolDownLeft.Minutes} minutes and {tama.CoolDownLeft.Seconds} seconds.");
                    }
                    else if (tama.CoolDownLeft.Hours == 0 && tama.CoolDownLeft.Minutes > 0)
                    {
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Minutes} minutes and {tama.CoolDownLeft.Seconds} seconds.");
                    }
                    else if (tama.CoolDownLeft.Hours == 0 && tama.CoolDownLeft.Minutes == 0)
                    {
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Seconds} seconds.");
                    }
                }

                WriteLine();

                WriteLine("Type [quit] to close the application." + NewLine +
                          "Type [back] to go back to the Tamgotchi overview." + NewLine +
                          "Type [rules] to view the rules for this Tamagotchi." + NewLine +
                          "Type [refresh]/[r] to update this page.");

                if (tama.HasDied)
                {
                    WriteLine("Type [delete] to delete this Tamagotchi.");
                }

                if (!tama.IsInCoolDown && !tama.HasDied)
                {
                    WriteLine("Available actions:" + NewLine +
                              "    [eat] [sleep] [play] [workout] [hug]");
                }

                WriteLine();

                try { _repo.HasData(); }
                catch (Exception) { ShowConnectionError(); }

                string input = AskForInput();

                if (input == "quit" || input == "back")
                {
                    return(input);
                }

                switch (input)
                {
                case "quit":
                case "back":
                    return(input);

                case "refresh":
                case "r":
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "eat":
                    if (!_repo.Eat(tama.Name))
                    {
                        AskForInput("Action not available, press any button to continue");
                    }
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "sleep":
                    if (!_repo.Sleep(tama.Name))
                    {
                        AskForInput("Action not available, press any button to continue");
                    }
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "play":
                    if (!_repo.Play(tama.Name))
                    {
                        AskForInput("Action not available, press any button to continue");
                    }
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "workout":
                    if (!_repo.Workout(tama.Name))
                    {
                        AskForInput("Action not available, press any button to continue");
                    }
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "hug":
                    if (!_repo.Hug(tama.Name))
                    {
                        AskForInput("Action not available, press any button to continue");
                    }
                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    break;

                case "rule":
                case "rules":
                    var output = StartRulesView(tama);
                    if (output == "quit")
                    {
                        return("quit");
                    }

                    try { tama = _repo.Get(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }

                    break;

                case "delete":
                case "remove":
                case "d":
                    if (!tama.HasDied)
                    {
                        WriteLine("Alive Tamagotchis cannot be deleted.", ConsoleColor.Red);
                        AskForInput("Press any button to continue");
                        break;
                    }

                    try { _repo.Remove(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }

                    return("back");

                case "delete -g":
                case "remove -g":
                case "d -g":
                    try { _repo.Remove(tama.Name); }
                    catch (Exception) { ShowConnectionError(); }
                    return("back");

                default:
                    WriteLine("Command not recognized.", ConsoleColor.Red);
                    AskForInput("Press any button to continue");
                    break;
                }
            }
        }
Exemplo n.º 4
0
 void WriteTamagotchiStatus(TamagotchiContract tama)
 {
     WriteLine($"Viewing Tamagotchi: {tama.Name} [Status: {tama.Status}]");
     if (!tama.HasDied)
         WriteLine($"[Bordedom: {tama.Boredom}] [Health: {tama.Health}] [Hunger: {tama.Hungriness}] [Sleep: {tama.Sleepiness}]");
 }
Exemplo n.º 5
0
        string StartRulesView(TamagotchiContract tama)
        {
            var rules = tama.Rules;
            var index = 0;

            Func<RuleContract> current = () => rules.ElementAt(index);
            Action next = () => index = (index + 1) % rules.Count();
            Action refresh = () =>
            {
                tama = _repo.Get(tama.ID);
                rules = tama.Rules;
            };

            while (true)
            {
                var rule = current.Invoke();

                System.Console.Clear();
                WriteHeader();

                WriteTamagotchiStatus(tama);

                WriteLine("Type [quit] to close the application.");
                WriteLine("Type [back] to go back to the start.");
                WriteLine("Type [next] to go to the next rule");

                if (rule.IsActive)
                    WriteLine("Type [off] to deactivate the rule");
                else
                    WriteLine("Type [on] to activate the rule");

                WriteLine();
                Write($"[Name: {rule.Name}] [Active: ", ConsoleColor.Gray);

                ConsoleColor color = ConsoleColor.Green;

                if (!rule.IsActive)
                    color = ConsoleColor.Red;

                Write($"{rule.IsActive}", color);
                Write("]", ConsoleColor.Gray);
                WriteLine();

                WriteLine($"Discription:{NewLine}[{rule.Discription}]");
                WriteLine();

                try { _repo.HasData(); }
                catch (Exception) { ShowConnectionError(); }

                var input = AskForInput();

                if (input == "off")
                {
                    _repo.SetRule(tama.Name, rule.Name, false);
                    refresh.Invoke();
                    continue;
                }

                if (input == "on")
                {
                    _repo.SetRule(tama.Name, rule.Name, true);
                    refresh.Invoke();
                    continue;
                }

                if (input == "next")
                {
                    next.Invoke();
                    continue;
                }

                if (input == "quit" || input == "back")
                    return input;
            }
        }
Exemplo n.º 6
0
        string StartDetailView(TamagotchiContract tama)
        {
            if (tama == null)
                return "";

            while (true)
            {
                System.Console.Clear();
                WriteHeader();

                WriteTamagotchiStatus(tama);

                if (tama.IsInCoolDown)
                {
                    WriteLine();
                    WriteLine($"Cooldown in effect until {tama.CoolDownUntilUtc.ToLocalTime()}.");
                    if (tama.CoolDownLeft.Hours > 0)
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Hours} hours {tama.CoolDownLeft.Minutes} minutes and {tama.CoolDownLeft.Seconds} seconds.");
                    else if (tama.CoolDownLeft.Hours == 0 && tama.CoolDownLeft.Minutes > 0)
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Minutes} minutes and {tama.CoolDownLeft.Seconds} seconds.");
                    else if (tama.CoolDownLeft.Hours == 0 && tama.CoolDownLeft.Minutes == 0)
                        WriteLine($"    Cooldown will take another {tama.CoolDownLeft.Seconds} seconds.");
                }

                WriteLine();

                WriteLine("Type [quit] to close the application." + NewLine +
                        "Type [back] to go back to the Tamgotchi overview." + NewLine +
                        "Type [rules] to view the rules for this Tamagotchi." + NewLine +
                        "Type [refresh]/[r] to update this page.");

                if (tama.HasDied)
                    WriteLine("Type [delete] to delete this Tamagotchi.");

                if (!tama.IsInCoolDown && !tama.HasDied)
                    WriteLine("Available actions:" + NewLine +
                              "    [eat] [sleep] [play] [workout] [hug]");

                WriteLine();

                try { _repo.HasData(); }
                catch (Exception) { ShowConnectionError(); }

                string input = AskForInput();

                if (input == "quit" || input == "back")
                    return input;

                switch (input)
                {
                    case "quit":
                    case "back":
                        return input;

                    case "refresh":
                    case "r":
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "eat":
                        if (!_repo.Eat(tama.Name))
                            AskForInput("Action not available, press any button to continue");
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "sleep":
                        if (!_repo.Sleep(tama.Name))
                            AskForInput("Action not available, press any button to continue");
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "play":
                        if (!_repo.Play(tama.Name))
                            AskForInput("Action not available, press any button to continue");
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "workout":
                        if (!_repo.Workout(tama.Name))
                            AskForInput("Action not available, press any button to continue");
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "hug":
                        if (!_repo.Hug(tama.Name))
                            AskForInput("Action not available, press any button to continue");
                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        break;

                    case "rule":
                    case "rules":
                        var output = StartRulesView(tama);
                        if (output == "quit")
                            return "quit";

                        try { tama = _repo.Get(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }

                        break;

                    case "delete":
                    case "remove":
                    case "d":
                        if (!tama.HasDied)
                        {
                            WriteLine("Alive Tamagotchis cannot be deleted.", ConsoleColor.Red);
                            AskForInput("Press any button to continue");
                            break;
                        }

                        try { _repo.Remove(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }

                        return "back";

                    case "delete -g":
                    case "remove -g":
                    case "d -g":
                        try { _repo.Remove(tama.Name); }
                        catch (Exception) { ShowConnectionError(); }
                        return "back";

                    default:
                        WriteLine("Command not recognized.", ConsoleColor.Red);
                        AskForInput("Press any button to continue");
                        break;
                }

            }
        }
Exemplo n.º 7
0
 public void TamagotchiEdit(TamagotchiContract contract)
 {
     throw new NotImplementedException();
 }