Форум программистов, компьютерный форум, киберфорум
PascalABC.NET
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.75/4: Рейтинг темы: голосов - 4, средняя оценка - 4.75
0 / 0 / 0
Регистрация: 07.07.2017
Сообщений: 2

Змейка: добавить паузу и лучший результат

07.07.2017, 15:11. Показов 907. Ответов 5

Студворк — интернет-сервис помощи студентам
Написал тут змейку на паскале и хочется добавить паузу и лучший результат, а с файлами не очень хорошо работаю, если вам не сложно, то помогите с хотя бы одной проблемой, тобиш либо пауза либо лучший результат и скажите на сколько хороша программа и можно ли что-нибудь доработать? Заранее спасибо(при переносе некоторые символы испортились, но это не так важно║ и тд)
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
program zmeika;
 
uses crt; //Sestem.Windows.Forms, System.Drawing,;
type
  spoint = record
    x: integer;
    y: integer;
  end;
 
const
  maxwidth = 200;
 
var
  width: integer;
  e: spoint;
  snakebody: array[1..maxwidth] of spoint;
  i, nx, ny: integer;
  v: byte;
  gameover: boolean;
  key: char;
  sl,speed: integer;
  //f: Form;
 
function checknext(x: integer; y: integer): boolean;
var
  isset: boolean;
  i: integer;
  
//  begin
//f:= new Form();
//f.icon:= new Icon('F:\Кружки\Paskal\Программы PascalABC.NET\Змейка\змейка.ico');
//Application.Run(f);
//end;
 
Begin
  isset := true;
  for i := 1 to width do
  begin
    if (x = snakebody[i].x) and (y = snakebody[i].y) then
      isset := false;
  end;
  if isset then
  begin
    if (x <= 0) or (y <= 0) or (x >= 80) or (y >= 25) then
      isset := false;
  end;
  checknext := isset;
end;
//ASCII 
procedure neweat;
begin
  e.x := random(78) + 2;
  e.y := random(23) + 2;
  
  while (not checknext(e.x, e.y)) do
  begin
    e.x := random(78) + 2;
    e.y := random(23) + 2;
  end;
end;
 
procedure movesnake(x, y: integer);
var
  i: integer;
begin
  for i := 1 to width do
  begin
    snakebody[i] := snakebody[i + 1];
  end;
  
  snakebody[width].x := x;
  snakebody[width].y := y;
  if (x = e.x) and (y = e.y) then 
  begin
    width := width + 1;
    snakebody[width].x := x;
    snakebody[width].y := y;
    neweat;
  end;
end;
 
