program GameSnake; uses WinCrt, Graph, ModuleS; var sterownik,tryb: integer; wscore,ewscore: string; procedure DrawingSnakeAndFood(wsp_x,wsp_y: integer); var wi,wj: byte; point_x1,point_y1,point_x2,point_y2: integer; wl,wk: integer; begin point_x1 := 0; point_y1 := 0; for wi := 1 to 10 do begin for wj := 1 to 10 do begin point_y1 := wsp_y * (wi - 1); point_y2 := point_y1 + wsp_y; if wi in [2..3] then begin point_y2 := point_y2 - 1; if wi = 3 then point_y1 := point_y1 - 1 end else if wi in [4..6] then begin point_y1 := point_y1 - 1; point_y2 := point_y2 - 1; if wi = 6 then point_y2 := point_y2 - 1 end else if wi = 10 then point_y1 := point_y1 - 3 else if wi in [7..9] then begin point_y1 := point_y1 - 2; point_y2 := point_y2 - 2; if wi = 9 then point_y2 := point_y2 - 1 end; point_x1 := wsp_x * (wj - 1); point_x2 := point_x1 + wsp_x; if wj in [6..10] then begin if wj = 6 then point_x2 := point_x2 - 1 else begin point_x1 := point_x1 - 1; point_x2 := point_x2 - 1 end end; if board[wi,wj] = 'X' then begin setcolor(4); rectangle(point_x1,point_y1,point_x2-1,point_y2-1); setcolor(10); circle(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2) - 1,(wsp_y div 2) - 2); putpixel(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2),12) end else if board[wi,wj] = '0' then begin setcolor(2); rectangle(point_x1,point_y1,point_x2-1,point_y2-1); setcolor(13); circle(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2) - 1,(wsp_y div 2) - 2); putpixel(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2),11) end else if board[wi,wj] = ' ' then begin setcolor(0); rectangle(point_x1,point_y1,point_x2-1,point_y2-1); setcolor(0); circle(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2) - 1,(wsp_y div 2) - 2); putpixel(point_x1 + (wsp_x div 2),point_y1 + (wsp_y div 2),0) end end end end; procedure ClearArray(nmax_rows,nmax_cols: byte); var j,k: byte; begin for j := 1 to nmax_rows do for k := 1 to nmax_cols do board[j,k] := ' ' end; begin sterownik := detect; InitGraph(sterownik,tryb,' '); ClearArray(10,10); New(snake); tail := nil; snake := nil; y := 5; x := 6; AddSegment(1); SnakeDisplayStart; input := #75; randomize; x1 := random(10)+1; y1 := random(10)+1; while (y = y1) and (x = x1) do begin x1 := random(10)+1; y1 := random(10)+1 end; FoodInsideSnake := true; TheEnd := false; score := 0; repeat if (x = x1) and (y = y1) then begin AddSegment(1); x1 := random(10)+1; y1 := random(10)+1; FoodInsideSnake := true; score := score + 1 end else FoodInsideSnake := false; tail := snake; if keypressed then begin key := readkey; if ord(key) = 0 then key := readkey; if ((key = #72) and (input <> #80)) or ((key = #80) and (input <> #72)) or ((key = #75) and (input <> #77)) or ((key = #77) and (input <> #75)) then input := key end; if input = #72 then y := y - 1; if input = #80 then y := y + 1; if input = #75 then x := x - 1; if input = #77 then x := x + 1; if y = 10 + 1 then y := 1; if x = 10 + 1 then x := 1; if y = 0 then y := 10; if x = 0 then x := 10; ClearArray(10,10); SnakeDisplay; board[y1,x1] := 'X'; tail^.coordinate_y := y; tail^.coordinate_x := x; with tail^ do begin if FoodInsideSnake = true then while (coordinate_y = y1) and (coordinate_x = x1) do begin x1 := random(10)+1; y1 := random(10)+1 end; board[coordinate_y,coordinate_x] := '0'; DrawingSnakeAndFood(Round(getmaxx/10),Round(getmaxy/10)) end; delay(500) until TheEnd = true; str(score,wscore); ewscore := 'SCORE: '+wscore; ClearDevice; setcolor(3); SetTextStyle(SansSerifFont,HorizDir,5); OutTextXY((getmaxx div 2) - (TextWidth('GAME OVER') div 2),(getmaxy div 4),'GAME OVER'); OutTextXY((getmaxx div 2) - (TextWidth(ewscore) div 2),(getmaxy div 2),ewscore); OutTextXY((getmaxx div 2) - (TextWidth('PRESS ESC') div 2),(getmaxy - (getmaxy div 4)),'PRESS ESC'); While readkey <> #27 do end.