From 064cf8e2f51280e74f8e8fe692638f8ea61e2a51 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Feb 2019 21:37:12 -0600 Subject: [PATCH 01/22] getting the big picture done then working on the games --- gameboy/.vscode/launch.json | 26 ++++++ gameboy/.vscode/tasks.json | 15 +++ gameboy/Controllers/CheatController.cs | 11 +++ gameboy/Controllers/Display.cs | 109 ++++++++++++++++++++++ gameboy/Controllers/GamesController.cs | 10 ++ gameboy/Controllers/MainMenuController.cs | 27 ++++++ gameboy/Controllers/ProfileController.cs | 33 +++++++ gameboy/Program.cs | 13 +++ gameboy/bash.exe.stackdump | 16 ++++ gameboy/gameboy.csproj | 8 ++ 10 files changed, 268 insertions(+) create mode 100644 gameboy/.vscode/launch.json create mode 100644 gameboy/.vscode/tasks.json create mode 100644 gameboy/Controllers/CheatController.cs create mode 100644 gameboy/Controllers/Display.cs create mode 100644 gameboy/Controllers/GamesController.cs create mode 100644 gameboy/Controllers/MainMenuController.cs create mode 100644 gameboy/Controllers/ProfileController.cs create mode 100644 gameboy/Program.cs create mode 100644 gameboy/bash.exe.stackdump create mode 100644 gameboy/gameboy.csproj 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/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs new file mode 100644 index 00000000..1c953fc0 --- /dev/null +++ b/gameboy/Controllers/CheatController.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class CheatController + { + public bool active { get; private set; } = false; + } +} \ No newline at end of file diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs new file mode 100644 index 00000000..bfc286f7 --- /dev/null +++ b/gameboy/Controllers/Display.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace gameboy +{ + class Display + { + private static int index = 0; + + public string getInput(List items) + { + Console.CursorVisible = false; + while (true) + { + string selectedMenuItem = drawMenu(items); + foreach (var item in items) + { + if (selectedMenuItem == "Exit") + { + break; + } + else if (selectedMenuItem == item) + { + Console.Clear(); + return item; + } + } + } + } + private static string drawMenu(List items) + { + Console.WriteLine("*************************"); + for (int i = 0; i < items.Count; i++) + { + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + else + { + string buildLine = ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + Console.ResetColor(); + } + Console.WriteLine("*************************"); + string userInput = MenuController(items); + return userInput; + + + } + private static string MenuController(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.DownArrow) + { + if (index == items.Count - 1) + { + index = 0; + } + else { index++; } + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + if (index <= 0) + { + index = items.Count - 1; + } + else { index--; } + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + else + { + return ""; + } + + Console.Clear(); + return ""; + } + private static string ReturnLine(string formatMe) + { + StringBuilder buildLine = new StringBuilder(); + int spaces = (((25 - formatMe.Length) / 2) - 1); + char[] chars = new char[2] { '*', ' ' }; + 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/Controllers/GamesController.cs b/gameboy/Controllers/GamesController.cs new file mode 100644 index 00000000..5886222c --- /dev/null +++ b/gameboy/Controllers/GamesController.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class GamesController + { + } +} \ No newline at end of file diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs new file mode 100644 index 00000000..2e5a75d1 --- /dev/null +++ b/gameboy/Controllers/MainMenuController.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class MainMenuController + { + private List menuItems = new List() { "Play Games", "Cheat", "Stats", "Exit" }; + private ProfileController profile = new ProfileController(); + private CheatController cheats = new CheatController(); + private GamesController games = new GamesController(); + private Display display = new Display(); + public void StartMainMenu() + { + do + { + profile.Create(); + + } while (!profile.active); + + string userRequest = display.getInput(menuItems); + // + + } + } +} diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs new file mode 100644 index 00000000..b04b1701 --- /dev/null +++ b/gameboy/Controllers/ProfileController.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace gameboy +{ + class ProfileController + { + public bool active { get; private set; } = false; + private string firstName = ""; + private string lastName = ""; + + public void Create() + { + do + { + 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 = true; + + } + } +} \ 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/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 + + + From a6916956305776042b9e720bddf8d3140defff0d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Feb 2019 00:02:12 -0600 Subject: [PATCH 02/22] menus are all set up --- gameboy/Controllers/CheatController.cs | 9 +++++++++ gameboy/Controllers/Display.cs | 8 +------- gameboy/Controllers/GamesController.cs | 8 ++++++++ gameboy/Controllers/MainMenuController.cs | 20 +++++++++++++++++--- gameboy/Controllers/ProfileController.cs | 9 +++++++-- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index 1c953fc0..937cd6f1 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -7,5 +7,14 @@ namespace gameboy class CheatController { public bool active { get; private set; } = false; + private List cheats = new List() { "Enter Cheat", "View Active", "Disable Cheats", "Disable All Cheats", "Exit" }; + Display display = new Display(); + public CheatController CheatMenu(CheatController cheat) + { + CheatController current = cheat; + string userRequest = display.getInput(cheats); + return current; + } + } } \ No newline at end of file diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs index bfc286f7..a8a418f5 100644 --- a/gameboy/Controllers/Display.cs +++ b/gameboy/Controllers/Display.cs @@ -16,11 +16,7 @@ public string getInput(List items) string selectedMenuItem = drawMenu(items); foreach (var item in items) { - if (selectedMenuItem == "Exit") - { - break; - } - else if (selectedMenuItem == item) + if (selectedMenuItem == item) { Console.Clear(); return item; @@ -50,8 +46,6 @@ private static string drawMenu(List items) Console.WriteLine("*************************"); string userInput = MenuController(items); return userInput; - - } private static string MenuController(List items) { diff --git a/gameboy/Controllers/GamesController.cs b/gameboy/Controllers/GamesController.cs index 5886222c..1a85e21c 100644 --- a/gameboy/Controllers/GamesController.cs +++ b/gameboy/Controllers/GamesController.cs @@ -6,5 +6,13 @@ namespace gameboy { class GamesController { + private List games = new List() { "Towers Of Hanoi", "Mastermind", "Rock Paper Scissor", "Tic Tac Toe", "Exit" }; + Display display = new Display(); + public ProfileController SelectGame(ProfileController profile, CheatController cheat) + { + ProfileController user = profile; + string userRequest = display.getInput(games); + return user; + } } } \ No newline at end of file diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs index 2e5a75d1..c8603a7b 100644 --- a/gameboy/Controllers/MainMenuController.cs +++ b/gameboy/Controllers/MainMenuController.cs @@ -6,7 +6,7 @@ namespace gameboy { class MainMenuController { - private List menuItems = new List() { "Play Games", "Cheat", "Stats", "Exit" }; + private List menuItems = new List() { "Play Games", "Cheats", "Profile", "Exit" }; private ProfileController profile = new ProfileController(); private CheatController cheats = new CheatController(); private GamesController games = new GamesController(); @@ -20,8 +20,22 @@ public void StartMainMenu() } while (!profile.active); string userRequest = display.getInput(menuItems); - // - + StartSelection(userRequest); + } + private void StartSelection(string request) + { + if (request == "Play Games") + { + this.profile = games.SelectGame(profile, cheats); + } + if (request == "Cheats") + { + this.cheats = cheats.CheatMenu(cheats); + } + if (request == "Profile") + { + this.profile.ProfileMenu(); + } } } } diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index b04b1701..2e179dd4 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -9,6 +9,7 @@ class ProfileController public bool active { get; private set; } = false; private string firstName = ""; private string lastName = ""; + private List profileOptions = new List() { "Game Stats", "Change Name", "Exit" }; public void Create() { @@ -26,8 +27,12 @@ public void Create() } Console.Clear(); } while (firstName == "" || lastName == ""); - active = true; - + this.active = true; + } + private Display display = new Display(); + public void ProfileMenu() + { + string userRequest = display.getInput(profileOptions); } } } \ No newline at end of file From 32618cae5da524cd4719a125de61d9d669d58b6e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Feb 2019 01:27:09 -0600 Subject: [PATCH 03/22] outter Menu finish need selections still and games need to be built --- gameboy/Controllers/CheatController.cs | 12 ++++++++--- gameboy/Controllers/Display.cs | 20 ++++++++++++----- gameboy/Controllers/GamesController.cs | 13 +++++++++--- gameboy/Controllers/MainMenuController.cs | 26 +++++++++++++++++------ gameboy/Controllers/ProfileController.cs | 12 ++++++++--- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index 937cd6f1..a2ed0f12 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Threading; + namespace gameboy { @@ -8,11 +8,17 @@ class CheatController { public bool active { get; private set; } = false; private List cheats = new List() { "Enter Cheat", "View Active", "Disable Cheats", "Disable All Cheats", "Exit" }; - Display display = new Display(); + private string menuType = "CHEATS"; + private Display display; public CheatController CheatMenu(CheatController cheat) { CheatController current = cheat; - string userRequest = display.getInput(cheats); + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(cheats, menuType); + } return current; } diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs index a8a418f5..8da7a571 100644 --- a/gameboy/Controllers/Display.cs +++ b/gameboy/Controllers/Display.cs @@ -7,10 +7,16 @@ namespace gameboy class Display { private static int index = 0; + private string title; - public string getInput(List items) + public Display() { - Console.CursorVisible = false; + index = 0; + } + public string getInput(List items, string menuTitle) + { + title = menuTitle; + while (true) { string selectedMenuItem = drawMenu(items); @@ -24,11 +30,15 @@ public string getInput(List items) } } } - private static string drawMenu(List items) + private string drawMenu(List items) { + string buildTitle = ReturnLine(title); + Console.WriteLine("*************************"); + Console.WriteLine(buildTitle); Console.WriteLine("*************************"); for (int i = 0; i < items.Count; i++) { + Console.CursorVisible = false; if (i == index) { Console.BackgroundColor = ConsoleColor.Gray; @@ -47,7 +57,7 @@ private static string drawMenu(List items) string userInput = MenuController(items); return userInput; } - private static string MenuController(List items) + private string MenuController(List items) { ConsoleKeyInfo userInput = Console.ReadKey(); @@ -79,7 +89,7 @@ private static string MenuController(List items) Console.Clear(); return ""; } - private static string ReturnLine(string formatMe) + private string ReturnLine(string formatMe) { StringBuilder buildLine = new StringBuilder(); int spaces = (((25 - formatMe.Length) / 2) - 1); diff --git a/gameboy/Controllers/GamesController.cs b/gameboy/Controllers/GamesController.cs index 1a85e21c..caed5ba3 100644 --- a/gameboy/Controllers/GamesController.cs +++ b/gameboy/Controllers/GamesController.cs @@ -1,17 +1,24 @@ using System; using System.Collections.Generic; -using System.Threading; + namespace gameboy { class GamesController { private List games = new List() { "Towers Of Hanoi", "Mastermind", "Rock Paper Scissor", "Tic Tac Toe", "Exit" }; - Display display = new Display(); + private string menuType = "GAMES"; + private Display display; public ProfileController SelectGame(ProfileController profile, CheatController cheat) { ProfileController user = profile; - string userRequest = display.getInput(games); + CheatController activeCheats = cheat; + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(games, menuType); + } return user; } } diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs index c8603a7b..ae82de29 100644 --- a/gameboy/Controllers/MainMenuController.cs +++ b/gameboy/Controllers/MainMenuController.cs @@ -6,23 +6,29 @@ namespace gameboy { class MainMenuController { - private List menuItems = new List() { "Play Games", "Cheats", "Profile", "Exit" }; + 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 = new Display(); + private Display display; public void StartMainMenu() { + + string userRequest = ""; do { profile.Create(); } while (!profile.active); - - string userRequest = display.getInput(menuItems); - StartSelection(userRequest); + do + { + display = new Display(); + userRequest = display.getInput(menuItems, menuType); + StartSelection(userRequest); + } while (userRequest != "Exit"); } - private void StartSelection(string request) + private bool StartSelection(string request) { if (request == "Play Games") { @@ -36,6 +42,14 @@ private void StartSelection(string request) { this.profile.ProfileMenu(); } + if (request == "Exit") + { + Console.Clear(); + Console.WriteLine("Thanks For Playing!"); + Thread.Sleep(1000); + return false; + } + return true; } } } diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index 2e179dd4..86dd8bfe 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Threading; + namespace gameboy { @@ -10,6 +10,7 @@ class ProfileController private string firstName = ""; private string lastName = ""; private List profileOptions = new List() { "Game Stats", "Change Name", "Exit" }; + private string menuType = "PROFILE"; public void Create() { @@ -29,10 +30,15 @@ public void Create() } while (firstName == "" || lastName == ""); this.active = true; } - private Display display = new Display(); + private Display display; public void ProfileMenu() { - string userRequest = display.getInput(profileOptions); + string userRequest = ""; + while (userRequest != "Exit") + { + display = new Display(); + userRequest = display.getInput(profileOptions, menuType); + } } } } \ No newline at end of file From ee3fd41f547ada1631d0835dc91716df584c0142 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Feb 2019 01:43:35 -0600 Subject: [PATCH 04/22] fixed minor bug with menu --- gameboy/Controllers/CheatController.cs | 1 - gameboy/Controllers/Display.cs | 40 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index a2ed0f12..711556d1 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -21,6 +21,5 @@ public CheatController CheatMenu(CheatController cheat) } return current; } - } } \ No newline at end of file diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs index 8da7a571..0d71040c 100644 --- a/gameboy/Controllers/Display.cs +++ b/gameboy/Controllers/Display.cs @@ -33,9 +33,10 @@ public string getInput(List items, string menuTitle) private string drawMenu(List items) { string buildTitle = ReturnLine(title); - Console.WriteLine("*************************"); + string buildBorder = ReturnLine("*"); + Console.WriteLine(buildBorder); Console.WriteLine(buildTitle); - Console.WriteLine("*************************"); + Console.WriteLine(buildBorder); for (int i = 0; i < items.Count; i++) { Console.CursorVisible = false; @@ -53,7 +54,7 @@ private string drawMenu(List items) } Console.ResetColor(); } - Console.WriteLine("*************************"); + Console.WriteLine(buildBorder); string userInput = MenuController(items); return userInput; } @@ -91,23 +92,32 @@ private string MenuController(List items) } private string ReturnLine(string formatMe) { - StringBuilder buildLine = new StringBuilder(); - int spaces = (((25 - formatMe.Length) / 2) - 1); - char[] chars = new char[2] { '*', ' ' }; - buildLine.Append(chars[0]).Append(chars[1], spaces).Append(formatMe).Append(chars[1], spaces); - while (buildLine.Length < 25) + char[] chars = new char[3] { '|', ' ', '~' }; + if (formatMe == "*") { - if (buildLine.Length == 24) + StringBuilder buildBorder = new StringBuilder(); + buildBorder.Append(chars[2], 25); + return buildBorder.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) { - buildLine.Append(chars[0]); + if (buildLine.Length == 24) + { + buildLine.Append(chars[0]); + } + else if (buildLine.Length < 24) + { + buildLine.Append(chars[1]); + } } - else if (buildLine.Length < 24) - { - buildLine.Append(chars[1]); - } + return buildLine.ToString(); } - return buildLine.ToString(); } } } \ No newline at end of file From e3876853c0d098ae61f059d2d189200cdc3bfbbf Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Feb 2019 15:21:37 -0600 Subject: [PATCH 05/22] finished Cheats menu --- gameboy/Controllers/CheatController.cs | 126 +++++++++++++++++++++- gameboy/Controllers/Display.cs | 53 +++++++++ gameboy/Controllers/MainMenuController.cs | 2 +- 3 files changed, 175 insertions(+), 6 deletions(-) diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index 711556d1..55e9afae 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; namespace gameboy @@ -7,19 +8,134 @@ namespace gameboy class CheatController { public bool active { get; private set; } = false; - private List cheats = new List() { "Enter Cheat", "View Active", "Disable Cheats", "Disable All Cheats", "Exit" }; + private List cheats = new List() { "Enter Cheat", "View Active Cheats", "Disable Cheats", "Exit" }; private string menuType = "CHEATS"; private Display display; - public CheatController CheatMenu(CheatController cheat) + public List ActiveCheats { get; private set; } = new List(); + private List InactiveCheats = new List() { "Immortality" }; + private List CheatCodes = new List() { "l1v3s" }; + public void CheatMenu() { - CheatController current = cheat; + 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; + } + } + 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 (InactiveCheats[i] != item) + { + result = code; + ActiveCheats.Add(InactiveCheats[i]); + } + } + } + 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"); + Display deactivateCheats = new Display(); + string userRequest = deactivateCheats.getInput(active, "DISABLE CHEATS"); + if (userRequest == "Remove All") + { + ActiveCheats.RemoveRange(0, ActiveCheats.Count); + active.Remove("Remove All"); + } + else + { + ActiveCheats.Remove(userRequest); + active.Remove("Remove All"); } - return current; } } -} \ No newline at end of file +} diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs index 0d71040c..63f268ef 100644 --- a/gameboy/Controllers/Display.cs +++ b/gameboy/Controllers/Display.cs @@ -30,6 +30,15 @@ public string getInput(List items, string menuTitle) } } } + 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 = ReturnLine(title); @@ -37,6 +46,31 @@ private string drawMenu(List items) Console.WriteLine(buildBorder); Console.WriteLine(buildTitle); Console.WriteLine(buildBorder); + + for (int i = 0; i < items.Count; i++) + { + Console.CursorVisible = false; + if (i == index) + { + Console.BackgroundColor = ConsoleColor.Gray; + Console.ForegroundColor = ConsoleColor.Black; + string buildLine = ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + else + { + string buildLine = ReturnLine(items[i]); + Console.WriteLine(buildLine); + } + Console.ResetColor(); + } + Console.WriteLine(buildBorder); + string userInput = MenuController(items); + return userInput; + } + private string drawExit(List items) + { + string buildBorder = ReturnLine("*"); for (int i = 0; i < items.Count; i++) { Console.CursorVisible = false; @@ -58,6 +92,25 @@ private string drawMenu(List items) string userInput = MenuController(items); return userInput; } + private string drawData(List items) + { + string buildTitle = ReturnLine(title); + string buildBorder = ReturnLine("*"); + Console.WriteLine(buildBorder); + Console.WriteLine(buildTitle); + Console.WriteLine(buildBorder); + + for (int i = 0; i < items.Count; i++) + { + Console.WriteLine(ReturnLine(items[i])); + } + Console.WriteLine(buildBorder); + + List exit = new List() { "Exit" }; + string userInput = drawExit(exit); + return userInput; + + } private string MenuController(List items) { ConsoleKeyInfo userInput = Console.ReadKey(); diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs index ae82de29..6f4768ce 100644 --- a/gameboy/Controllers/MainMenuController.cs +++ b/gameboy/Controllers/MainMenuController.cs @@ -36,7 +36,7 @@ private bool StartSelection(string request) } if (request == "Cheats") { - this.cheats = cheats.CheatMenu(cheats); + cheats.CheatMenu(); } if (request == "Profile") { From 1f93d842fe773e62fd53eda332f47f8686bd0cb2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Feb 2019 20:51:09 -0600 Subject: [PATCH 06/22] the menus are done how to display data is done can accept any data correctly formated Data. need to work on profile and how games are stored/displayed and games --- gameboy/Controllers/CheatController.cs | 25 +++++++++-- gameboy/Controllers/Display.cs | 51 +++++++++++++++++++---- gameboy/Controllers/MainMenuController.cs | 9 ++-- gameboy/Controllers/ProfileController.cs | 2 +- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index 55e9afae..8e8c3d23 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -12,8 +12,8 @@ class CheatController private string menuType = "CHEATS"; private Display display; public List ActiveCheats { get; private set; } = new List(); - private List InactiveCheats = new List() { "Immortality" }; - private List CheatCodes = new List() { "l1v3s" }; + private List InactiveCheats = new List() { "Immortality", "Unlimited Money", "Unlocked R.P.C", "Unlocked T.T.T" }; + private List CheatCodes = new List() { "l1v3s", "MrBurns", "rps", "ttt" }; public void CheatMenu() { Console.Clear(); @@ -82,6 +82,7 @@ private string CheckCheat(string input) if (input == item) { validate = input; + break; } } return validate; @@ -93,16 +94,23 @@ private string ActivateCheat(string code) { if (code == CheatCodes[i]) { - if (ActiveCheats.Count != 0) + if (ActiveCheats.Count > 0) { foreach (var item in ActiveCheats) { - if (InactiveCheats[i] != item) + if (item == InactiveCheats[i]) + { + break; + } + else { result = code; ActiveCheats.Add(InactiveCheats[i]); + break; } + } + } else { @@ -111,6 +119,7 @@ private string ActivateCheat(string code) } } } + return result; } private void ViewActiveCheats() @@ -123,6 +132,7 @@ private void ViewActiveCheats() private void DisableCheat() { List active = ActiveCheats; + active.Add("Cancel"); active.Add("Remove All"); Display deactivateCheats = new Display(); string userRequest = deactivateCheats.getInput(active, "DISABLE CHEATS"); @@ -130,11 +140,18 @@ private void DisableCheat() { 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/Controllers/Display.cs b/gameboy/Controllers/Display.cs index 63f268ef..2fe34b9f 100644 --- a/gameboy/Controllers/Display.cs +++ b/gameboy/Controllers/Display.cs @@ -42,7 +42,7 @@ public void ShowData(List items, string menuTitle) private string drawMenu(List items) { string buildTitle = ReturnLine(title); - string buildBorder = ReturnLine("*"); + string buildBorder = ReturnLine("~"); Console.WriteLine(buildBorder); Console.WriteLine(buildTitle); Console.WriteLine(buildBorder); @@ -70,7 +70,7 @@ private string drawMenu(List items) } private string drawExit(List items) { - string buildBorder = ReturnLine("*"); + string buildBottem = ReturnLine("~"); for (int i = 0; i < items.Count; i++) { Console.CursorVisible = false; @@ -88,23 +88,30 @@ private string drawExit(List items) } Console.ResetColor(); } - Console.WriteLine(buildBorder); + Console.WriteLine(buildBottem); string userInput = MenuController(items); return userInput; } private string drawData(List items) { string buildTitle = ReturnLine(title); - string buildBorder = ReturnLine("*"); + string buildBorder = ReturnLine("~"); + string buildBottom = ReturnLine("*"); + string buildBlank = ReturnLine("| "); Console.WriteLine(buildBorder); Console.WriteLine(buildTitle); - Console.WriteLine(buildBorder); + Console.WriteLine(buildBottom); + Console.WriteLine(buildBlank); + for (int i = 0; i < items.Count; i++) { - Console.WriteLine(ReturnLine(items[i])); + Console.WriteLine(ReturnLine("|" + items[i])); } - Console.WriteLine(buildBorder); + + Console.WriteLine(buildBlank); + Console.WriteLine(buildBottom); + List exit = new List() { "Exit" }; string userInput = drawExit(exit); @@ -145,13 +152,39 @@ private string MenuController(List items) } private string ReturnLine(string formatMe) { - char[] chars = new char[3] { '|', ' ', '~' }; - if (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(); diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs index 6f4768ce..e2edf65c 100644 --- a/gameboy/Controllers/MainMenuController.cs +++ b/gameboy/Controllers/MainMenuController.cs @@ -16,11 +16,14 @@ public void StartMainMenu() { string userRequest = ""; - do + if (!profile.active) { - profile.Create(); + do + { + profile.Create(); - } while (!profile.active); + } while (!profile.active); + } do { display = new Display(); diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index 86dd8bfe..de75caed 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -6,7 +6,7 @@ namespace gameboy { class ProfileController { - public bool active { get; private set; } = false; + public bool active { get; private set; } = true;//bypass profile with true private string firstName = ""; private string lastName = ""; private List profileOptions = new List() { "Game Stats", "Change Name", "Exit" }; From 680fa0135c2f0967268a08f47157dadfb2603ecb Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 10 Feb 2019 01:29:06 -0600 Subject: [PATCH 07/22] all menus, and stats views are done --- gameboy/Controllers/CheatController.cs | 18 +- gameboy/Controllers/Display.cs | 209 ---------------------- gameboy/Controllers/MainMenuController.cs | 4 +- gameboy/Controllers/ProfileController.cs | 78 +++++++- 4 files changed, 87 insertions(+), 222 deletions(-) delete mode 100644 gameboy/Controllers/Display.cs diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs index 8e8c3d23..ece4a965 100644 --- a/gameboy/Controllers/CheatController.cs +++ b/gameboy/Controllers/CheatController.cs @@ -132,25 +132,29 @@ private void ViewActiveCheats() private void DisableCheat() { List active = ActiveCheats; + active.Add("!! Remove All !!"); active.Add("Cancel"); - active.Add("Remove All"); Display deactivateCheats = new Display(); string userRequest = deactivateCheats.getInput(active, "DISABLE CHEATS"); - if (userRequest == "Remove All") + if (userRequest == "!! Remove All !!") { - ActiveCheats.RemoveRange(0, ActiveCheats.Count); - active.Remove("Remove All"); - active.Remove("Cancel"); + //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"); + active.Remove("!! Remove All !!"); } else { ActiveCheats.Remove(userRequest); - active.Remove("Remove All"); + active.Remove("!! Remove All !!"); active.Remove("Cancel"); } } diff --git a/gameboy/Controllers/Display.cs b/gameboy/Controllers/Display.cs deleted file mode 100644 index 2fe34b9f..00000000 --- a/gameboy/Controllers/Display.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace gameboy -{ - class Display - { - private static int index = 0; - 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 = ReturnLine(title); - string buildBorder = ReturnLine("~"); - Console.WriteLine(buildBorder); - Console.WriteLine(buildTitle); - Console.WriteLine(buildBorder); - - for (int i = 0; i < items.Count; i++) - { - Console.CursorVisible = false; - if (i == index) - { - Console.BackgroundColor = ConsoleColor.Gray; - Console.ForegroundColor = ConsoleColor.Black; - string buildLine = ReturnLine(items[i]); - Console.WriteLine(buildLine); - } - else - { - string buildLine = ReturnLine(items[i]); - Console.WriteLine(buildLine); - } - Console.ResetColor(); - } - Console.WriteLine(buildBorder); - string userInput = MenuController(items); - return userInput; - } - private string drawExit(List items) - { - string buildBottem = 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 = ReturnLine(items[i]); - Console.WriteLine(buildLine); - } - else - { - string buildLine = ReturnLine(items[i]); - Console.WriteLine(buildLine); - } - Console.ResetColor(); - } - Console.WriteLine(buildBottem); - string userInput = MenuController(items); - return userInput; - } - private string drawData(List items) - { - string buildTitle = ReturnLine(title); - string buildBorder = ReturnLine("~"); - string buildBottom = ReturnLine("*"); - string buildBlank = ReturnLine("| "); - Console.WriteLine(buildBorder); - Console.WriteLine(buildTitle); - Console.WriteLine(buildBottom); - Console.WriteLine(buildBlank); - - - for (int i = 0; i < items.Count; i++) - { - Console.WriteLine(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) - { - if (index == items.Count - 1) - { - index = 0; - } - else { index++; } - } - else if (userInput.Key == ConsoleKey.UpArrow) - { - if (index <= 0) - { - index = items.Count - 1; - } - else { index--; } - } - else if (userInput.Key == ConsoleKey.Enter) - { - return items[index]; - } - else - { - return ""; - } - - Console.Clear(); - return ""; - } - private 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/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs index e2edf65c..d985073a 100644 --- a/gameboy/Controllers/MainMenuController.cs +++ b/gameboy/Controllers/MainMenuController.cs @@ -20,13 +20,13 @@ public void StartMainMenu() { do { - profile.Create(); + this.profile.Create(); } while (!profile.active); } do { - display = new Display(); + this.display = new Display(); userRequest = display.getInput(menuItems, menuType); StartSelection(userRequest); } while (userRequest != "Exit"); diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index de75caed..73e0b3db 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -6,15 +6,48 @@ namespace gameboy { class ProfileController { - public bool active { get; private set; } = true;//bypass profile with true + 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", "Tic Tac Toe", "Rock Paper Scissor" }; + private List> labels = new List>(); + private List> scores = new List>(); + public ProfileController() + { + for (int i = 0; i < game.Count; i++) + { + List label = new List { "Games Played", "wins", "Losses", "Times Cheated", "Best Score" }; + List startScores = new List { 0, 0, 0, 0, 0 }; + labels.Add(label); + scores.Add(startScores); + } + } public void Create() { - do + 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 == "") { @@ -27,8 +60,8 @@ public void Create() this.lastName = Console.ReadLine(); } Console.Clear(); - } while (firstName == "" || lastName == ""); - this.active = true; + } while (firstName == "" || lastName == "" && !active); + this.active = true;//activate profile } private Display display; public void ProfileMenu() @@ -38,7 +71,44 @@ public void ProfileMenu() { 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 From 0394ad42d8e0f56eaf7315088f2dab8a92880854 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 10 Feb 2019 01:31:25 -0600 Subject: [PATCH 08/22] all menus, and stats views are done --- gameboy/Controllers/ProfileController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index 73e0b3db..dbb9030a 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -19,7 +19,7 @@ public ProfileController() { for (int i = 0; i < game.Count; i++) { - List label = new List { "Games Played", "wins", "Losses", "Times Cheated", "Best Score" }; + List label = new List { "Games Played", "wins", "Losses", "Times Cheated", "Best Score", "Worst Score" }; List startScores = new List { 0, 0, 0, 0, 0 }; labels.Add(label); scores.Add(startScores); From ae4e658034c0f3a98d6e012365d4489370a59af4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 10 Feb 2019 02:25:01 -0600 Subject: [PATCH 09/22] added files? --- gameboy/Controllers/ProfileController.cs | 2 +- gameboy/Display.cs | 176 +++++++++++++++++++++++ gameboy/DisplayUtility.cs | 65 +++++++++ gameboy/GetLines.cs | 168 ++++++++++++++++++++++ gameboy/StartGames.cs | 9 ++ gameboy/TwoOptionMenu.cs | 111 ++++++++++++++ 6 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 gameboy/Display.cs create mode 100644 gameboy/DisplayUtility.cs create mode 100644 gameboy/GetLines.cs create mode 100644 gameboy/StartGames.cs create mode 100644 gameboy/TwoOptionMenu.cs diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index dbb9030a..b760f447 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -20,7 +20,7 @@ public ProfileController() for (int i = 0; i < game.Count; i++) { List label = new List { "Games Played", "wins", "Losses", "Times Cheated", "Best Score", "Worst Score" }; - List startScores = new List { 0, 0, 0, 0, 0 }; + List startScores = new List { 0, 0, 0, 0, 0, 0 }; labels.Add(label); scores.Add(startScores); } diff --git a/gameboy/Display.cs b/gameboy/Display.cs new file mode 100644 index 00000000..789dcc30 --- /dev/null +++ b/gameboy/Display.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; + +namespace gameboy +{ + class Display + { + private static int index = 0; + 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) + { + if (index == items.Count - 1) + { + index = 0; + } + else { index++; } + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + if (index <= 0) + { + index = items.Count - 1; + } + else { index--; } + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + else + { + + } + + 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]; + } + else + { + + } + } + + 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/GetLines.cs b/gameboy/GetLines.cs new file mode 100644 index 00000000..dfa80738 --- /dev/null +++ b/gameboy/GetLines.cs @@ -0,0 +1,168 @@ +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[1]; + lessThan11.RemoveRange(0, 3); + int space = ((36 - (first.Length + second.Length + third.Length)) / 3); + 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) + { + if (lessThan11.Count > 1) + { + StringBuilder nextLine = new StringBuilder(); + string first = lessThan11[0]; + string second = lessThan11[1]; + lessThan17.RemoveRange(0, 2); + int space = ((36 - (first.Length + second.Length)) / 2); + 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 - lessThan11[0].Length) / 2); + nextLine.Append(chars[0]).Append(chars[3]).Append(lessThan11[0]).Append(chars[3], space).Append(chars[3]).Append(chars[0]); + lessThan11.RemoveRange(0, 1); + } + } + else + { + break; + } + + } while (true); + + } + } +} \ No newline at end of file diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs new file mode 100644 index 00000000..f8547178 --- /dev/null +++ b/gameboy/StartGames.cs @@ -0,0 +1,9 @@ +using System; + +namespace gameboy +{ + class StartGames + { + + } +} \ No newline at end of file diff --git a/gameboy/TwoOptionMenu.cs b/gameboy/TwoOptionMenu.cs new file mode 100644 index 00000000..7bdfa0ba --- /dev/null +++ b/gameboy/TwoOptionMenu.cs @@ -0,0 +1,111 @@ +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 From 11397f0780eb6107c17fc61974422a6f90ddd137 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 10 Feb 2019 15:16:15 -0600 Subject: [PATCH 10/22] all menus for the games are working and dynamic based off menu item label length --- gameboy/Controllers/ProfileController.cs | 4 ++-- gameboy/GetLines.cs | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gameboy/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs index b760f447..f7955932 100644 --- a/gameboy/Controllers/ProfileController.cs +++ b/gameboy/Controllers/ProfileController.cs @@ -11,7 +11,7 @@ class ProfileController 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", "Tic Tac Toe", "Rock Paper Scissor" }; + private List game = new List { "Towers Of Hanoi", "Mastermind" }; private List> labels = new List>(); private List> scores = new List>(); @@ -19,7 +19,7 @@ public ProfileController() { for (int i = 0; i < game.Count; i++) { - List label = new List { "Games Played", "wins", "Losses", "Times Cheated", "Best Score", "Worst Score" }; + List label = new List { "Games Played", "wins", "Loss", "Times Cheated", "Best Score", "Worst Score" }; List startScores = new List { 0, 0, 0, 0, 0, 0 }; labels.Add(label); scores.Add(startScores); diff --git a/gameboy/GetLines.cs b/gameboy/GetLines.cs index dfa80738..4039a53f 100644 --- a/gameboy/GetLines.cs +++ b/gameboy/GetLines.cs @@ -124,36 +124,37 @@ public void BuildData(List label, List scores) } while (true); do { - if (lessThan11.Count > 3) + if (lessThan11.Count >= 3) { StringBuilder nextLine = new StringBuilder(); string first = lessThan11[0]; string second = lessThan11[1]; - string third = lessThan11[1]; + string third = lessThan11[2]; lessThan11.RemoveRange(0, 3); - int space = ((36 - (first.Length + second.Length + third.Length)) / 3); - nextLine.Append(chars[0]).Append(chars[3]).Append(first).Append(chars[3], space).Append(second).Append(chars[3]).Append(chars[0]); + 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) + if (lessThan11.Count > 1 && lessThan11.Count > 3) { StringBuilder nextLine = new StringBuilder(); string first = lessThan11[0]; string second = lessThan11[1]; - lessThan17.RemoveRange(0, 2); - int space = ((36 - (first.Length + second.Length)) / 2); + 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 + else if (lessThan11.Count > 0) { StringBuilder nextLine = new StringBuilder(); - int space = ((36 - lessThan11[0].Length) / 2); + 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 From bead73034f614128d7a097047d1488afa5107621 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 17 Feb 2019 20:24:30 -0600 Subject: [PATCH 11/22] switching --- Mastermind/Mastermind.cs | 35 ++--- gameboy/Controllers/CheatController.cs | 162 ---------------------- gameboy/Controllers/GamesController.cs | 25 ---- gameboy/Controllers/MainMenuController.cs | 58 -------- gameboy/Controllers/ProfileController.cs | 114 --------------- gameboy/Display.cs | 24 +--- gameboy/StartGames.cs | 24 +++- gameboy/TwoOptionMenu.cs | 2 - 8 files changed, 44 insertions(+), 400 deletions(-) delete mode 100644 gameboy/Controllers/CheatController.cs delete mode 100644 gameboy/Controllers/GamesController.cs delete mode 100644 gameboy/Controllers/MainMenuController.cs delete mode 100644 gameboy/Controllers/ProfileController.cs diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 365fb84c..8817d436 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -6,23 +6,23 @@ 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'}; - + public static char[] solution = new char[] { 'a', 'b', 'c', 'd' }; + // game board public static string[][] board = new string[allowedAttempts][]; - - + + public static void Main() { char[] guess = new char[4]; @@ -35,25 +35,25 @@ public static void Main() // leave this command at the end so your program does not close automatically Console.ReadLine(); } - + public static bool CheckSolution(char[] guess) { // Your code here return false; } - + public static string GenerateHint(char[] guess) { // Your code here return " "; } - + public static void InsertCode(char[] guess) { // Your code here } - + public static void CreateBoard() { for (var i = 0; i < allowedAttempts; i++) @@ -65,19 +65,20 @@ public static void CreateBoard() } } } - + public static void DrawBoard() { for (var i = 0; i < board.Length; i++) { Console.WriteLine("|" + String.Join("|", board[i])); } - + } - - public static void GenerateRandomCode() { + + public static void GenerateRandomCode() + { Random rnd = new Random(); - for(var i = 0; i < codeSize; i++) + for (var i = 0; i < codeSize; i++) { solution[i] = letters[rnd.Next(0, letters.Length)]; } diff --git a/gameboy/Controllers/CheatController.cs b/gameboy/Controllers/CheatController.cs deleted file mode 100644 index ece4a965..00000000 --- a/gameboy/Controllers/CheatController.cs +++ /dev/null @@ -1,162 +0,0 @@ -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" }; - private List CheatCodes = new List() { "l1v3s", "MrBurns", "rps", "ttt" }; - 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]); - 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/Controllers/GamesController.cs b/gameboy/Controllers/GamesController.cs deleted file mode 100644 index caed5ba3..00000000 --- a/gameboy/Controllers/GamesController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; - - -namespace gameboy -{ - class GamesController - { - private List games = new List() { "Towers Of Hanoi", "Mastermind", "Rock Paper Scissor", "Tic Tac Toe", "Exit" }; - private string menuType = "GAMES"; - private Display display; - public ProfileController SelectGame(ProfileController profile, CheatController cheat) - { - ProfileController user = profile; - CheatController activeCheats = cheat; - string userRequest = ""; - while (userRequest != "Exit") - { - display = new Display(); - userRequest = display.getInput(games, menuType); - } - return user; - } - } -} \ No newline at end of file diff --git a/gameboy/Controllers/MainMenuController.cs b/gameboy/Controllers/MainMenuController.cs deleted file mode 100644 index d985073a..00000000 --- a/gameboy/Controllers/MainMenuController.cs +++ /dev/null @@ -1,58 +0,0 @@ -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/Controllers/ProfileController.cs b/gameboy/Controllers/ProfileController.cs deleted file mode 100644 index f7955932..00000000 --- a/gameboy/Controllers/ProfileController.cs +++ /dev/null @@ -1,114 +0,0 @@ -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>(); - private List> scores = new List>(); - - public ProfileController() - { - for (int i = 0; i < game.Count; i++) - { - List label = new List { "Games Played", "wins", "Loss", "Times Cheated", "Best Score", "Worst Score" }; - List startScores = new List { 0, 0, 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/Display.cs b/gameboy/Display.cs index 789dcc30..b8ad5d9c 100644 --- a/gameboy/Display.cs +++ b/gameboy/Display.cs @@ -5,7 +5,7 @@ namespace gameboy { class Display { - private static int index = 0; + private static int index; private string title; public Display() @@ -126,29 +126,16 @@ private string MenuController(List items) if (userInput.Key == ConsoleKey.DownArrow) { - if (index == items.Count - 1) - { - index = 0; - } - else { index++; } + index = index == items.Count - 1 ? 0 : index + 1; } else if (userInput.Key == ConsoleKey.UpArrow) { - if (index <= 0) - { - index = items.Count - 1; - } - else { index--; } + index = index <= 0 ? items.Count - 1 : index - 1; } else if (userInput.Key == ConsoleKey.Enter) { return items[index]; } - else - { - - } - Console.Clear(); return ""; } @@ -162,12 +149,7 @@ private string quitController(List items) { return items[index]; } - else - { - - } } - Console.Clear(); return ""; } diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs index f8547178..4b0cbd34 100644 --- a/gameboy/StartGames.cs +++ b/gameboy/StartGames.cs @@ -4,6 +4,28 @@ namespace gameboy { class StartGames { - + public ProfileController Game(string gameRequest, ProfileController profile, CheatController cheat) + { + switch (gameRequest) + { + case "Tic Tac Toe": + //TicTacToe TTT = new TicTacToe(profile, cheat); + //profile = TTT.Run(); + break; + case "Rock Paper Scissor": + //RockPaperScissor RPC = new RockPaperScissor(profile, cheat); + //profile = RockPaperScissor.Run(); + break; + case "Mastermind": + Mastermind mastermind = new Mastermind(profile, cheat); + profile = mastermind.Run(); + break; + case "Towers Of Hanoi": + //TowersOfHanoi towersOfHanoi = new TowersOfHanoi(profile, cheat); + //profile = towersOfHanoi.Run(); + break; + } + return profile; + } } } \ No newline at end of file diff --git a/gameboy/TwoOptionMenu.cs b/gameboy/TwoOptionMenu.cs index 7bdfa0ba..d71030bc 100644 --- a/gameboy/TwoOptionMenu.cs +++ b/gameboy/TwoOptionMenu.cs @@ -42,8 +42,6 @@ private string DrawDisplay(List currentLabels, List currentscores, string options = DrawOptions(); return options; } - - private string DrawOptions() { GetLines choice = new GetLines(); From e57d393cad410ef123d0474f0544c7a37b4c0a3c Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 17 Feb 2019 22:28:52 -0600 Subject: [PATCH 12/22] mastermind completed --- Mastermind/Mastermind.cs | 167 +++++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 51 deletions(-) diff --git a/Mastermind/Mastermind.cs b/Mastermind/Mastermind.cs index 8817d436..297c880b 100644 --- a/Mastermind/Mastermind.cs +++ b/Mastermind/Mastermind.cs @@ -1,87 +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; + } + } + + class Game + { + private List rows = new List(); + public string[] answer { get; private set; } = new string[4]; - return false; + 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 ""; } } + } + + class Ball + { + public string Letter { get; private set; } - public static void DrawBoard() + public Ball(string letter) { - for (var i = 0; i < board.Length; i++) - { - Console.WriteLine("|" + String.Join("|", board[i])); - } + this.Letter = letter; + } + } + class Row + { + public Ball[] balls = new Ball[4]; + + public Row(Ball[] balls) + { + this.balls = balls; } - public static void GenerateRandomCode() + public string Balls { - Random rnd = new Random(); - for (var i = 0; i < codeSize; i++) + 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 From 7ae90a2e2802a498115532dd20e420c07f79cedb Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Feb 2019 00:34:57 -0600 Subject: [PATCH 13/22] worked mastermind into game tracking system --- gameboy/StartGames.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs index 4b0cbd34..79a13cbd 100644 --- a/gameboy/StartGames.cs +++ b/gameboy/StartGames.cs @@ -17,8 +17,15 @@ public ProfileController Game(string gameRequest, ProfileController profile, Che //profile = RockPaperScissor.Run(); break; case "Mastermind": - Mastermind mastermind = new Mastermind(profile, cheat); - profile = mastermind.Run(); + Mastermind game = new Mastermind(); + if (cheat.ActiveCheats.Contains("Immortality") || cheat.ActiveCheats.Contains("Not So Mastermind")) + { + profile.scores[1][3]++; + } + int result = Mastermind.Play(cheat); + profile.scores[1][1] = result == 1 ? profile.scores[1][1] + 1 : profile.scores[1][1]; + profile.scores[1][2] = result == 0 ? profile.scores[1][2] + 1 : profile.scores[1][2]; + profile.scores[1][0] = profile.scores[1][0] + 1; break; case "Towers Of Hanoi": //TowersOfHanoi towersOfHanoi = new TowersOfHanoi(profile, cheat); From db2900f392bef21d779f55095e62501d09ffed4c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Feb 2019 00:35:21 -0600 Subject: [PATCH 14/22] worked mastermind into game tracking system --- gameboy/CheatController.cs | 166 ++++++++++++++++++++++++++++++++ gameboy/GamesController.cs | 44 +++++++++ gameboy/MainMenuController.cs | 58 ++++++++++++ gameboy/Mastermind.cs | 174 ++++++++++++++++++++++++++++++++++ gameboy/ProfileController.cs | 114 ++++++++++++++++++++++ 5 files changed, 556 insertions(+) create mode 100644 gameboy/CheatController.cs create mode 100644 gameboy/GamesController.cs create mode 100644 gameboy/MainMenuController.cs create mode 100644 gameboy/Mastermind.cs create mode 100644 gameboy/ProfileController.cs diff --git a/gameboy/CheatController.cs b/gameboy/CheatController.cs new file mode 100644 index 00000000..93bdf3d7 --- /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" }; + private List CheatCodes = new List() { "l1v3s", "MrBurns", "rps", "ttt", "dummy" }; + 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/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/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..5b2ec66f --- /dev/null +++ b/gameboy/Mastermind.cs @@ -0,0 +1,174 @@ +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: "); + 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(1000); + TurnsRemaining = turns; + break; + } + game.AddRow(row); + Console.WriteLine(game.Rows); + + } + Console.WriteLine(TurnsRemaining != 0 ? "Great Job" : "Out Of Turns"); + 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 From 2ca3a86f364b4c667e2f0333b56e6439c1b8486b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Feb 2019 18:35:12 -0600 Subject: [PATCH 15/22] still working on towers of ahnoi --- gameboy/CheatController.cs | 4 ++-- gameboy/StartGames.cs | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gameboy/CheatController.cs b/gameboy/CheatController.cs index 93bdf3d7..8e1f3def 100644 --- a/gameboy/CheatController.cs +++ b/gameboy/CheatController.cs @@ -12,8 +12,8 @@ class CheatController 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" }; - private List CheatCodes = new List() { "l1v3s", "MrBurns", "rps", "ttt", "dummy" }; + 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() diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs index 79a13cbd..e5e48e9a 100644 --- a/gameboy/StartGames.cs +++ b/gameboy/StartGames.cs @@ -17,19 +17,26 @@ public ProfileController Game(string gameRequest, ProfileController profile, Che //profile = RockPaperScissor.Run(); break; case "Mastermind": - Mastermind game = new Mastermind(); + Mastermind masterMind = new Mastermind(); if (cheat.ActiveCheats.Contains("Immortality") || cheat.ActiveCheats.Contains("Not So Mastermind")) { profile.scores[1][3]++; } - int result = Mastermind.Play(cheat); - profile.scores[1][1] = result == 1 ? profile.scores[1][1] + 1 : profile.scores[1][1]; - profile.scores[1][2] = result == 0 ? profile.scores[1][2] + 1 : profile.scores[1][2]; + 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": - //TowersOfHanoi towersOfHanoi = new TowersOfHanoi(profile, cheat); - //profile = towersOfHanoi.Run(); + Towers towers = new Towers(cheat); + if (cheat.ActiveCheats.Contains("Immortality") || cheat.ActiveCheats.Contains("Not So Mastermind")) + { + profile.scores[1][3]++; + } + int TResult = towers.Play(cheat); + 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; From 4906d3cc898151aff88e16afaec7d8e395c2c4c5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Feb 2019 20:33:21 -0600 Subject: [PATCH 16/22] working need to build display and game tower --- gameboy/Towers.cs | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 gameboy/Towers.cs diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs new file mode 100644 index 00000000..0e9da32b --- /dev/null +++ b/gameboy/Towers.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +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 { 3, 6, 9, 12 }; + public List> Pegs { get; private set; } = new List>(); + List Board = new List(); + public Towers(CheatController c) + { + StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 10 : 4; + PegHight = StartingBlocks + 2; + Stack p1 = new Stack(); + Pegs.Add(p1); + Pegs.Add(p1); + Pegs.Add(p1); + } + public int Play(CheatController c) + { + int result = 0; + cheats = c; + ConstructBlocks(); + while (true) + { + ConstructPegs(); + ConstructLines(); + //ChooseBlock(); + // ChoosePeg(); + // if (CheckWin()) + // { + // result = 1; + // break; + // } + Console.Write("Continue y/n: "); + string input = Console.ReadLine(); + if (input != "y" || input != "Y") + { + break; + } + } + return result; + } + private void ConstructBlocks() + { + if (StartingBlocks > 4) + { + for (int i = 1; i == StartingBlocks - 4; i++) + { + Blocks.Add(12 + (3 * i)); + } + } + } + private void ConstructPegs() + { + int height = Blocks.Count + 2; + foreach (var item in Blocks) + { + Pegs[0].Push(item); + } + Pegs[0].Push(0); + Pegs[0].Push(0); + for (int i = 0; i < height; i++) + { + Pegs[1].Push(0); + Pegs[2].Push(0); + } + } + private void ConstructLines() + { + int space = (StartingBlocks) * 2; + Char[] buildElements = new Char[] { ' ', '[', ']', '|' }; + Stack pegOne = Pegs[0]; + Stack pegTwo = Pegs[1]; + Stack pegThree = Pegs[2]; + for (int i = 0; i < PegHight; i++) + { + ; + } + + + } + } +} From 92feaccfa68fb9a6c5ba3ef4ef706b6005d86283 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Feb 2019 20:33:28 -0600 Subject: [PATCH 17/22] working need to build display and game tower --- gameboy/Towers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index 0e9da32b..546264ec 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -39,7 +39,7 @@ public int Play(CheatController c) // result = 1; // break; // } - Console.Write("Continue y/n: "); + Console.Write("Quit? y/n: "); string input = Console.ReadLine(); if (input != "y" || input != "Y") { From 7ce3ed0e88778a848c14d0516ea089338cb9d10e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Feb 2019 01:46:40 -0600 Subject: [PATCH 18/22] still having an issue with pegs --- gameboy/StartGames.cs | 2 +- gameboy/Towers.cs | 231 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 204 insertions(+), 29 deletions(-) diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs index e5e48e9a..ae7e98e0 100644 --- a/gameboy/StartGames.cs +++ b/gameboy/StartGames.cs @@ -33,7 +33,7 @@ public ProfileController Game(string gameRequest, ProfileController profile, Che { profile.scores[1][3]++; } - int TResult = towers.Play(cheat); + 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; diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index 546264ec..7f85e85b 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -11,29 +11,83 @@ class Towers 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 { 3, 6, 9, 12 }; + 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; + //StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 10 : 4; + //for (int i = 4; i == StartingBlocks; i++) + //{ + // Blocks.Add(12 + 4 * i); + //} PegHight = StartingBlocks + 2; + Blocks.Reverse(); Stack p1 = new Stack(); + Stack p2 = new Stack(); + Stack p3 = new Stack(); Pegs.Add(p1); - Pegs.Add(p1); - Pegs.Add(p1); + Pegs.Add(p2); + Pegs.Add(p3); + ConstructPegs(); } - public int Play(CheatController c) + public int Play() { int result = 0; - cheats = c; - ConstructBlocks(); while (true) { - ConstructPegs(); - ConstructLines(); - //ChooseBlock(); - // ChoosePeg(); + ConstructBoard(); + int pullBlock = 0; + string chosen = ""; + while (true) + { + chosen = ChooseBlock(); + int block = Convert.ToInt32(chosen.Replace(" ", String.Empty).Substring(0, 1)); + int amount = 0; + while (Pegs[block].Peek() == 0 && Pegs[block].Count > 1) + { + Pegs[block].Pop(); + amount++; + } + int currentBlock = Pegs[block].Peek(); + if (currentBlock != 0) + { + pullBlock = Pegs[block].Pop(); + Pegs[block].Push(0); + Pegs[block].Push(0); + break; + } + for (var j = amount; j == 0; j--) + { + Pegs[block].Push(0); + } + } + while (true) + { + int tally = 0; + string toPeg = ChoosePeg(); + int peg = Convert.ToInt32(toPeg.Replace(" ", String.Empty).Substring(0, 1)); + while (Pegs[peg].Peek() == 0 && Pegs[peg].Count > 1) + { + Pegs[peg].Pop(); + tally++; + } + int current = Pegs[peg].Peek(); + if (chosen.Length < current) + { + Pegs[peg].Pop(); + Pegs[peg].Push(pullBlock); + Pegs[peg].Push(0); + Pegs[peg].Push(0); + break; + } + for (var j = tally; j == 0; j--) + { + Pegs[peg].Push(0); + } + } + // if (CheckWin()) // { // result = 1; @@ -48,44 +102,165 @@ public int Play(CheatController c) } return result; } - private void ConstructBlocks() - { - if (StartingBlocks > 4) - { - for (int i = 1; i == StartingBlocks - 4; i++) - { - Blocks.Add(12 + (3 * i)); - } - } - } private void ConstructPegs() { int height = Blocks.Count + 2; foreach (var item in Blocks) { Pegs[0].Push(item); + Pegs[1].Push(0); + Pegs[2].Push(0); } - Pegs[0].Push(0); - Pegs[0].Push(0); - for (int i = 0; i < height; i++) + for (int i = 0; i < 2; i++) { + Pegs[0].Push(0); Pegs[1].Push(0); Pegs[2].Push(0); } } - private void ConstructLines() + private void ConstructBoard() { int space = (StartingBlocks) * 2; - Char[] buildElements = new Char[] { ' ', '[', ']', '|' }; Stack pegOne = Pegs[0]; Stack pegTwo = Pegs[1]; Stack pegThree = Pegs[2]; - for (int i = 0; i < PegHight; i++) + + List stackOne = buildLines(pegOne); + List stackTwo = buildLines(pegTwo); + List stackThree = buildLines(pegThree); + + 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 ChooseBlock() + { + 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 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 ""; } } } + From 0d091be21c7e7ea798b3b1c8000b07c91e049e7a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Feb 2019 19:20:32 -0600 Subject: [PATCH 19/22] in --- gameboy/Towers.cs | 119 +++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index 7f85e85b..e83f128d 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -22,7 +22,7 @@ public Towers(CheatController c) //{ // Blocks.Add(12 + 4 * i); //} - PegHight = StartingBlocks + 2; + PegHight = Blocks.Count + 2; Blocks.Reverse(); Stack p1 = new Stack(); Stack p2 = new Stack(); @@ -30,6 +30,10 @@ public Towers(CheatController c) Pegs.Add(p1); Pegs.Add(p2); Pegs.Add(p3); + foreach (var item in Blocks) + { + Pegs[0].Push(item); + } ConstructPegs(); } public int Play() @@ -37,97 +41,94 @@ public int Play() int result = 0; while (true) { - ConstructBoard(); - int pullBlock = 0; - string chosen = ""; + int requestedBlock = 0; + int from = 0; while (true) { - chosen = ChooseBlock(); - int block = Convert.ToInt32(chosen.Replace(" ", String.Empty).Substring(0, 1)); - int amount = 0; - while (Pegs[block].Peek() == 0 && Pegs[block].Count > 1) + string unformatedChoice = Choice(); + from = Convert.ToInt32(unformatedChoice.Replace(" ", String.Empty).Substring(0, 1)); + ClearPegs(); + if (Pegs[from].Count != 0) { - Pegs[block].Pop(); - amount++; - } - int currentBlock = Pegs[block].Peek(); - if (currentBlock != 0) - { - pullBlock = Pegs[block].Pop(); - Pegs[block].Push(0); - Pegs[block].Push(0); + requestedBlock = Pegs[from].Pop(); break; } - for (var j = amount; j == 0; j--) - { - Pegs[block].Push(0); - } } while (true) { - int tally = 0; - string toPeg = ChoosePeg(); - int peg = Convert.ToInt32(toPeg.Replace(" ", String.Empty).Substring(0, 1)); - while (Pegs[peg].Peek() == 0 && Pegs[peg].Count > 1) + string unformattedPeg = Choice(); + int formatPeg = Convert.ToInt32(unformattedPeg.Replace(" ", String.Empty).Substring(0, 1)); + ClearPegs(); + int pegdel = Pegs[formatPeg].Peek(); + if (pegdel > requestedBlock || Pegs[formatPeg].Count == 0) { - Pegs[peg].Pop(); - tally++; - } - int current = Pegs[peg].Peek(); - if (chosen.Length < current) - { - Pegs[peg].Pop(); - Pegs[peg].Push(pullBlock); - Pegs[peg].Push(0); - Pegs[peg].Push(0); + Pegs[formatPeg].Push(requestedBlock); break; } - for (var j = tally; j == 0; j--) + else { - Pegs[peg].Push(0); + Pegs[from].Push(requestedBlock); + break; } } - + ConstructPegs(); // if (CheckWin()) // { // result = 1; // break; // } - Console.Write("Quit? y/n: "); - string input = Console.ReadLine(); - if (input != "y" || input != "Y") + } + return result; + } + public void ClearPegs() + { + Stack peg = Pegs[0]; + for (var i = 0; i < PegHight; i++) + { + if (peg.Peek() == 0) { - break; + 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(); } } - return result; } private void ConstructPegs() { - int height = Blocks.Count + 2; - foreach (var item in Blocks) + while (Pegs[0].Count < PegHight) { - Pegs[0].Push(item); - Pegs[1].Push(0); - Pegs[2].Push(0); + Pegs[0].Push(0); } - for (int i = 0; i < 2; i++) + while (Pegs[1].Count < PegHight) { - Pegs[0].Push(0); Pegs[1].Push(0); + } + while (Pegs[2].Count < PegHight) + { Pegs[2].Push(0); } } private void ConstructBoard() { - int space = (StartingBlocks) * 2; - Stack pegOne = Pegs[0]; - Stack pegTwo = Pegs[1]; - Stack pegThree = Pegs[2]; + ConstructPegs(); - List stackOne = buildLines(pegOne); - List stackTwo = buildLines(pegTwo); - List stackThree = buildLines(pegThree); + List stackOne = buildLines(Pegs[0]); + List stackTwo = buildLines(Pegs[1]); + List stackThree = buildLines(Pegs[2]); for (int i = 0; i < stackOne.Count; i++) { @@ -160,7 +161,7 @@ private List buildLines(Stack peg) return stack; } - private string ChooseBlock() + private string Choice() { index = 0; int spaces = (Blocks.Count * 4); @@ -176,9 +177,9 @@ private string ChooseBlock() while (response == "") { - Console.Clear(); ConstructBoard(); response = DrawOptions(options); + Console.Clear(); } return response; } From 7b8dea3b5ba31516c42170e5a9c80467eb9197dc Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Feb 2019 21:54:03 -0600 Subject: [PATCH 20/22] fixed the issue still spegettie --- gameboy/StartGames.cs | 13 +++++++++---- gameboy/Towers.cs | 37 +++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/gameboy/StartGames.cs b/gameboy/StartGames.cs index ae7e98e0..927010ea 100644 --- a/gameboy/StartGames.cs +++ b/gameboy/StartGames.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; namespace gameboy { @@ -9,12 +10,16 @@ public ProfileController Game(string gameRequest, ProfileController profile, Che switch (gameRequest) { case "Tic Tac Toe": - //TicTacToe TTT = new TicTacToe(profile, cheat); - //profile = TTT.Run(); + Console.Clear(); + Console.WriteLine("feature coming soon. Check back shortly!"); + Thread.Sleep(1500); + Console.Clear(); break; case "Rock Paper Scissor": - //RockPaperScissor RPC = new RockPaperScissor(profile, cheat); - //profile = RockPaperScissor.Run(); + Console.Clear(); + Console.WriteLine("feature coming soon! Check back shortly!"); + Thread.Sleep(1500); + Console.Clear(); break; case "Mastermind": Mastermind masterMind = new Mastermind(); diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index e83f128d..9b3a80b0 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -17,11 +17,15 @@ class Towers public int index { get; private set; } public Towers(CheatController c) { - //StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 10 : 4; - //for (int i = 4; i == StartingBlocks; i++) - //{ - // Blocks.Add(12 + 4 * i); - //} + StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 20 : 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(); @@ -59,8 +63,7 @@ public int Play() string unformattedPeg = Choice(); int formatPeg = Convert.ToInt32(unformattedPeg.Replace(" ", String.Empty).Substring(0, 1)); ClearPegs(); - int pegdel = Pegs[formatPeg].Peek(); - if (pegdel > requestedBlock || Pegs[formatPeg].Count == 0) + if (Pegs[formatPeg].Count == 0 || Pegs[formatPeg].Peek() > requestedBlock) { Pegs[formatPeg].Push(requestedBlock); break; @@ -72,11 +75,11 @@ public int Play() } } ConstructPegs(); - // if (CheckWin()) - // { - // result = 1; - // break; - // } + if (CheckWin()) + { + result = 1; + break; + } } return result; } @@ -262,6 +265,16 @@ private string MenuController(List items) } return ""; } + public bool CheckWin() + { + ClearPegs(); + bool win = false; + if (Pegs[1].Count == PegHight - 2 || Pegs[2].Count == PegHight - 2) + { + win = true; + } + return win; + } } } From 7adf8955f467305201b5b0ac57d233cc501590ac Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Feb 2019 22:26:09 -0600 Subject: [PATCH 21/22] finished added cheats for hanoi --- gameboy/Towers.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index 9b3a80b0..eea118a3 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Text; namespace gameboy @@ -17,7 +18,7 @@ class Towers public int index { get; private set; } public Towers(CheatController c) { - StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 20 : 4; + StartingBlocks = c.ActiveCheats.Contains("Extra Blocks") ? 10 : 4; if (StartingBlocks > 4) { Blocks.RemoveRange(0, Blocks.Count); @@ -77,7 +78,11 @@ public int Play() ConstructPegs(); if (CheckWin()) { + Console.Clear(); + Console.WriteLine("You have Won!"); + Thread.Sleep(1500); result = 1; + Console.Clear(); break; } } From 0b12544740c247818797c52b843c46d8bc536dbb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Feb 2019 18:25:32 -0600 Subject: [PATCH 22/22] added forced exit condition to the games it ends in autoloss --- gameboy/Mastermind.cs | 10 ++++++++-- gameboy/Towers.cs | 25 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/gameboy/Mastermind.cs b/gameboy/Mastermind.cs index 5b2ec66f..7642dcb8 100644 --- a/gameboy/Mastermind.cs +++ b/gameboy/Mastermind.cs @@ -25,10 +25,14 @@ public static int Play(CheatController cheats) string letters = ""; while (letters.Length != 4) { - Console.WriteLine("Choose four letters: "); + 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++) { @@ -46,6 +50,7 @@ public static int Play(CheatController cheats) Console.WriteLine("You Win"); Thread.Sleep(1000); TurnsRemaining = turns; + Console.Clear(); break; } game.AddRow(row); @@ -53,6 +58,7 @@ public static int Play(CheatController cheats) } Console.WriteLine(TurnsRemaining != 0 ? "Great Job" : "Out Of Turns"); + Console.Clear(); return TurnsRemaining != 0 ? 1 : 0; } public static string[] GenerateSolution(CheatController cheats) diff --git a/gameboy/Towers.cs b/gameboy/Towers.cs index eea118a3..c0026c68 100644 --- a/gameboy/Towers.cs +++ b/gameboy/Towers.cs @@ -44,13 +44,20 @@ public Towers(CheatController c) public int Play() { int result = 0; - while (true) + bool play = true; + while (play) { int requestedBlock = 0; int from = 0; - while (true) + 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) @@ -61,8 +68,14 @@ public int Play() } while (true) { - string unformattedPeg = Choice(); - int formatPeg = Convert.ToInt32(unformattedPeg.Replace(" ", String.Empty).Substring(0, 1)); + 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) { @@ -85,6 +98,9 @@ public int Play() Console.Clear(); break; } + Console.Clear(); + Console.WriteLine("Continue Playing? y/n"); + } return result; } @@ -181,6 +197,7 @@ private string Choice() 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 == "")