Inheritance: MonoBehaviour
        // If the user's input is valid, determine if the number is too high or too low.
        public void HighOrLow(int guess)
        {
            // If the guess is in bounds, take a guess away.
            if (guess >= MinGuess && guess <= MaxGuess)
            {
                Player.Guesses--;

                if (guess == CorrectNumber)
                {
                    Fancy.Write(
                        "\n  *******************\n" +
                        "        You Win!\n" +
                        "  *******************\n", 5, color: ConsoleColor.Magenta);
                    Player.Won = true;
                }
                else if (guess > CorrectNumber)
                {
                    Fancy.Write("\tToo High", "\n", 60, pause: 250, afterPause: 0);
                }
                else if (guess < CorrectNumber)
                {
                    Fancy.Write("\tToo Low", "\n", 60, pause: 250, afterPause: 0);
                }
            }
            else
            {
                Fancy.Write($"\tOut of bounds!  Your guess should be between {MinGuess} and {MaxGuess}\n");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Fancy f = new Fancy();

            f.Append(4);
            f.MultAll(2);
            f.AddAll(3);
            int p4 = f.GetIndex(0);

            Console.WriteLine($"Result: {p4} - Expect: {11}");

            f = new Fancy();
            f.Append(2);
            f.AddAll(3);
            f.Append(7);
            f.MultAll(2);
            int p0 = f.GetIndex(0);

            Console.WriteLine($"Result: {p0} - Expect: {10}");
            f.AddAll(3);
            f.Append(10);
            f.MultAll(2);
            p0 = f.GetIndex(0);
            Console.WriteLine($"Result: {p0} - Expect: {26}");
            p0 = f.GetIndex(1);
            Console.WriteLine($"Result: {p0} - Expect: {34}");
            p0 = f.GetIndex(2);
            Console.WriteLine($"Result: {p0} - Expect: {20}");

            Console.WriteLine($"{9 * f.PowMod(3, Fancy.MOD - 2, Fancy.MOD) % Fancy.MOD}");
            Console.WriteLine("Hello World!");
        }
示例#3
0
        // Saves the game by removing the player's data from the old file and adding the player back to the file
        public static void SaveGame(Player player, Difficulty diff)
        {
            // Format of each playerDataString: NAME|ID|SCORE|WIN|LOSS|PLAYS|DIFF

            string        oldFile    = File.ReadAllText(GameFile);                                                        // Read the game file
            List <string> allPlayers = oldFile.Split(",").ToList();                                                       // List all of the players

            allPlayers.RemoveAll(x => x.Equals(""));                                                                      // Get rid of any blank cells from the split method

            allPlayers.Remove(allPlayers.Where(x => x.Contains(player.ID)).First());                                      // Remove the specific player from the file based on ID.  Removes old player info.

            allPlayers.Add($"{player.Name}|{player.ID}|{player.Score}|{player.Win}|{player.Loss}|{player.Plays}|{diff}"); // Add the player back to the file

            StringBuilder newFile = new StringBuilder();

            // Put the , delimeter back
            for (int i = 0; i < allPlayers.Count; i++)
            {
                allPlayers[i] += ",";
                newFile.Append(allPlayers[i]);
            }

            File.WriteAllText(GameFile, newFile.ToString());

            Fancy.Write("\n=== Data saved ===\n", 100, color: ConsoleColor.Green);
        }
 // Checks the user input against a bunch of if statements and redirects to the method that is needed
 public void EvaluateGuess(string guess, out bool invalidGuess)
 {
     if (guess == "rules")
     {
         invalidGuess = false;
         throw new NotImplementedException();
     }
     else if (guess == "settings")
     {
         invalidGuess = false;
         throw new NotImplementedException();
     }
     else                // The guess is a number
     {
         try
         {
             HighOrLow(Convert.ToInt32(guess));
             invalidGuess = false;
         }
         catch (FormatException)
         {
             Fancy.Write("\tYou need to guess a number...\n", 30, afterPause: 250, color: ConsoleColor.Yellow);
             invalidGuess = true;
         }
     }
 }
示例#5
0
    void OnDrawGizmos()
    {
        if (Application.isPlaying)
        {
            return;
        }

        if (should_show && GameObject.FindWithTag("Player") == null)
        {
            should_show = false;
            (new SetupCodeSpells()).Init();
        }


        if (should_destroy)
        {
            should_destroy = false;
            DestroyImmediate(GameObject.Find("ConversationDisplayer"));
            DestroyImmediate(GameObject.Find("Forest"));
            DestroyImmediate(GameObject.Find("IDE"));
            DestroyImmediate(GameObject.Find("Inventory"));
            DestroyImmediate(GameObject.Find("Popup"));
            DestroyImmediate(GameObject.Find("Server"));
            DestroyImmediate(GameObject.Find("InitialScroll"));
            DestroyImmediate(GameObject.Find("Camp"));
            DestroyImmediate(GameObject.Find("temp"));

            Fancy.Clear();
        }
    }
示例#6
0
    public void Init()
    {
        GameObject prefab = Resources.Load("Forest") as GameObject;

        GameObject obj = Fancy.InstantiatePrefab(prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;

        obj.name = prefab.name;
    }
        // This method fulfills step 2 and step 3 of the assignment on Page 218.
        // Writes the user input to file and then prints the text back from the file.
        public static void BackUpAssignment(int difficulty)
        {
            // This little bit satifies the assignment (I think)
            Fancy.Write("\n\nFor the sake of the assignment, Writing your number to a file...  ", 40, afterPause: 750);
            File.WriteAllText(GameIO.AssignmentFile, difficulty.ToString());
            Fancy.Write("Done\n", $"Printing the contents of the file below:\n{File.ReadAllText(GameIO.AssignmentFile)}", 20, 25, pause: 250, afterPause: 250);

            Fancy.Write("\n\nNow...", " time to put way too much work into this assignment!\n\n", pause: 500, afterPause: 500);
        }
        public void Play()
        {
            // Reset Variables
            Player.Guesses = 7;
            Player.Won     = false;

            // Add difficulty multiplier later
            CorrectNumber = rand.Next(MinGuess, MaxGuess);
            Console.WriteLine(CorrectNumber);

            // As long as the player has guesses, guess.
            while (Player.Guesses > 0 && !Player.Won)
            {
                // Determine if the guess is actually valid.
                bool invalidGuess = true;
                while (invalidGuess)
                {
                    Fancy.Write($"\t({Player.Guesses} left) Guess a number: ");
                    string guess = Fancy.ReadLine(ConsoleColor.Green).ToLower();
                    EvaluateGuess(guess, out invalidGuess);
                }
            }

            if (Player.Won)
            {
                Fancy.Write("\nWell done!  ", afterPause: 500);

                Player.Won = true;
                Player.Win++;
                Player.Plays++;

                int scoreGained = (Player.Guesses + 1) * (int)Diff;
                Fancy.Write("You got " + scoreGained + " points!  Here are your stats:\n", color: ConsoleColor.Green);
                Player.Score += scoreGained;
            }
            else
            {
                Fancy.Write("\nYou lost.  It happens to the best of us....\n", afterPause: 750);

                Player.Won = false;
                Player.Loss++;
                Player.Plays++;
            }

            Player.ShowAll();

            GameIO.SaveGame(Player, Diff);            // Save the game.

            Fancy.Write("\nDo you want to play again? (y or n) ");
            string answer = Fancy.ReadLine(ConsoleColor.Cyan);

            if (answer != "y")
            {
                Player.IsPlaying = false;
            }
        }
        public static void RunEx10_13()
        {
            FastFood   krystal   = new FastFood("Krystal");
            CoffeeShop starbucks = new CoffeeShop("Starbucks");
            Fancy      snooty    = new Fancy("Snooty Grill");

            krystal.EatOut();
            starbucks.EatOut();
            snooty.EatOut();
        }
示例#10
0
{ //Only append content to this class as the test suite depends on line info
    public static int CreateObject(int foo, int bar)
    {
        var f = new Fancy()
        {
            Foo = foo,
            Bar = bar,
        };

        Console.WriteLine($"{f.Foo} {f.Bar}");
        return(f.Foo + f.Bar);
    }
 // Show all of the information associated with the player.
 public void ShowAll()
 {
     Fancy.Write(String.Format("\n" +
                               "==================================\n" +
                               $"\tName:         {Name}\n" +
                               $"\tScore:        {Score}\n" +
                               $"\tWins:         {Win}\n" +
                               $"\tLosses:       {Loss}\n" +
                               $"\tGames Played: {Plays}\n" +
                               $"\tWin Rate:     {((double) Win / Plays) * 100:F2}%\n" +
                               $"\tLoss Rate:    {((double) Loss / Plays) * 100:F2}%\n" +
                               "==================================\n", 5));
 }
        static void Main(string[] args)
        {
            Fancy.Write("This program uses classes to ", "divide", " a number by 2.\n", pause: 500, afterPause: 500);

            DivBy2 div = new DivBy2();

            bool loop = true;

            while (loop)
            {
                // Get the number to be divided by 2
                int  number    = 0;
                bool badNumber = true;
                while (badNumber)
                {
                    Fancy.Write("Enter an integer:  ");
                    try
                    {
                        number    = Convert.ToInt32(Console.ReadLine());
                        badNumber = false;
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Enter an INTEGER, please...\n");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Unknown exception: {0}", e.GetType());
                    }
                }

                Fancy.Write(String.Format("\n\tYour number divided by Two: {0} / 2 = ", number));
                div.Divide(number);

                Fancy.Write("This is how many times we could divide " + number + " Before we are less than 2: ");

                // Getting the out parameter
                int divisions = 0;
                div.Divide(number, out divisions);

                Fancy.Write(divisions + "\n", 100, afterPause: 250);

                // Go again?
                Fancy.Write("\nDo you want to enter a new number? (y or n) ", 5);
                string loopChoice = Console.ReadLine();
                if (loopChoice != "y")
                {
                    loop = false;
                }
            }
        }
        // Peice of code that returns the difficulty that the player chooses.
        public static int AskForDifficulty()
        {
            try
            {
                int difficulty = Convert.ToInt32(Fancy.ReadLine(ConsoleColor.Red));
                if (difficulty <= 0 || difficulty >= 5)
                {
                    throw new FormatException();
                }

                Fancy.Write("Going with " + SetDifficulty(difficulty) + " difficulty");
                return(difficulty);
            }
            catch (FormatException)
            {
                int difficulty = 2;
                Fancy.Write("That is not a valid difficulty.  I'll just set you at " + SetDifficulty(difficulty) + "\n", afterPause: 500);
                return(difficulty);
            }
        }
示例#14
0
    public void Init()
    {
        (new SetupBasicWorld()).Init();
        (new SetupInventory()).Init();
        (new SetupUnidee()).Init();
        (new SetupPopup()).Init();
        (new SetupJune()).Init();
        (new SetupConversations()).Init();
        (new SetupSpellbook()).Init();


        GameObject prefab = Resources.Load("Camp") as GameObject;

        GameObject obj = Fancy.InstantiatePrefab(prefab, new Vector3(3.633766f, -0.6606301f, 17.04282f), Quaternion.identity) as GameObject;

        obj.name = prefab.name;


        givePlayerAScroll();
        addEnchantments();
    }
示例#15
0
 void OnDrawGizmosSelected()
 {
     Fancy.setSelected(gameObject);
 }
 // Just some text that shows the tutorial.
 public static void Tutorial()
 {
     Fancy.Write("\n\n\tThe objective of this game is to guess the number I am thinking of.\n\t", 35, afterPause: 1000);
     // Fancy.Write("You can change the difficulty to increase your score for winning.\n\t", 35, afterPause: 750);
     // Fancy.Write("To do so, type 'settings' whenever you are prompted to type a number.\n", 35, afterPause: 750);
 }
示例#17
0
        public Call(string filename)
        {
            Name = Walker.PureName(filename);
            if (Name.Length > 6 && Char.IsDigit(Name[Name.Length - 1]) && Char.IsDigit(Name[Name.Length - 2]) && Char.IsDigit(Name[Name.Length - 3]) && Char.IsDigit(Name[Name.Length - 4]) && Name[Name.Length - 5] == '-')
            {
                ReadableName = Name.Substring(0, Name.LastIndexOf('-')) + " " + Name.Substring(Name.Length - 4);
            }
            else
            {
                ReadableName = Name;
            }

            var lines = File.ReadAllLines(filename);

            foreach (var rawline in lines)
            {
                var line    = rawline.Trim();
                var addline = rawline;
                if (String.IsNullOrEmpty(line))
                {
                    Content += rawline;
                    continue;
                }
                if (new HashSet <char>(line.ToCharArray()).Count == 1 && (line[0] == '-' || line[0] == '='))
                {
                    Content += "<hr/><br/>" + Environment.NewLine;
                    continue;
                }
                if (addline.StartsWith("  ", StringComparison.Ordinal))
                {
                    int i = 0;
                    while (i < addline.Length && addline[i] == ' ')
                    {
                        i++;
                    }
                    addline = Fancy.Times("&nbsp;", i) + addline.TrimStart();
                }
                if (line.StartsWith("###", StringComparison.Ordinal))
                {
                    addline = Fancy.ReplaceFirst(addline, "###", "<h3>") + "</h3>";
                }
                if (line.Contains("**"))
                {
                    while (addline.Contains("**"))
                    {
                        addline = Fancy.ReplaceFirst(addline, "**", "<b>");
                        addline = Fancy.ReplaceFirst(addline, "**", "</b>");
                    }
                }
                if (addline[0] == '*')
                {
                    addline = '•' + addline.Substring(1);
                }
                Content += addline + "<br/>";
            }
            while (Content.Contains("[["))
            {
                int beg = Content.IndexOf("[[", StringComparison.Ordinal);
                int end = Content.IndexOf("]]", StringComparison.Ordinal);
                if (beg < 0 || end < 0 || end < beg)
                {
                    Logger.Log($"Call '{filename}' broken w.r.t. metabrackets");
                    return;
                }
                string before = Content.Substring(0, beg);
                string inside = Content.Substring(beg + 2, end - beg - 2);
                string after = Content.Substring(end + 2);
                string target, text;
                var    split = inside.Split('|');
                if (split.Length == 1)
                {
                    target = inside;
                    text   = inside;
                }
                else if (split.Length == 2)
                {
                    target = split[0];
                    text   = split[1];
                }
                else
                {
                    Logger.Log($"Call '{filename}' broken w.r.t. pipelines");
                    return;
                }

                target = target.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Replace("<br/>", " ").Replace("  ", " ");

                // [[X]]s
                while (after.Length > 0 && Char.IsLetter(after[0]))
                {
                    text += after[0];
                    after = after.Substring(1);
                }

                // linkification
                if (String.IsNullOrEmpty(target) || String.IsNullOrEmpty(text))
                {
                    Logger.Log($"Call '{filename}' broken w.r.t. metalinks");
                    return;
                }

                if (target.StartsWith("http", StringComparison.Ordinal))
                {
                    inside = $"<a href=\"{target}\">{text}</a>";
                }
                else if (target[0] == '@')
                {
                    target = target.Substring(1);
                    if (text[0] == '@')
                    {
                        text = text.Substring(1);
                    }
                    inside = $"<a href=\"../person/{Fancy.DeUmlautify(target.Replace(' ', '_'))}.html\">{text}</a>";
                }
                else if (target[0] == '#')
                {
                    target = target.Substring(1).ToLower();
                    if (text[0] == '#')
                    {
                        text = text.Substring(1);
                    }
                    inside = $"<a href=\"../tag/{target}.html\">{text}</a>";
                }
                else
                {
                    inside = $"<a href=\"../{target}.html\">{text}</a>";
                    //Logger.Log($"Call '{filename}' contvains unintelligible metabracket '{inside}'");
                }

                // get it back together
                Content = before + inside + after;
            }
        }
 public void Divide(int num)
 {
     Fancy.Write(num / 2 + "\n\n", afterPause: 1200);
 }
        static void Main(string[] args)
        {
            // Get the player's name
            Fancy.Write("Welcome to Guess a Game.", "  What is your name: ", 15, 30, pause: 500);
            string playerName = Console.ReadLine();

            string[] playerDataArray;       // Will store the information from saved game file.

            Player player;

            // If there is already a text file, find the player's information
            int        difficulty;          // The number representation of the difficulty
            Difficulty difficultyName;      // The actual difficulty

            // Determine if this player is new or has played before.  If the player is a returning player, get the player's data from the game file.
            bool newPlayer;

            if (File.Exists(GameIO.GameFile))
            {
                playerDataArray = GameIO.GetPlayerData(playerName, out newPlayer);                                // Get the data relating to that player from the game file.
            }
            else
            {
                playerDataArray = null;
                newPlayer       = true;
            }

            // If the player is not new load their information from the game file.
            if (!newPlayer)
            {
                Fancy.Write("Welcome back, " + playerDataArray[0], 50, afterPause: 500, color: ConsoleColor.Magenta);
                try
                {
                    Fancy.Write($"\nYour previous Difficulty: {playerDataArray[6]} | Choose Game Difficulty (1-4): ", 20);

                    // If the player has a save game, instantiate the information.
                    player = new Player(
                        name:       playerDataArray[0],
                        id:         playerDataArray[1],
                        totalScore: Convert.ToInt64(playerDataArray[2]),
                        win:        Convert.ToInt32(playerDataArray[3]),
                        loss:       Convert.ToInt32(playerDataArray[4]),
                        plays:      Convert.ToInt32(playerDataArray[5]));
                }
                catch (IndexOutOfRangeException)
                {
                    Fancy.Write(
                        ".  You closed the program prematurely: no saved data.\n" +
                        "To save your game history, be sure to exit the program as intended.\n", afterPause: 500, color: ConsoleColor.Yellow);
                    Fancy.Write("Choose Game Difficulty: ", 20);
                    player = new Player(playerName);
                }
                catch (Exception ex)
                {
                    Fancy.Write($"\n\n\tI don't know what went wrong!!\n\t{ex.GetType()}\n\t{ex.Message}\n\n");
                    player = new Player(playerName);
                }

                difficulty     = AskForDifficulty();
                difficultyName = SetDifficulty(difficulty);
            }
            else                // No text file? make one with the player's information.
            {
                player = new Player(playerName);

                Fancy.Write("What difficulty do you want to play? (1, 2, 3, 4): ", 20);
                difficulty     = AskForDifficulty();
                difficultyName = SetDifficulty(difficulty);

                GameIO.AddPlayerToFile(player, difficultyName);

                Tutorial();
            }

            BackUpAssignment(difficulty);

            GuessANumber game = new GuessANumber(player, difficultyName);

            // Game Loop, stops when the player doesn't want to play anymore.
            while (player.IsPlaying)
            {
                game.Play();
            }

            Fancy.Write("\n\nThanks for playing!", 75, color: ConsoleColor.Green);
            Console.Read();
        }
示例#20
0
 void OnDrawGizmos()
 {
     Fancy.gizmoFor(gameObject);
 }