popovIliya

guess the number-VB

Feb 24th, 2022 (edited)
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.76 KB | None | 0 0
  1. 'Игра познай числото; 23.02.2022 автор Илия Попов
  2. Option Explicit On
  3. Option Strict On
  4. Imports System
  5. Module Program
  6.  
  7.     Function inputNumber() As Integer
  8.         Dim n As Integer
  9.         Console.Write("Въведете число в диапазона 1-20:")
  10.         If Integer.TryParse(Console.ReadLine(), n) Then
  11.             Return n
  12.         Else
  13.             Return 0
  14.         End If
  15.     End Function
  16.     Function rndNumber() As Integer
  17.         Randomize()
  18.         Return CInt(Int(19 * Rnd()) + 1)
  19.     End Function
  20.  
  21.     Sub banner()
  22.         Console.WriteLine("Игра познай числото")
  23.     End Sub
  24.  
  25.     Function result(ByRef cpValue As Integer, ByRef plValue As Integer) As String
  26.         Dim value As String
  27.  
  28.         Select Case plValue
  29.             Case Is < cpValue
  30.                 value = "Бонус: Числото е по-голямо!"
  31.             Case Is > cpValue
  32.                 value = "Бонус: Числото е по-малко!"
  33.             Case Is = cpValue
  34.                 Console.Clear()
  35.                 value = "Познахте числото!"
  36.             Case Else
  37.                 value = "Не познахте числото!"
  38.         End Select
  39.  
  40.  
  41.         Return value
  42.     End Function
  43.     Sub move()
  44.         Dim a, b As Integer
  45.         a = rndNumber()
  46.         Do
  47.             b = inputNumber()
  48.             Console.WriteLine(result(a, b))
  49.         Loop Until a = b
  50.  
  51.     End Sub
  52.     Sub gameOver()
  53.         Console.WriteLine("Спечелихте играта свърши!")
  54.     End Sub
  55.  
  56.     Sub appRun()
  57.         banner()
  58.         move()
  59.         gameOver()
  60.     End Sub
  61.     Sub Main(args As String())
  62.         appRun()
  63.         Console.ReadKey()
  64.     End Sub
  65.  
  66. End Module
  67.  
Advertisement
Add Comment
Please, Sign In to add comment