Created
March 10, 2016 23:13
-
-
Save MorkHub/241b1fc90c25dde8cc74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Dim rnd As New Random() | |
Dim fmt1, fmt2, fmt3 As Int32 | |
Dim str1, str2, oprs(), opr, answer As String | |
Dim Playing As Boolean = True | |
Dim Display As Boolean = True | |
Sub Main() | |
While Display | |
DisplayMenu() | |
End While | |
End Sub | |
Sub DrawArray(ByVal ui() As String, ByVal writeLine As Boolean, ByVal ParamArray params() As String) | |
For i = 0 To ui.Count - 1 | |
For p = 0 To params.Count - 1 | |
ui(i) = Replace(ui(i), "{" & p & "}", params(p)) | |
Next | |
Console.Write(ui(i)) | |
If writeLine Or i < ui.Count - 1 Then Console.WriteLine() | |
Next | |
End Sub | |
Public topleft = "┌" | |
Public topright = "┐" | |
Public bottomleft = "└" | |
Public bottomright = "┘" | |
Public verticalbar = "│" | |
Public horizontalbar = "─" | |
Public horizontaldown = "┬" | |
Public horizontalup = "┴" | |
Public verticalright = "┤" | |
Public verticalleft = "├" | |
Public cross = "┼" | |
Sub DisplayMenu() | |
Console.Clear() | |
Dim MenuItems() As String = {"Play", "Options", "Leaderboards", "Quit"} | |
Dim MainMenu() As String = { | |
"┌───────────┐ ", | |
"│ Main Menu │", | |
"├───┬───────┴──────┐"} | |
Console.SetWindowSize(MainMenu(0).Count() + 2, MainMenu.Count() + MenuItems.Count + 2) | |
Console.SetBufferSize(MainMenu(0).Count() + 2, MainMenu.Count() + MenuItems.Count + 2) | |
DrawArray(MainMenu, True) | |
For i As Integer = 0 To MenuItems.Count - 1 | |
Console.Write("│ {0} │ {1}", i + 1, MenuItems(i)) | |
For j = 0 To 12 - MenuItems(i).Count | |
Console.Write(" ") | |
Next | |
Console.WriteLine("│") | |
Next | |
Console.WriteLine("└───┴──────────────┘") | |
SelectMenu(MenuItems) | |
End Sub | |
Sub SelectMenu(ByVal MenuItems() As String) | |
Dim Screens As New ScreensClass | |
Dim Selection As Integer = 0 | |
While (Selection > MenuItems.Count Or Selection <= 0) | |
Selection = Val(Console.ReadKey(True).KeyChar()) | |
End While | |
CallByName(Screens, MenuItems(Selection - 1), CallType.Method) | |
End Sub | |
Public Class ScreensClass | |
Sub Play() | |
Playing = True | |
Dim GameUI() As String = { | |
"┌───────────────────────────────────────────────────┐", | |
"│ Type 'exit' to stop playing, or 'back' to go back │", | |
"├───────────────────────────────────────────────────┘", | |
"│ Question: {0} (base {1}) {2} {3} (base {4})", | |
"│ Answer: (base {1}) " | |
} | |
While (Playing) | |
Console.SetWindowSize(GameUI(0).Count() + 2, GameUI.Count() + 3) | |
Console.SetBufferSize(GameUI(0).Count() + 2, GameUI.Count() + 3) | |
fmt1 = RandomFormat() | |
fmt2 = RandomFormat() | |
fmt3 = RandomFormat() | |
str1 = GetNumberOfFormat(fmt1) | |
str2 = GetNumberOfFormat(fmt2) | |
oprs = {"+", "-", "*", "/"} | |
opr = oprs(rnd.Next(0, oprs.Count)) | |
answer = GetAnswer(str1, fmt1, opr, str2, fmt2, fmt3) | |
Console.Clear() | |
DrawArray(GameUI, False, str1, fmt1, opr, str2, fmt2, fmt3) | |
Console.WriteLine(str1 & fmt1 & opr & str2 & fmt2 & fmt3) | |
Dim guess As String = Console.ReadLine() | |
If guess = "exit" Or guess = "q" Then | |
Playing = False | |
Display = False | |
ElseIf guess = "back" | |
Playing = False | |
ElseIf answer.ToUpper().Equals(guess.ToUpper()) Then | |
Console.WriteLine("Correct!") | |
Console.ReadKey(True) | |
Else | |
Console.WriteLine("Incorrect, the answer was " + answer) | |
Console.ReadKey(True) | |
End If | |
End While | |
End Sub | |
Sub Options() | |
Console.WriteLine("THERE ARE NO OPTIONS") | |
Console.ReadKey(True) | |
Console.Clear() | |
End Sub | |
Sub Leaderboards() | |
Console.WriteLine("NOBODY PLAYS THIS GAME") | |
Console.ReadKey(True) | |
Console.Clear() | |
End Sub | |
Sub Quit() | |
Playing = False | |
Display = False | |
End Sub | |
End Class | |
Function GetNumberOfFormat(ByVal format As Integer) As String | |
Dim num As Int32 = rnd.Next(255) | |
Select Case format | |
Case 10 'Dec | |
Return num.ToString() | |
Case 16 'Hex | |
Return Convert.ToString(num, 16).PadLeft(2, "0"c).ToUpper() | |
Case 2 'Bin | |
Return Convert.ToString(num, 2).PadLeft(8, "0"c).ToUpper() | |
End Select | |
End Function | |
Function RandomFormat() As Int32 | |
Dim bases() As Integer = {2, 10, 16} | |
Dim num As Int32 = rnd.Next(bases.count()) | |
Return bases(num) | |
End Function | |
Function GetAnswer(ByVal str1 As String, ByVal fmt1 As Int32, ByVal opr As String, ByVal str2 As String, ByVal fmt2 As Int32, ByVal fmt3 As Int32) | |
Dim num1 As Int32 = Convert.ToInt32(str1, fmt1) | |
Dim num2 As Int32 = Convert.ToInt32(str2, fmt2) | |
Select Case opr | |
Case "+" | |
Return Convert.ToString(CInt(num1 + num2), fmt3) | |
Case "-" | |
Return Convert.ToString(CInt(num1 - num2), fmt3) | |
Case "*" | |
Return Convert.ToString(CInt(num1 * num2), fmt3) | |
Case "/" | |
Return Convert.ToString(CInt(num1 / num2), fmt3) | |
End Select | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment