Discussion:
hide user input in vb
(too old to reply)
l***@gmail.com
2018-06-07 20:53:05 UTC
Permalink
i'm new to visual basic and i want to make a 2 player game where player1 inputs a number and player2 has to guess it

i'm having trouble in finding ways to hide user inputs so that player2 has to actually guess the number

here's my code so far:
Module Module1

Sub Main()
Dim guess As Integer = 0
Dim N2guess As Integer = 0
Dim attempts As Integer = 0
Dim P1 As String = "P1"
Dim P2 As String = "P2"

Console.WriteLine("P1, please enter a number between 1-10 ")
N2guess = Console.ReadLine()
While N2guess < 1 Or N2guess > 10
Console.WriteLine("INVALID OPTION")
Console.WriteLine("please try again")
N2guess = Console.ReadLine()
End While


While guess <> N2guess And attempts < 5
Console.WriteLine("P2 have a guess")
guess = Console.ReadLine()
attempts = attempts + 1
End While

If guess = N2guess Then
Console.WriteLine("P2 WINS!")
Else
Console.WriteLine("P1 WINS!")
End If
Console.ReadLine()
End Sub

End Module
Evertjan.
2018-06-07 21:07:58 UTC
Permalink
Post by l***@gmail.com
i'm new to visual basic and i want to make a 2 player game where player1
inputs a number and player2 has to guess it
This NG is about the scriptig language VBS, NOT about VB.
Post by l***@gmail.com
i'm having trouble in finding ways to hide user inputs so that player2
has to actually guess the number
Module Module1
Sub Main()
Dim guess As Integer = 0
Dim N2guess As Integer = 0
Dim attempts As Integer = 0
Dim P1 As String = "P1"
Dim P2 As String = "P2"
Console.WriteLine("P1, please enter a number between 1-10 ")
N2guess = Console.ReadLine()
While N2guess < 1 Or N2guess > 10
Console.WriteLine("INVALID OPTION")
Console.WriteLine("please try again")
N2guess = Console.ReadLine()
End While
While guess <> N2guess And attempts < 5
Console.WriteLine("P2 have a guess")
guess = Console.ReadLine()
attempts = attempts + 1
End While
If guess = N2guess Then
Console.WriteLine("P2 WINS!")
Else
Console.WriteLine("P1 WINS!")
End If
Console.ReadLine()
End Sub
End Module
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mayayana
2018-06-07 21:52:16 UTC
Permalink
<***@gmail.com> wrote

| i'm new to visual basic and i want to make a 2 player game where player1
inputs a number and player2 has to guess it
|
| i'm having trouble in finding ways to hide user inputs so that player2 has
to actually guess the number
|

There could be different options. A password
input. Or maybe a custom design. For instance,
#1 enters "21" and clicks a button, which then
puts "21" into texbox 2. But textbox 2
is red background with red forecolor. If #2
guesses the number then textbox 2 background
turns white to show the matching number in red.

.... Just an idea. You could use asll sorts of methods.

As Evertjian said, this group is for VBS. VBScript
is similar to VB, but it's text-based code with no
data types. Everything is a variant. VBS is very
similar to the most primitive version of VB.

VB refers to VB5 or 6. This is pretty much
the last active group:

microsoft.public.vb.general.discussion

Then there's also VB.Net. Some people who
don't know about VB call VB.Net VB. So it can
get confusing. VB.Net is very different from
both VB and VBS. VB is to VB.Net sort of like
C++ is to Java. VB is used to write compiled
software that uses ActiveX controls, COM,
and the Win32 API. VB.Net mainly uses the
.Net runtime, similar to Java, and creates
"assemblies" that run JIT-compiled.

If you're using VB.Net thre are also newsgroups
for that, but I don't remember what they are offhand.
Do a search of group names for "dotnet".

If those are no longer busy then another
option would be to join the Microsoft Web forums.
Unfortunately, those are web-based, so the
format is very inefficient. Also, you have to
join and the groups are moderated by Microsofties.
The result is more a marketing venue than a
discussion.
JJ
2018-06-08 06:06:51 UTC
Permalink
Post by l***@gmail.com
i'm new to visual basic and i want to make a 2 player game where player1
inputs a number and player2 has to guess it
i'm having trouble in finding ways to hide user inputs so that player2
has to actually guess the number
[snip]

For a VB application, IMO, the easiest way is to move the console cursor up
one line where the previous user inputted number is shown, then outputs
space characters to overwrite the number characters.

I don't know if VBA runtime library has a built in function that modifies
the console cursor, not not. If it doesn't, then you'll need to call the
Windows' Console API functions directly.
R.Wieser
2018-06-08 08:20:33 UTC
Permalink
lysaali,
Post by l***@gmail.com
i'm having trouble in finding ways to hide user inputs so that player2 has
to actually guess the number
You could print a number of blank lines (in a "for" loop) after player #1
has input the number, so it will be pushed down and off the screen.

... that is, if "Console.Clear" doesn't work for you (I have no idea which
version of Visual Basic you're running. The beforementioned "Clear" seems
to work for the .NET version)

Regards,
Rudy Wieser
R.Wieser
2018-06-08 19:49:58 UTC
Permalink
Post by R.Wieser
so it will be pushed down and off the screen.
Up! Pushed *up* and off the the screen ofcourse.

Regards,
Rudy Wieser

Loading...