I need some help with my C# text adventure game.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: I need some help with my C# text adventure game.

  1. #1
    Join Date
    Oct 2010
    Posts
    1

    I need some help with my C# text adventure game.

    anyway, I've been making a old school text adventure using a bunch of IF statements. Anyway, I'm not sure how to get it to stop breaking lines in the middle of words.
    you see, if the stuff to be printed looks like this:

    Console.WriteLine("You are now playing as Urist McMagus, dwarven wizard of the 8th arcane circle. Ahead of him, there is an obsidian tower, raised from the ground by the evil power of Maliboros, the last Dark Lord! What will Urist do? Go away Or head onward:");

    it prints like this
    You are now playing as Urist McMagus, dwarven wizard of the 8th arcane circle. A
    head of him there is an obsidian tower, raised from the ground by the evil power o
    f Maliboros blah blah blah.

    Please help.
    Oh, and in case you were wondering my code looks like this:


    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                int number;
                string input;
                int othernumber;
                number = 1;
                othernumber = 2;
    
    
                Console.WriteLine("You are now playing as Urist McMagus, dwarven wizard of the 8th arcane circle. Ahead of him, there is an obsidian tower, raised from the ground by the evil power of Maliboros, the last Dark Lord! What will Urist do? Go away Or head onward:");
    
                while (number < 100)
                {
                    input = Console.ReadLine();
                    input = input.ToLower();
    
                    {
                        if (input == "go away")
                        {
                            Console.WriteLine("Fine then. The world is taken over and undergoes a thousand years of darkness! And it’s all your fault. GAME OVER!");
                            number = 101;
    
                        }
                        else if (input == "die")
                        {
                            Console.WriteLine("Okay. GAME OVER!");
                            number = 101;
    
                        }
                        else if (input == "find an easter egg")
                        {
                            Console.WriteLine("Hrm... Let me think about that. Shure, why not.");
    
    
                        }
                        else if (input == "neither")
                        {
                            Console.WriteLine("Argghhhh.... Binary! No! Third! Option!... Oh my god! I see it all! I can see the Matrix! I! AM! THE! ONE!!!!!!... Just kidding.");
    
    
                        }
                        else if (input == "tie shoelaces")
                        {
                            Console.WriteLine("You're wearing boots.");
    
    
                        }
                        else if (input == "tie bootlaces")
                        {
                            Console.WriteLine("You're wearing METAL boots.");
    
    
                        }
                        else if (input == "don't find an easter egg")
                        {
                            Console.WriteLine("Sucks to be you I suppose.");
    
    
                        }
                        else if (input == "head onward")
                        {
    
                            Console.WriteLine("You look at the door and then rush in blindly. The door shuts behind you and out of the darkness come zombies, moaning in pain. What will Urist do! Fireball them Or magic missile them Or run away:");
                        part1:
                            input = Console.ReadLine();
                            input = input.ToLower();
                            if (input == "fireball them")
                            {
                                Console.WriteLine("Congrads. You burnt their flesh off, leaving skeletons. What did you expect! THEY KILL YOU! GAME OVER");
                                number = 101;
                            }
                            else if (input == "run away")
                            {
                                Console.WriteLine("You turn around and hit the door. Bad move. The undead on you.  OM NOM NOM NOM NOM NOM NOM. GAME OVER!");
                                number = 101;
                            }
                            else if (input == "kiss zombie")
                            {
                                Console.WriteLine("You just got your lips eaten off. I hope you're happy with yourself. GAME OVER!");
                                number = 202;
    
                            }
                            else if (input == "magic missile them")
                            {
    
                                Console.WriteLine("The magic missile bursts out and bounces off the zombies. Then the screen blacks out and when it turns back on little bits of zombie are scattered everywhere and Urist is saying \"That was awesome! The only downside is I'll never get to do that again!\" Anyway you have Urist head onward.");
                            part10:
                                Console.WriteLine("Urist is in a maze of twisty little passages, all alike. On the floor you see the words \"The Konami Code\" What will Urist do? go north Or go south Or go east Or go west:");
                            part2:
                                input = Console.ReadLine();
                                input = input.ToLower();
                                if (input == "go north")
                                {
                                   (code removed due to being repeditive)
                                                        
                                                                Console.WriteLine("Success! Where the entrance once stood there is a pannel with three buttons on it. One says \"A\", one says \"B\" and one says \"Start\". Will Urist press \"A\" Or \"B\" Or press \"Start\".");
                                                            part18:
                                                                input = Console.ReadLine();
                                                                input = input.ToLower();
                                                                if (input == "press start")
                                                                {
                                                                    Console.WriteLine("The buttons glow for a second, but then it fades.");
                                                                        goto part18;
                                                                }
                                                                else if (input == "press b")
                                                                    {
                                                                    Console.WriteLine("The buttons glow for a second, but then it fades.");
                                                                        goto part18;
                                                                }
                                                                else if (input == "press a")
                                                                {
                                                                    Console.WriteLine("The button glows with a yellow light. Now should Urist press \"B\" or press \"Start\"?");
                                                                    input = Console.ReadLine();
                                                                    input = input.ToLower();
                                                                    if (input == "press start")
                                                                    {
                                                                        Console.WriteLine("The button glows for a second, but then they all fade.");
                                                                        goto part18;
                                                                    }
                                                                    else if (input == "press a")
                                                                    {
                                                                        Console.WriteLine("The button glows for a second, but then they all fade.");
                                                                        goto part18;
                                                                    }
                                                                    else if (input == "press b")
                                                                    {
                                                                        Console.WriteLine("The button glows with a yellow light. Then, Urist goes and presses \"Start\" as it's the only other option. Then, the slab lowers and behind it you see a pasageway.");
                                                                        number = 2;
                                                                    }
                                                                    else
                                                                    {
                                                                        Console.WriteLine("Hrm... Let me think about that. No!");
                                                                        goto part18;
                                                                    }
                                                               
                                                        (code also removed due to being repeditive)
                                }
                                else if (input == "go south")
                                {
                                    goto part10;
                                }
                                else if (input == "go east")
                                {
                                    goto part10;
                                }
                                else if (input == "go west")
                                {
                                    goto part10;
                                }
    
                                if (number == othernumber)
                                {
                                
                                    Console.WriteLine("After wandering through the passages for some time you come across a minotaur. What will Urist do? Fireball it Or talk to it Or warhammer it:");
                                part3:
                                    input = Console.ReadLine();
                                    input = input.ToLower();
                                    if (input == "warhammer it")
                                    {
                                        Console.WriteLine("The minotaur shrugs off the blow and pimp slaps Urist into a wall, breaking several of Urist's ribs and puncturing Urist's trachea. He spends the rest of his life gasping for a breath that will never come. GAME OVER!");
                                        number = 101;
                                    }
    
                                    else if (input == "fireball it")
                                    {
                                        Console.WriteLine("The minotaur dies horably, screaming in pain and ripping at its burning flesh. Urist continues on until- OHMYGOD DEATH ON SWIFT WINGS OH DEAR ARMOK ITS EATING MY FACE! GAME OVER");
                                        number = 101;
                                    }
                                    else if (input == "talk to it")
                                    {
    
                                        Console.WriteLine("The minotaur starts to pimp slap Urist and then stops when asked \"Why are you here?\" the minotaur thinks for a bit and starts to cry. Through the sobs you hear him say \"My brother always got the attention. He could find his way out of mazes. Mom always loved him better and I wanted to prove I was just as good as him. Here. Take this string. I'll hold on to the other end and if you get out, I can follow you.\" Urist agrees and then, after a lot of twisty turns, you guide Urist and the minotaur out. Then, a horrid fell monstrosity with wings and claws jumps from the ceiling and slashes at the minotaur, who fights back. Urist runs, and from behind him you hear the sound of a minotaur dying and a forgotten beast renaming itself \"Jozan Snugglepuffs the cuteness of kittens\" in order to confuse anyone using the unit screen. What should Urist do? Steal the minotaur’s wallet or head onward?");
                                    part4:
                                        input = Console.ReadLine();
                                        input = input.ToLower();
                                        if (input == "steal the minotaur's wallet")
                                        {
                                            Console.WriteLine("You head back and attempt to take the minotaur’s wallet. Unfortunately, not only was he not wearing any pants to contain a wallet, the forgotten beast is still there. GAME OVER");
                                            number = 101;
                                        }
                                        else if (input == "head onward")
                                        {
    
                                            Console.WriteLine("Urist goes onward and enters a room. Suddenly, the door closes behind him and you see in front of him... Maliboros, the last Dark Lord! What should Urist do: Fireball him Or magic missile him Or warhammer him Or kill him?");
                                        part5:
                                            input = Console.ReadLine();
                                            input = input.ToUpper();
                                            if (input == "FIREBALL HIM")
                                            {
                                                Console.WriteLine("Urist moves his hands into the casting position but when the fireball should come out all you hear is a click. \"Out of spells?\" says the Dark Lord. \"Pity. I've still got mine.\" GAME OVER");
                                                number = 101;
                                            }
                                            else if (input == "MAGIC MISSILE HIM")
                                            {
                                                Console.WriteLine("The magic missile burst out and bounces off the Dark Lord. He laughs and then kills Urist. GAME OVER!");
                                                number = 101;
                                            }
                                            else if (input == "WARHAMMER HIM")
                                            {
                                                Console.WriteLine("You run forward and the Dark Lord hits Urist with his mace. GAME OVER");
                                                number = 101;
                                            }
                                            else if (input == "DIE")
                                            {
                                                Console.WriteLine("Suicide is not the answer.");
                                                goto part5;
                                            }
    
    
                                            else if (input == "KILL HIM")
                                            {
    
                                                Console.WriteLine("What, with your bare hands?");
                                            part6:
                                                input = Console.ReadLine();
                                                input = input.ToLower();
                                                if (input == "no")
                                                {
    
                                                    Console.WriteLine("Okay then. GAME OVER");
                                                    number = 101;
                                                }
                                                else if (input == "yes")
                                                {
                                                    Console.WriteLine("Okay then... Wait... Oh my god... YOU JUST KILLED THE DARK LORD WITH YOUR BARE HANDS! The tower collapses due to a complete lack of ontological inertia but that's no challenge to someone as awesome as you. As the fans carry Urist away and chant \"All hail Lord Urist!\" You look up to the sky and realize what’s going to happen next. You're going to kill Chuck Norris.");
                                                    Console.WriteLine("To be continued.");
                                                    number = 101;
                                                }
                                                else
                                                {
                                                    Console.WriteLine("Hrm... Let me think about that. No!");
                                                    goto part6;
                                                }
                                            }
    
                                            else
                                            {
                                                Console.WriteLine("Hrm... Let me think about that. No!");
                                                goto part5;
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("Hrm... Let me think about that. No!");
                                            goto part4;
                                        }
                                    }
    
                                    else
                                    {
                                        Console.WriteLine("Hrm... Let me think about that. No!");
                                        goto part3;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Hrm... Let me think about that. No!");
                                    goto part2;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Hrm... Let me think about that. No!");
                                goto part1;
                            }
    
                        }
                        else
                        {
                            Console.WriteLine("Hrm... Let me think about that. No!");
                        }
                    }
    
                }
                Console.ReadKey();
    
            }
        }
    
    }
    Last edited by PeejAvery; October 30th, 2010 at 12:16 PM. Reason: Added code tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,865

    Re: I need some help with my C# text adventure game.

    [ moved thread ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: I need some help with my C# text adventure game.

    Create a Subroutine() that formats lines.

    Pass the string to it.

    Parse the lines using Left$,Right$,Mid$ functions

    Produce a string (with VbCrLF) in the right place(s)

    Return result, and print it!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Aug 2008
    Posts
    902

    Re: I need some help with my C# text adventure game.

    Well in windows the default console is 80 characters wide. You could either take the time and initiative to insert a '/n' no less than every 80 characters, where appropriate, in all your string literals.

    You could also write a routine to take a string and add newlines to it where appropriate.

    You should probably consider refactoring your program to make it more manageable. I assume you're still leaning so its ok, but you don't normally write a game as 100+ if else statements and a bunch of WriteLine("string literal here")'s.

    Consider creating a List<string> to hold all your strings, and maybe load the strings from an XML file or something, that way you don't have a bunch of random strings floating around your program code. In other words, separate your data from your code.

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: I need some help with my C# text adventure game.

    XML in a console app?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: I need some help with my C# text adventure game.

    You should have your own OutputText / InputText methods anyway, which uses Console. The output method could do all the formatting.

    An added bonus would be: You could very easily change from using the console to using a Form, for example, without having to change lots of code all over the place.
    My hobby projects:
    www.rclsoftware.org.uk

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center