Skip to content

Instantly share code, notes, and snippets.

@janellbaxter
Last active October 25, 2017 16:39
Show Gist options
  • Save janellbaxter/426ebbb094e6b15ea9df8d76bcc113ef to your computer and use it in GitHub Desktop.
Save janellbaxter/426ebbb094e6b15ea9df8d76bcc113ef to your computer and use it in GitHub Desktop.
8.1 Branching Framework; Programming is Fun: C# Adventure Game (Learn C#)
/*
* 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();
}
}
}
@BoxFanHero
Copy link

BoxFanHero commented Oct 20, 2017

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.

@MAX-P0W3R
Copy link

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