欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vb.net编写的吃蘑菇小游戏(贪吃蛇)

程序员文章站 2024-03-18 12:34:28
...

 毛毛虫的类:

Imports System.Drawing
Public Class ClassMMcong
    Private mTouPoint As Point '毛毛虫头位置坐标
    Private mFangxiang As Integer '毛毛虫头的方向,角度值,逆时针赋值
    Public mmcShenti() As Point '毛毛虫身体的位置
    Public mmcShentiFX() As Integer '毛毛虫身体的方向,角度值,逆时针赋值
    Public isComputer As Boolean = True  '是否电脑
    Public isAlive As Boolean = True '是否存活
    Private mChangdu As Integer = mLen '毛毛虫的长度
    Public JiBenDanYuan As Integer = dw '基本单元格大小
    Public Sub New(ByVal starPoint As Point, ByVal starFangxiang As Integer, ByVal isComputerControl As Boolean)
        isComputer = isComputerControl
        mmcTouPoint = starPoint
        mmcTouFX = (360 + starFangxiang) Mod 360
        isAlive = True
        JiBenDanYuan = dw
        mmcchangdu = mChangdu
        ReDim mmcShenti(mmcchangdu - 1)
        ReDim mmcShentiFX(mmcchangdu - 1)
        mmcShentiFX(0) = mmcTouFX
        mmcShenti(0) = mynextPoint(starPoint, mmcTouFX, False)
        For i As Integer = 1 To mmcchangdu - 1
            mmcShentiFX(i) = mmcShentiFX(i - 1)
            mmcShenti(i) = mynextPoint(mmcShenti(i - 1), mmcShentiFX(i - 1), False)
        Next
    End Sub
    Public Property mmcchangdu() As Integer
        Set(ByVal value As Integer)
            If value < 4 Then value = 4
            mChangdu = value
        End Set
        Get
            Return mChangdu
        End Get
    End Property
    Public Property mmcTouPoint() As Point
        Get
            Return mTouPoint
        End Get
        Set(ByVal value As Point)
            mTouPoint = value
        End Set
    End Property
    Public Property mmcTouFX() As Integer
        Get
            Return mFangxiang
        End Get
        Set(ByVal value As Integer)
            mFangxiang = (value + 360) Mod 360
        End Set
    End Property
End Class

 蘑菇的类:

Public Class ClassMogu
    Public mgpointList As New List(Of Point) '存储蘑菇的位置坐标
    Public mgIsShowList As New List(Of Boolean) '存储蘑菇是否显示的列表,True为显示,False为不显示
    Public mgIsGoodList As New List(Of Boolean) '存储蘑菇好坏的列表,True为好,False为坏
    Public Sub New(ByVal mapWidth As Integer, ByVal mapHeight As Integer)
        If Not IsNothing(mgpointList) Then mgpointList.Clear()
        If Not IsNothing(mgIsShowList) Then mgIsShowList.Clear()
        If Not IsNothing(mgIsGoodList) Then mgIsGoodList.Clear()
        For i As Integer = 0 To numofMG - 1
            Randomize()
            mgpointList.Add(New Point(Int(Rnd() * (mapWidth - 4 * dw) + 2 * dw), Int(Rnd() * (mapHeight - 4 * dw) + 2 * dw)))
            mgIsShowList.Add(True)
            mgIsGoodList.Add(True)
        Next
        Randomize()
        For j As Integer = 1 To Int(0.15 * numofMG) '15%坏蘑菇
            mgIsGoodList.Item(Int(Rnd() * numofMG)) = False
        Next
    End Sub
End Class

游戏主模块:

