منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : الحلقة صفر من السلسلة 167 للبرمجة
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
كاتب الموضوع : FlyToAbd

نشرت هذه الحلقة بعد الحلقة الاولى في محاولة لتبسيط البداية للسلسلة

البرنامج عبارة عن لعبة بسيطة قابلة للتطوير

اضف زر باسم BtnBall وزر اخر باسم btnStand ومؤقت باسم Timer1 والصق الكود التالي في نموذج في مشروع جديد وشغل البرنامج

انتبه لحركة الكرة وحدود اصطدامها وصدها بالمضرب ثم اتركها بدون المضرب ستعيد اللعبة من جديد

ارجو من الزملاء اذا الكود يحتاج لشرح ان يبينوا ذلك وانا مستعد

كما وارجو التعليق والرد اذا يوجد من يتابع معي


كود :
Public Class Form1
' Insert Button with name: BtnBall
' Insert Button with name: btnStand
' Insert Timer with name: Timer1

Private Grid As Integer = 20
Private GameSize As New Size(24, 20)
Private StandWidth As Integer = 4

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Height = 1.2 * GameSize.Height * Grid
Me.Width = GameSize.Width * Grid

With btnStand
.Text = ""
.Height = Grid
.Width = StandWidth * Grid
.Top = GameSize.Height * Grid
.Left = Grid * (GameSize.Width / 2 - StandWidth / 2)
End With
With btnBall
.Text = ""
.Height = Grid
.Width = Grid
.Top = 10 * Grid
.Left = 5 * Grid
End With
With Timer1
.Interval = 200
.Enabled = True
End With
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
btnStand.Left = e.X - btnStand.Width / 2
End Sub

Private BallDirection As New Point(-1, -1)

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
With btnBall
.Left += BallDirection.X * Grid / 2
.Top += BallDirection.Y * Grid / 2

If .Left + Grid / 2 <= 0 Then BallDirection.X *= -1
If .Left + .Width + Grid / 2 >= Me.Width Then BallDirection.X *= -1

If .Top <= 0 Then BallDirection.Y *= -1
If .Top + .Height >= (GameSize.Height * Grid) Then
If .Left > btnStand.Left And (.Left + .Width) < (btnStand.Left + btnStand.Width) Then
BallDirection.Y *= -1
ElseIf .Top > Me.Height Then
.Left = GameSize.Width / 2 * Grid
.Top = 0
BallDirection = New Point(1, 1)
End If
End If
End With
End Sub
End Class
مع تحياتي
عبدالله العبيدي