今天做了 井字遊戲

需要 都不用

程式碼如下

Public Class Form1
Dim Turn As Integer = 1
Dim w, h As Integer

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
w = Me.ClientSize.Width \ 3
h = Me.ClientSize.Height \ 3
Dim g As Graphics = Me.CreateGraphics
g.DrawLine(Pens.Gray, 0, h, w * 3, h)
g.DrawLine(Pens.Gray, 0, h * 2, w * 3, h * 2)
g.DrawLine(Pens.Gray, w, 0, w, h * 3)
g.DrawLine(Pens.Gray, w * 2, 0, w * 2, h * 3)
g.Dispose()
End Sub

Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Dim g As Graphics = Me.CreateGraphics
Dim x1, y1 As Integer
If e.X < w Then 'e.X取得滑鼠的X座標
x1 = 0
ElseIf e.X < w * 2 Then
x1 = w
Else
x1 = w * 2
End If
If e.Y < h Then 'e.Y取得滑鼠的Y座標
y1 = 0
ElseIf e.Y < h * 2 Then
y1 = h
Else
y1 = h * 2
End If
If Turn = 1 Then
g.DrawEllipse(Pens.Blue, x1, y1, w, h) '畫圓
Turn = 2
Else
g.DrawLine(Pens.Red, x1, y1, x1 + w, y1 + h) '畫左上到右下的線
g.DrawLine(Pens.Red, x1 + w, y1, x1, y1 + h) '畫右上到左下的線
Turn = 1
End If
End Sub
End Class


其他可自行更改 與修正

完成後 如下圖

arrow
arrow
    全站熱搜

    ip612256374 發表在 痞客邦 留言(1) 人氣()