Imports System.Drawing
Imports System.Threading
Imports System.Media
Module ModuleMain
    Public Declare Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
    '播放声音wav文件
    Const SND_FILENAME As Integer = &H20000 ' 文件模式
    Const SND_ALIAS As Integer = &H10000    '注册表或WIN.INI中的系统事件的别名
    Const SND_SYNC As Integer = &H0  '同步
    Const SND_ASYNC As Integer = &H1  '异步
    Const SND_LOOP As Integer = &H8  '循环
    '-------------------------------------------------
    Public dw As Integer = 20 '毛毛虫单节大小
    Public numofMG As Integer = 40 '蘑菇的数量
    Public mLen As Integer = 4 '初始毛毛虫长度
    Public mymmc As ClassMMcong '我的毛毛虫
    Public mymogu As ClassMogu '蘑菇的类(集合)
    Public Cmmc As New List(Of ClassMMcong) 'AI控制的毛毛虫
    Public numCmmc As Integer = 7 'AI控制的毛毛虫数量
    Public gameKaiShi As Boolean = False '游戏是否开始
    Public gameWidth As Integer = 1024 '游戏区宽度
    Public gameHeight As Integer = 768 '游戏区高度
    Public myDefen As Integer = 0 '游戏得分
    Public shijianJiange As Integer = 300 '游戏刷新间隔,毫秒
    Public weitiaoJiaodu As Integer = 30 '每次按键的角度,微调,a和d
    Public datiaoJiaodu As Integer = 60 '每次按键的角度,大调,w和s
    Public mykeyA As Integer = 15 '键A偏转角度
    Public mykeyW As Integer = 30 '键W偏转角度
    Public mykeyD As Integer = 15 '键D偏转角度
    Public mykeyS As Integer = 30 '键sS偏转角度
    Public isMogugb As Boolean = False '蘑菇数量不变为False,否则为True
    Public bofangBJY As Boolean = True '播放背景音乐
    Public yinyuePath As String = My.Application.Info.DirectoryPath + "\01.wav" '背景音乐的路径
    Public Sub Newgame()
        FrmChiMoGu.Timer1.Interval = shijianJiange
        mymmc = New ClassMMcong(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)), Int(Rnd() * 360), False)
        mymogu = New ClassMogu(gameWidth, gameHeight)
        If Not IsNothing(Cmmc) Then Cmmc.Clear()
        Randomize()
        For i As Integer = 1 To numCmmc
            Cmmc.Add(New ClassMMcong(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)), Int(Rnd() * 360), True))
        Next
        gameKaiShi = True
        myDefen = 0
    End Sub
    Public Sub playBJyy()
        If bofangBJY Then
            PlaySound(yinyuePath, 0, SND_LOOP Or SND_ASYNC)
        Else
            PlaySound(0, 0, 0)
        End If
    End Sub
    Public Sub playS() '播放声音
        Dim myPlayer1 As New System.Media.SoundPlayer
        ' myPlayer1.Stream = My.Resources._01
        Try
            If bofangBJY Then
                myPlayer1.PlayLooping()
            Else
                myPlayer1.Stop()
            End If
        Catch ex As Exception
            MsgBox("error")
        End Try
    End Sub
    Public Sub mmcMove(ByRef mmc As ClassMMcong) '毛毛虫移动
        If gameKaiShi Then
            mmc.mmcTouFX = (mmc.mmcTouFX + 360) Mod 360
            mmc.JiBenDanYuan = dw
            If mmc.isComputer Then 'AI控制的毛毛虫
                If mmc.mmcTouPoint.X > 5 * dw And mmc.mmcTouPoint.X < gameWidth - 5 * dw And mmc.mmcTouPoint.Y > 5 * dw And mmc.mmcTouPoint.Y < gameHeight - 5 * dw Then
                    Randomize()
                    Dim a As Single = Rnd()
                    If a < 0.3234 Then mmc.mmcTouFX += Int(Rnd() * 20)
                    If a > 0.7765 Then mmc.mmcTouFX -= Int(Rnd() * 20)
                Else
                    If mmc.mmcTouPoint.X >= gameWidth - 2 * dw Then
                        Randomize()
                        If mmc.mmcTouFX <= 90 And mmc.mmcTouFX >= 0 Then mmc.mmcTouFX = Int(Rnd() * 70 + 90)
                        If mmc.mmcTouFX < 360 And mmc.mmcTouFX >= 270 Then mmc.mmcTouFX = Int(Rnd() * 70 + 180)
                    End If
                    If mmc.mmcTouPoint.X <= dw Then
                        Randomize()
                        If mmc.mmcTouFX <= 180 And mmc.mmcTouFX >= 90 Then mmc.mmcTouFX = Int(Rnd() * 70)
                        If mmc.mmcTouFX <= 270 And mmc.mmcTouFX > 180 Then mmc.mmcTouFX = Int(Rnd() * 70 + 270)
                    End If
                    If mmc.mmcTouPoint.Y >= gameHeight - 2 * dw Then
                        Randomize()
                        If mmc.mmcTouFX <= 360 And mmc.mmcTouFX >= 270 Then mmc.mmcTouFX = Int(Rnd() * 70)
                        If mmc.mmcTouFX <= 270 And mmc.mmcTouFX >= 180 Then mmc.mmcTouFX = Int(Rnd() * 70 + 90)
                    End If
                    If mmc.mmcTouPoint.Y <= dw Then
                        Randomize()
                        If mmc.mmcTouFX < 90 And mmc.mmcTouFX >= 0 Then mmc.mmcTouFX = Int(Rnd() * 70 + 270)
                        If mmc.mmcTouFX <= 180 And mmc.mmcTouFX > 90 Then mmc.mmcTouFX = Int(Rnd() * 70 + 180)
                    End If
                End If
            Else '玩家控制的毛毛虫
            End If
            mmc.mmcTouFX = (mmc.mmcTouFX + 360) Mod 360
            Dim stp As Point = mmc.mmcTouPoint
            Dim stfx As Integer = mmc.mmcTouFX
            mmc.mmcTouPoint = mynextPoint(mmc.mmcTouPoint, mmc.mmcTouFX, True)
            For i As Integer = mmc.mmcchangdu - 1 To 1 Step -1
                mmc.mmcShentiFX(i) = mmc.mmcShentiFX(i - 1)
                mmc.mmcShenti(i) = mmc.mmcShenti(i - 1)
            Next
            mmc.mmcShenti(0) = stp
            mmc.mmcShentiFX(0) = stfx
            Dim p As Point = mynextPoint(mmc.mmcTouPoint, mmc.mmcTouFX, True)
            Dim pz As Integer = checkMMC(mmc.mmcTouPoint, mmc)
            '检查毛毛虫碰撞情况,0-无碰撞,100+-吃好蘑菇,200+-吃坏蘑菇,3-碰到边界,4-碰到玩家控制的毛毛虫,5-碰到AI控制的毛毛虫,6-毛毛虫已死
            Select Case pz
                Case 0
                Case 100 To 199
                    mmcChanged(mmc, True)
                    If isMogugb Then '蘑菇数量改变
                        mymogu.mgIsShowList.Item(pz - 100) = False
                    Else
                        mymogu.mgpointList.Item(pz - 100) = New Point(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)))
                        mymogu.mgIsGoodList.Item(pz - 100) = True
                        mymogu.mgIsShowList.Item(pz - 100) = True
                    End If
                    If Not mmc.isComputer Then myDefen += 100
                Case 200 To 299
                    mmcChanged(mmc, False)
                    If isMogugb Then '蘑菇数量改变
                        mymogu.mgIsShowList.Item(pz - 200) = False
                    Else
                        mymogu.mgpointList.Item(pz - 200) = New Point(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)))
                        mymogu.mgIsGoodList.Item(pz - 200) = False
                        mymogu.mgIsShowList.Item(pz - 200) = True
                    End If
                    If Not mmc.isComputer Then myDefen -= 100
                Case 3, 6
                    If mmc.isComputer Then
                        mmc = New ClassMMcong(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)), Int(Rnd() * 360), True)
                    Else
                        gameKaiShi = False
                    End If
                Case 4
                    If mmc.isComputer Then
                        myDefen += mmc.mmcchangdu * 25
                        mmc = New ClassMMcong(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)), Int(Rnd() * 360), True)
                    Else
                    End If
                Case 5
                    If mmc.isComputer Then
                    Else
                        gameKaiShi = False
                    End If
            End Select
        End If
    End Sub
    Public Sub moveofAI() '所有的毛毛虫移动
        For i As Integer = 0 To Cmmc.Count - 1
            mmcMove(Cmmc.Item(i))
        Next
        mmcMove(mymmc)
    End Sub
    Public Function RotatePic(ByVal b As Bitmap, ByVal angle As Integer) As Bitmap '按角度旋转图片(图片长宽改变)
        angle = (360 + angle) Mod 360
        '弧度转换 
        Dim radian As Double = angle * System.Math.PI / 180.0
        Dim cos As Double = System.Math.Cos(radian)
        Dim sin As Double = System.Math.Sin(radian)
        '原图的宽和高 
        Dim w__1 As Integer = b.Width
        Dim h__2 As Integer = b.Height
        Dim W__3 As Integer = CInt((System.Math.Max(System.Math.Abs(w__1 * cos - h__2 * sin), System.Math.Abs(w__1 * cos + h__2 * sin))))
        Dim H__4 As Integer = CInt((System.Math.Max(System.Math.Abs(w__1 * sin - h__2 * cos), System.Math.Abs(w__1 * sin + h__2 * cos))))
        '目标位图 
        Dim dsImage As New Bitmap(W__3, H__4)
        Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(dsImage)
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
        '计算偏移量 
        Dim Offset As New Point((W__3 - w__1) \ 2, (H__4 - h__2) \ 2)
        '构造图像显示区域:让图像的中心与窗口的中心点一致 
        Dim rect As New Rectangle(Offset.X, Offset.Y, w__1, h__2)
        Dim center As New Point(rect.X + rect.Width \ 2, rect.Y + rect.Height \ 2)
        g.TranslateTransform(center.X, center.Y)
        g.RotateTransform(360 - angle)
        '恢复图像在水平和垂直方向的平移 
        g.TranslateTransform(-center.X, -center.Y)
        g.DrawImage(b, rect)
        '重至绘图的所有变换 
        g.ResetTransform()
        'dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
        Return dsImage
        g.Dispose()
    End Function
    Public Function mynextPoint(ByVal starPoint As Point, ByVal Jiaodu As Integer, ByVal isZhengJia As Boolean) As Point '根据角度得到下一点坐标
        Dim newPoint As Point
        Jiaodu = (Jiaodu + 360) Mod 360
        Dim dx As Integer = Math.Abs(Int(Math.Cos(Jiaodu / 180 * Math.PI) * dw))
        Dim dy As Integer = Math.Abs(Int(Math.Sin(Jiaodu / 180 * Math.PI) * dw))
        If isZhengJia Then '沿角度方向增加
            If Jiaodu >= 0 And Jiaodu < 90 Then
                newPoint = New Point(starPoint.X + dx, starPoint.Y - dy)
            ElseIf Jiaodu >= 90 And Jiaodu < 180 Then
                newPoint = New Point(starPoint.X - dx, starPoint.Y - dy)
            ElseIf Jiaodu >= 180 And Jiaodu < 270 Then
                newPoint = New Point(starPoint.X - dx, starPoint.Y + dy)
            ElseIf Jiaodu >= 270 And Jiaodu < 360 Then
                newPoint = New Point(starPoint.X + dx, starPoint.Y + dy)
            End If
        Else '沿角度方向减小
            If Jiaodu >= 0 And Jiaodu < 90 Then
                newPoint = New Point(starPoint.X - dx, starPoint.Y + dy)
            ElseIf Jiaodu >= 90 And Jiaodu < 180 Then
                newPoint = New Point(starPoint.X + dx, starPoint.Y + dy)
            ElseIf Jiaodu >= 180 And Jiaodu < 270 Then
                newPoint = New Point(starPoint.X + dx, starPoint.Y - dy)
            ElseIf Jiaodu >= 270 And Jiaodu < 360 Then
                newPoint = New Point(starPoint.X - dx, starPoint.Y - dy)
            End If
        End If
        Return newPoint
    End Function
    Public Sub mmcChanged(ByRef mmc As ClassMMcong, ByVal isZhengjia As Boolean) '毛毛虫长度加或减一节
        If isZhengjia Then
            Dim p As Point = mmc.mmcTouPoint
            Dim a As Integer = mmc.mmcTouFX
            Dim uX As Integer = mmc.mmcchangdu + 1
            Dim STP(uX - 1) As Point
            Dim FX(uX - 1) As Integer
            STP(0) = p
            FX(0) = a
            For i As Integer = 1 To uX - 1
                STP(i) = mmc.mmcShenti(i - 1)
                FX(i) = mmc.mmcShentiFX(i - 1)
            Next
            mmc.mmcchangdu = uX
            mmc.mmcTouPoint = mynextPoint(p, a, True)
            mmc.mmcTouFX = a
            mmc.isAlive = mmc.isAlive
            mmc.isComputer = mmc.isComputer
            mmc.JiBenDanYuan = dw
            ReDim mmc.mmcShenti(uX - 1)
            ReDim mmc.mmcShentiFX(uX - 1)
            For j As Integer = 0 To uX - 1
                mmc.mmcShenti(j) = STP(j)
                mmc.mmcShentiFX(j) = FX(j)
            Next
        Else
            Dim p As Point = mmc.mmcTouPoint
            Dim a As Integer = mmc.mmcTouFX
            Dim uX As Integer = mmc.mmcchangdu - 1
            If uX < mLen Then
                If mmc.isComputer Then
                    mmc = New ClassMMcong(New Point(Int(Rnd() * (gameWidth - 4 * dw) + 2 * dw), Int(Rnd() * (gameHeight - 4 * dw) + 2 * dw)), Int(Rnd() * 360), True)
                Else
                    mmc.isAlive = False
                End If
            Else
                Dim STP(uX - 1) As Point
                Dim FX(uX - 1) As Integer
                STP(0) = p
                FX(0) = a
                For i As Integer = 1 To uX - 1
                    STP(i) = mmc.mmcShenti(i - 1)
                    FX(i) = mmc.mmcShentiFX(i - 1)
                Next
                mmc.mmcchangdu = uX
                mmc.mmcTouPoint = mynextPoint(p, a, True)
                mmc.mmcTouFX = a
                mmc.isAlive = mmc.isAlive
                mmc.isComputer = mmc.isComputer
                mmc.JiBenDanYuan = dw
                ReDim mmc.mmcShenti(uX - 1)
                ReDim mmc.mmcShentiFX(uX - 1)
                For j As Integer = 0 To uX - 1
                    mmc.mmcShenti(j) = STP(j)
                    mmc.mmcShentiFX(j) = FX(j)
                Next
            End If
        End If

    End Sub
    Public Sub drawMMC(ByVal e As System.Windows.Forms.PaintEventArgs) '画毛毛虫蘑菇
        If IsNothing(mymmc) Then
            Dim s As String = "请开始游戏"
            Dim f As Font = New Font("宋体", 50)
            Dim strwh As SizeF = e.Graphics.MeasureString(s, New Font("宋体", 50))
            e.Graphics.DrawString(s, New Font("宋体", 50), Brushes.Blue, New Point(Int((gameWidth - strwh.Width) / 2), Int((gameHeight - strwh.Height) / 2)))
        Else
            '画蘑菇
            For i As Integer = 0 To mymogu.mgpointList.Count - 1
                If mymogu.mgIsGoodList(i) Then
                    If mymogu.mgIsShowList(i) Then e.Graphics.DrawImage(My.Resources.mogu, mymogu.mgpointList(i).X - dw \ 2, mymogu.mgpointList(i).Y - dw \ 2, dw, dw)
                Else
                    If mymogu.mgIsShowList(i) Then e.Graphics.DrawImage(My.Resources.mogudu, mymogu.mgpointList(i).X - dw \ 2, mymogu.mgpointList(i).Y - dw \ 2, dw, dw)
                End If
            Next
            '画毛毛虫
            If mymmc.isAlive Then
                Dim bmp As Bitmap = RotatePic(My.Resources.shetou, mymmc.mmcTouFX - 90)
                Dim dxy As Integer = bmp.Width / My.Resources.shetou.Width * mymmc.JiBenDanYuan
                e.Graphics.DrawImage(RotatePic(My.Resources.shetou, mymmc.mmcTouFX - 90), mymmc.mmcTouPoint.X - dxy \ 2, mymmc.mmcTouPoint.Y - dxy \ 2, dxy, dxy)
                For i As Integer = 0 To mymmc.mmcchangdu - 2
                    Dim bmp1 As Bitmap = RotatePic(My.Resources.sheshenti, mymmc.mmcShentiFX(i) - 90)
                    Dim dxy1 As Integer = bmp1.Width / My.Resources.sheshenti.Width * mymmc.JiBenDanYuan
                    e.Graphics.DrawImage(bmp1, mymmc.mmcShenti(i).X - dxy1 \ 2, mymmc.mmcShenti(i).Y - dxy1 \ 2, dxy1, dxy1)
                Next
                Dim bmp2 As Bitmap = RotatePic(My.Resources.shewei, mymmc.mmcShentiFX(mymmc.mmcchangdu - 1) - 90)
                Dim dxy2 As Integer = bmp2.Width / My.Resources.shewei.Width * mymmc.JiBenDanYuan
                e.Graphics.DrawImage(bmp2, mymmc.mmcShenti(mymmc.mmcchangdu - 1).X - dxy2 \ 2, mymmc.mmcShenti(mymmc.mmcchangdu - 1).Y - dxy2 \ 2, dxy2, dxy2)
            End If
            '画电脑的毛毛虫
            For i As Integer = 0 To Cmmc.Count - 1
                If Cmmc.Item(i).isAlive Then
                    Dim bmp As Bitmap = RotatePic(My.Resources.shetouComputer, Cmmc.Item(i).mmcTouFX - 90)
                    Dim dxy As Integer = bmp.Width / My.Resources.shetouComputer.Width * Cmmc.Item(i).JiBenDanYuan
                    e.Graphics.DrawImage(bmp, Cmmc.Item(i).mmcTouPoint.X - dxy \ 2, Cmmc.Item(i).mmcTouPoint.Y - dxy \ 2, dxy, dxy)
                    For j As Integer = 0 To Cmmc.Item(i).mmcchangdu - 2
                        Dim bmp1 As Bitmap = RotatePic(My.Resources.sheshentiComputer, Cmmc.Item(i).mmcShentiFX(j) - 90)
                        Dim dxy1 As Integer = bmp1.Width / My.Resources.sheshentiComputer.Width * Cmmc.Item(i).JiBenDanYuan
                        e.Graphics.DrawImage(bmp1, Cmmc.Item(i).mmcShenti(j).X - dxy1 \ 2, Cmmc.Item(i).mmcShenti(j).Y - dxy1 \ 2, dxy1, dxy1)
                    Next
                    Dim bmp2 As Bitmap = RotatePic(My.Resources.sheweiComputer, Cmmc.Item(i).mmcShentiFX(Cmmc.Item(i).mmcchangdu - 1) - 90)
                    Dim dxy2 As Integer = bmp2.Width / My.Resources.sheweiComputer.Width * Cmmc.Item(i).JiBenDanYuan
                    e.Graphics.DrawImage(bmp2, Cmmc.Item(i).mmcShenti(Cmmc.Item(i).mmcchangdu - 1).X - dxy2 \ 2, Cmmc.Item(i).mmcShenti(Cmmc.Item(i).mmcchangdu - 1).Y - dxy2 \ 2, dxy2, dxy2)
                End If
            Next
            If gameKaiShi Then
            Else
                Dim s As String = "游戏已结束,得分:" + myDefen.ToString
                Dim f As Font = New Font("宋体", 30)
                Dim strwh As SizeF = e.Graphics.MeasureString(s, New Font("宋体", 30))
                e.Graphics.DrawString(s, New Font("宋体", 30), Brushes.Red, New Point(Int((gameWidth - strwh.Width) / 2), Int((gameHeight - strwh.Height) / 2)))
            End If
        End If

    End Sub
    Public Function checkMMC(ByVal newpoint As Point, ByVal mmc As ClassMMcong) As Integer
        '检查毛毛虫碰撞情况,0-无碰撞,100+-吃好蘑菇,200+-吃坏蘑菇,3-碰到边界,4-碰到玩家控制的毛毛虫,5-碰到AI控制的毛毛虫,6-毛毛虫已死
        Dim jieguo As Integer = 0
        If mmc.isAlive Then
            If newpoint.X < -dw \ 2 Or newpoint.X > gameWidth + dw \ 2 Or newpoint.Y < -dw \ 2 Or newpoint.Y > gameHeight + dw \ 2 Then
                jieguo = 3
            Else
                For i As Integer = 0 To mymogu.mgpointList.Count - 1 '检查蘑菇的坐标
                    If getJuLi(newpoint, mymogu.mgpointList.Item(i)) <= dw Then
                        If mymogu.mgIsGoodList.Item(i) Then
                            jieguo = 100 + i
                        Else
                            jieguo = 200 + i
                        End If
                    End If
                Next
                If jieguo < 100 Then
                    If mmc.isComputer Then
                        If isInMyMMC(newpoint) Then jieguo = 4
                    Else
                        If isInAIMMC(newpoint) Then jieguo = 5
                    End If
                End If
            End If
        Else
            jieguo = 6
        End If
        Return jieguo
    End Function
    Public Function getJuLi(ByVal p1 As Point, ByVal p2 As Point) As Integer '计算两点间距离
        Dim jl As Integer = dw
        jl = Math.Sqrt((p1.X - p2.X) ^ 2 + (p1.Y - p2.Y) ^ 2)
        Return jl
    End Function
    Private Function isInMyMMC(ByVal p As Point) As Boolean '计算某坐标是否属于玩家控制的毛毛虫
        Dim jieguo As Boolean = False
        If getJuLi(p, mymmc.mmcTouPoint) < dw Then
            jieguo = True
        Else
            For i As Integer = 0 To mymmc.mmcShenti.Count - 1
                If mymmc.isAlive Then
                    If getJuLi(mymmc.mmcShenti(i), p) < dw Then jieguo = True
                End If
            Next
        End If
        Return jieguo
    End Function
    Private Function isInAIMMC(ByVal p As Point) As Boolean '计算某坐标是否属于AI控制的毛毛虫
        Dim jieguo As Boolean = False
        For i As Integer = 0 To Cmmc.Count - 1
            If Cmmc.Item(i).isAlive Then
                If getJuLi(p, Cmmc.Item(i).mmcTouPoint) < dw Then
                    jieguo = True
                Else
                    For j As Integer = 0 To Cmmc.Item(i).mmcShenti.Count - 1
                        If getJuLi(p, Cmmc.Item(i).mmcShenti(j)) < dw Then jieguo = True
                    Next
                End If
            End If
        Next
        Return jieguo
    End Function
