![snake game in c language snake game in c language](https://www.codewithc.com/wp-content/uploads/2014/05/pacman-game-in-c.jpg)
Note that lines 10 to 210 and 580 to 890-more than half the program-define graphics characters for the snake's head (facing in different directions) and for its food. If you are playing this in CPCBasic, first click on the CPC screen so it gets keyboard input and then enter "run" (clicking the Run button would deselect the screen again).Ģ0 sx= 20:sy= 5:dx= 1:dy= 0:ml= 20: dim ox (ml ),oy (ml ):oi= 1:ll= 4:skill= 6ģ0 f$= chr$ ( 228 ):w$= chr$ ( 127 ):b$= chr$ ( 231 )ĥ0 for i= 2 to 20: print w$ space$ ( 38 ) w$ : nextħ0 locate 10, 12: print string$ ( 20,w$ ) ġ40 locate sx,sy: print chr$ ( 224 ) :ox (oi )=sx:oy (oi )=syġ80 if a$=w$ or a$=b$ then sound 2, 62500/ 20, 100: locate 13, 6: print "You have died!": endġ90 if a$=f$ then sound 2, 62500/ 500, 10: sound 1, 62500/ 1000, 10: sound 4, 62500/ 2000, 10:p=p+ 100: print " " : gosub 260: if ll 0 then locate ox (nn ),oy (nn ): print " " īy ancient tradition, the controls are Q for up, A for down, O for left, and P for right.
![snake game in c language snake game in c language](https://ecdn.teacherspayteachers.com/thumbitem/Math-Game-No-Prep-Multiplication-and-Division-Snake-3677081-1559869593/original-3677081-2.jpg)
Lower the skill parameter in line 20 or increase ml (maximum length) if you find gameplay too easy. Use the cursor keys to control movement direction. Locate 10, 18: Print "Has muerto! Con" puntos " puntos." : Sleep If posX = x (contar ) And posY = y (contar ) Then convida = false If direccion = "izquierda" Then posX -= 1 Locate posY, posX: Print Chr ( 219 ) '"Û" If oldX > 0 And oldY > 0 Then Locate oldY, oldX : Print " " OldX = x (longitud ) : oldY = y (longitud ) Locate fruitY, fruitX : Color 12: Print Chr (01 ) : Color 10 ( 0 ) = posX : y ( 0 ) = posY Locate 23, 2: Print "SNAKE - salir - Puntos: " puntos Locate 14, 4: Print "M xima puntuaci¢n: " oldhi Print " \_/- para velocidad, o para salir." BASIC FreeBASIC ĭim Shared As Integer puntos, contar, longitud, posX, posY, oldhi = 0ĭim Shared As Integer x ( 500 ), y ( 500 )ĭim Shared As Byte fruitX, fruitY, convida MsgBox, 262180, ,% "Your Score is " Score "`nPlay Again?" GuiControl, EditGrid , % grid2Text (oGrid ) GuiControl, Score , % "Your Score = " ++Score || ( ( A_ThisHotkey = "Down" ) & (Direction = "Down" ) )Ĭase "Right" : oGrid := 1 || ( ( A_ThisHotkey = "up" ) & (Direction = "up" ) ) || ( ( A_ThisHotkey = "left" ) & (Direction = "left" ) ) || ( ( A_ThisHotkey = "right" ) & (Direction = "right" ) ) || ( ( A_ThisHotkey = "Down" ) & (Direction = "up" ) ) || ( ( A_ThisHotkey = "up" ) & (Direction = "Down" ) ) || ( ( A_ThisHotkey = "left" ) & (Direction = "right" ) ) If ( ( A_ThisHotkey = "right" ) & (Direction = "left" ) ) Width := 100, Height := 30 set grid size Gui, add, Text, vScore x10 y + 10 w200 ReadOnly , % "Your Score = " Score Gui, add, Edit, vEditGrid x10 y10 ReadOnly , % grid2Text (oGrid )