begin
  clrscr;
  textcolor(5);
  gotoxy(50, 10);
  write('1 - ЛЕГКО');
  gotoxy(50,12);
  write('2 - СРЕДНЕ');
  gotoxy(50,14);
  write('3 - СЛОЖНО');
  gotoxy(33, 10);
  textcolor(14);
  write('**********ЗМЕЕЧКА**********');
  textcolor(4);
  gotoxy(33, 28);
  write('ТОЛЬКО АНГЛИЙСКАЯ РАСКЛАДКА');
  textcolor(14);
  gotoxy(20, 12);
  write('НАЖМИ W ДЛЯ ПЕРЕДВИЖЕНИЯ ВПЕРЕД');
  gotoxy(20, 14);
  write('НАЖМИ А ДЛЯ ПОВОРОТА НАПРАВО');
  gotoxy(20, 16);
  write('НАЖМИ D ДЛЯ ПОВОРОТА НАЛЕВО');
  gotoxy(20, 18);
  write('НАЖМИ S ДЛЯ ПЕРЕДВИЖЕНИЯ ВНИЗ');
  gotoxy(27, 22);
  write('ВЫБЕРИ УРОВЕНЬ СЛОЖНОСТИ И НАЖМИ ENTER');
  gotoxy(42,23);
  write('╔═╗');
  gotoxy(42,25);
  write('╚═╝');
  gotoxy(43,24);
  readln(sl);
  clrscr;
  gameover := false;
  width := 3;
  snakebody[1].x := 1;
  snakebody[1].y := 1;
  snakebody[2].x := 2;
  snakebody[2].y := 1;
  snakebody[3].x := 2;
  snakebody[3].y := 1;
  clrscr;
  v := 1;
  randomize;
  neweat;
  while (width < maxwidth) do 
  begin
    if (keypressed) then
    begin
      key := readkey; 
      case key of
        'w': begin if v = 4 then continue;v := 3; end;
        's': begin if v = 3 then continue;v := 4; end;
        'a': begin if v = 1 then continue;v := 2; end;
        'd': begin if v = 2 then continue;v := 1; end;
        //'p': begin repeat delay(1000); until KeyDetect(Ord(readkey))='p';end; 
        #27: break; 
      end;
    end;
    clrscr;
    case v of
      1:
        begin
          nx := snakebody[width].x + 1;
          ny := snakebody[width].y; end; 
      2:
        begin
          nx := snakebody[width].x - 1;
          ny := snakebody[width].y; end;
      3:
        begin
          nx := snakebody[width].x;
          ny := snakebody[width].y - 1; end;
      4:
        begin
          nx := snakebody[width].x;
          ny := snakebody[width].y + 1; end;
    end;
    
    if (not checknext(nx, ny)) then
    begin
      gameover := true;
      break;
    end;
    
    textcolor(15);
    //правая стенка
    gotoxy(80, 1);
    write('║');
    gotoxy(80, 2);
    write('║');
    gotoxy(80, 3);
    write('║');
    gotoxy(80, 4);
    write('║');
    gotoxy(80, 5);
    write('║');
    gotoxy(80, 6);
    write('║');
    gotoxy(80, 7);
    write('║');
    gotoxy(80, 8);
    write('║');
    gotoxy(80, 9);
    write('║');
    gotoxy(80, 10);
    write('║');
    gotoxy(80, 11);
    write('║');
    gotoxy(80, 12);
    write('║');
    gotoxy(80, 13);
    write('║');
    gotoxy(80, 14);
    write('║');
    gotoxy(80, 15);
    write('║');
    gotoxy(80, 16);
    write('║');
    gotoxy(80, 17);
    write('║');
    gotoxy(80, 18);
    write('║');
    gotoxy(80, 19);
    write('║');
    gotoxy(80, 20);
    write('║');
    gotoxy(80, 21);
    write('║');
    gotoxy(80, 22);
    write('║');
    gotoxy(80, 23);
    write('║');
    gotoxy(80, 24);
    write('║');
    //нижняя граница
    gotoxy(1, 25);
    write('═══════════════════════════════════════════════════════════════════════════════╝');
    
    case sl of
    1: if sl=1 then begin speed:=300;end;
    2: if sl=2 then begin speed:=200; end;
    3: if sl=3 then begin speed:=100;end;
      end;  
    textcolor(12); //яблоко
    movesnake(nx, ny);
    gotoxy(e.x, e.y);
    write('¤'); 
    for i := 1 to width do
    begin
      gotoxy(snakebody[i].x, snakebody[i].y);  //голова
      textcolor(10);
      write('█');
 
    end;
    gotoxy(snakebody[width].x, snakebody[i].y);
    textcolor(14);
    write('█');
    gotoxy(80, 25);
    delay(speed)
  end;
  clrscr;
  if (gameover) then 
  begin
    textcolor(12);
    //game
    gotoxy(17, 3);
    write('  _______       __       ___      ___   _______ ');
    gotoxy(17,4);
    write(' /" _   "|     /""\     |"  \    /"  | /"     "|');
    gotoxy(17,5);
    write('(: ( \___)    /    \     \   \  //   |(: ______)');
    gotoxy(17,6);
    write(' \/ \        /  /\  \    /\\  \/.    | \/    |  ');
    gotoxy(17,7);
    write(' //  \ ___  //  __   \  |: \.        | // ___)_ ');
    gotoxy(17,8);
    write('(:   _(  _|/   /  \\  \ |.  \    /:  |(:      "| ');
    gotoxy(17,9);
    write(' \_______)(___/    \___)|___|\__/|___| \_______)  ');
    //OVER
    gotoxy(17,11);
    write('    ______  ___      ___  _______   _______  ');
    gotoxy(17,12);
    write('   /    " \|"  \    /"  |/"     "| /"      \ ');
    gotoxy(17,13);
    write('  // ____  \\   \  //  /(: ______)|:        | ');
    gotoxy(17,14);
    write(' /  /    ) :)\\  \/. ./  \/    |  |_____/   )  ');
    gotoxy(17,15);
    write('(: (____/ //  \.    //   // ___)_  //      /  ');
    gotoxy(17,16);
    write(' \        /    \\   /   (:      "||:  __   \');
    gotoxy(17,17);
    write('  "_____/      \__/     \_______)|__|  \___)  ');
    gotoxy(1, 1);
    write('╔══════════════════════════════════════════════════════════════════════════════╗');
    gotoxy(80, 2);
    write('║');
    gotoxy(80, 3);
    write('║');
    gotoxy(80, 4);
    write('║');
    gotoxy(80, 5);
    write('║');
    gotoxy(80, 6);
    write('║');
    gotoxy(80, 7);
    write('║');
    gotoxy(80, 8);
    write('║');
    gotoxy(80, 9);
    write('║');
    gotoxy(80, 10);
    write('║');
    gotoxy(80, 11);
    write('║');
    gotoxy(80, 12);
    write('║');
    gotoxy(80, 13);
    write('║');
    gotoxy(80, 14);
    write('║');
    gotoxy(80, 15);
    write('║');
    gotoxy(80, 16);
    write('║');
    gotoxy(80, 17);
    write('║');
    gotoxy(80, 18);
    write('║');
    gotoxy(80, 19);
    write('║');
    gotoxy(80, 20);
    write('║');
    gotoxy(80, 21);
    write('║');
    gotoxy(80, 22);
    write('║');
    gotoxy(80, 23);
    write('║');
    gotoxy(80, 24);
    write('║');
    gotoxy(1, 2);
    write('║');
    gotoxy(1, 3);
    write('║');
    gotoxy(1, 4);
    write('║');
    gotoxy(1, 5);
    write('║');
    gotoxy(1, 6);
    write('║');
    gotoxy(1, 7);
    write('║');
    gotoxy(1, 8);
    write('║');
    gotoxy(1, 9);
    write('║');
    gotoxy(1, 10);
    write('║');
    gotoxy(1, 11);
    write('║');
    gotoxy(1, 12);
    write('║');
    gotoxy(1, 13);
    write('║');
    gotoxy(1, 14);
    write('║');
    gotoxy(1, 15);
    write('║');
    gotoxy(1, 16);
    write('║');
    gotoxy(1, 17);
    write('║');
    gotoxy(1, 18);
    write('║');
    gotoxy(1, 19);
    write('║');
    gotoxy(1, 20);
    write('║');
    gotoxy(1, 21);
    write('║');
    gotoxy(1, 22);
    write('║');
    gotoxy(1, 23);
    write('║');
    gotoxy(1, 24);
    write('║');
    gotoxy(1, 25);
    write('╚══════════════════════════════════════════════════════════════════════════════╝');
  end
  else
  begin
    textcolor(11);
    gotoxy(35, 12);
    writeln('*****ВЫ ВЫЙГРАЛИ!*****');
  end;
  textcolor(12);
  gotoxy(25, 20);
  writeln('*****НАЖМИТЕ ENTER ДЛЯ ВЫХОДА*****');
  textcolor(15);
  readln;
end.
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
07.07.2017, 15:11
Ответы с готовыми решениями:

Ввести в типизированный файл ФИО и лучший результат спортсмена, а потом изменить его так, чтобы осталось N лучший спортсменов
Задание состоит в том, чтобы ввести в типизированный файл ФИО и лучший результат спортсмена, а потом изменить его так, чтобы осталось N...

Вывести лучший результат заплыва
Лаба №1 Вариант 11. 1. В ЭВМ поступают результаты соревнований по плаванию для трех спортсменов. Составьте программу,...

Определить лучший результат по прыжкам в длину
В соревнованиях по прыжкам в длину участвовали N-спортсменов. Каждый спортсмен мог сделать М-попыток. Результаты (длины прыжков) ...

5
0 / 0 / 0
Регистрация: 07.07.2017
Сообщений: 2
08.07.2017, 10:50  [ТС]
Накодил змейку и нужно теперь сделать лучший результат, а я не знаю как. Можете примерно оюбъяснить как сделать это. Знаю что нужен файл отдельный
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
program zmeika;
 
uses crt; //Sestem.Windows.Forms, System.Drawing,;
type
  spoint = record
    x: integer;
    y: integer;
  end;
 
const
  maxwidth = 101;
 
var
  thebest: text;
  thebestwidth,width: integer;
  e: spoint;
  snakebody: array[1..maxwidth] of spoint;
  i, nx, ny: integer;
  v: byte;
  gameover: boolean;
  key: char;
  sl: byte;
  speed: integer;
  //f: Form;
 
 
function checknext(x: integer; y: integer): boolean;
var
  isset: boolean;
  i: integer;
  
//  begin
//f:= new Form();
//f.icon:= new Icon('F:\Кружки\Paskal\Программы PascalABC.NET\Змейка\змейка.ico');
//Application.Run(f);
//end;
 
Begin
  assign(thebest,'thebestresult');
  isset := true;
  for i := 1 to width do
  begin
    if (x = snakebody[i].x) and (y = snakebody[i].y) then
      isset := false;
  end;
  if isset then
  begin
    if (x <= 0) or (y <= 0) or (x >= 80) or (y >= 25) then
      isset := false;
  end;
  checknext := isset;
end;
//ASCII 
procedure neweat;
begin
  e.x := random(78) + 2;
  e.y := random(23) + 2;
  
  while (not checknext(e.x, e.y)) do
  begin
    e.x := random(78) + 2;
    e.y := random(23) + 2;
  end;
end;
 
procedure movesnake(x, y: integer);
var
  i: integer;
begin
  for i := 1 to width do
  begin
    snakebody[i] := snakebody[i + 1];
  end;
  
  snakebody[width].x := x;
  snakebody[width].y := y;
  if (x = e.x) and (y = e.y) then 
  begin
    width := width + 1;
    snakebody[width].x := x;
    snakebody[width].y := y;
    neweat;
  end;
end;
 
begin
  clrscr;
  textcolor(5);
  gotoxy(50, 2);
  write('1 - ЛЕГКО');
  gotoxy(50,4);
  write('2 - СРЕДНЕ');
  gotoxy(50,6);
  write('3 - СЛОЖНО');
  gotoxy(33, 10);
  textcolor(14);
  write('**********ЗМЕЕЧКА**********');
  textcolor(4);
  gotoxy(33, 28);
  write('ТОЛЬКО АНГЛИЙСКАЯ РАСКЛАДКА');
  textcolor(14);
  gotoxy(20, 12);
  write('НАЖМИ W ДЛЯ ПЕРЕДВИЖЕНИЯ ВПЕРЕД');
  gotoxy(20, 14);
  write('НАЖМИ А ДЛЯ ПОВОРОТА НАПРАВО');
  gotoxy(20, 16);
  write('НАЖМИ D ДЛЯ ПОВОРОТА НАЛЕВО');
  gotoxy(20, 18);
  write('НАЖМИ S ДЛЯ ПЕРЕДВИЖЕНИЯ ВНИЗ');
  gotoxy(27, 22);
  write('ВЫБЕРИ УРОВЕНЬ СЛОЖНОСТИ И НАЖМИ ENTER');
  gotoxy(42,23);
  write('╔═╗');
  gotoxy(42,25);
  write('╚═╝');
  gotoxy(43,24);
  readln(sl);
  clrscr;
  //if sl>3 then begin clrscr; gotoxy(42,24);write('ERROR 404     INVALID BUTTON'); gameover := True; end; 
  gameover := false;
  width := 3;
  snakebody[1].x := 1;
  snakebody[1].y := 1;
  snakebody[2].x := 2;
  snakebody[2].y := 1;
  snakebody[3].x := 2;
  snakebody[3].y := 1;
  clrscr;
  v := 1;
  randomize;
  neweat;
  while (width < maxwidth) do 
  begin
    if (keypressed) then
    begin
      key := readkey; 
      case key of
        'w': begin if v = 4 then continue;v := 3; end;
        's': begin if v = 3 then continue;v := 4; end;
        'a': begin if v = 1 then continue;v := 2; end;
        'd': begin if v = 2 then continue;v := 1; end;
        'q': begin if v = 8 then continue;v := 7; end;
        'e': begin if v = 7 then continue;v := 8; end;
        'z': begin if v = 5 then continue;v := 6; end;
        'c': begin if v = 6 then continue;v := 5; end;
        //'p': begin repeat delay(1000); until KeyDetect(Ord(readkey))='p';end; 
        #27: break; 
      end;
    end;
    clrscr;
    case v of
      1:
        begin
          nx := snakebody[width].x + 1;
          ny := snakebody[width].y; end; 
      2:
        begin
          nx := snakebody[width].x - 1;
          ny := snakebody[width].y; end;
      3:
        begin
          nx := snakebody[width].x;
          ny := snakebody[width].y - 1; end;
      4:
        begin
          nx := snakebody[width].x;
          ny := snakebody[width].y + 1; end;
      5:
        begin
          nx := snakebody[width].x + 1;
          ny := snakebody[width].y + 1; end;
      6:
        begin
          nx := snakebody[width].x - 1;
          ny := snakebody[width].y + 1; end;
      7:
        begin
          nx := snakebody[width].x - 1;
          ny := snakebody[width].y - 1; end;
      8:
        begin
          nx := snakebody[width].x + 1;
          ny := snakebody[width].y - 1; end;
    end;
    
    if (not checknext(nx, ny)) then
    begin
      gameover := true;
      break;
    end;
    
    textcolor(15);
    //правая стенка
   for i:=1 to 24 do
   begin
   gotoxy(80,i);
   write('║');
   end;
    //нижняя граница
    gotoxy(1, 25);
    write('═══════════════════════════════════════════════════════════════════════════════╝');
    //лучший счет
      textcolor(12);
      gotoxy(82,10);
      write('999');
      textcolor(9);
      gotoxy(81,10);
      write('║');
      gotoxy(86,10);
      write('║');
      gotoxy(81,9);
      write('╔════╗');
      gotoxy(81,11);
      write('╚════╝');
      textcolor(12);
      gotoxy(81,8);
      write('Лучший счет:');
    
    case sl of
    1: if sl=1 then begin speed:=300;end;
    2: if sl=2 then begin speed:=200; end;
    3: if sl=3 then begin speed:=100;end;
      end;  
    textcolor(12); //яблоко     provide предоставлять
    movesnake(nx, ny);
    gotoxy(e.x, e.y);
    write('¤'); 
    for i := 1 to width do
    begin
      gotoxy(snakebody[i].x, snakebody[i].y);  //голова
      textcolor(10);
      write('█');
      gotoxy(82,5);
      write(width-3);
      gotoxy(81,5);
      write('║');
      gotoxy(85,5);
      write('║');
      gotoxy(81,4);
      write('╔═══╗');
      gotoxy(81,6);
      write('╚═══╝');
      gotoxy(81,3);
      write('Счет:');
    end;
    gotoxy(snakebody[width].x, snakebody[i].y);
    textcolor(14);
    write('█');
    gotoxy(80, 25);
    delay(speed)
  end;
  clrscr;
  if (gameover) then 
  begin
    textcolor(12);
    //game
    gotoxy(17, 3);
    write('  _______       __       ___      ___   _______ ');
    gotoxy(17,4);
    write(' /" _   "|     /""\     |"  \    /"  | /"     "|');
    gotoxy(17,5);
    write('(: ( \___)    /    \     \   \  //   |(: ______)');
    gotoxy(17,6);
    write(' \/ \        /  /\  \    /\\  \/.    | \/    |  ');
    gotoxy(17,7);
    write(' //  \ ___  //  __   \  |: \.        | // ___)_ ');
    gotoxy(17,8);
    write('(:   _(  _|/   /  \\  \ |.  \    /:  |(:      "| ');
    gotoxy(17,9);
    write(' \_______)(___/    \___)|___|\__/|___| \_______)  ');
    //OVER
    gotoxy(17,11);
    write('    ______  ___      ___  _______   _______  ');
    gotoxy(17,12);
    write('   /    " \|"  \    /"  |/"     "| /"      \ ');
    gotoxy(17,13);
    write('  // ____  \\   \  //  /(: ______)|:        | ');
    gotoxy(17,14);
    write(' /  /    ) :)\\  \/. ./  \/    |  |_____/   )  ');
    gotoxy(17,15);
    write('(: (____/ //  \.    //   // ___)_  //      /  ');
    gotoxy(17,16);
    write(' \        /    \\   /   (:      "||:  __   \');
    gotoxy(17,17);
    write('  "_____/      \__/     \_______)|__|  \___)  ');
    gotoxy(1, 1);
    write('╔══════════════════════════════════════════════════════════════════════════════╗');
   for i:=2 to 24 do
   begin
   gotoxy(80,i);
   write('║');
   end;
for i:=2 to 24 do
   begin
   gotoxy(1,i);
   write('║');
   end;
    gotoxy(1, 25);
    write('╚══════════════════════════════════════════════════════════════════════════════╝');
  end
  else
  begin
    textcolor(11);
    gotoxy(35, 12);
    writeln('*****ВЫ ВЫЙГРАЛИ!*****');
  end;
  textcolor(12);
  gotoxy(25, 20);
  writeln('*****НАЖМИТЕ ENTER ДЛЯ ВЫХОДА*****');
  textcolor(15);
  readln;
end.
То что не читаемо это просто символы ╚═ и тд
0
Alvin Seville
 Аватар для Соколиный глаз
343 / 273 / 134
Регистрация: 25.07.2014
Сообщений: 4,537
Записей в блоге: 22
11.07.2017, 16:41
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
uses GraphABC;
const
  step = 10;
 
type
  Direction = (UP, DOWN, LEFT, RIGHT);
 
type
  Point = class
  private 
    xc, yc: integer;
  public 
    property X: integer read xc write xc;
    property Y: integer read yc write yc;
    
    constructor(xc, yc: integer);
    begin
      X := xc;Y := yc;
    end;
    
    class function operator=(p, p2: Point) := (p.X = p2.X) and (p.Y = p2.Y);
  end;
  
  Vector = class
  private 
    Ap, Bp: Point;
    
    function CoordinateRead()  := new Point(Bp.X - Ap.X, Bp.Y - Ap.Y);
  
  public 
    property A: Point read Ap write Ap;
    property B: Point read Bp write Bp;
    ///Vector coodinates
    property Coordinate: Point read CoordinateRead;
    
    constructor(Ap, Bp: Point);
    begin
      A := Ap;B := Bp;
    end;
    
    function Dist()  := Sqrt(Sqr(Coordinate.X) + Sqr(Coordinate.Y));
    
    class function VectorDirection(v: Vector): Direction;
    begin
      if (v.Coordinate.X = 0) and (v.Coordinate.Y > 0) then VectorDirection := UP;
      if (v.Coordinate.X = 0) and (v.Coordinate.Y < 0) then VectorDirection := DOWN;
      if (v.Coordinate.X > 0) and (v.Coordinate.Y = 0) then VectorDirection := RIGHT;
      if (v.Coordinate.X < 0) and (v.Coordinate.Y = 0) then VectorDirection := LEFT;
    end;
    
    class function VectorsInversed(v1, v2: Vector): boolean;
    begin
      var a := ((VectorDirection(v1) = UP) and (VectorDirection(v2) = DOWN)) or ((VectorDirection(v1) = RIGHT) and (VectorDirection(v2) = LEFT));
      var b := ((VectorDirection(v2) = UP) and (VectorDirection(v1) = DOWN)) or ((VectorDirection(v2) = RIGHT) and (VectorDirection(v1) = LEFT));
      VectorsInversed := a or b;
    end;
  end;
 
var
  a: List<Point>;
  w, h: integer;
 
procedure DrawSnake();
begin
  ClearWindow;
  for var i := 0 to a.Count - 2 do Line(a[i].X, a[i].Y, a[i + 1].X, a[i + 1].Y);
  Redraw;
end;
 
procedure KeyDown(Key: integer);
var
  vL, vC, vF: Vector;
  d1, d2: Direction;
  done: boolean;
begin
  var PrevP := a[a.Count - 2];
  var LastP := a[a.Count - 1];
  vL := new Vector(PrevP, LastP);
  d1 := Vector.VectorDirection(vL);
  
  done := false;
  case Key of
    VK_Left:
      begin
        vC := new Vector(LastP, new Point(LastP.X - step, LastP.Y));
        d2 := Vector.VectorDirection(vC);
        if not Vector.VectorsInversed(vC, vL) then
        begin
          if Vector.VectorDirection(vL) <> Vector.VectorDirection(vC) then
            a.Add(new Point(LastP.X - step, LastP.Y))
          else
          begin
            LastP.X := LastP.X - step;
            LastP.Y := LastP.Y;
          end;
          done := true;
        end;
      end;
    VK_Right:
      begin
        vC := new Vector(LastP, new Point(LastP.X + step, LastP.Y));
        d2 := Vector.VectorDirection(vC);
        if not Vector.VectorsInversed(vC, vL) then
        begin
          if Vector.VectorDirection(vL) <> Vector.VectorDirection(vC) then
            a.Add(new Point(LastP.X + step, LastP.Y))
          else
          begin
            LastP.X := LastP.X + step;
            LastP.Y := LastP.Y;
          end;
          done := true;
        end;
      end;
    VK_Up:
      begin
        vC := new Vector(LastP, new Point(LastP.X, LastP.Y - step));
        d2 := Vector.VectorDirection(vC);
        if not Vector.VectorsInversed(vC, vL) then
        begin
          if Vector.VectorDirection(vL) <> Vector.VectorDirection(vC) then
            a.Add(new Point(LastP.X, LastP.Y - step))
          else
          begin
            LastP.X := LastP.X;
            LastP.Y := LastP.Y - step;
          end;
          done := true;
        end;
      end;
    VK_Down:
      begin
        vC := new Vector(LastP, new Point(LastP.X, LastP.Y + step));
        d2 := Vector.VectorDirection(vC);
        if not Vector.VectorsInversed(vC, vL) then
        begin
          if Vector.VectorDirection(vL) <> Vector.VectorDirection(vC) then
            a.Add(new Point(LastP.X, LastP.Y + step))
          else
          begin
            LastP.X := LastP.X;
            LastP.Y := LastP.Y + step;
          end;
          done := true;
        end;
      end;
  end;
  
  if done then
  begin
    vF := new Vector(a[0], a[1]);
    if Vector.VectorDirection(vF) = UP then vF.A.Y := vF.A.Y + step;
    if Vector.VectorDirection(vF) = DOWN then vF.A.Y := vF.A.Y - step;
    if Vector.VectorDirection(vF) = RIGHT then vF.A.X := vF.A.X + step;
    if Vector.VectorDirection(vF) = LEFT then vF.A.X := vF.A.X - step;
    if vF.A = a[1] then a.Remove(a[0]);
    DrawSnake();
  end;
end;
 
begin
  SetWindowCaption('Snake');
  
  w := 600;h := 600;
  SetWindowSize(w, h);
  SetWindowIsFixedSize(true);
  
  LockDrawing;
  
  a := new List<Point>();
  a.Add(new Point(100, 100));
  a.Add(new Point(400, 100));
  
  DrawSnake();
  
  OnKeyDown := KeyDown;
end.
Как вариант. В списке - только углы поворотов змейки

Добавлено через 5 часов 9 минут
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
uses GraphABC;
const
  step = 20;
 
type
  Point = class
  private 
    xc, yc: integer;
  public 
    property X: integer read xc write xc;
    property Y: integer read yc write yc;
    
    constructor(xc, yc: integer);
    begin
      X := xc;Y := yc;
    end;
    
    class function operator=(p, p2: Point) := (p.X = p2.X) and (p.Y = p2.Y);
  end;
  
  Vector = class
  private 
    xc, yc: integer;
  
  public 
    property X: integer read xc write xc;
    property Y: integer read yc write yc;
    
    constructor(xc, yc: integer);
    begin
      X := xc;Y := yc;
    end;
    
    function Dist()  := Sqrt(Sqr(X) + Sqr(Y));
    
    procedure Normalize();
    begin
      X := Round(X / Dist);
      Y := Round(Y / Dist);
    end;
    
    class function VectorsInversed(v1, v2: Vector) := (v1.X - v2.X = 0) and (v1.Y - v2.Y = 0);
  end;
 
var
  a: List<Point>;
  w, h: integer;
 
procedure DrawSnake();
begin
  ClearWindow;
  for var i := 0 to a.Count - 2 do Line(a[i].X, a[i].Y, a[i + 1].X, a[i + 1].Y);
  for var i := 0 to a.Count - 1 do DrawCircle(a[i].X, a[i].Y, 4);
  DrawCircle(a[a.Count - 1].X, a[a.Count - 1].Y, 10);
  FillCircle(a[a.Count - 1].X, a[a.Count - 1].Y, 10);
  Redraw;
end;
 
procedure KeyDown(Key: integer);
var
  vL, vC, vF: Vector;
  done: boolean;
begin
  var PrevP := a[a.Count - 2];
  var LastP := a[a.Count - 1];
  vL := new Vector(PrevP.X - LastP.X, PrevP.Y - LastP.Y);
  vL.Normalize();
  
  done := false;
  case Key of
    VK_Left:
      begin
        vC := new Vector(-step, 0);
        vC.Normalize();
        if (LastP.X - step > 0) and not Vector.VectorsInversed(vC, vL) then
        begin
          if (vL.X <> vC.X) and (vL.Y <> vC.Y) then
            a.Add(new Point(LastP.X - step, LastP.Y))
          else
          begin
            LastP.X := LastP.X - step;
            LastP.Y := LastP.Y;
          end;
          done := true;
        end;
      end;
    VK_Right:
      begin
        vC := new Vector(step, 0);
        vC.Normalize();
        if (LastP.X + step < w) and not Vector.VectorsInversed(vC, vL) then
        begin
          if (vL.X <> vC.X) and (vL.Y <> vC.Y) then
            a.Add(new Point(LastP.X + step, LastP.Y))
          else
          begin
            LastP.X := LastP.X + step;
            LastP.Y := LastP.Y;
          end;
          done := true;
        end;
      end;
    VK_Up:
      begin
        vC := new Vector(0, -step);
        vC.Normalize();
        if (LastP.Y - step > 0) and not Vector.VectorsInversed(vC, vL) then
        begin
          if (vL.X <> vC.X) and (vL.Y <> vC.Y) then
            a.Add(new Point(LastP.X, LastP.Y - step))
          else
          begin
            LastP.X := LastP.X;
            LastP.Y := LastP.Y - step;
          end;
          done := true;
        end;
      end;
    VK_Down:
      begin
        vC := new Vector(0, step);
        vC.Normalize();
        if (LastP.Y + step < h) and not Vector.VectorsInversed(vC, vL) then
        begin
          if (vL.X <> vC.X) and (vL.Y <> vC.Y) then
            a.Add(new Point(LastP.X, LastP.Y + step))
          else
          begin
            LastP.X := LastP.X;
            LastP.Y := LastP.Y + step;
          end;
          done := true;
        end;
      end;
  end;
  
  if done then
  begin
    vF := new Vector(a[1].X - a[0].X, a[1].Y - a[0].Y);
    vF.Normalize();
    vF.X:=vF.X*step;
    vF.Y:=vF.Y*step;
    a[0].X:=a[0].X+vF.X;
    a[0].Y:=a[0].Y+vF.Y;
    if (a[0].X = a[1].X) and (a[0].Y = a[1].Y) then a.Remove(a[0]);
    DrawSnake();
  end;
end;
 
begin
  SetWindowCaption('Snake');
  
  w := 600;h := 600;
  SetWindowSize(w, h);
  SetWindowIsFixedSize(true);
  
  LockDrawing;
  SetPenColor(clRed);
  SetPenRoundCap(true);
  SetPenWidth(5);
  
  a := new List<Point>();
  a.Add(new Point(100, 100));
  a.Add(new Point(400, 100));
  
  DrawSnake();
  
  OnKeyDown := KeyDown;
end.
Вот, посмотрите, почитайте на ночь.
0
 Аватар для kolay_ne
16 / 18 / 11
Регистрация: 07.03.2016
Сообщений: 362
13.07.2017, 22:19
Ну это же не змейка! Это не настоящая змейка!

Добавлено через 21 секунду
И вообще: где её пища?
0
 Аватар для Zwelenewskiy
129 / 127 / 107
Регистрация: 09.01.2017
Сообщений: 1,651
13.07.2017, 23:07
По-моему, она слишком сильно похудела без пищи...
0
Alvin Seville
 Аватар для Соколиный глаз
343 / 273 / 134
Регистрация: 25.07.2014
Сообщений: 4,537
Записей в блоге: 22
17.07.2017, 16:41
Цитата Сообщение от Zwelenewskiy Посмотреть сообщение
По-моему, она слишком сильно похудела без пищи...
Да
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
17.07.2017, 16:41
Помогаю со студенческими работами здесь

Выбрать и напечатать лучший результат соревнований
Сороки выполнения желательно до 24:00. В ЭВМ поступают результаты соревнований по плаванию для трех спортсменов. Выбрать и напечатать...

Составьте программу, которая выбирает лучший результат
В компьютер поступают результаты соревнований по плаванию для трех спортсменов. Составьте программу, которая выбирает лучший результат и...

Напечатать лучший результат соревнований по прыжкам в длину
Помогите написать программу пожалуйста: Напечатать лучший результат соревнований по прыжкам в длину. Всего в соревнованиях...

Вывести лучший результат плюс фамилию победителя
Нам дано условие задачи: &quot;в базу данных поступают результаты соревнований по метанию мяча. В соревнованиях n спортсменов. Вывести лучший...

Выдать данные о спортсмене, показавшем лучший результат.
Даны сведения о результатах соревнования по бегу на 100 метров: фамилия и имя спортсмена, спортивное общество, результат в секундах. Выдать...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
6
Ответ Создать тему
Новые блоги и статьи
PhpStorm 2025.3: WSL Terminal всегда стартует в ~
and_y87 14.12.2025
PhpStorm 2025. 3: WSL Terminal всегда стартует в ~ (home), игнорируя директорию проекта Симптом: После обновления до PhpStorm 2025. 3 встроенный терминал WSL открывается в домашней директории. . .
Как объединить две одинаковые БД Access с разными данными
VikBal 11.12.2025
Помогите пожалуйста !! Как объединить 2 одинаковые БД Access с разными данными.
Новый ноутбук
volvo 07.12.2025
Всем привет. По скидке в "черную пятницу" взял себе новый ноутбук Lenovo ThinkBook 16 G7 на Амазоне: Ryzen 5 7533HS 64 Gb DDR5 1Tb NVMe 16" Full HD Display Win11 Pro
Музыка, написанная Искусственным Интеллектом
volvo 04.12.2025
Всем привет. Некоторое время назад меня заинтересовало, что уже умеет ИИ в плане написания музыки для песен, и, собственно, исполнения этих самых песен. Стихов у нас много, уже вышли 4 книги, еще 3. . .
От async/await к виртуальным потокам в Python
IndentationError 23.11.2025
Армин Ронахер поставил под сомнение async/ await. Создатель Flask заявляет: цветные функции - провал, виртуальные потоки - решение. Не threading-динозавры, а новое поколение лёгких потоков. Откат?. . .
Поиск "дружественных имён" СОМ портов
Argus19 22.11.2025
Поиск "дружественных имён" СОМ портов На странице: https:/ / norseev. ru/ 2018/ 01/ 04/ comportlist_windows/ нашёл схожую тему. Там приведён код на С++, который показывает только имена СОМ портов, типа,. . .
Сколько Государство потратило денег на меня, обеспечивая инсулином.
Programma_Boinc 20.11.2025
Сколько Государство потратило денег на меня, обеспечивая инсулином. Вот решила сделать интересный приблизительный подсчет, сколько государство потратило на меня денег на покупку инсулинов. . . .
Ломающие изменения в C#.NStar Alpha
Etyuhibosecyu 20.11.2025
Уже можно не только тестировать, но и пользоваться C#. NStar - писать оконные приложения, содержащие надписи, кнопки, текстовые поля и даже изображения, например, моя игра "Три в ряд" написана на этом. . .
Мысли в слух
kumehtar 18.11.2025
Кстати, совсем недавно имел разговор на тему медитаций с людьми. И обнаружил, что они вообще не понимают что такое медитация и зачем она нужна. Самые базовые вещи. Для них это - когда просто люди. . .
Создание Single Page Application на фреймах
krapotkin 16.11.2025
Статья исключительно для начинающих. Подходы оригинальностью не блещут. В век Веб все очень привыкли к дизайну Single-Page-Application . Быстренько разберем подход "на фреймах". Мы делаем одну. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2025, CyberForum.ru