This article introduces the general way to prepare a greedy snake game, which does not contain a high-profile algorithm, only the primary VB programming method, easy to understand.
If you have any insights, please don't know.
I qq: 190317890 (please write "9CBS" in the authentication)
Mailbox Bugs1984@126.com
Friends who need this Program VB source file, please leave your E-mail, I will send it as soon as possible.
=======================================================================================================================================================
Design ideas: ================================ (1) Start new game 1.1 get and apply various parameters (current level , Control keys, etc.), initialize the random number. 1.2 Clear all items on the map, and set zero. 1.3 Initialization Map: Food, bomb, snake body position, and snake head move direction - Pain images on PictureBox and modify the corresponding map bit property value (mapproperty () array). 1.4 Start Timer Timer, the game begins.
(2) Game operation 2.1 Pause / recovery - Modify the Boolean variable value indicating the status of the game; display / hide the label of the game status; pause / restore the Timer Timer.
2.2 Control Direction (according to NOKIA Running Snake Operation) - Since the snake head can move in 4 directions in the upper and lower, the arrow keys have eight, so the control key and horizontal, vertical direction of the "slash direction" Key code is a bit different
2.2.1 The slash direction button (in the "right" arrow key as an example) - If the current snake head moves toward the left (horizontal direction), the component in the horizontal direction becomes 0, and the component in the vertical direction becomes - 1 (upward movement); if the current snake head moves toward the upper (vertical direction), the component in the vertical direction becomes 0, and the component in the horizontal direction becomes 1 (moving to the right). The remaining "upper left, left, lower right" direction key coding is similar to the above.
2.2.2 "horizontal, vertical" arrow keys - When the snake moves in the horizontal direction, the "left" and "right" button is invalid; (ie, the button event is not processed) When the snake moves in the vertical direction, "upper" and The button of "next" is invalid.
(3) Mobile snake body 3.1 According to the direction of exercise, find the new coordinates of the snake head; 3. Decision of the map properties of the snake head new coordinates - (1) If the new coordinates of the snake head coordinate, it is not GameOver - Because with the movement of the snake head, all nodes of the snake body will follow up, so that the grid of the current snail coordinates will become blank after moving. (2) If the map attribute of the current snake head position is "food" - increase the length of the snake body, the number of foods that players eat, increase the score, supplement the food on the map, record (accumulated) the items that are currently eaten, if eating Cuetcount reaches a certain amount (EatcountPrize) shows prizes on a map. (3) If the map attribute of the current snake head is "Bomb" (trap) - the number of bombs that the players eat, deduction (if the score is less than 0, on the GameOver), supplement the bomb on the map, record (accumulation) current Eat items, if you eat into a certain amount, you will show prizes. (4) If the map attribute of the current snake head is "prizes" - add points, recipient number of items to eat (cureatcount = 0) 3.3 Refresh snakes coordinates, update map grid properties, and screen (1) in updating snake Before the body, save the original snake end; (2) Wipe the old snake head on the map, then draw a new snake head on the map; (3) Modify the variable, mark the map of the snake headfinder For: snake body; (4) To update the coordinates of the snake body in addition to the rest of the snake head; (5), then update the coordinates of the snake head; (6) Judgment whether it is necessary to increase the snake length - If you want to increase the length: Old snake The coordinates are constant, snake length 1; otherwise (no need to increase snake length): If the new coordinates of the snake head coordinate with the old snake tail, you don't have a blank pattern under the old snake end (because the grid) The attribute is already a snake head, not a white) (7) erase the old snake tail, painting blank; (8) set the property of the old snake tail coordinates to blankly; "Standard module Module1 Code "
Option expedition
'********************************************************** *********************************************************** *************************** Grove constant
Public Enum Map_Property 'Map Properties Map_empty = 0' White Map_food 'Food Map_bomb' Bomb, Trap Map_Prize 'Different Prize Map_Snake' Snake End Enum
Public const map_scale as integer = 15 'map magnification
'Map Grid (INDEX value, first value is 0) public const max_col_index as integer = 19public const Max_row_index as integer = 10public const start_snake_length as integer = 8' snake body initial length
Public const speed_lv1 as integer = 200 'first level (slower) speed (Timer.Interval, fastest level 9 = 40) public const speed_change as integer = 20' Interval difference between 2 rating before and after (milliseconds )
'Defined control keys Public Const KEY_PAUSE As Integer = vbKeyNumpad5 Public Const KEY_UP As Integer = vbKeyNumpad8 Public Const KEY_DN As Integer = vbKeyNumpad2 Public Const KEY_LF As Integer = vbKeyNumpad4 Public Const KEY_RT As Integer = vbKeyNumpad6 Public Const KEY_LFUP As Integer = vbKeyNumpad7 Public Const KEY_LFDN As Integer = vbkeynumpad1 public const key_rtup as integer = vbkeynumpad9 public const key_rtdn as integer = vbkeynumpad3
'Define a fill color Public Const HEAD_COLOR As Long = & H80FF' snakehead color Public Const BODY_COLOR As Long = vbGreen 'snake color Public Const EMPTY_COLOR As Long = & HE0E0E0' white ground color Public Const FOOD_COLOR As Long = vbBlue 'food color Public Const BOMB_COLOR As Long = VBRED 'Bomb Color Public Const Full_Color As long = 255 ^ 3 public const record_file_name as string = "/record.dat"' recorded file name
Public const Max_prize as integer = 50 'The upper limit of the start reward score public const min_prize as integer = 20' starting reward score lower limit 'global variable
'Record the information of the player and set the value: public Type Theplayerinfo Score AS Integer' Record the score of the score Headcolor As long 'snake head padding color bodycolor as long' snake body filling color food as integer 'records the amount of food Bomb as integer' record The number of bombs BLNGAMEOVER AS Boolean 'marks whether the player has game over' snakecolor as long 'Painting snake body fill color ... Temporary ... SnakeLength AS Integer' snake length 'snake head movement direction (value -1, 0, 1) X_WAY AS INTEGER Y_WAY AS INTEGER 'Control Key (8) ... Temporary (using the default control key) end type' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Record Players' Score and Name Type Twsycord Name AS String * 15 Score as Integered Type
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' Uses two-dimensional coordinate values public type theposition x as integer y as integrend type
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Public Foodcount_atonetime AS INTEGER' Map The number of foods simultaneously occurs PUBLIC BOMBCOUNT_TONETIME AS INTEGER 'Map The number of bombs appeared at the same time PUBLIC Prizeremain As INTEGER 'Current remaining reward score PUBLIC EATCOUNTPERSHOWPRIZE' Recording how many items in the snake eat (including food and bombs, prizes are not counted) only show a prize
Public addscoreperfood as integer 'Every time I eat a food, the increased score PUBLIC AddScoreperbomb As INTEGER' Every time I eat a bomb, the score of the buckle is' ***************** *********************************************************** *********************************************************** ****
Sub main () frMplay.show fmscorelist.show 'first runs first
End Sub
=======================================================================================================================================================
"Main Factory FRMPLAY Code" -
Private blnStartgame as boolean 'marks whether the new game has been started (T = game has started) Private blnpause as boolean' marks whether the current blocked state (T = pause) private blnthroughwall as boolean 'mark is a wall mode (t = can wear Wall) Private BLNONKEYEVENTS AS BOOLEAN 'The mark can receive the keyboard event (t = can be received), this variable prevents the form_keydown () event repeatedly
Private Map_Width As Integer 'Map Width (pixels) Private Map_Height As Integer' height map (pixel) Private Map_Empty_Color 'map - the white color Private Map_Bomb_Color' map - bomb color Private Map_Food_Color 'map - Food Color Private MapProperty () As Integer 'Recording the properties of each grid of the map, the Private CureatCount as integer' Before you have a prize, you eat how many items (including food and bombs, prizes are not counted). When the prize appears, this variable value is zero "0", Then enter the next statistical Curlevel AS Integer 'Current Level Private P1 as TheplayerInfo' Information Recording Player1
PRIVATE SNAKE_P1 () as theposition 'Record the snake coordinate prizepos as theposition' Record the coordinates of prizes
Private record (9) as there with the top ten score logging information
Option expedition
Private Sub cmdhelp_click () if blnpause = false kilsens_keydown (key_pause, 0) 'If the game is in progress, send "Pause" button event, suspend the game frmhelp.show end Sub
'New Game Private Sub cmdNewGame_Click () Dim i As Integer Randomize' regenerated random number sequence blnStartGame = Not blnStartGame If blnStartGame Then cmdNewGame.Caption = "stop" Else cmdNewGame.Caption = "new game" End If 'suspended game If blnStartGame = False Ten 'If the last prize has not disappeared (with prizeremain> 0 as a sign), you will first remove the old prize, and then display the new prizter IF prizeremain> 0 Ten Call showprize (false)
picDisplay.Cls P1.Score = 0 'initial player's score P1.Food = 0 P1.Bomb = 0 curEatCount = 0 PrizeRemain = 0 blnPause = False lblPause.Visible = False lblScore.Caption = P1.Score lblFoodCount.Caption = P1. Food lblBombCount.Caption = P1.Bomb P1.blnGameOver = True HscrLevel.Enabled = True tmrMove.Enabled = False Exit Sub End If blnThroughWall = True 'entrapment mode blnOnKeyEvents = True' default to using the fill color Map_Bomb_Color = BOMB_COLOR Map_Empty_Color = EMPTY_COLOR Map_Food_Color = FOOD_COLOR P1.BodyColor = BODY_COLOR P1.HeadColor = HEAD_COLOR 'map initialization ReDim MapProperty (MAX_COL_INDEX, MAX_ROW_INDEX) Map_Width = (MAX_COL_INDEX 1) * MAP_SCALE Map_Height = (MAX_ROW_INDEX 1) * MAP_SCALE picDisplay.Cls picDisplay.Width = Map_Width 2 Picdisplay.height = map_height 2 picdisplay.Line (0, 0) -Step (Map_Width, Map_Height), Map_empty_Color, BF FoodCount_ AtonEtime = 2 'The number of foods existing on the map bombcount_atonetime = 1' map The number of bombs in the same time EatcountPershowprize = 5 'Set how many items (including food and bombs, prizes are not considered), showing prizes Curlevel = HScrlevel. Value addscoreperfood = curlevel 'Every time I eat a food, the added score = Current level value addscoreperbomb = -Curlevel * 2' Each time I eat a bomb, the score of the score p1.score = ABS (AddScoreperbomb) 1 'player The initial score = 'Every time I eat a bomb, the score of the buckle is 1 p1.food = 0 p1.bomb = 0 prizeremain = 0 p1.blngameover = false lblscore.caption =
P1.score lblfoodcount.caption = p1.food lbombCount.caption = p1.bomb 'initialization P1 snake body redim snake_p1 (start_snake_length) for i = 0 to ubound (snake_p1)' Set the starting position of the snake body Snake_p1 (i ) .X = max_col_index - ubound (snake_p1) i snake_p1 (i) .y = max_row_index 'initialization movement P1.X_WAY = -1 p1.y_way = 0 mapproperty (snake_p1 (i) .x, snake_p1 (i) .y ) = MAP_SNAKE picDisplay.Line (Snake_P1 (i) .X * MAP_SCALE, Snake_P1 (i) .Y * MAP_SCALE) -Step (MAP_SCALE, MAP_SCALE), BODY_COLOR, BF Next 'to re-use a color painting snakehead snakehead picDisplay.Line (Snake_P1 ( 0) .X * MAP_SCALE, Snake_P1 (0) .Y * MAP_SCALE) -Step (MAP_SCALE, MAP_SCALE), HEAD_COLOR, BF 'food is placed For i = 1 To FoodCount_AtOneTime Call AddFood Next' bombs For i = 1 To BombCount_AtOneTime Call AddBomb Next lblpause.visible = false lblscore.caption = p1.score lblfoodcount.caption = p1.food lblbombcount.caption = p1.bomb p1.blngameover = false hscrlevel.enabl ED = false 'game can not change the level TMRMOVE.ENABED = TrueEnd Sub' Display Private Sub Cmdshowscorelist_Click () if blnpause = false kilick () if BLNPAUSE = FALSE THEN CALL FORM_KEYDOWN (KEY_PAUSE, 0) 'If the game is in progress, send "Pause" button event , Suspend game frmscorelist.show end sub
Private Sub Form_KeyDown (Keycode AS Integer, Shift As Integer) If P1.BLNGAMEOVER OR BLNSTARTGAME = false or blnonkeyevents = false the eXIT SUB 'The following cases (the game is over, the game has not started, disabling the key event) does not receive the button operation.
"Press" Numpad 5 "key - Pause / Resume If KeyCode = KEY_PAUSE Then blnPause = Not blnPause lblPause.Visible = blnPause tmrMove.Enabled = Not blnPause Exit Sub End If If blnPause Then Exit Sub 'is not acceptable in suspended state" ESC "Other Button SELECT CASE KeyCode Case Key_LFUP BLNONKEYEVENTS = FALSE IF P1.X_WAY <> 0 THEN P1.X_WAY = 0 p1.y_way = -1 elseif p1.y_way <> 0 THEN P1.X_WAY = -1 p1.y_way = 0 end if case key_lfdn blnonkeyevents = false if p1.x_way <> 0 THEN P1.X_WAY = 0 p1.y_way = 1 elseif p1.y_way <> 0 THEN P1.X_WAY = -1 p1.y_way = 0 end if case key_rtup BLNONKEYEVENTS = False if p1.x_way <> 0 THEN P1.X_WAY = 0 p1.y_way = -1 elseif p1.y_way <> 0 THEN P1.X_WAY = 1 P1.y_way = 0 end if case key_rtdn blnonkeyevents = false if p1.x_way <> 0 THEN P1.X_WAY = 0 p1.y_way = 1 elseif p1.y_way <> 0 THEN P1.X_WAY = 1 p1.y_way = 0 end if 'When the snake moves in the horizontal direction, the LF and RT buttons are invalid case key_lf blnonkeyevents = false if p1.x_way = 0 THEN P1.X_WAY = -1 p1.y_way = 0 end if case key_rt blnonkeyevents =
False if p1.x_way = 0 THEN P1.X_WAY = 1 p1.y_way = 0 end if 'When the snake moves in a vertical direction, the UP and DN button are invalid case key_up blnonkeyevents = false if p1.y_way = 0 THEN P1.X_WAY = 0 p1.y_way = -1 end if case key_dn blnonkeyevents = false if p1.y_way = 0 THEN P1.X_WAY = 0 p1.y_way = 1 end if copy else exit sub * SETMRMOVE.Enabled = false 'Pause Timer event, wait until After all of this mobile operation (ie, the sub refreshsnake (...) process is executed), then start Timer Call Playermove End Subprivate Sub Form_Keyup (Keycode As Integer, Shift As Integer) After the BLNONKEYEVENTS = true 'will be able to Receive button event END SUB
Private sub form_load () me.keypreview = true picdisplay.backcolor = EMPTY_COLOR CURLEVEL = 6 'Default Level: 6 HScrlevel.Value = Curlevel End Sub
'Game End Private Sub GameOver () DIM ANS AS INTEGER P1.BLNGAMEOVER = True TMRMOVE.ENABED = FALSE IF PrizeRemain> 0 The Call showprize (false) msgbox "game end. Your score is:" & vbcrlf & p1.score, Vbinformation, "Game over" Call CheckRecord (p1.score) 'Check the score to list the call cmdnewgame_click' Prepare a new round of games
End Sub
'Snake Mobile Treatment Process Private Sub Playermove () Dim Temphead As Theposition' Temporary Snake Head's New Coordinate Dim Blnaddlengh As Boolean 'Is Adding Snake Less (T = Increase)' Favoring New Coordinate Temphead.x = snake_p1 (0) .x p1.x_way temphead.y = snake_p1 (0) .y p1.y_way if blnthroughwall the 'If the current Wall Wall mode (default) if Temphead.x <0 Tenshead.x = max_col_index elseif Temphead .X> max_col_index the temphead.x = 0 elseif Temphead.y <0 Tensead.y = max_row_index elseif temphead.y> max_row_index the temphead.y = 0 END IF ELSE 'Non-Wall Mode Mobile Code does not set end if' Judging the map attribute of the snake head, Select Case mapproperty (Temphead.x, TempHead.y) case map_empty 'White, there is no blank mobile operation Case map_snake' snake body "If the new coordinates of the snake head and the coordinate of the current snake It is not that GameOver - because of the movement of the snake head, the snakes will follow up, so that the grid of the current snake tail is turned into a blank ground.
If Not (tempHead.X = Snake_P1 (UBound (Snake_P1)). X And tempHead.Y = Snake_P1 (UBound (Snake_P1)). Y) Then Call GameOver Exit Sub End If Case MAP_FOOD 'food blnAddLengh = True' snake increasing length P1.food = p1.food 1 'Statistian Player Evil Number LBLFOODCOUNT.CAPTION = P1.food' Show a total of foods Call Changescore (addcoreperfood, true) 'extra points Call addfood' supplementary food Case map_bomb 'bomb p1.bomb = p1.bomb 1' statistical players eat the number of bombs LBLBMBCOUNT.CAPTION = p1.bomb 'Show a total of a total of a total bomb number Call Changescore (addcoreperbomb, true)' deducted Call AddBomb 'supplement bomb Case MAP_PRIZE on the map 'prize Call ChangeScore (PrizeRemain, False) Call ShowPrize (False)' Clear the prize End Select on the map Call RefreshSnake (tempHead.X, tempHead.Y, blnAddLengh) 'refresh snake image on the map' TMRMOVE.ENABLED = True End Subprivate Sub Form_UNLOAD (Cancel As Integer) Dim Ans as INTEGER IF BLNSTARTGAME THEN '' If the game has started, Ask if you want to quit if blnpause = false kiln call form_keydown (key_pause, 0) 'If the game is in progress, send "Pause" button event, suspend the game ANS = msgbox ("The game has not ended, do you want to quit? ", vbquestion or vbyesno or vbdefaultbutton2) if Ans = vbyes the end else caled = true endiff = true end =
'Set the game level (speed) private sub hscrlevel_change () Curlevel = HSCRLEVEL.VALUE LBLLEVEL.CAPTION = Curlevel TMRMOVE.INTERVAL = Speed_LV1 - (Curlevel - 1) * Speed_change' According to the level, set the speed END SUB
Private Sub TMRMOVE_TIMER () Call Playermovend Sub 'Changes the Player's Score' Parameters: AddScore - Added Scores (Positive = Different Divide, Negative Number = Dividing) 'BLNADDEATCOUNT - Judging whether it is necessary to add CureatCount (T = accumulation) If the current is not eating food or bomb, not accumulate) Private Sub ChangeScore (AddScore As Integer, blnAddEatCount As Boolean) P1.Score = P1.Score AddScore If blnAddEatCount Then curEatCount = curEatCount 1 'recorded (accumulated) current Eat items' If you eat, the item is reached a certain amount (EatcountPrize) Displays the prize if cureatcount = eatcountPershowprize kiluretcount = 0 'Recipe Items Number' If the last prize has not disappeared (with prizeemain > 0 is a sign, first clear the old prize, then show the new prizir if prizeremain> 0 Then Call showprize (false) Call showprize (true) end if lblscore.caption = p1.score if p1.score <= 0 Then Call GameOverend Sub
'Add food on the map Private sub addfood () Dim Tempfood as theposition' Looking for a blank ground for placing food DO Tempfood.x = int (RND () * (MAX_COL_INDEX 1)) Tempfood.y = Int (RND ) * (MAX_ROW_INDEX 1)) Loop Until MapProperty (tempFood.X, tempFood.Y) = MAP_EMPTY MapProperty (tempFood.X, tempFood.Y) = MAP_FOOD 'map grid tag attributes food picDisplay.Line (tempFood.X * Map_scale, tempfood.y * map_scale) -step (map_scale, map_scale), map_food_color, bf 'draws food END SUB on the map
'Increase the bomb private sub addbomb () Dim Tempbomb as theposition' looking for a blank, used to place bomb do tempBomb.x = int (RND () * (MAX_COL_INDEX 1)) Tempbomb.Y = Int (RND ) * (MAX_ROW_INDEX 1)) Loop Until MapProperty (tempBomb.X, tempBomb.Y) = MAP_EMPTY MapProperty (tempBomb.X, tempBomb.Y) = MAP_BOMB 'attributes for the tag map grid bomb picDisplay.Line (tempBomb.X * Map_scale, tempbomb.y * map_scale) -step (map_scale, map_scale), map_bomb_color, bf 'draws the bomb End sub' on a map display prizes and reward score 'parameters: blnshow (t = display prize, f = clear Prize) Private Sub showprize (blnshow as boolean) DIM TEMPPRIZE AS TEPSITION DIM TEMPCOLOR As Long
If BLNSHOW THEN 'Display Prizes' Looking for a blank ground for place the prize DO TEMPPRIZE.X = INT (RND () * (MAX_COL_INDEX 1)) TemppPrize.y = int (RND () * (MAX_ROW_INDEX 1)) loop Until MapProperty (tempPrize.X, tempPrize.Y) = MAP_EMPTY PrizePos = tempPrize 'prize record coordinates MapProperty (PrizePos.X, PrizePos.Y) = MAP_PRIZE' map grid tag attribute prizes tempColor = Int (Rnd () * ( Full_color 1)) 'Generate random color Picdisplay.Line (PrizePos.x * map_scale, prizepos.y * map_scale) -Step (map_scale, map_scale), TempColor, BF' in map with random color painting prizeremain = int (RND () * (MAX_PRIZE - MIN_PRIZE 1)) min_prize 'Random Set Starting Reward Score LBLprizRemain.ForeColor = FULL_COLOR - TempColor' Surplus Score, Display LBLPrizeRemain.caption = prizeremain 'Display the current remaining reward score LBLPRIZEREMAIN.MOVE PrizePos.x * map_scale, prizepos.y * map_scale, map_scale, map_scale 'will display the Label of the reward score to the map of the prize in the map. lblPrizeRemain.Visible = True tmrPrize.Enabled = True 'start tmrPrize, continue to decrease bonus score Else' Clear prize picDisplay.Line (PrizePos.X * MAP_SCALE, PrizePos.Y * MAP_SCALE) -Step (MAP_SCALE, MAP_SCALE), Map_Empty_Color, BF 'Erase the prize pattern mapproperty (prizepos.x, prizos.y) = map_empty' markup map grid LBLPRIZEREMAIN. Visible = false TMRPRIZE.ENABLED = FALSE END IF END SUB
'Refresh the snake coordinates, update the map grid properties and screen' parameters: snake head's new coordinate _x, snake head new coordinate _y, increase snake length (t = increase) private sub refreshsnake (newhead_x as integer, newhead_y as Integer, blnAddLength As Boolean) Dim i As Integer Dim OldTail As thePosition 'snake coordinates for before updating, save the original coordinate tail OldTail = Snake_P1 (UBound (Snake_P1))' tail to save the old coordinate picDisplay.Line (Snake_P1 ( 0) .x * map_scale, snake_p1 (0) .y * map_scale) -Step (map_scale, map_scale), p1.bodycolor, bf 'on the map to erase the old snake head PicDisplay.Line (newhead_x * map_scale, newhead_y * map_scale ) -Step (map_scale, map_scale), P1.HEADCOLOR, BF 'Painting new snake head mapproperty on the map (new_x, newhead_y) = map_snake' marked the map of the snake head new coordinates to the player snake "must be new snake To obey the coordinates of the rest of the snake.
Otherwise, FOR i = (Ubound (snake_p1)) to 1 step -1 snake_p1 (i) = snake_p1 (i - 1) Next 'then updating the coordinate of the snake head Snake_p1 (0) .x = newhead_x snake_p1 (0) .y = NEWHEAD_Y 'Judging whether I need to increase the snake length if blnaddlength then' increase the length Redim preserve snake_p1 (Ubound (snake_p1) 1) 'Finally set new snake distant coordinates (keyword "preserve" role is: retaining the original array ) Snake_p1 (Ubound (snake_p1)) = Oldtail 'The coordinates of the old snake tail unchanged p1.snakelength = ubound (snake_p1) 1' snake body 1 else 'snake body does not change' if the snake head of the new coordinates with the old snake tail Coordinate, no need to paint blank patterns under the old snake end (because the grid property is already a snake head, not white) if not (newhead_x = ildtail.x and newhead_y = Oldtail.y) THEN MAPPROPERTY (Oldtail .X, oldtail.y) = map_empty 'Set the property of the map grid under the old snake tail, set to blank PicDisplay.Line (Oldtail.x * map_scale, oldtail.y * map_scale) -Step (map_scale, map_scale) , Map_empty_Color, BF 'Erase the old snake on the map, painting blank end if end if tmrmove.enabled = trueEnd Sub
'Check whether score can list - if you can list, update list Public Sub Checkrecord (Score As Integer) Dim Filenum As Integer Dim Pos AS INTEGER, I AS INTEGER, LIST AS ListBox' Pos - Rank Dim Name AS String 'Record the player name DIM TOPTEN AS BOOLEAN' Judgment the score to enter the top ten DIM ANS AS INTEGER FILENUM = freefile set list = frmscorelist.lstscore 'mapped to list box frmscorelist.lstscore do if score> = VAL (list.list )) The Topten = True Do 'loop, set the player player name Name = INPUTBOX ("Your score is the" & Pos 1 & "" & vbcrf & "Please enter your name (no more than 15 characters)" "Before 10!") If len (name) = 0 Then msgbox "You cancel TOP 10 Score Registration", Vbinformation Exit Sub End IF Len (Rtrim (Name))> 15 THEN ANS = MSGBOX ("Player The length of the name cannot exceed 15 characters! "& VBCRLF &" You entered "& Name &" "" "" "" & Left (name, 15) & "" is agreeable? " , vbquestion or vbyesno, "Enter the Player Name") if Ans = Vbyes Ten Name = Left (Name, 15) End if loop until len (RTRIM (Name)) <= 15 and len (RTRIM (Name))> 0 'until the length of the player name meets the rules, only exits the loop END IF POS = POS 1 Loop Until Pos = 10 or Topten = True if Topten = True the List.Additem Score, POS - 1 frmscorelist.lstname.additem name, POS - 1 if list.listcount> 10 Ten list.removeItem List.ListCount - 1 if frscorelist.lstname.listcount>
10 Then frmScoreList.lstName.RemoveItem frmScoreList.lstName.ListCount - 1 Call PutRecord 'refresh the contents of the log file End If End Sub' scoring record is written to file Private Sub PutRecord () Dim FileNum As Integer, i As Integer FileNum = FreeFile Open app.path & record_file_name for random as #filenum len = len (record (0)) for i = 0 to 9 record (i) .score = val (frmscorelist.lstscore.list (i)) Record (i) .name = frmscorelist.lstname.list (i) Put #filenum,, Record (i) Next Close #filenumend SUB
'Diminishing reward score Private Sub tmrPrize_Timer () Dim tempColor As Long PrizeRemain = PrizeRemain - 1 If PrizeRemain = 0 Then Call ShowPrize (False)' when the bonus score reduced to zero, the prize is erased Exit Sub End If tempColor = Int (RND () * (Full_Color 1)) "Generates Random Colors Picdisplay.Line (PrizePos.x * Map_scale, PrizePos.y * Map_scale) -Step (Map_Scale, Map_Scale), TempColor, BF 'with random color painting on the map Prize LBLPrizeRemain.ForeColor = FULL_COLOR - TempColor 'The remaining score, display lblprizeremain.caption = prizeremain' with the anti-color, display the current remaining reward score end sub
=======================================================================================================================================================
"Route Forms FRMSCORIST Code" -
Private record (9) as there with the score and name of the top 10 players
Option expedition
Private Sub Form_Load () DIM FILENUM AS INTEGER, I AS Integer Lstpos.clear for i = 1 To 10 Lstpos.addItem I, I - 1 Next Lstscore.clear Lstname.clear 'Read Score Record Filenum = FreeFile Open App.Path & RECORD_FILE_NAME for Random As #filenum len = le (Record (0)) 'Call ScoreSort (filenum) for i = 0 to 9 get #filenum,, Record (i) Lstscore.Additem Record (i) .score, i lstname.addItem Record (i) .name, I next close #filenum End Sub 'Synchronous 3 Listbox -
Private sub Lstname_Click () Lstpos.listIndex = Lstname.listIndex LSTSCORE.LISTINDEX = Lstname.listIndexend Sub
Private sub Lstpos_Click () LSTSCore.ListIndex = Lstpos.listIndex Lstname.listIndex = Lstpos.listIndexend Sub
Private sub lstscore_click () Lstpos.listIndex = LSTSCORE.LISTINDEX LSTNAME.LISTINDEX = LSTSCORE.LISTINDEXEND SUB
============================================================================================================================================================================================================= =========================
"Description Form FRMHELP" -
Simply add a TextBox, its Text property is filled in the operation description:
"Greedering Snake 1.1 Single Edition (Wall)" Game Description
(1) Control key: "Enter" - New game / abort game; "5" - Pause / Recovery - (Digital Keyboard, Numlock Status);
Direction Control - (Digital Keyboard, Numlock Status): "8, 2, 4, 6" - Up, Left, Right; "1" - Left / Under; "3" - Right / Lower; " 7 "- Left / on;" 9 "- right / on. (When the snake head and snakes are over, the game is over (2) Map: Blue checkered - food (after eating food, the snake body increases); red square - bomb; lavender - snake head; bright green strip - snake body. Flashing checkered - prize; (the number above the prize indicates the increase of the score after eating the prize.) (The initial value of each prize fraction is 20 ~ 50 The random number, when the prize is the score of rewards, will be reduced.)
(3) Score method: (When the total score <= 0, the game is over)
Each of the increased scores of the food is equal to the value of the level; each of the scores that eat a bomb is twice the number of levels;
Player starting score is equal to 2 times more than 1 point. (For example, the level is 6, the player's starting score is 13 points; each eats a food plus 6 points; each eat a bomb 12 points) After the game runs, create a "repland.dat" file in the directory. , Store score records.
============================================================================================================================================================================================================= =========================
☆☆☆ Misphy Empire (BUGS1984), November 1, 2003 ☆☆☆