static void system(string command, directory dir) { string[] files = new string[] { "contract.txt" }; string[] stringSplit = command.Split(' '); Dictionary<string, string> lsCommands = new Dictionary<string, string>() { { "temp", "displays temp" }, { "dir", "displays current directory" }, { "cd", "change directory" }, { "help", "display list of commands" } }; string username = "******"; string name = "Ralph Walters"; string department = "Marketing & Branding"; bool moderator = false; command = stringSplit.First(); switch (command) { case "account" : write("Username: {0}", username); write("Name: {0}", name); write("Department: {0}", department); if (moderator == true) { write("Terminal Access: Moderator"); } else { write("Terminal Access: Low"); } break; case "mod" : string userInput = stringSplit[1]; if(userInput == username) { moderator = true; write("Mod granted"); } else { write("Ah-ah-ah! You didn't say the magic word"); } break; case "read" : string document = stringSplit[1]; read(document); break; case "ls" : ls(files); break; case "help" : foreach (var pair in lsCommands) { write(indent(5) + "{0} - {1}", pair.Key, pair.Value); } break; case "pwd" : dir.pwd(); break; case "cd" : if (stringSplit.Length < 2) { break; } switch (stringSplit[1]) { case "" : break; case ".." : dir.removeDir(); break; case "root" : dir.rootDir(); break; default : dir.addDir(stringSplit[1]); break; } break; default : write("{0} not a recognised command.", command); break; } }
static void root(string command, directory dir) { string[] files = new string[] { "whistleblower.txt", "ruling.txt", "server.txt" }; string[] stringSplit = command.Split(' '); Dictionary<string, string> lsCommands = new Dictionary<string, string>(){{"write", "prints input"}, {"read", "read files"}, {"ls", "lists files in current directory"}, {"pwd", "prints working directory"}, {"cd","change directory"}, {"help", "display list of commands"}}; Form1 Form1 = new Form1(); command = stringSplit.First(); switch (command) { case "write" : if (stringSplit.Length == 1) { write("{0} takes an argument.", command); break; } string text = string.Join(" ", stringSplit.Skip(1)); write(text); break; case "read" : string document = stringSplit[1]; read(document); break; case "ls" : ls(files); break; case "help" : foreach (var pair in lsCommands) { write(indent(5) + "{0} - {1}", pair.Key, pair.Value); } break; case "pwd" : dir.pwd(); break; case "cd" : if (stringSplit.Length < 2) { break; } switch(stringSplit[1]) { case "" : break; case ".." : dir.removeDir(); break; case "root": dir.rootDir(); break; default : dir.addDir(stringSplit[1]); break; } break; default : write("{0} not a recognised command.", command); break; } }
static void maintenance(string command, directory dir) { string[] stringSplit = command.Split(' '); command = stringSplit.First(); switch (command) { case "reboot": displayReboot(); dir.reactorPassEnabled = false; dir.serverDir(); display(); break; case "pwd" : dir.pwd(); break; case "cd": if (stringSplit.Length < 2) { break; } switch (stringSplit[1]) { case "": break; case "..": dir.removeDir(); break; case "root": dir.rootDir(); break; default: dir.addDir(stringSplit[1]); break; } break; default: write("{0} not a recognised command.", command); break; } }
static void reactor(string command, directory dir) { string[] stringSplit = command.Split(' '); command = stringSplit.First(); if (!dir.reactorPassEnabled || command == "swordfish") { dir.reactorPassEnabled = false; switch (command) { case "pwd" : dir.pwd(); break; case "cd" : if (stringSplit.Length < 2) { break; } switch (stringSplit[1]) { case "": break; case "..": dir.removeDir(); break; case "root": dir.rootDir(); break; default: dir.addDir(stringSplit[1]); break; } break; case "swordfish" : write("How did you guess the password!?"); break; default: write("{0} not a recognised command.", command); break; } } else { write("Password incorrect!"); dir.removeDir(); } }
static void Main(string[] args) { directory dir = new directory(); dir.addDir("tomIndustries"); bool computerSystem = true; display(); while (computerSystem) { switch (dir.currentDir()) { case "tomIndustries" : root(Console.ReadLine(), dir); break; case "system" : system(Console.ReadLine(), dir); break; case "maintenance" : maintenance(Console.ReadLine(), dir); break; case "reactor" : reactor(Console.ReadLine(), dir); break; } } }