End Module

 游戏界面:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class FrmChiMoGu
    Inherits System.Windows.Forms.Form

    'Form 重写 Dispose,以清理组件列表。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改它。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(FrmChiMoGu))
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip()
        Me.游戏GToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.新游戏ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.暂停游戏ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.退出游戏ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.选项OToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.设置ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripSeparator()
        Me.有背景音乐ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.选择背景音乐ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.帮助HToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.帮助ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.关于ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.MenuStrip1.SuspendLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'MenuStrip1
        '
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.游戏GToolStripMenuItem, Me.选项OToolStripMenuItem, Me.帮助HToolStripMenuItem})
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(1025, 25)
        Me.MenuStrip1.TabIndex = 0
        Me.MenuStrip1.Text = "MenuStrip1"
        '
        '游戏GToolStripMenuItem
        '
        Me.游戏GToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.新游戏ToolStripMenuItem, Me.暂停游戏ToolStripMenuItem, Me.退出游戏ToolStripMenuItem})
        Me.游戏GToolStripMenuItem.Name = "游戏GToolStripMenuItem"
        Me.游戏GToolStripMenuItem.Size = New System.Drawing.Size(85, 21)
        Me.游戏GToolStripMenuItem.Text = "游 戏 (&G)"
        '
        '新游戏ToolStripMenuItem
        '
        Me.新游戏ToolStripMenuItem.Name = "新游戏ToolStripMenuItem"
        Me.新游戏ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F2
        Me.新游戏ToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.新游戏ToolStripMenuItem.Text = "新游戏"
        '
        '暂停游戏ToolStripMenuItem
        '
        Me.暂停游戏ToolStripMenuItem.Name = "暂停游戏ToolStripMenuItem"
        Me.暂停游戏ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F3
        Me.暂停游戏ToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.暂停游戏ToolStripMenuItem.Text = "暂停游戏"
        '
        '退出游戏ToolStripMenuItem
        '
        Me.退出游戏ToolStripMenuItem.Name = "退出游戏ToolStripMenuItem"
        Me.退出游戏ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F4
        Me.退出游戏ToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
        Me.退出游戏ToolStripMenuItem.Text = "退出游戏"
        '
        '选项OToolStripMenuItem
        '
        Me.选项OToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.设置ToolStripMenuItem, Me.ToolStripMenuItem1, Me.有背景音乐ToolStripMenuItem, Me.选择背景音乐ToolStripMenuItem})
        Me.选项OToolStripMenuItem.Name = "选项OToolStripMenuItem"
        Me.选项OToolStripMenuItem.Size = New System.Drawing.Size(82, 21)
        Me.选项OToolStripMenuItem.Text = "选 项(&O)"
        '
        '设置ToolStripMenuItem
        '
        Me.设置ToolStripMenuItem.Name = "设置ToolStripMenuItem"
        Me.设置ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5
        Me.设置ToolStripMenuItem.Size = New System.Drawing.Size(176, 22)
        Me.设置ToolStripMenuItem.Text = "设置"
        '
        'ToolStripMenuItem1
        '
        Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
        Me.ToolStripMenuItem1.Size = New System.Drawing.Size(173, 6)
        '
        '有背景音乐ToolStripMenuItem
        '
        Me.有背景音乐ToolStripMenuItem.Name = "有背景音乐ToolStripMenuItem"
        Me.有背景音乐ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F8
        Me.有背景音乐ToolStripMenuItem.Size = New System.Drawing.Size(176, 22)
        Me.有背景音乐ToolStripMenuItem.Text = "关闭背景音乐"
        '
        '选择背景音乐ToolStripMenuItem
        '
        Me.选择背景音乐ToolStripMenuItem.Name = "选择背景音乐ToolStripMenuItem"
        Me.选择背景音乐ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F10
        Me.选择背景音乐ToolStripMenuItem.Size = New System.Drawing.Size(176, 22)
        Me.选择背景音乐ToolStripMenuItem.Text = "选择背景音乐"
        '
        '帮助HToolStripMenuItem
        '
        Me.帮助HToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.帮助ToolStripMenuItem, Me.关于ToolStripMenuItem})
        Me.帮助HToolStripMenuItem.Name = "帮助HToolStripMenuItem"
        Me.帮助HToolStripMenuItem.Size = New System.Drawing.Size(81, 21)
        Me.帮助HToolStripMenuItem.Text = "帮 助(&H)"
        '
        '帮助ToolStripMenuItem
        '
        Me.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem"
        Me.帮助ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F1
        Me.帮助ToolStripMenuItem.Size = New System.Drawing.Size(155, 22)
        Me.帮助ToolStripMenuItem.Text = "帮助"
        '
        '关于ToolStripMenuItem
        '
        Me.关于ToolStripMenuItem.Name = "关于ToolStripMenuItem"
        Me.关于ToolStripMenuItem.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.H), System.Windows.Forms.Keys)
        Me.关于ToolStripMenuItem.Size = New System.Drawing.Size(155, 22)
        Me.关于ToolStripMenuItem.Text = "关于..."
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 300
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.Green
        Me.PictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.PictureBox1.Location = New System.Drawing.Point(0, 28)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(1024, 768)
        Me.PictureBox1.TabIndex = 1
        Me.PictureBox1.TabStop = False
        '
        'FrmChiMoGu
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.AutoSize = True
        Me.BackColor = System.Drawing.SystemColors.ControlDark
        Me.ClientSize = New System.Drawing.Size(1025, 797)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.MenuStrip1)
        Me.DoubleBuffered = True
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MainMenuStrip = Me.MenuStrip1
        Me.MaximizeBox = False
        Me.Name = "FrmChiMoGu"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "吃蘑菇"
        Me.MenuStrip1.ResumeLayout(False)
        Me.MenuStrip1.PerformLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents 游戏GToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 新游戏ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 暂停游戏ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 退出游戏ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 选项OToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 帮助HToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents 帮助ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 设置ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents 有背景音乐ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 选择背景音乐ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents 关于ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog

End Class

vb.net编写的吃蘑菇小游戏(贪吃蛇)

窗体的代码:

Public Class FrmChiMoGu
       Private Sub FrmChiMoGu_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        Select Case e.KeyCode
            Case Keys.A
                mymmc.mmcTouFX += mykeyA
                mymmc.mmcTouFX = mymmc.mmcTouFX Mod 360
            Case Keys.W
                mymmc.mmcTouFX += mykeyW
                mymmc.mmcTouFX = mymmc.mmcTouFX Mod 360
            Case Keys.D
                mymmc.mmcTouFX -= mykeyD
                mymmc.mmcTouFX = mymmc.mmcTouFX Mod 360
            Case Keys.S
                mymmc.mmcTouFX -= mykeyS
                mymmc.mmcTouFX = mymmc.mmcTouFX Mod 360
        End Select
    End Sub
    Private Sub 新游戏ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 新游戏ToolStripMenuItem.Click
        Newgame()
        PictureBox1.Refresh()
       
    End Sub
    Public Overridable Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
       drawMMC(e)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        PictureBox1.Refresh()
        moveofAI()
         Me.Text = "吃蘑菇  得分:" + myDefen.ToString
    End Sub
    Private Sub 暂停游戏ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 暂停游戏ToolStripMenuItem.Click
        If 暂停游戏ToolStripMenuItem.Text = "暂停游戏" Then
            暂停游戏ToolStripMenuItem.Text = "继续游戏"
            Timer1.Enabled = False
        Else
            暂停游戏ToolStripMenuItem.Text = "暂停游戏"
            Timer1.Enabled = True
        End If
    End Sub

    Private Sub 帮助ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 帮助ToolStripMenuItem.Click
        Dim s As String = ""
        s += "                            毛毛虫吃蘑菇                   " + vbCrLf + vbCrLf
        s += "    游戏中用A、W、D、S控制毛毛虫。A、W逆时针偏转,D、S" + vbCrLf
        s += "顺时针偏转,各键偏转角度不同。AI控制的毛毛虫不会出边界。" + vbCrLf
        MsgBox(s, vbInformation + vbOKOnly, "毛毛虫吃蘑菇")
       
    End Sub

    Private Sub 退出游戏ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出游戏ToolStripMenuItem.Click
        End
    End Sub
    Private Sub FrmChiMoGu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        playBJyy()

    End Sub

    Private Sub 设置ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 设置ToolStripMenuItem.Click
        Timer1.Enabled = False
        FrmXuanxiang.ShowDialog()
    End Sub

    Private Sub 关于ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关于ToolStripMenuItem.Click
        Dim s As String = ""
        s += "                            毛毛虫吃蘑菇                   " + vbCrLf + vbCrLf
        s += "    游戏中玩家控制一条毛毛虫在场景里进行移动,吃到好蘑菇或 " + vbCrLf
        s += "AI控制的毛毛虫死亡毛毛虫长度增加1节同时会获得积分。毛毛" + vbCrLf
        s += "虫出边界或碰到其它毛毛虫死亡,游戏结束并显示积分。           " + vbCrLf + vbCrLf
        s += "游戏用vb2010编写,作者保留一切权利。   2019年5月     " + vbCrLf + vbCrLf
        MsgBox(s, vbInformation + vbOKOnly, "毛毛虫吃蘑菇")
    End Sub

    Private Sub 有背景音乐ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 有背景音乐ToolStripMenuItem.Click
        If 有背景音乐ToolStripMenuItem.Text = "关闭背景音乐" Then
            bofangBJY = False
            有背景音乐ToolStripMenuItem.Text = "打开背景音乐"
            playBJyy()
        Else
            bofangBJY = True
            有背景音乐ToolStripMenuItem.Text = "关闭背景音乐"
            playBJyy()
        End If
    End Sub

    Private Sub 选择背景音乐ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 选择背景音乐ToolStripMenuItem.Click
        OpenFileDialog1.Filter = "wav音乐文件|*.wav"
        OpenFileDialog1.ShowDialog()
        If OpenFileDialog1.FileName <> "" Then
            If IO.File.Exists(OpenFileDialog1.FileName) Then
                yinyuePath = OpenFileDialog1.FileName
                playBJyy()
            End If
        End If
    End Sub
