HOME

HOME

Game with computer dice 25 in (console application)vb.net

Code

 Imports System

Public Class game

    Dim a, b, computer, user, choose, d As Integer

    Dim r As Random = New Random

    Public Sub rule()

        computer = 0

        user = 0

        Console.WriteLine("Welcome User!" & vbCrLf & " let's play a round of game")

        Console.WriteLine("#Rules ( Read Carefully)" & vbCrLf & "1.  only computer and you can play ")

        Console.WriteLine("2.One who reachs first to a total of 25 will win " & vbCrLf & "3. press 1 to roll dice ")

        Console.WriteLine(vbCrLf & vbCrLf & "         SCORE")

        Console.WriteLine(" computer " & "      user")

        Console.WriteLine("     " & computer & "           " & user)

    End Sub

    Public Sub toss()

        b = r.Next(1, 3)

        Console.WriteLine("so let's start with toss")

        Console.WriteLine("press 1 for head or 2 for tail")

start:

        choose = Console.ReadLine

        If (choose = 1 Or choose = 2) Then

            If (choose = b) Then

                Console.WriteLine("congratulation! you won toss," & vbCrLf & "enter 1 to roll dice ")

                d = Console.ReadLine()

            ElseIf (choose <> b) Then

                Console.WriteLine("Bad luck! you lost, press any key to start")

                Console.ReadKey()

            End If

        Else

            Console.WriteLine("Invalid Value,enter again")

            GoTo start

        End If

    End Sub

    Public Sub dic()

        computer = 0

        user = 0

        Do Until (computer >= 25 Or user >= 25)

star:

            a = r.Next(1, 7)

            If (d = 0) Then

                computer = computer + a

                Console.WriteLine(" and computer gets " & a)

                GoTo ready

            ElseIf (d = 1) Then

                user = user + a

                Console.WriteLine("you gets " & a)

                d = 0

                GoTo star

            Else

                Console.WriteLine("invalid value,enter again")

                d = Console.ReadLine

                GoTo star

            End If

ready:

            Console.WriteLine(vbCrLf & vbCrLf & "         SCORE")

            Console.WriteLine(" computer " & "      user")

            Console.WriteLine("     " & computer & "           " & user)

            If (computer >= 25 Or user >= 25) Then

                Exit Do

            End If

            Console.WriteLine("enter 1 to roll dice")

            d = Console.ReadLine

            Console.WriteLine(" ")

        Loop

    End Sub

    Public Sub result()

        If computer >= 25 Then

            Console.WriteLine("computer wins")

        Else

            Console.WriteLine("user wins")

        End If

    End Sub

End Class

Module Program

    Sub Main(args As String())

        Dim g As New game

        g.rule()

        g.toss()

        g.dic()

        g.result()

        Console.ReadKey()

    End Sub

End Module

output






No comments:

Post a Comment