1、游戲開始界面進行一個簡單的展示,
2、選擇1進入游戲,可以看到左面的游戲界面,還有旁邊的說明模塊
3、如果死掉的話,游戲就會結束,就會有選擇階段。
4、選擇2,進行游戲的說明,需要對界面的設置,還有清屏等功能。
前期準備階段
1首先,我們需要做一個蛇的身體,就是在界面上顯示一條蛇的樣子。
2下面是代碼展示模塊,通過輸出語句組成了我們想要的蛇的樣子。
3我們需要一個開始界面所以現在來繪制開始游戲界面
4畫出開始游戲菜單的邊框
5畫出游戲菜單中間的字體以及選項框
貪吃蛇Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)Dim C As LongIf KeyCode = 27 Then EndIf KeyCode = 32 ThenIf Timer1.Enabled = True ThenTimer1.Enabled = FalseLabel1.Visible = TrueElseTimer1.Enabled = TrueLabel1.Visible = FalseEnd IfEnd IfC = UBound(She)If GFangXiang = True Then Exit SubSelect Case KeyCodeCase 37If She(C).F = 2 Then Exit SubShe(C).F = 0GFangXiang = TrueCase 38If She(C).F = 3 Then Exit SubShe(C).F = 1GFangXiang = TrueCase 39If She(C).F = 0 Then Exit SubShe(C).F = 2GFangXiang = TrueCase 40If She(C).F = 1 Then Exit SubShe(C).F = 3GFangXiang = TrueEnd SelectEnd SubPrivate Sub Form_Load()Me.AutoRedraw = TrueMe.BackColor = &HC000&Me.FillColor = 255Me.FillStyle = 0Me.ScaleWidth = 24Me.ScaleHeight = 24Me.WindowState = 2Set Timer1 = Controls.Add("VB.Timer", "Timer1")Set Label1 = Controls.Add("VB.Label", "Label1")Label1.AutoSize = TrueLabel1.BackStyle = 0Label1 = "暫停"Label1.ForeColor = RGB(255, 255, 0)Label1.FontSize = 50ChuShiHuaEnd SubPrivate Sub Form_Resize()On Error GoTo 1:With MeIf .WindowState <> 1 Then.Cls.ScaleMode = 3HWB = .ScaleHeight / .ScaleWidth.ScaleWidth = 24.ScaleHeight = 24Label1.Move (Me.ScaleWidth - Label1.Width) / 2, (Me.ScaleHeight - Label1.Height) / 2HuaTuMe.Line (X, Y)-(X + 1, Y + 1), RGB(255, 255, 0), BFEnd IfEnd With1:End SubPrivate Sub Timer1_Timer()Dim C As Long, I As LongOn Error GoTo 2:QingChuC = UBound(She)Select Case She(C).FCase 0If ZhuangTai(She(C).X - 1, She(C).Y) = 2 ThenC = C + 1ReDim Preserve She(C)She(C).F = She(C - 1).FShe(C).X = She(C - 1).X - 1She(C).Y = She(C - 1).YChanShengShiWuGoTo 1:ElseIf ZhuangTai(She(C).X - 1, She(C).Y) = 1 ThenGoTo 2:End IfCase 1If ZhuangTai(She(C).X, She(C).Y - 1) = 2 ThenC = C + 1ReDim Preserve She(C)She(C).F = She(C - 1).FShe(C).X = She(C - 1).XShe(C).Y = She(C - 1).Y - 1ChanShengShiWuGoTo 1:ElseIf ZhuangTai(She(C).X, She(C).Y - 1) = 1 ThenGoTo 2:End IfCase 2If ZhuangTai(She(C).X + 1, She(C).Y) = 2 ThenC = C + 1ReDim Preserve She(C)She(C).F = She(C - 1).FShe(C).X = She(C - 1).X + 1She(C).Y = She(C - 1).YChanShengShiWuGoTo 1:ElseIf ZhuangTai(She(C).X + 1, She(C).Y) = 1 ThenGoTo 2:End IfCase 3If ZhuangTai(She(C).X, She(C).Y + 1) = 2 ThenC = C + 1ReDim Preserve She(C)She(C).F = She(C - 1).FShe(C).X = She(C - 1).XShe(C).Y = She(C - 1).Y + 1ChanShengShiWuGoTo 1:ElseIf ZhuangTai(She(C).X, She(C).Y + 1) = 1 ThenGoTo 2:End IfEnd SelectZhuangTai(She(0).X, She(0).Y) = 0For I = 0 To CSelect Case She(I).FCase 0She(I).X = She(I).X - 1Case 1She(I).Y = She(I).Y - 1Case 2She(I).X = She(I).X + 1Case 3She(I).Y = She(I).Y + 1End SelectNextTiaoZheng1:GFangXiang = FalseZhuangTai(She(C).X, She(C).Y) = 1HuaTuExit Sub2:If MsgBox("游戲結束,點“是”重新開始游戲,點“否”", vbYesNo, "貪吃蛇") = vbYes ThenChuShiHuaElseEndEnd IfEnd SubPrivate Sub ChuShiHua()Me.ClsTimer1.Enabled = TrueTimer1.Interval = 200Erase ZhuangTaiReDim She(2)She(0).F = 2She(0).X = 9She(0).Y = 11ZhuangTai(9, 11) = 1She(1).F = 2She(1).X = 10She(1).Y = 11ZhuangTai(10, 11) = 1She(2).F = 2She(2).X = 11She(2).Y = 11ZhuangTai(11, 11) = 1HuaTuChanShengShiWuEnd SubPrivate Sub QingChu()Dim I As LongFor I = 0 To UBound(She)Me.Line (She(I).X, She(I).Y)-(She(I).X + 1, She(I).Y + 1), Me.BackColor, BFNextEnd SubPrivate Sub HuaTu()Dim I As LongFor I = 0 To UBound(She)Me.Circle (She(I).X + 0.5, She(I).Y + 0.5), 0.49, RGB(255, 255, 0), , , HWBNextEnd SubPrivate Sub TiaoZheng()Dim I As LongFor I = 0 To UBound(She) - 1She(I).F = She(I + 1).FNextEnd SubPrivate Sub ChanShengShiWu()Randomize Timer1:X = Int(Rnd * 24)Y = Int(Rnd * 24)If ZhuangTai(X, Y) > 0 Then GoTo 1:ZhuangTai(X, Y) = 2Me.Line (X, Y)-(X + 1, Y + 1), RGB(255, 255, 0), BFEnd Sub
窗體放兩個Label控件,一個Timer控件:Dim n As IntegerPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)Select Case KeyCodeCase vbKeyUpIf Label1.Top > 0 Then Label1.Top = Label1.Top - 50Case vbKeyDownIf Label1.Top 0 Then Label1.Left = Label1.Left - 50Case vbKeyRightIf Label1.Left
1、基礎語言階段:常用的編程語言有,C,C++,JAVA,其中最廣泛被使用的就是C++,C++語言是一切游戲程序的基礎,換而言之,一個優秀的游戲程序員,必須非常熟練掌握并應用C++.
2、數據結構:在掌握C++之后,需要進行數據結構的學習,形象的講,就是那么一大堆數據,如何去有序的排列其結構。通過對數據結構的學習,便能夠開始閱讀他人編寫的代碼,嘗試 開發簡單的程序,可以實現一些編程者自己的構想,是每個程序員必須掌握的技巧。
3、“庫”的學習及應用:最常用的有MFC(微軟公司類庫),GUI(圖形界面庫),當然“庫”的知識及功能非常龐大,通常來說,熟練掌握一部分經常涉及的知識即可。
通過以上三點的學習,c++基礎語言,數據結構,庫的使用。你基本已經可以自己獨立制作一個小游戲了,比如貪吃蛇,俄羅斯方塊等等。
然后,將進入的高階階段,也將是直接涉及到游戲程序相關知識。
4、游戲程序對于硬件的操縱。比如,內存,CPU,顯卡,這將會涉及到一些數學知識,比如立體幾何,線性代數等,但是也不用驚慌,并不是非常困難。通過對硬件的熟練操縱,才能將游戲的畫面,流暢度等等充分給予表達。
5、對于相關知識的學習。包括物理,腳本,美術等等。不需要深入了解,但相關知識的豐富對于你將來做游戲程序會有直接幫助。
6、對于游戲引擎的熟悉及使用。游戲引擎一般包括渲染器,內存管理器,組織管理幾部分。對游戲的畫面做出渲染,高效使用內存以及如何控制動畫播放等功能。熟悉引擎的使用,也將對于游戲程序員有直觀的幫助。