End Class

 创建游戏设置窗体的代码:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class FrmXuanxiang
    Inherits System.Windows.Forms.Form

    'Form 重写 Dispose,以清理组件列表。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改它。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.RadioButton1 = New System.Windows.Forms.RadioButton()
        Me.RadioButton2 = New System.Windows.Forms.RadioButton()
        Me.RadioButton3 = New System.Windows.Forms.RadioButton()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.CheckBox1 = New System.Windows.Forms.CheckBox()
        Me.RadioButton6 = New System.Windows.Forms.RadioButton()
        Me.RadioButton5 = New System.Windows.Forms.RadioButton()
        Me.RadioButton4 = New System.Windows.Forms.RadioButton()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.RadioButton9 = New System.Windows.Forms.RadioButton()
        Me.RadioButton8 = New System.Windows.Forms.RadioButton()
        Me.RadioButton7 = New System.Windows.Forms.RadioButton()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.NumericUpDown3 = New System.Windows.Forms.NumericUpDown()
        Me.NumericUpDown2 = New System.Windows.Forms.NumericUpDown()
        Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.GroupBox5 = New System.Windows.Forms.GroupBox()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.NumericUpDown7 = New System.Windows.Forms.NumericUpDown()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.NumericUpDown6 = New System.Windows.Forms.NumericUpDown()
        Me.NumericUpDown5 = New System.Windows.Forms.NumericUpDown()
        Me.NumericUpDown4 = New System.Windows.Forms.NumericUpDown()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        CType(Me.NumericUpDown3, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox5.SuspendLayout()
        CType(Me.NumericUpDown7, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown6, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown5, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.NumericUpDown4, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(383, 387)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(91, 39)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "确 定"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(73, 387)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(91, 39)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "取 消"
        Me.Button2.UseVisualStyleBackColor = True
        '
        'RadioButton1
        '
        Me.RadioButton1.AutoSize = True
        Me.RadioButton1.Location = New System.Drawing.Point(13, 21)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton1.TabIndex = 2
        Me.RadioButton1.Text = "小型场景    800 X 600"
        Me.RadioButton1.UseVisualStyleBackColor = True
        '
        'RadioButton2
        '
        Me.RadioButton2.AutoSize = True
        Me.RadioButton2.Checked = True
        Me.RadioButton2.Location = New System.Drawing.Point(13, 43)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton2.TabIndex = 2
        Me.RadioButton2.TabStop = True
        Me.RadioButton2.Text = "普通场景   1024 X 768"
        Me.RadioButton2.UseVisualStyleBackColor = True
        '
        'RadioButton3
        '
        Me.RadioButton3.AutoSize = True
        Me.RadioButton3.Location = New System.Drawing.Point(13, 65)
        Me.RadioButton3.Name = "RadioButton3"
        Me.RadioButton3.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton3.TabIndex = 2
        Me.RadioButton3.Text = "大型场景   1280 X 800"
        Me.RadioButton3.UseVisualStyleBackColor = True
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.RadioButton3)
        Me.GroupBox1.Controls.Add(Me.RadioButton2)
        Me.GroupBox1.Controls.Add(Me.RadioButton1)
        Me.GroupBox1.Location = New System.Drawing.Point(28, 15)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(196, 95)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "场 景"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.CheckBox1)
        Me.GroupBox2.Controls.Add(Me.RadioButton6)
        Me.GroupBox2.Controls.Add(Me.RadioButton5)
        Me.GroupBox2.Controls.Add(Me.RadioButton4)
        Me.GroupBox2.Location = New System.Drawing.Point(262, 15)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(293, 95)
        Me.GroupBox2.TabIndex = 4
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "蘑 菇"
        '
        'CheckBox1
        '
        Me.CheckBox1.AutoSize = True
        Me.CheckBox1.Location = New System.Drawing.Point(161, 61)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(108, 16)
        Me.CheckBox1.TabIndex = 1
        Me.CheckBox1.Text = "蘑菇不进行重生"
        Me.CheckBox1.UseVisualStyleBackColor = True
        '
        'RadioButton6
        '
        Me.RadioButton6.AutoSize = True
        Me.RadioButton6.Location = New System.Drawing.Point(17, 60)
        Me.RadioButton6.Name = "RadioButton6"
        Me.RadioButton6.Size = New System.Drawing.Size(125, 16)
        Me.RadioButton6.TabIndex = 0
        Me.RadioButton6.Text = "大量蘑菇数(60) "
        Me.RadioButton6.UseVisualStyleBackColor = True
        '
        'RadioButton5
        '
        Me.RadioButton5.AutoSize = True
        Me.RadioButton5.Checked = True
        Me.RadioButton5.Location = New System.Drawing.Point(161, 29)
        Me.RadioButton5.Name = "RadioButton5"
        Me.RadioButton5.Size = New System.Drawing.Size(125, 16)
        Me.RadioButton5.TabIndex = 0
        Me.RadioButton5.TabStop = True
        Me.RadioButton5.Text = "中等蘑菇数(40) "
        Me.RadioButton5.UseVisualStyleBackColor = True
        '
        'RadioButton4
        '
        Me.RadioButton4.AutoSize = True
        Me.RadioButton4.Location = New System.Drawing.Point(17, 29)
        Me.RadioButton4.Name = "RadioButton4"
        Me.RadioButton4.Size = New System.Drawing.Size(125, 16)
        Me.RadioButton4.TabIndex = 0
        Me.RadioButton4.Text = "少量蘑菇数(20) "
        Me.RadioButton4.UseVisualStyleBackColor = True
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.RadioButton9)
        Me.GroupBox3.Controls.Add(Me.RadioButton8)
        Me.GroupBox3.Controls.Add(Me.RadioButton7)
        Me.GroupBox3.Location = New System.Drawing.Point(28, 129)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(213, 124)
        Me.GroupBox3.TabIndex = 5
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "难 度"
        '
        'RadioButton9
        '
        Me.RadioButton9.AutoSize = True
        Me.RadioButton9.Location = New System.Drawing.Point(23, 93)
        Me.RadioButton9.Name = "RadioButton9"
        Me.RadioButton9.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton9.TabIndex = 0
        Me.RadioButton9.Text = "困难(每200毫秒刷新)"
        Me.RadioButton9.UseVisualStyleBackColor = True
        '
        'RadioButton8
        '
        Me.RadioButton8.AutoSize = True
        Me.RadioButton8.Checked = True
        Me.RadioButton8.Location = New System.Drawing.Point(23, 61)
        Me.RadioButton8.Name = "RadioButton8"
        Me.RadioButton8.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton8.TabIndex = 0
        Me.RadioButton8.TabStop = True
        Me.RadioButton8.Text = "中等(每300毫秒刷新)"
        Me.RadioButton8.UseVisualStyleBackColor = True
        '
        'RadioButton7
        '
        Me.RadioButton7.AutoSize = True
        Me.RadioButton7.Location = New System.Drawing.Point(23, 29)
        Me.RadioButton7.Name = "RadioButton7"
        Me.RadioButton7.Size = New System.Drawing.Size(149, 16)
        Me.RadioButton7.TabIndex = 0
        Me.RadioButton7.Text = "简单(每400毫秒刷新)"
        Me.RadioButton7.UseVisualStyleBackColor = True
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.Add(Me.NumericUpDown3)
        Me.GroupBox4.Controls.Add(Me.NumericUpDown2)
        Me.GroupBox4.Controls.Add(Me.NumericUpDown1)
        Me.GroupBox4.Controls.Add(Me.Label3)
        Me.GroupBox4.Controls.Add(Me.Label2)
        Me.GroupBox4.Controls.Add(Me.Label1)
        Me.GroupBox4.Location = New System.Drawing.Point(284, 129)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(264, 124)
        Me.GroupBox4.TabIndex = 6
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "毛毛虫"
        '
        'NumericUpDown3
        '
        Me.NumericUpDown3.Location = New System.Drawing.Point(172, 93)
        Me.NumericUpDown3.Maximum = New Decimal(New Integer() {12, 0, 0, 0})
        Me.NumericUpDown3.Minimum = New Decimal(New Integer() {5, 0, 0, 0})
        Me.NumericUpDown3.Name = "NumericUpDown3"
        Me.NumericUpDown3.Size = New System.Drawing.Size(54, 21)
        Me.NumericUpDown3.TabIndex = 2
        Me.NumericUpDown3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown3.Value = New Decimal(New Integer() {7, 0, 0, 0})
        '
        'NumericUpDown2
        '
        Me.NumericUpDown2.Increment = New Decimal(New Integer() {4, 0, 0, 0})
        Me.NumericUpDown2.Location = New System.Drawing.Point(126, 63)
        Me.NumericUpDown2.Maximum = New Decimal(New Integer() {26, 0, 0, 0})
        Me.NumericUpDown2.Minimum = New Decimal(New Integer() {14, 0, 0, 0})
        Me.NumericUpDown2.Name = "NumericUpDown2"
        Me.NumericUpDown2.Size = New System.Drawing.Size(54, 21)
        Me.NumericUpDown2.TabIndex = 2
        Me.NumericUpDown2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown2.Value = New Decimal(New Integer() {20, 0, 0, 0})
        '
        'NumericUpDown1
        '
        Me.NumericUpDown1.Location = New System.Drawing.Point(126, 28)
        Me.NumericUpDown1.Maximum = New Decimal(New Integer() {6, 0, 0, 0})
        Me.NumericUpDown1.Minimum = New Decimal(New Integer() {4, 0, 0, 0})
        Me.NumericUpDown1.Name = "NumericUpDown1"
        Me.NumericUpDown1.Size = New System.Drawing.Size(54, 21)
        Me.NumericUpDown1.TabIndex = 1
        Me.NumericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown1.Value = New Decimal(New Integer() {4, 0, 0, 0})
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(19, 97)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(137, 12)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "被AI控制的毛毛虫数量:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(19, 65)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(101, 12)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "毛毛虫单节大小:"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(21, 30)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(65, 12)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "初始长度:"
        '
        'GroupBox5
        '
        Me.GroupBox5.Controls.Add(Me.Label7)
        Me.GroupBox5.Controls.Add(Me.Label5)
        Me.GroupBox5.Controls.Add(Me.Label6)
        Me.GroupBox5.Controls.Add(Me.NumericUpDown7)
        Me.GroupBox5.Controls.Add(Me.Label4)
        Me.GroupBox5.Controls.Add(Me.NumericUpDown6)
        Me.GroupBox5.Controls.Add(Me.NumericUpDown5)
        Me.GroupBox5.Controls.Add(Me.NumericUpDown4)
        Me.GroupBox5.Location = New System.Drawing.Point(28, 266)
        Me.GroupBox5.Name = "GroupBox5"
        Me.GroupBox5.Size = New System.Drawing.Size(446, 103)
        Me.GroupBox5.TabIndex = 7
        Me.GroupBox5.TabStop = False
        Me.GroupBox5.Text = "键盘"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(230, 68)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(131, 12)
        Me.Label7.TabIndex = 0
        Me.Label7.Text = "S:顺时针转的角度——"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(230, 28)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(131, 12)
        Me.Label5.TabIndex = 0
        Me.Label5.Text = "W:逆时针转的角度——"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(21, 68)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(131, 12)
        Me.Label6.TabIndex = 0
        Me.Label6.Text = "D:顺时针转的角度——"
        '
        'NumericUpDown7
        '
        Me.NumericUpDown7.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.NumericUpDown7.Location = New System.Drawing.Point(366, 66)
        Me.NumericUpDown7.Maximum = New Decimal(New Integer() {80, 0, 0, 0})
        Me.NumericUpDown7.Minimum = New Decimal(New Integer() {10, 0, 0, 0})
        Me.NumericUpDown7.Name = "NumericUpDown7"
        Me.NumericUpDown7.Size = New System.Drawing.Size(46, 21)
        Me.NumericUpDown7.TabIndex = 1
        Me.NumericUpDown7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown7.Value = New Decimal(New Integer() {30, 0, 0, 0})
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(21, 28)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(131, 12)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "A:逆时针的转角度——"
        '
        'NumericUpDown6
        '
        Me.NumericUpDown6.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.NumericUpDown6.Location = New System.Drawing.Point(158, 66)
        Me.NumericUpDown6.Maximum = New Decimal(New Integer() {80, 0, 0, 0})
        Me.NumericUpDown6.Minimum = New Decimal(New Integer() {10, 0, 0, 0})
        Me.NumericUpDown6.Name = "NumericUpDown6"
        Me.NumericUpDown6.Size = New System.Drawing.Size(46, 21)
        Me.NumericUpDown6.TabIndex = 1
        Me.NumericUpDown6.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown6.Value = New Decimal(New Integer() {15, 0, 0, 0})
        '
        'NumericUpDown5
        '
        Me.NumericUpDown5.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.NumericUpDown5.Location = New System.Drawing.Point(366, 26)
        Me.NumericUpDown5.Maximum = New Decimal(New Integer() {80, 0, 0, 0})
        Me.NumericUpDown5.Minimum = New Decimal(New Integer() {10, 0, 0, 0})
        Me.NumericUpDown5.Name = "NumericUpDown5"
        Me.NumericUpDown5.Size = New System.Drawing.Size(46, 21)
        Me.NumericUpDown5.TabIndex = 1
        Me.NumericUpDown5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown5.Value = New Decimal(New Integer() {30, 0, 0, 0})
        '
        'NumericUpDown4
        '
        Me.NumericUpDown4.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.NumericUpDown4.Location = New System.Drawing.Point(158, 26)
        Me.NumericUpDown4.Maximum = New Decimal(New Integer() {80, 0, 0, 0})
        Me.NumericUpDown4.Minimum = New Decimal(New Integer() {10, 0, 0, 0})
        Me.NumericUpDown4.Name = "NumericUpDown4"
        Me.NumericUpDown4.Size = New System.Drawing.Size(46, 21)
        Me.NumericUpDown4.TabIndex = 1
        Me.NumericUpDown4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.NumericUpDown4.Value = New Decimal(New Integer() {15, 0, 0, 0})
        '
        'FrmXuanxiang
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(567, 438)
        Me.Controls.Add(Me.GroupBox5)
        Me.Controls.Add(Me.GroupBox4)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "FrmXuanxiang"
        Me.Opacity = 0.9R
        Me.ShowIcon = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "游戏设置"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox2.PerformLayout()
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox3.PerformLayout()
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox4.PerformLayout()
        CType(Me.NumericUpDown3, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox5.ResumeLayout(False)
        Me.GroupBox5.PerformLayout()
        CType(Me.NumericUpDown7, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown6, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown5, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown4, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents RadioButton6 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents RadioButton9 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton8 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton7 As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents NumericUpDown2 As System.Windows.Forms.NumericUpDown
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents NumericUpDown3 As System.Windows.Forms.NumericUpDown
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents GroupBox5 As System.Windows.Forms.GroupBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents NumericUpDown4 As System.Windows.Forms.NumericUpDown
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents NumericUpDown7 As System.Windows.Forms.NumericUpDown
    Friend WithEvents NumericUpDown6 As System.Windows.Forms.NumericUpDown
    Friend WithEvents NumericUpDown5 As System.Windows.Forms.NumericUpDown
End Class

 游戏设置窗体:

 vb.net编写的吃蘑菇小游戏(贪吃蛇)

 游戏设置窗体代码:

Public Class FrmXuanxiang

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '取消按钮
        Me.Hide()
        FrmChiMoGu.Timer1.Enabled = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Me.FormClosed '确定按钮
        If RadioButton1.Checked Then
            gameWidth = 800
            gameHeight = 600
        End If
        If RadioButton2.Checked Then
            gameWidth = 1024
            gameHeight = 768
        End If
        If RadioButton3.Checked Then
            gameWidth = 1280
            gameHeight = 800
        End If
        FrmChiMoGu.PictureBox1.Width = gameWidth
        FrmChiMoGu.PictureBox1.Height = gameHeight
        FrmChiMoGu.Width = gameWidth + 7
        FrmChiMoGu.Height = gameHeight + 57
        If RadioButton4.Checked Then
            numofMG = 20
        End If
        If RadioButton5.Checked Then
            numofMG = 40
        End If
        If RadioButton6.Checked Then
            numofMG = 60
        End If
        If CheckBox1.Checked Then
            isMogugb = True
        Else
            isMogugb = False
        End If
        If RadioButton7.Checked Then
            shijianJiange = 400
        End If
        If RadioButton8.Checked Then
            shijianJiange = 300
        End If
        If RadioButton9.Checked Then
            shijianJiange = 200
        End If
        mLen = NumericUpDown1.Value
        dw = NumericUpDown2.Value
        numCmmc = NumericUpDown3.Value
        mykeyA = NumericUpDown4.Value
        mykeyW = NumericUpDown5.Value
        mykeyD = NumericUpDown6.Value
        mykeyS = NumericUpDown7.Value
        Me.Hide()
        Newgame()
        If FrmChiMoGu.Timer1.Enabled Then
        Else
            FrmChiMoGu.Timer1.Enabled = True
        End If
    End Sub
End Class

游戏资源:

vb.net编写的吃蘑菇小游戏(贪吃蛇)

 

游戏画面:

vb.net编写的吃蘑菇小游戏(贪吃蛇)