diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 365fb84c..297c880b 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -1,86 +1,152 @@ using System; +using System.Collections.Generic; +using System.Threading; namespace Mastermind { class Program { - // possible letters in code - public static char[] letters = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; - - // size of code - public static int codeSize = 4; - - // number of allowed attempts to crack the code - public static int allowedAttempts = 10; - - // number of tried guesses - public static int numTry = 0; - - // test solution - public static char[] solution = new char[] {'a', 'b', 'c', 'd'}; - - // game board - public static string[][] board = new string[allowedAttempts][]; - - - public static void Main() + static void Main(string[] args) { - char[] guess = new char[4]; - CreateBoard(); - DrawBoard(); - Console.WriteLine("Enter Guess:"); - guess = Console.ReadLine().ToCharArray(); + Game game = new Game(GenerateSolution()); + int TurnsRemaining = 0; + for (int turns = 10; turns > 0; turns--) + { + Console.WriteLine($"You have {turns} tries left"); + Console.WriteLine("Choose four letters: "); + string letters = Console.ReadLine(); + Ball[] balls = new Ball[4]; + for (int i = 0; i < 4; i++) + { + balls[i] = new Ball(letters[i].ToString()); + } + Row row = new Row(balls); + string winningString = ""; + foreach (var item in game.answer) + { + winningString = winningString + item; + } + if (letters == winningString) + { + Console.Clear(); + Console.WriteLine("You Win"); + Thread.Sleep(3000); + TurnsRemaining = turns; + break; + } + game.AddRow(row); + Console.WriteLine(game.Rows); - // leave this command at the end so your program does not close automatically - Console.ReadLine(); + } + Console.WriteLine(TurnsRemaining > 0 ? "Great Job" : "Out Of Turns"); } - - public static bool CheckSolution(char[] guess) + public static string[] GenerateSolution() { - // Your code here + Random rnd = new Random(); + List available = new List { "a", "b", "c", "d", "e", "f" }; + string[] solution = new string[4]; + int one = rnd.Next(1, 6); + solution[0] = available[one]; + available.RemoveRange(one, 1); + int two = rnd.Next(1, 5); + solution[1] = available[two]; + available.RemoveRange(two, 1); + int three = rnd.Next(1, 4); + solution[2] = available[three]; + available.RemoveRange(three, 1); + int four = rnd.Next(1, 3); + solution[3] = available[four]; + available.RemoveRange(four, 1); + //uncomment to print solution Console.WriteLine(solution[0] + solution[1] + solution[2] + solution[3]); + return solution; + } + } - return false; + class Game + { + private List rows = new List(); + public string[] answer { get; private set; } = new string[4]; + + public Game(string[] answer) + { + this.answer = answer; } - - public static string GenerateHint(char[] guess) + + private string Score(Row row) { - // Your code here - return " "; + string[] answerClone = (string[])this.answer.Clone(); + int red = 0; + for (int i = 0; i < 4; i++) + { + if (answerClone[i] == row.balls[i].Letter) + { + red++; + } + } + + int white = 0; + for (int i = 0; i < 4; i++) + { + int foundIndex = Array.IndexOf(answerClone, row.balls[i].Letter); + if (foundIndex > -1) + { + white++; + answerClone[foundIndex] = null; + } + } + return $" {red} - {white - red}"; } - - public static void InsertCode(char[] guess) + + public void AddRow(Row row) { - // Your code here + this.rows.Add(row); } - - public static void CreateBoard() + + public string Rows { - for (var i = 0; i < allowedAttempts; i++) + get { - board[i] = new string[codeSize + 1]; - for (var j = 0; j < codeSize + 1; j++) + + foreach (var row in this.rows) { - board[i][j] = " "; + Console.Write(row.Balls); + Console.WriteLine(Score(row)); } + return ""; } } - - public static void DrawBoard() + } + + class Ball + { + public string Letter { get; private set; } + + public Ball(string letter) { - for (var i = 0; i < board.Length; i++) - { - Console.WriteLine("|" + String.Join("|", board[i])); - } - + this.Letter = letter; } - - public static void GenerateRandomCode() { - Random rnd = new Random(); - for(var i = 0; i < codeSize; i++) + } + + class Row + { + public Ball[] balls = new Ball[4]; + + public Row(Ball[] balls) + { + this.balls = balls; + } + + public string Balls + { + get { - solution[i] = letters[rnd.Next(0, letters.Length)]; + foreach (var ball in this.balls) + { + Console.Write(ball.Letter); + } + return ""; } } } -} +} \ No newline at end of file diff --git a/gameboy/.vscode/launch.json b/gameboy/.vscode/launch.json new file mode 100644 index 00000000..47c6e637 --- /dev/null +++ b/gameboy/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/gameboy.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/gameboy/.vscode/tasks.json b/gameboy/.vscode/tasks.json new file mode 100644 index 00000000..c7a5f1d2 --- /dev/null +++ b/gameboy/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/gameboy.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/gameboy/CheatController.cs b/gameboy/CheatController.cs new file mode 100644 index 00000000..8e1f3def --- /dev/null +++ b/gameboy/CheatController.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.Threading; + + +namespace gameboy +{ + class CheatController + { + public bool active { get; private set; } = false; + private List cheats = new List() { "Enter Cheat", "View Active Cheats", "Disable Cheats", "Exit" }; + private string menuType = "CHEATS"; + private Display display; + public List ActiveCheats { get; private set; } = new List(); + private List InactiveCheats = new List() { "Immortality", "Unlimited Money", "Unlocked R.P.C", "Unlocked T.T.T", "Not So Mastermind", "Extra Blocks" }; + private List CheatCodes = new List() { "l1v3s", "MrBurns", "rps", "ttt", "dummy", "harder" }; + public bool mastermind { get; private set; } = false; + public bool towers { get; private set; } = false; + public void CheatMenu() + { + Console.Clear(); + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(cheats, menuType); + + if (userRequest == "Enter Cheat") + { + AddCheat(); + } + if (userRequest == "View Active Cheats") + { + ViewActiveCheats(); + } + if (userRequest == "Disable Cheats") + { + DisableCheat(); + } + } + + } + + public void AddCheat() + { + Console.Clear(); + Console.Write("Enter Cheat Code: "); + string checkThis = CheckCheat(Console.ReadLine()); + + if (checkThis == "Invalid") + { + Console.Clear(); + Console.WriteLine("Invalid Code"); + Thread.Sleep(1000); + Console.Clear(); + } + else + { + string activated = ActivateCheat(checkThis); + if (activated != "Active") + { + Console.Clear(); + Console.WriteLine("you have activated a cheat"); + Thread.Sleep(1000); + Console.Clear(); + } + else + { + Console.Clear(); + Console.WriteLine("This code is already active"); + Thread.Sleep(1000); + Console.Clear(); + } + } + + + } + private string CheckCheat(string input) + { + string validate = "Invalid"; + + foreach (var item in CheatCodes) + { + if (input == item) + { + validate = input; + break; + } + } + return validate; + } + private string ActivateCheat(string code) + { + string result = "Active"; + for (int i = 0; i < CheatCodes.Count; i++) + { + if (code == CheatCodes[i]) + { + if (ActiveCheats.Count > 0) + { + foreach (var item in ActiveCheats) + { + if (item == InactiveCheats[i]) + { + break; + } + else + { + result = code; + ActiveCheats.Add(InactiveCheats[i]); + this.mastermind = true; + this.towers = true; + break; + } + + } + + } + else + { + result = code; + ActiveCheats.Add(InactiveCheats[i]); + } + } + } + + return result; + } + private void ViewActiveCheats() + { + Console.Clear(); + Display showCheats = new Display(); + string title = "ACTIVE CHEATS"; + showCheats.ShowData(ActiveCheats, title); + } + private void DisableCheat() + { + List active = ActiveCheats; + active.Add("!! Remove All !!"); + active.Add("Cancel"); + Display deactivateCheats = new Display(); + string userRequest = deactivateCheats.getInput(active, "DISABLE CHEATS"); + if (userRequest == "!! Remove All !!") + { + //build 2 choice menu left /right + if (userRequest == "!! Remove All !!") + { + ActiveCheats.RemoveRange(0, ActiveCheats.Count); + active.Remove("!! Remove All !!"); + active.Remove("Cancel"); + } + } + else if (userRequest == "Cancel") + { + active.Remove("Cancel"); + active.Remove("!! Remove All !!"); + } + else + { + ActiveCheats.Remove(userRequest); + active.Remove("!! Remove All !!"); + active.Remove("Cancel"); + } + } + } +} diff --git a/gameboy/Display.cs b/gameboy/Display.cs new file mode 100644 index 00000000..b8ad5d9c --- /dev/null +++ b/gameboy/Display.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; + +namespace gameboy +{ + class Display + { + private static int index; + private string title; + + public Display() + { + index = 0; + } + public string getInput(List items, string menuTitle) + { + title = menuTitle; + + while (true) + { + string selectedMenuItem = drawMenu(items); + foreach (var item in items) + { + if (selectedMenuItem == item) + { + Console.Clear(); + return item; + } + } + } + } + public void ShowData(List items, string menuTitle) + { + title = menuTitle; + string done = drawData(items); + if (done == "Exit") + { + Console.Clear(); + } + } + private string drawMenu(List items) + { + string buildTitle = DisplayUtility.ReturnLine(title); + string buildBorder = DisplayUtility.ReturnLine("~"); + string buildBottom = DisplayUtility.ReturnLine("*"); + + Console.WriteLine(buildBorder); + Console.WriteLine(buildTitle); + Console.WriteLine(buildBottom); + + for (int i = 0; i < items.Count; i++) + { + Console.CursorVisible = false; + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = DisplayUtility.ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + else + { + string buildLine = DisplayUtility.ReturnLine("|" + items[i]); + Console.WriteLine(buildLine); + } + Console.ResetColor(); + } + Console.WriteLine(buildBottom); + string userInput = MenuController(items); + return userInput; + } + private string drawExit(List items) + { + string buildBottem = DisplayUtility.ReturnLine("~"); + for (int i = 0; i < items.Count; i++) + { + Console.CursorVisible = false; + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = DisplayUtility.ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + else + { + string buildLine = DisplayUtility.ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + Console.ResetColor(); + } + Console.WriteLine(buildBottem); + string userInput = quitController(items); + return userInput; + } + private string drawData(List items) + { + string buildTitle = DisplayUtility.ReturnLine(title); + string buildBorder = DisplayUtility.ReturnLine("~"); + string buildBottom = DisplayUtility.ReturnLine("*"); + string buildBlank = DisplayUtility.ReturnLine("| "); + Console.WriteLine(buildBorder); + Console.WriteLine(buildTitle); + Console.WriteLine(buildBottom); + Console.WriteLine(buildBlank); + + + for (int i = 0; i < items.Count; i++) + { + Console.WriteLine(DisplayUtility.ReturnLine("|" + items[i])); + } + + Console.WriteLine(buildBlank); + Console.WriteLine(buildBottom); + + + List exit = new List() { "Exit" }; + string userInput = drawExit(exit); + return userInput; + + } + + private string MenuController(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.DownArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + Console.Clear(); + return ""; + } + private string quitController(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + while (userInput.Key != ConsoleKey.Enter) + { + userInput = Console.ReadKey(); + if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + } + Console.Clear(); + return ""; + } + + } +} \ No newline at end of file diff --git a/gameboy/DisplayUtility.cs b/gameboy/DisplayUtility.cs new file mode 100644 index 00000000..0301afa3 --- /dev/null +++ b/gameboy/DisplayUtility.cs @@ -0,0 +1,65 @@ +using System; + +using System.Text; + +namespace gameboy +{ + class DisplayUtility + { + public static string ReturnLine(string formatMe) + { + char[] chars = new char[4] { '*', ' ', '~', '|' }; + if (formatMe == "~") + { + StringBuilder buildBorder = new StringBuilder(); + buildBorder.Append(chars[2], 25); + return buildBorder.ToString(); + } + else if (formatMe == "*") + { + StringBuilder buildBorder = new StringBuilder(); + buildBorder.Append(chars[0], 25); + return buildBorder.ToString(); + } + else if (formatMe.Substring(0, 1) == "|") + { + formatMe = formatMe.Substring(1); + StringBuilder buildLine = new StringBuilder(); + int spaces = (((25 - formatMe.Length) / 2) - 1); + buildLine.Append(chars[3]).Append(chars[1], spaces).Append(formatMe).Append(chars[1], spaces); + while (buildLine.Length < 25) + { + if (buildLine.Length == 24) + { + buildLine.Append(chars[3]); + + } + else if (buildLine.Length < 24) + { + buildLine.Append(chars[1]); + } + } + return buildLine.ToString(); + } + else + { + StringBuilder buildLine = new StringBuilder(); + int spaces = (((25 - formatMe.Length) / 2) - 1); + buildLine.Append(chars[0]).Append(chars[1], spaces).Append(formatMe).Append(chars[1], spaces); + while (buildLine.Length < 25) + { + if (buildLine.Length == 24) + { + buildLine.Append(chars[0]); + + } + else if (buildLine.Length < 24) + { + buildLine.Append(chars[1]); + } + } + return buildLine.ToString(); + } + } + } +} \ No newline at end of file diff --git a/gameboy/GamesController.cs b/gameboy/GamesController.cs new file mode 100644 index 00000000..014da914 --- /dev/null +++ b/gameboy/GamesController.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; + + +namespace gameboy +{ + class GamesController + { + private List games = new List() { "Towers Of Hanoi", "Mastermind" }; + private string menuType = "GAMES"; + private Display display; + public ProfileController SelectGame(ProfileController profile, CheatController cheat) + { + ProfileController user = profile; + List activeCheats = cheat.ActiveCheats; + foreach (var item in activeCheats) + { + if (item == "Unlocked R.P.C" || item == "Unlocked T.T.T") + { + games.Add(item == "Unlocked R.P.C" ? "Rock Paper Scissor" : "Tic Tac Toe"); + } + } + games.Add("Exit"); + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(games, menuType); + StartGames start = new StartGames(); + user = start.Game(userRequest, profile, cheat); + } + foreach (var item in activeCheats) + { + if (item == "Unlocked R.P.C" || item == "Unlocked T.T.T") + { + games.Remove(item == "Unlocked R.P.C" ? "Rock Paper Scissor" : "Tic Tac Toe"); + } + } + games.Remove("Exit"); + + return user; + } + } +} \ No newline at end of file diff --git a/gameboy/GetLines.cs b/gameboy/GetLines.cs new file mode 100644 index 00000000..4039a53f --- /dev/null +++ b/gameboy/GetLines.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace gameboy +{ + class GetLines + { + //private int item = 0; + public char[] chars = new char[5] { '*', '~', '_', ' ', '|' }; + public string BorderH(string borderStyle) + { + int request; + if (borderStyle == "*") + { + request = 0; + } + else if (borderStyle == "~") + { + request = 1; + } + else + { + request = 2; + } + StringBuilder border = new StringBuilder(); + border.Append(chars[request], 40); + return border.ToString(); + } + public void Title(string title) + { + Console.WriteLine(BorderH("*")); + Console.WriteLine(Line(title)); + Console.WriteLine(BorderH("*")); + } + public string Line(string item) + { + StringBuilder builtString = new StringBuilder(); + int space = (38 - item.Length) / 2; + builtString.Append(chars[0]).Append(chars[3], space).Append(item).Append(chars[3], space); + while (builtString.ToString().Length != 39) + { + builtString.Append(chars[3]); + } + builtString.Append(chars[0]); + return builtString.ToString(); + } + public string MenuLine(string item) + { + StringBuilder builtString = new StringBuilder(); + int space = (13 - item.Length) / 2; + builtString.Append(chars[3], space).Append(item).Append(chars[3], space); + return builtString.ToString(); + } + public void BuildData(List label, List scores) + { + List cList = new List(); + for (int i = 0; i < label.Count; i++) + { + cList.Add(label[i] + ": " + scores[i].ToString()); + } + List returnMe = new List(); + List lessThan11 = new List(); + List lessThan17 = new List(); + List large = new List(); + foreach (var item in cList) + { + if (item.Length <= 11) + { + lessThan11.Add(item); + } + else if (item.Length <= 17) + { + lessThan17.Add(item); + } + else + { + large.Add(item); + } + } + foreach (var item in large) + { + Console.WriteLine(Line(item)); + } + do + { + if (lessThan17.Count > 2) + { + StringBuilder nextLine = new StringBuilder(); + string first = lessThan17[0]; + string second = lessThan17[1]; + lessThan17.RemoveRange(0, 2); + int space = 36 - (first.Length + second.Length); + nextLine.Append(chars[0]).Append(chars[3]).Append(first).Append(chars[3], space).Append(second).Append(chars[3]).Append(chars[0]); + Console.WriteLine(nextLine.ToString()); + } + else if (lessThan17.Count > 0) + { + if (lessThan11.Count > 0) + { + lessThan17.Add(lessThan11[0]); + lessThan11.RemoveRange(0, 1); + StringBuilder nextLine = new StringBuilder(); + string first = lessThan17[0]; + string second = lessThan17[1]; + lessThan17.RemoveRange(0, 2); + int space = 36 - (first.Length + second.Length); + nextLine.Append(chars[0]).Append(chars[3]).Append(first).Append(chars[3], space).Append(second).Append(chars[3]).Append(chars[0]); + Console.WriteLine(nextLine.ToString()); + } + else + { + StringBuilder nextLine = new StringBuilder(); + int space = ((36 - lessThan17[0].Length) / 2); + nextLine.Append(chars[0]).Append(chars[3]).Append(lessThan17[0]).Append(chars[3], space).Append(chars[3]).Append(chars[0]); + lessThan17.RemoveRange(0, 1); + } + } + else + { + break; + } + + } while (true); + do + { + if (lessThan11.Count >= 3) + { + StringBuilder nextLine = new StringBuilder(); + string first = lessThan11[0]; + string second = lessThan11[1]; + string third = lessThan11[2]; + lessThan11.RemoveRange(0, 3); + int space = ((36 - (first.Length + second.Length + third.Length)) / 2); + nextLine.Append(chars[0]).Append(chars[3]).Append(first).Append(chars[3], space).Append(second).Append(chars[3]).Append(chars[3], space).Append(third).Append(chars[3]).Append(chars[0]); + Console.WriteLine(nextLine.ToString()); + } + else if (lessThan11.Count > 0) + { + if (lessThan11.Count > 1 && lessThan11.Count > 3) + { + StringBuilder nextLine = new StringBuilder(); + string first = lessThan11[0]; + string second = lessThan11[1]; + lessThan11.RemoveRange(0, 2); + int space = ((36 - (first.Length + second.Length))); + nextLine.Append(chars[0]).Append(chars[3]).Append(first).Append(chars[3], space).Append(second).Append(chars[3]).Append(chars[0]); + Console.WriteLine(nextLine.ToString()); + } + else if (lessThan11.Count > 0) + { + + StringBuilder nextLine = new StringBuilder(); + int space = ((36 - lessThan11[0].Length)); + nextLine.Append(chars[0]).Append(chars[3]).Append(lessThan11[0]).Append(chars[3], space).Append(chars[3]).Append(chars[0]); + lessThan11.RemoveRange(0, 1); + Console.WriteLine(nextLine.ToString()); + } + } + else + { + break; + } + + } while (true); + + } + } +} \ No newline at end of file diff --git a/gameboy/MainMenuController.cs b/gameboy/MainMenuController.cs new file mode 100644 index 00000000..d985073a --- /dev/null +++ b/gameboy/MainMenuController.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class MainMenuController + { + private List menuItems = new List() { "Profile", "Play Games", "Cheats", "Exit" }; + private string menuType = "MAIN MENU"; + private ProfileController profile = new ProfileController(); + private CheatController cheats = new CheatController(); + private GamesController games = new GamesController(); + private Display display; + public void StartMainMenu() + { + + string userRequest = ""; + if (!profile.active) + { + do + { + this.profile.Create(); + + } while (!profile.active); + } + do + { + this.display = new Display(); + userRequest = display.getInput(menuItems, menuType); + StartSelection(userRequest); + } while (userRequest != "Exit"); + } + private bool StartSelection(string request) + { + if (request == "Play Games") + { + this.profile = games.SelectGame(profile, cheats); + } + if (request == "Cheats") + { + cheats.CheatMenu(); + } + if (request == "Profile") + { + this.profile.ProfileMenu(); + } + if (request == "Exit") + { + Console.Clear(); + Console.WriteLine("Thanks For Playing!"); + Thread.Sleep(1000); + return false; + } + return true; + } + } +} diff --git a/gameboy/Mastermind.cs b/gameboy/Mastermind.cs new file mode 100644 index 00000000..7642dcb8 --- /dev/null +++ b/gameboy/Mastermind.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class Mastermind + { + public static int Play(CheatController cheats) + { + int totalTurns = 10; + foreach (var item in cheats.ActiveCheats) + { + totalTurns = item == "Immortality" ? -1 : totalTurns; + } + Console.Clear(); + Game game = new Game(GenerateSolution(cheats)); + int TurnsRemaining = 0; + + for (int turns = totalTurns; turns != 0; turns--) + { + string turnsLeft = turns.ToString(); + turnsLeft = turns < 0 ? "Unlimited" : turnsLeft; + Console.WriteLine($"You have {turnsLeft} tries left"); + string letters = ""; + while (letters.Length != 4) + { + Console.WriteLine("Choose four letters or e for exit: "); + letters = Console.ReadLine(); + } + if (letters.ToLower() == "exit") + { + turns = 0; + break; + } + Ball[] balls = new Ball[4]; + for (int i = 0; i < 4; i++) + { + balls[i] = new Ball(letters[i].ToString()); + } + Row row = new Row(balls); + string winningString = ""; + foreach (var item in game.answer) + { + winningString = winningString + item; + } + if (letters == winningString) + { + Console.Clear(); + Console.WriteLine("You Win"); + Thread.Sleep(1000); + TurnsRemaining = turns; + Console.Clear(); + break; + } + game.AddRow(row); + Console.WriteLine(game.Rows); + + } + Console.WriteLine(TurnsRemaining != 0 ? "Great Job" : "Out Of Turns"); + Console.Clear(); + return TurnsRemaining != 0 ? 1 : 0; + } + public static string[] GenerateSolution(CheatController cheats) + { + Random rnd = new Random(); + List available = new List { "a", "b", "c", "d", "e", "f" }; + string[] solution = new string[4]; + int one = rnd.Next(1, 6); + solution[0] = available[one]; + available.RemoveRange(one, 1); + int two = rnd.Next(1, 5); + solution[1] = available[two]; + available.RemoveRange(two, 1); + int three = rnd.Next(1, 4); + solution[2] = available[three]; + available.RemoveRange(three, 1); + int four = rnd.Next(1, 3); + solution[3] = available[four]; + available.RemoveRange(four, 1); + bool preview = false; + foreach (var item in cheats.ActiveCheats) + { + preview = item == "Not So Mastermind" ? true : preview; + } + if (preview) + { + Console.WriteLine(solution[0] + solution[1] + solution[2] + solution[3]); + } + return solution; + } + } + + class Game + { + private List rows = new List(); + public string[] answer { get; private set; } = new string[4]; + + public Game(string[] answer) + { + this.answer = answer; + } + + private string Score(Row row) + { + string[] answerClone = (string[])this.answer.Clone(); + int red = 0; + for (int i = 0; i < 4; i++) + { + if (answerClone[i] == row.balls[i].Letter) + { + red++; + } + } + + int white = 0; + for (int i = 0; i < 4; i++) + { + int foundIndex = Array.IndexOf(answerClone, row.balls[i].Letter); + if (foundIndex > -1) + { + white++; + answerClone[foundIndex] = null; + } + } + return $" {red} - {white - red}"; + } + + public void AddRow(Row row) + { + this.rows.Add(row); + } + + public string Rows + { + get + { + + foreach (var row in this.rows) + { + Console.Write(row.Balls); + Console.WriteLine(Score(row)); + } + return ""; + } + } + } + + class Ball + { + public string Letter { get; private set; } + + public Ball(string letter) + { + this.Letter = letter; + } + } + + class Row + { + public Ball[] balls = new Ball[4]; + + public Row(Ball[] balls) + { + this.balls = balls; + } + + public string Balls + { + get + { + foreach (var ball in this.balls) + { + Console.Write(ball.Letter); + } + return ""; + } + } + } +} \ No newline at end of file diff --git a/gameboy/ProfileController.cs b/gameboy/ProfileController.cs new file mode 100644 index 00000000..f82ab38c --- /dev/null +++ b/gameboy/ProfileController.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; + + +namespace gameboy +{ + class ProfileController + { + public bool active { get; private set; } = false;//bypass profile with true + private string firstName = ""; + private string lastName = ""; + private List profileOptions = new List() { "Game Stats", "Change Name", "Exit" }; + private string menuType = "PROFILE"; + private List game = new List { "Towers Of Hanoi", "Mastermind" }; + private List> labels = new List>(); + public List> scores { get; set; } = new List>(); + + public ProfileController() + { + for (int i = 0; i < game.Count; i++) + { + List label = new List { "Games Played", "wins", "Loss", "Times Cheated" }; + List startScores = new List { 0, 0, 0, 0 }; + labels.Add(label); + scores.Add(startScores); + } + } + public void Create() + { + if (active) + { + firstName = ""; + lastName = ""; + do // until 1st and last have at least 1 char + { + if (firstName == "") + { + Console.Write("Enter first name: "); + this.firstName = Console.ReadLine(); + } + if (lastName == "") + { + Console.Write("Enter last name: "); + this.lastName = Console.ReadLine(); + } + Console.Clear(); + } while (firstName == "" || lastName == ""); + + } + do // until 1st and last have at least 1 char + { + if (firstName == "") + { + Console.Write("Enter first name: "); + this.firstName = Console.ReadLine(); + } + if (lastName == "") + { + Console.Write("Enter last name: "); + this.lastName = Console.ReadLine(); + } + Console.Clear(); + } while (firstName == "" || lastName == "" && !active); + this.active = true;//activate profile + } + private Display display; + public void ProfileMenu() + { + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(profileOptions, menuType); + if (userRequest == "Change Name") + { + this.Create(); + } + else if (userRequest == "Game Stats") + { + TwoOptionMenu listStats = new TwoOptionMenu(game, labels, scores); + int index = 0; + while (true) + { + if (index > game.Count - 1) + { + index = 0; + } + else if (index == -1) + { + index = game.Count - 1; + } + string view = listStats.BuildDisplay(index); + if (view == "<- Back") + { + index--; + } + else if (view == "Next ->" && index <= game.Count) + { + index++; + } + else if (view == "Exit") + { + Console.Clear(); + break; + } + + + } + } + } + + } + } +} \ No newline at end of file diff --git a/gameboy/Program.cs b/gameboy/Program.cs new file mode 100644 index 00000000..0c5041bd --- /dev/null +++ b/gameboy/Program.cs @@ -0,0 +1,13 @@ +using System; + +namespace gameboy +{ + class Program + { + static void Main(string[] args) + { + MainMenuController MainMenu = new MainMenuController(); + MainMenu.StartMainMenu(); + } + } +} diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs new file mode 100644 index 00000000..927010ea --- /dev/null +++ b/gameboy/StartGames.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading; + +namespace gameboy +{ + class StartGames + { + public ProfileController Game(string gameRequest, ProfileController profile, CheatController cheat) + { + switch (gameRequest) + { + case "Tic Tac Toe": + Console.Clear(); + Console.WriteLine("feature coming soon. Check back shortly!"); + Thread.Sleep(1500); + Console.Clear(); + break; + case "Rock Paper Scissor": + Console.Clear(); + Console.WriteLine("feature coming soon! Check back shortly!"); + Thread.Sleep(1500); + Console.Clear(); + break; + case "Mastermind": + Mastermind masterMind = new Mastermind(); + if (cheat.ActiveCheats.Contains("Immortality") || cheat.ActiveCheats.Contains("Not So Mastermind")) + { + profile.scores[1][3]++; + } + int Mresult = Mastermind.Play(cheat); + profile.scores[1][1] = Mresult == 1 ? profile.scores[1][1] + 1 : profile.scores[1][1]; + profile.scores[1][2] = Mresult == 0 ? profile.scores[1][2] + 1 : profile.scores[1][2]; + profile.scores[1][0] = profile.scores[1][0] + 1; + break; + case "Towers Of Hanoi": + Towers towers = new Towers(cheat); + if (cheat.ActiveCheats.Contains("Immortality") || cheat.ActiveCheats.Contains("Not So Mastermind")) + { + profile.scores[1][3]++; + } + int TResult = towers.Play(); + profile.scores[0][1] = TResult == 1 ? profile.scores[0][1] + 1 : profile.scores[0][1]; + profile.scores[0][2] = TResult == 0 ? profile.scores[0][2] + 1 : profile.scores[0][2]; + profile.scores[0][0] = profile.scores[0][0] + 1; + break; + } + return profile; + } + } +} \ No newline at end of file diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs new file mode 100644 index 00000000..c0026c68 --- /dev/null +++ b/gameboy/Towers.cs @@ -0,0 +1,302 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Text; + +namespace gameboy +{ + + class Towers + { + public bool Block { get; private set; } = true; + public static int StartingBlocks { get; private set; } + public static int PegHight { get; private set; } + public CheatController cheats { get; private set; } + public List Blocks { get; private set; } = new List() { 4, 8, 12, 16 }; + public List> Pegs { get; private set; } = new List>(); + List Board = new List(); + public int index { get; private set; } + public Towers(CheatController c) + { + StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 10 : 4; + if (StartingBlocks > 4) + { + Blocks.RemoveRange(0, Blocks.Count); + for (int i = 0; i < StartingBlocks; i++) + { + Blocks.Add(4 * i); + } + } + PegHight = Blocks.Count + 2; + Blocks.Reverse(); + Stack p1 = new Stack(); + Stack p2 = new Stack(); + Stack p3 = new Stack(); + Pegs.Add(p1); + Pegs.Add(p2); + Pegs.Add(p3); + foreach (var item in Blocks) + { + Pegs[0].Push(item); + } + ConstructPegs(); + } + public int Play() + { + int result = 0; + bool play = true; + while (play) + { + int requestedBlock = 0; + int from = 0; + while (play) + { + + string unformatedChoice = Choice(); + if (unformatedChoice == "Exit") + { + play = false; + break; + } + from = Convert.ToInt32(unformatedChoice.Replace(" ", String.Empty).Substring(0, 1)); + ClearPegs(); + if (Pegs[from].Count != 0) + { + requestedBlock = Pegs[from].Pop(); + break; + } + } + while (true) + { + if (!play) { break; } + string unformatedChoice = Choice(); + if (unformatedChoice == "Exit") + { + play = false; + break; + } + int formatPeg = Convert.ToInt32(unformatedChoice.Replace(" ", String.Empty).Substring(0, 1)); + ClearPegs(); + if (Pegs[formatPeg].Count == 0 || Pegs[formatPeg].Peek() > requestedBlock) + { + Pegs[formatPeg].Push(requestedBlock); + break; + } + else + { + Pegs[from].Push(requestedBlock); + break; + } + } + ConstructPegs(); + if (CheckWin()) + { + Console.Clear(); + Console.WriteLine("You have Won!"); + Thread.Sleep(1500); + result = 1; + Console.Clear(); + break; + } + Console.Clear(); + Console.WriteLine("Continue Playing? y/n"); + + } + return result; + } + public void ClearPegs() + { + Stack peg = Pegs[0]; + for (var i = 0; i < PegHight; i++) + { + if (peg.Peek() == 0) + { + peg.Pop(); + } + } + peg = Pegs[1]; + for (var i = 0; i < PegHight; i++) + { + if (peg.Peek() == 0) + { + peg.Pop(); + } + } + peg = Pegs[2]; + for (var i = 0; i < PegHight; i++) + { + if (peg.Peek() == 0) + { + peg.Pop(); + } + } + } + private void ConstructPegs() + { + while (Pegs[0].Count < PegHight) + { + Pegs[0].Push(0); + } + while (Pegs[1].Count < PegHight) + { + Pegs[1].Push(0); + } + while (Pegs[2].Count < PegHight) + { + Pegs[2].Push(0); + } + } + private void ConstructBoard() + { + ConstructPegs(); + + List stackOne = buildLines(Pegs[0]); + List stackTwo = buildLines(Pegs[1]); + List stackThree = buildLines(Pegs[2]); + + for (int i = 0; i < stackOne.Count; i++) + { + Console.WriteLine(stackOne[i] + stackTwo[i] + stackThree[i]); + } + } + private List buildLines(Stack peg) + { + + List stack = new List(); + Char[] buildElements = new Char[] { ' ', '[', ']', '|' }; + int spaces = (Blocks.Count * 4); + foreach (var block in peg) + { + StringBuilder buildString = new StringBuilder(); + buildString.Append(buildElements[0]); + if (block == 0) + { + buildString.Append(buildElements[0], spaces / 2).Append(buildElements[1]).Append(buildElements[2]).Append(buildElements[0], spaces / 2); + } + else + { + int item = block; + int front = (spaces - item) / 2; + buildString.Append(buildElements[0], front).Append(buildElements[1]).Append(buildElements[3], item).Append(buildElements[2]).Append(buildElements[0], front); + } + buildString.Append(buildElements[0], 2); + stack.Add(buildString.ToString()); + } + + return stack; + } + private string Choice() + { + index = 0; + int spaces = (Blocks.Count * 4); + Char[] MenuElements = new Char[] { ' ', '/', '\\' }; + List options = new List(); + for (int i = 0; i < 3; i++) + { + StringBuilder menuOption = new StringBuilder(); + menuOption.Append(MenuElements[0], spaces / 2 - 1).Append(i).Append(MenuElements[1]).Append(MenuElements[2]).Append(MenuElements[0], 1).Append(MenuElements[0], spaces / 2 - 1); + options.Add(menuOption.ToString()); + } + options.Add("Exit"); + string response = ""; + + while (response == "") + { + ConstructBoard(); + response = DrawOptions(options); + Console.Clear(); + } + return response; + } + private string ChoosePeg() + { + index = 0; + int spaces = (Blocks.Count * 4); + Char[] MenuElements = new Char[] { ' ', '/', '\\' }; + List options = new List(); + for (int i = 0; i < 3; i++) + { + StringBuilder menuOption = new StringBuilder(); + menuOption.Append(MenuElements[0], spaces / 2 - 1).Append(i).Append(MenuElements[1]).Append(MenuElements[2]).Append(MenuElements[0], 1).Append(MenuElements[0], spaces / 2 - 1); + options.Add(menuOption.ToString()); + } + string response = ""; + + while (response == "") + { + Console.Clear(); + ConstructBoard(); + response = DrawOptions(options); + } + return response; + } + private string DrawOptions(List options) + { + StringBuilder line = new StringBuilder(); + List items = options; + + int spaces = (Blocks.Count * 4); + Console.Write(" "); + for (int i = 0; i < items.Count; i++) + { + Console.CursorVisible = false; + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = items[i]; + Console.Write(buildLine); + } + else + { + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = items[i]; + Console.Write(buildLine); + } + Console.ResetColor(); + Console.Write(" "); + } + Console.Write(" "); + Console.WriteLine(); + string userInput = MenuController(items); + return userInput; + } + private string MenuController(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.RightArrow) + { + if (index == items.Count - 1) + { + index = 0; + } + else { index++; } + } + else if (userInput.Key == ConsoleKey.LeftArrow) + { + if (index <= 0) + { + index = items.Count - 1; + } + else { index--; } + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + return ""; + } + public bool CheckWin() + { + ClearPegs(); + bool win = false; + if (Pegs[1].Count == PegHight - 2 || Pegs[2].Count == PegHight - 2) + { + win = true; + } + return win; + } + } +} + diff --git a/gameboy/TwoOptionMenu.cs b/gameboy/TwoOptionMenu.cs new file mode 100644 index 00000000..d71030bc --- /dev/null +++ b/gameboy/TwoOptionMenu.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; + + +namespace gameboy +{ + class TwoOptionMenu + { + private int item = 0; + private int index = 0; + private List options = new List() { "<- Back", "Exit", "Next ->" }; + private List game; + private List> labels; + private List> scores; + + public TwoOptionMenu(List g, List> l, List> s) + { + this.game = g; + this.labels = l; + this.scores = s; + } + public string BuildDisplay(int indexOfGame) + { + this.item = indexOfGame; + Console.Clear(); + List userSelect = options; + List currentLabels = labels[item]; + List currentscores = scores[item]; + string menuTitle = game[item]; + string getUserRequest = DrawDisplay(currentLabels, currentscores, menuTitle); + return getUserRequest; + } + + private string DrawDisplay(List currentLabels, List currentscores, string menuTitle) + { + GetLines get = new GetLines(); + + get.Title(menuTitle); + get.BuildData(currentLabels, currentscores); + Console.WriteLine(get.BorderH("*")); + + string options = DrawOptions(); + return options; + } + private string DrawOptions() + { + GetLines choice = new GetLines(); + List items = options; + string buildBottem = choice.BorderH("*"); + + Console.Write("*"); + for (int i = 0; i < items.Count; i++) + { + Console.CursorVisible = false; + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = choice.MenuLine(items[i]); + Console.Write(buildLine); + } + else + { + string buildLine = choice.MenuLine(items[i]); + Console.Write(buildLine); + } + Console.ResetColor(); + } + Console.Write("*"); + Console.WriteLine(); + Console.WriteLine(buildBottem); + string userInput = MenuController(items); + return userInput; + } + private string MenuController(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.RightArrow) + { + if (index == items.Count - 1) + { + index = 0; + } + else { index++; } + } + else if (userInput.Key == ConsoleKey.LeftArrow) + { + if (index <= 0) + { + index = items.Count - 1; + } + else { index--; } + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + else + { + return ""; + } + + Console.Clear(); + return ""; + } + + } +} \ No newline at end of file diff --git a/gameboy/bash.exe.stackdump b/gameboy/bash.exe.stackdump new file mode 100644 index 00000000..4bc86685 --- /dev/null +++ b/gameboy/bash.exe.stackdump @@ -0,0 +1,16 @@ +Stack trace: +Frame Function Args +00180328AF0 0018006021E (00180247D00, 001802340B9, 00000000058, 000FFFFB740) +00180328AF0 00180048859 (00180236765, 00100000000, 00000000000, 00000000001) +00180328AF0 00180048892 (00000000000, 00000000000, 00000000058, 00180328950) +00180328AF0 0018006C179 (0000000000A, 00000000000, 0000000000A, 00000000000) +00180328AF0 0018006C342 (00000000003, 00000000000, 00180044EEF, 000FFFFCB30) +00000000000 0018006D3A8 (0000000000D, 000FFFFC920, 001800E4CF6, 000FFFFC920) +00000000000 00180058816 (000FFFF0000, 00000000000, 00000000000, 006FFFFFFFF) +00000000000 001800590A9 (000FFFFCAF0, 00600040000, 00000000000, 000FFFFCB80) +00180325CF8 001800595BA (001800C0322, 00000000000, 00000000000, 00000000000) +000FFFFCCD0 00180059937 (000FFFFCDF0, 000FFFFCCD0, FFFFFFFFFFFFFFD1, 00000000000) +000FFFFCCD0 00180048FE1 (00000000000, 00000000000, 00000000000, 00000000000) +00000000000 00180047963 (00000000000, 00000000000, 00000000000, 00000000000) +000FFFFFFF0 00180047A14 (00000000000, 00000000000, 00000000000, 00000000000) +End of stack trace diff --git a/gameboy/gameboy.csproj b/gameboy/gameboy.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/gameboy/gameboy.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + +