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();
}
}
}
@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