Last active
October 25, 2017 16:39
-
-
Save janellbaxter/426ebbb094e6b15ea9df8d76bcc113ef to your computer and use it in GitHub Desktop.
8.1 Branching Framework; Programming is Fun: C# Adventure Game (Learn C#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 8.1 Branching Framework | |
* Example code from Programming is Fun: C# Adventure Game | |
* Learn C# (for beginners) | |
* http://programmingisfun.com/learn/c-sharp-adventure-game | |
*/ | |
using System; | |
namespace Adventure | |
{ | |
public static class Game | |
{ | |
static string CharacterName; | |
public static void StartGame() | |
{ | |
Console.WriteLine("Game Title"); | |
Console.WriteLine("Welcome to ..."); | |
NameCharacter(); | |
Choice(); | |
} | |
static void Choice() | |
{ | |
string input = ""; | |
Console.WriteLine(CharacterName + " which path will you choose? A or B?"); | |
input = Console.ReadLine(); | |
if (input.ToLower() == "a") | |
{ | |
Console.WriteLine("You've chosen path A!"); | |
} | |
else | |
{ | |
Console.WriteLine("You've chosen path B!"); | |
} | |
} | |
static void NameCharacter() | |
{ | |
Console.WriteLine("What would you like your character's name to be?"); | |
CharacterName = Console.ReadLine(); | |
Console.WriteLine("Great! Your character is now named " + CharacterName); | |
} | |
} | |
class Item | |
{ | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
Game.StartGame(); | |
Console.Read(); | |
} | |
} | |
} |
Double check this section, I was hanging up here by not going back up and inserting the Choice();
public static void StartGame()
{
Console.WriteLine("Game Title");
Console.WriteLine("Welcome to ...");
NameCharacter();
Choice();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I'm currently following along with your lesson guide and I'm having an issue. My current code is written pretty much ver batim what you have here, barring my own personal assets and lines of course. However, when it gets to the point where the player inputs a response, it simply skips over the readline portion so it doesn't write the lines from the "if" and "else if" statements. I don't understand the language well enough to troubleshoot this properly, so any help would be much appreciated.