Votre bannière pub ici? contactez nous
Notes
 

Sujet : [VB.NET] Visual Basic for Applications: Pong Source Code

Affiche les résultats de 1 à 1 sur 1
  1. [VB.NET] Visual Basic for Applications: Pong Source Code 
    #1
    Administrateur Avatar de chahin
    Inscrit
    novembre 2011
    Messages
    748
    Remerciements
    58
    Remercié(e) 29 fois dans 29 messages
    Dim x, y, dx, dy As Integer
    Dim dPaddle, paddleY As Integer
    Dim maxX, maxY As Integer
    Dim done As Boolean
    Dim mouseLocation As POINTAPI
    Dim screenResY, screenResX As Integer
    Dim score As Integer

    Type POINTAPI ' Declare types
    x As Long
    y As Long
    End Type

    Type RECTANGLE
    x1 As Long
    y1 As Long
    x2 As Long
    y2 As Long
    End Type

    Private Declare Sub SleepKernel Lib "kernel32" Alias "Sleep" ( _
    ByVal dwMilliseconds As Long)

    Declare Function GetDesktopWindow Lib "User32" () As Long

    Declare Function GetWindowRect Lib "User32" (ByVal hWindow As Long, R As RECTANGLE) As Long

    Declare Function GetCursorPosUser Lib "User32" Alias "GetCursorPos" _
    (lpPoint As POINTAPI) As Long

    Sub determineScreenResolution()
    Dim R As RECTANGLE
    Dim hWindow As Long
    Dim RC As Long
    Dim WindowResolution As String
    hWindow = GetDesktopWindow()
    RC = GetWindowRect(hWindow, R)
    WindowResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
    screenResY = R.y2 - R.y1
    screenResX = R.x2 - R.x1
    'Cells(1, 3).Select
    'ActiveCell.Value = screenResY
    End Sub


    Sub init()
    x = 2
    y = 2
    dx = 1
    dy = 1
    maxX = 26
    maxY = 26
    Cells(y, x).Select
    Selection.Interior.ColorIndex = 3
    paddleY = 10
    dPaddle = 0
    determineScreenResolution
    clearField
    done = False
    score = 0
    updateScore
    drawPaddleFirst
    End Sub

    Sub drawPaddleFirst()
    For ctr = 0 To 5
    Cells(paddleY + ctr, 1).Select
    Selection.Interior.ColorIndex = 1
    Next ctr
    End Sub

    Sub ballmove()
    If Abs(dx) < 0.5 Then 'Ball is moving too slowly
    dx = dx * 2
    End If
    If Abs(dy) < 0.5 Then 'Ball is moving too slowly
    dy = dy * 5
    End If
    Cells(y, x).Select
    Selection.Interior.ColorIndex = 0
    x = x + dx
    y = y + dy
    If (x >= maxX) Then
    x = maxX - 1
    dx = -1.2 * dx * Rnd
    ElseIf x <= 2 Then
    x = 2
    dx = -1.2 * dx * Rnd
    End If
    If y >= maxY Then
    y = maxY
    dy = CInt(-1.2 * Rnd) - 1
    ElseIf y <= 1 Then
    y = 1
    dy = CInt(1.2 * Rnd) + 1
    End If
    Cells(y, x).Select
    Selection.Interior.ColorIndex = 3
    If x <= 2 Then 'Check whether the paddle is in position for scoring
    If y >= paddleY And y <= paddleY + 5 Then
    score = score + 1
    Else
    score = score - 1
    End If
    updateScore
    End If
    SleepKernel 50
    End Sub

    Sub movepaddle()
    m = getMouseY
    If m < (screenResY / 3) Then
    dPaddle = -1
    ElseIf m > (2 * screenResY / 3) Then
    dPaddle = 1
    Else
    dPaddle = 0
    End If
    If (dPaddle > 0 And paddleY >= maxY - 5) Or (dPaddle < 0 And paddleY <= 1) Or (dPaddle = 0) Then

    Else
    For ctr = 0 To 5
    Cells(paddleY + ctr, 1).Select
    Selection.Interior.ColorIndex = 0
    Next ctr
    paddleY = paddleY + dPaddle
    For ctr = 0 To 5
    Cells(paddleY + ctr, 1).Select
    Selection.Interior.ColorIndex = 1
    Next ctr
    End If
    End Sub


    Sub goPong() 'This is the program entry point
    init
    While Not done
    ballmove
    movepaddle
    checkDoneness
    Wend
    stopPong
    End Sub
    Sub stopPong()
    clearField
    Cells(28, 28).Select
    End Sub

    Sub checkDoneness()
    If getMouseX > (7 * screenResX / 8) Then
    done = True
    End If
    End Sub
    Sub clearField()
    Range("A1", "Z26").Interior.ColorIndex = 0
    End Sub

    Function getMouseY() As Integer
    GetCursorPosUser mouseLocation
    getMouseY = mouseLocation.y
    End Function


    Function getMouseX() As Integer
    GetCursorPosUser mouseLocation
    getMouseX = mouseLocation.x
    End Function

    Sub updateScore()
    Cells(29, 1) = score
    End Sub
     
     

  2. # ADS
    Pub
    Circuit publicitaire
    Inscrit
    Toujours
    Messages
    Plusieurs

    Rappel: N'oubliez pas de remercier les uploaders pour leur travail. Merci à vous

     

Règles des messages
  • Vous ne pouvez pas créer de sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas importer de fichiers joints
  • Vous ne pouvez pas modifier vos messages
  •