Vb visual basic控制台模式闪烁太多。有什么方法可以阻止它吗?

时间:2014-12-11 12:15:36

标签: vb.net visual-studio-2008

我已经编程了半年多了,很抱歉这段代码有多糟糕。但是我在2008年以vb控制台模式制作乒乓球。我正在为我的第6种形式做项目,为什么它在2008年。但是当球沿着它移动时,我导致整个事情闪烁。我正在使用带有自动收报机的2D阵列来移动球。代码很长,并且在不同的类中,所以我会把我认为导致问题的位置。最后一个下面有很多潜艇,只是向下和向上移动桨

Module Module1
Public arrfield(79, 11), readkey, secounds, key, score1, score2 As String
Public milliSecond As Integer = 0
Public secound As Integer = 0
Private Tick As New Timers.Timer(1)
Public h As Integer = 39
Public g As Integer = 6
<MTAThread()> _
Sub Main()
    AddHandler Tick.Elapsed, AddressOf ticker
    score1 = 0
    score2 = 0
    Console.WriteLine("Hello and welcome to Russell's pong program!")
    Console.WriteLine("This is a two player game, one person on WSAD and the other person on the arrow keys")
    Console.WriteLine("Press ENTER to start")
    Console.ReadLine()
    fireldsetup()
    field()
    ball1()
    win_lose()
    Paddle1_middle_Paddle2_middle()
End Sub
<MTAThread()> _
Sub ball1()
    Dim run As New ballphysics()
    Dim ballphysics As New Thread(AddressOf run.ball)
    ballphysics.Name = "ballphysics"
    ballphysics.IsBackground = True
    ballphysics.Start()
End Sub
<MTAThread()> _
Sub win_lose()
    Dim run As New win_lose()
    Dim win_lose As New Thread(AddressOf run.win)
    win_lose.Name = "win_lose"
    win_lose.IsBackground = True
    win_lose.Start()
End Sub
Sub fireldsetup()
    For i = 0 To 79
        For j = 0 To 11
            arrfield(i, j) = " "
        Next
    Next
    For i = 0 To 79
        arrfield(i, 1) = "_"
    Next
    For i = 0 To 79
        arrfield(i, 11) = "_"
    Next
    Tick.Enabled = True
End Sub
Sub field()
    Console.Clear()
    Console.WriteLine()
    Console.WriteLine("  " & "Player1" & "                                                             " & "Player2")
    Console.ForegroundColor = ConsoleColor.Green
    Console.WriteLine("  " & score1 & "                               !PONG!                                    " & score2)
    Console.ForegroundColor = ConsoleColor.White
    Console.WriteLine()
    Console.WriteLine()
    For i = 0 To 79
        Console.Write(arrfield(i, 1))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 2))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 3))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 4))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 5))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 6))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 7))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 8))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 9))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 10))
    Next
    For i = 0 To 79
        Console.Write(arrfield(i, 11))
    Next
End Sub
Private Sub LookForKeyPress()
    Dim k As ConsoleKeyInfo = Console.ReadKey()
    readkey = k.Key.ToString
End Sub
Sub ticker()
    milliSecond += 1
    secound = milliSecond
End Sub
Sub Paddle1_middle_Paddle2_middle()
    fireldsetup()
    arrfield(2, 7) = "│"
    arrfield(2, 6) = "│"
    arrfield(2, 5) = "│"
    arrfield(76, 7) = "│"
    arrfield(76, 6) = "│"
    arrfield(76, 5) = "│"
    field()
    LookForKeyPress()
    If readkey = "S" Then
        readkey = ""
        Paddle1_up1_Paddle2_middle()
    ElseIf readkey = "W" Then
        readkey = ""
        Paddle1_down1_Paddle2_middle()
    ElseIf readkey = "DownArrow" Then
        readkey = ""
        Paddle1_middle_Paddle2_up1()
    ElseIf readkey = "UpArrow" Then
        readkey = ""
        Paddle1_middle_Paddle2_down1()
    Else
        Paddle1_middle_Paddle2_middle()
    End If
End Sub

2 个答案:

答案 0 :(得分:0)

不确定它是否有帮助,而不是从代码中在控制台上编写所有内容,您应该考虑组装字符串并仅使用console.writeline一次。

Dim yourStringBuilder As New StringBuilder

yourstringBuilder.Append("yourContent")

Console.WriteLine(yourStringBuilder.ToString())

答案 1 :(得分:0)

不要使用导致闪烁的Console.Clear()。使用Console.SetCursorPosition(0, 0)将光标放回角落并覆盖文本。

当您拨打清除时,用户可以看到正在清除的屏幕。我建议你在写scrore2之后放几个空格,因为新分数比旧分数小。