Created
June 12, 2018 22:04
-
-
Save janell-baxter/8edc43111d478bb60fd4bb7418643eeb to your computer and use it in GitHub Desktop.
Experimental practice example with arrays, lists, I/O, classes/instances, conditional statements, etc.
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
using System; | |
using System.Collections.Generic; | |
using static System.Console; | |
namespace ExplorableAreasI | |
{ | |
class Game | |
{ | |
List<Location> locations = new List<Location>(); | |
Random random = new Random(); | |
public Game() | |
{ | |
Title = "Explorable Game"; | |
Player.GetPlayerName(); | |
ReadKey(); | |
SetUp(); | |
Run(); | |
} | |
public void Run() | |
{ | |
string input = ""; | |
while (input != "x") | |
{ | |
Clear(); | |
WriteLine("Your inventory: "); | |
foreach (string s in Player.Inventory) | |
{ | |
WriteLine(s); | |
} | |
WriteLine(Player.Name + ", where would you like to visit?"); | |
Menu(); | |
input = ReadLine(); | |
if (input == "x") | |
{ | |
//end game | |
WriteLine("Thanks for playing!"); | |
ReadKey(); | |
} | |
else | |
{ | |
//error checking would go here to make sure that it is a number | |
Travel(Convert.ToInt32(input)); | |
} | |
} | |
} | |
public void Menu() | |
{ | |
int i = 1; | |
foreach (Location l in locations) | |
{ | |
WriteLine(i + ". " + l.Name + " (" + l.Description + ")"); | |
i++; | |
} | |
} | |
public void Travel(int choice) | |
{ | |
int item = 0; | |
Clear(); | |
choice--; | |
WriteLine("You are now at " + locations[choice].Name); | |
item = random.Next(locations[choice].Items.Length); | |
if (locations[choice].Name== "Zjarri Grave") | |
{ | |
if (Player.Inventory.Contains("heat suit")) | |
{ | |
//they can enter the lava field | |
} | |
else | |
{ | |
Console.WriteLine("You are barred from entering. Return after you have found a safety heat suit."); | |
Console.WriteLine("Press any key to continue..."); | |
Console.ReadKey(); | |
Run(); | |
} | |
} | |
if (locations[choice].Items[item] == "") | |
{ | |
WriteLine("You look around the area. Not much to see. Maybe you should try visiting again later?"); | |
} | |
else | |
{ | |
WriteLine("You've found something! One " + locations[choice].Items[item] + " has been added to your inventory!"); | |
Player.Inventory.Add(locations[choice].Items[item]); | |
} | |
WriteLine("press any key to continue..."); | |
ReadKey(); | |
Run(); | |
} | |
public void SetUp() | |
{ | |
Title = "Super Awesome Adventure Exploration!"; | |
Location Sylth = new Location("Sylth", "Snow field", "ice sword", "snow gnome"); | |
Location BadCity = new Location("Bad City", "Technologically savvy urban city", "star", "grunge gnome"); | |
Location GoodeCity = new Location("Goode City", "Urban city with a dark side", "power gloves", "power gnome"); | |
Location ZjarriGrave = new Location("Zjarri Grave", "Lava field", "lava rock", "fire gnome"); | |
Location SweetSea = new Location("Sweet Sea", "Beautiful sea on the coast", "heal pack", "water gnome"); | |
Location LegsOnFire = new Location("Legs On Fire", "Picturesque mountains", "potion", "heat suit"); | |
Location ClockWerk = new Location("Clockwerk", "Fantastical town", "silver sword", "attack gnome"); | |
locations.Add(Sylth); | |
locations.Add(BadCity); | |
locations.Add(GoodeCity); | |
locations.Add(ZjarriGrave); | |
locations.Add(SweetSea); | |
locations.Add(LegsOnFire); | |
locations.Add(ClockWerk); | |
} | |
} | |
} |
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
namespace ExplorableAreasI | |
{ | |
class Location | |
{ | |
public string Name = ""; | |
public string Description = ""; | |
public string[] Items = new string[] { "", "", "rock", "credit", "apple", "" }; | |
public Location() | |
{ | |
} | |
public Location(string name, string description, string item1, string item2) | |
{ | |
Name = name; | |
Description = description; | |
Items[0] = item1; | |
Items[1] = item2; | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace ExplorableAreasI | |
{ | |
class Player | |
{ | |
public static string Name = "Anonymous Hero"; | |
public static List<string> Inventory = new List<string>(); | |
public static string DataFile = "data.txt"; | |
public static void GetPlayerName() | |
{ | |
if (File.Exists(DataFile)) | |
{ | |
Name = File.ReadAllText(DataFile); | |
Console.WriteLine("Welcome back " + Name + "!"); | |
} | |
else | |
{ | |
string name = ""; | |
Console.WriteLine("Please enter your name:"); | |
name = Console.ReadLine(); | |
File.WriteAllText(DataFile, name); | |
Name = name; | |
} | |
Console.WriteLine("Press any key to continue..."); | |
} | |
} | |
} |
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
/* | |
* [Your Title] | |
* by Your Name, Date | |
* | |
* This work is a derivative of | |
* "Explorable Areas I" | |
* by the Summer 2018 Introduction to Programming class (iam.colum.edu), used under CC BY. | |
* https://creativecommons.org/licenses/by/4.0/ | |
* "[Your Game Title]" is licensed under | |
* [license] by [Your name here]. | |
*/ | |
namespace ExplorableAreasI | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
Game game = new Game(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment