Форум программистов, компьютерный форум, киберфорум
C# для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.76/25: Рейтинг темы: голосов - 25, средняя оценка - 4.76
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6

Тетрисные гонки в консоли

06.01.2018, 04:10. Показов 4947. Ответов 14
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Доброго времени суток. Пишу курсовую по языку C#. Тему решил выбрать Консольные гонки, такие как были в тетрисе. Помогите разобраться. Программа рабочая, но во время выполнения вылетает за границы массива, и лагает в отображении. Я использовал потоки и массив чар. Вопрос в следующем, где моя ошибка. Мне нужно чтобы машинки падали вниз. Как правильно это сделать? Помогите пожалуйста. Я только учусь и не совсем могу понять где я допустил ошибку. Помогите. Не судите строго. Я начинающий программист.
Вот мой код.

C#
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace CarsKursova
{
    public static class Car
    {
        public static int x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,
                            x11, x12, x13, x14, x15, x16, x17, x18, x19, x20,
                            x21, x22, x23, x24, x25, x26, x27, x28, x29, x30,
                            x31, x32, x33, x34, x35, x36, x37, x38, x39, x40,
                            x41, x42, x43, x44, x45, x46, x47, x48, x49, x50,
                            x51, x52, x53, x54, x55, x56, x57, x58, x59, x60,
                            x61, x62, x63, x64, x65, x66, x67, x68, x69, x70,
                            x71, x72, x73, x74, x75, x76, x77, x78, x79, x80,
                            x81, x82, x83, x84,
                            y1, y2, y3, y4, y5, y6, y7, y8, y9, y10,
                            y11, y12, y13, y14, y15, y16, y17, y18, y19, y20,
                            y21, y22, y23, y24, y25, y26, y27, y28, y29, y30,
                            y31, y32, y33, y34, y35, y36, y37, y38, y39, y40,
                            y41, y42, y43, y44, y45, y46, y47, y48, y49, y50,
                            y51, y52, y53, y54, y55, y56, y57, y58, y59, y60,
                            y61, y62, y63, y64, y65, y66, y67, y68, y69, y70,
                            y71, y72, y73, y74, y75, y76, y77, y78, y79, y80,
                            y81, y82, y83, y84;
        public static string car = " ";
        public static bool game_over = false;
        public static bool fix = true;
        public static int score = 0;
        public static char[,] game_grond = new char[35, 29];
        public static char[,] game_gr = new char[35, 29];
        public static ConsoleKeyInfo key_info = new ConsoleKeyInfo();
        public static Thread background = new Thread(backgroundCars);
        public static int z;
        public static int p;
        public static void WriteAt(string s, int x, int y)
        {
            try
            {
                Console.SetCursorPosition(p + x, z + y);
                Console.Write(s);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
        public static void RisovPole()
        {
            p = Console.CursorTop;
            z = Console.CursorLeft;
            Console.ForegroundColor = ConsoleColor.Cyan;
            WriteAt("|*|", 29, 0);
            WriteAt("|*|", 29, 1);
            WriteAt("|*|", 29, 2);
            WriteAt("|*|", 29, 3);
            WriteAt("|*|", 29, 4);
            WriteAt("|*|", 29, 5);
            WriteAt("|*|", 29, 6);
            WriteAt("|*|", 29, 7);
            WriteAt("|*|", 29, 8);
            WriteAt("|*|", 29, 9);
            WriteAt("|*|", 29, 10);
            WriteAt("|*|", 29, 11);
            WriteAt("|*|", 29, 12);
            WriteAt("|*|", 29, 13);
            WriteAt("|*|", 29, 14);
            WriteAt("|*|", 29, 15);
            WriteAt("|*|", 29, 16);
            WriteAt("|*|", 29, 17);
            WriteAt("|*|", 29, 18);
            WriteAt("|*|", 29, 19);
            WriteAt("|*|", 29, 20);
            WriteAt("|*|", 29, 21);
            WriteAt("|*|", 29, 22);
            WriteAt("|*|", 29, 23);
            WriteAt("|*|", 29, 24);
            WriteAt("|*|", 29, 25);
            WriteAt("|*|", 29, 26);
            WriteAt("|*|", 29, 27);
            WriteAt("|*|", 29, 28);
            WriteAt("|*|", 29, 29);
            WriteAt("|*|", 29, 30);
            WriteAt("|*|", 29, 31);
            WriteAt("|*|", 29, 32);
            WriteAt("|*|", 29, 33);
            WriteAt("|*|", 29, 34);
            WriteAt("-----------------------------+*|", 0, 35);
            WriteAt("*******************************|", 0, 36);
            WriteAt("-------------------------------+\n\n\n\n\n\n\n\n\n\n\n", 0, 37);
            Console.ResetColor();
 
        }
        public static void carplins()
        {
            y1 = 27; x1 = 13; y22 = 31; x22 = 13;
            y2 = 27; x2 = 14; y23 = 31; x23 = 14;
            y3 = 27; x3 = 15; y24 = 31; x24 = 15;
            y4 = 28; x4 = 13; y25 = 32; x25 = 13;
            y5 = 28; x5 = 14; y26 = 32; x26 = 14;
            y6 = 28; x6 = 15; y27 = 32; x27 = 15;
 
            y7 = 29; x7 = 10; y28 = 33; x28 = 10;
            y8 = 29; x8 = 11; y29 = 33; x29 = 11;
            y9 = 29; x9 = 12; y30 = 33; x30 = 12;
            y10 = 29; x10 = 13; y31 = 33; x31 = 13;
            y11 = 29; x11 = 14; y32 = 33; x32 = 14;
            y12 = 29; x12 = 15; y33 = 33; x33 = 15;
            y13 = 29; x13 = 16; y34 = 33; x34 = 16;
            y14 = 29; x14 = 17; y35 = 33; x35 = 17;
            y15 = 29; x15 = 18; y36 = 33; x36 = 18;
 
            y16 = 30; x16 = 10; y37 = 34; x37 = 10;
            y17 = 30; x17 = 11; y38 = 34; x38 = 11;
            y18 = 30; x18 = 12; y39 = 34; x39 = 12;
            y19 = 30; x19 = 16; y40 = 34; x40 = 16;
            y20 = 30; x20 = 17; y41 = 34; x41 = 17;
            y21 = 30; x21 = 18; y42 = 34; x42 = 18;
        }
        public static void carplus()
        {
            game_grond[y1, x1] = '*'; game_grond[y22, x22] = '*';
            game_grond[y2, x2] = '*'; game_grond[y23, x23] = '*';
            game_grond[y3, x3] = '*'; game_grond[y24, x24] = '*';
            game_grond[y4, x4] = '*'; game_grond[y25, x25] = '*';
            game_grond[y5, x5] = '*'; game_grond[y26, x26] = '*';
            game_grond[y6, x6] = '*'; game_grond[y27, x27] = '*';
 
            game_grond[y7, x7] = '*'; game_grond[y28, x28] = '*';
            game_grond[y8, x8] = '*'; game_grond[y29, x29] = '*';
            game_grond[y9, x9] = '*'; game_grond[y30, x30] = '*';
            game_grond[y10, x10] = '_'; game_grond[y31, x31] = '_';
            game_grond[y11, x11] = '_'; game_grond[y32, x32] = '_';
            game_grond[y12, x12] = '_'; game_grond[y33, x33] = '_';
            game_grond[y13, x13] = '*'; game_grond[y34, x34] = '*';
            game_grond[y14, x14] = '*'; game_grond[y35, x35] = '*';
            game_grond[y15, x15] = '*'; game_grond[y36, x36] = '*';
 
            game_grond[y16, x16] = '*'; game_grond[y37, x37] = '*';
            game_grond[y17, x17] = '*'; game_grond[y38, x38] = '*';
            game_grond[y18, x18] = '*'; game_grond[y39, x39] = '*';
            game_grond[y19, x19] = '*'; game_grond[y40, x40] = '*';
            game_grond[y20, x20] = '*'; game_grond[y41, x41] = '*';
            game_grond[y21, x21] = '*'; game_grond[y42, x42] = '*';
 
        }
        public static void carview()
        {
            for (int i = 0; i < 35; i++)
            {
                Console.SetCursorPosition(0, i);
                for (int j = 0; j < 29; j++)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.Write(game_grond[i, j]);
                    Console.ResetColor();
                }
            }
        }
        public static void perview()
        {
            for (int i = 0; i < 26; i++)
            {
                Console.SetCursorPosition(0, i);
                for (int j = 0; j < 29; j++)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(game_gr[i, j]);
                    Console.ResetColor();
                }
            }
        }
        public static void pereshkoda()
        {
            Random h = new Random();
            int j = h.Next(1, 4);
            if (j == 1)
            {
                y43 = 0; x43 = 4; y64 = 4; x64 = 4;
                y44 = 0; x44 = 5; y65 = 4; x65 = 5;
                y45 = 0; x45 = 6; y66 = 4; x66 = 6;
                y46 = 1; x46 = 4; y67 = 5; x67 = 4;
                y47 = 1; x47 = 5; y68 = 5; x68 = 5;
                y48 = 1; x48 = 6; y69 = 5; x69 = 6;
 
                y49 = 2; x49 = 1; y70 = 6; x28 = 1;
                y50 = 2; x50 = 2; y71 = 6; x29 = 2;
                y51 = 2; x51 = 3; y72 = 6; x30 = 3;
                y52 = 2; x52 = 4; y73 = 3; x31 = 4;
                y53 = 2; x53 = 5; y74 = 6; x32 = 5;
                y54 = 2; x54 = 6; y75 = 6; x33 = 6;
                y55 = 2; x55 = 7; y76 = 6; x34 = 7;
                y56 = 2; x56 = 8; y77 = 6; x35 = 8;
                y57 = 2; x57 = 9; y78 = 6; x36 = 9;
 
                y58 = 3; x58 = 1; y79 = 7; x79 = 1;
                y59 = 3; x59 = 2; y80 = 7; x80 = 2;
                y60 = 3; x60 = 3; y81 = 7; x81 = 3;
                y61 = 3; x61 = 7; y82 = 7; x82 = 7;
                y62 = 3; x62 = 8; y83 = 7; x83 = 8;
                y63 = 3; x63 = 9; y84 = 7; x84 = 9;
            }
            if (j == 2)
            {
                y43 = 0; x43 = 13; y64 = 4; x64 = 13;
                y44 = 0; x44 = 14; y65 = 4; x65 = 14;
                y45 = 0; x45 = 15; y66 = 4; x66 = 15;
                y46 = 1; x46 = 13; y67 = 5; x67 = 13;
                y47 = 1; x47 = 14; y68 = 5; x68 = 14;
                y48 = 1; x48 = 15; y69 = 5; x69 = 15;
 
                y49 = 2; x49 = 10; y70 = 6; x28 = 10;
                y50 = 2; x50 = 11; y71 = 6; x29 = 11;
                y51 = 2; x51 = 12; y72 = 6; x30 = 12;
                y52 = 2; x52 = 13; y73 = 3; x31 = 13;
                y53 = 2; x53 = 14; y74 = 6; x32 = 14;
                y54 = 2; x54 = 15; y75 = 6; x33 = 15;
                y55 = 2; x55 = 16; y76 = 6; x34 = 16;
                y56 = 2; x56 = 17; y77 = 6; x35 = 17;
                y57 = 2; x57 = 18; y78 = 6; x36 = 18;
 
                y58 = 3; x58 = 10; y79 = 7; x79 = 10;
                y59 = 3; x59 = 11; y80 = 7; x80 = 11;
                y60 = 3; x60 = 12; y81 = 7; x81 = 12;
                y61 = 3; x61 = 16; y82 = 7; x82 = 16;
                y62 = 3; x62 = 17; y83 = 7; x83 = 17;
                y63 = 3; x63 = 18; y84 = 7; x84 = 18;
            }
            if (j == 3)
            {
                y43 = 0; x43 = 22; y64 = 4; x64 = 22;
                y44 = 0; x44 = 23; y65 = 4; x65 = 23;
                y45 = 0; x45 = 24; y66 = 4; x66 = 24;
                y46 = 1; x46 = 22; y67 = 5; x67 = 22;
                y47 = 1; x47 = 23; y68 = 5; x68 = 23;
                y48 = 1; x48 = 24; y69 = 5; x69 = 24;
 
                y49 = 2; x49 = 19; y70 = 6; x28 = 19;
                y50 = 2; x50 = 20; y71 = 6; x29 = 20;
                y51 = 2; x51 = 21; y72 = 6; x30 = 21;
                y52 = 2; x52 = 22; y73 = 3; x31 = 22;
                y53 = 2; x53 = 23; y74 = 6; x32 = 23;
                y54 = 2; x54 = 24; y75 = 6; x33 = 24;
                y55 = 2; x55 = 25; y76 = 6; x34 = 25;
                y56 = 2; x56 = 26; y77 = 6; x35 = 26;
                y57 = 2; x57 = 27; y78 = 6; x36 = 27;
 
                y58 = 3; x58 = 19; y79 = 7; x79 = 19;
                y59 = 3; x59 = 20; y80 = 7; x80 = 20;
                y60 = 3; x60 = 21; y81 = 7; x81 = 21;
                y61 = 3; x61 = 25; y82 = 7; x82 = 25;
                y62 = 3; x62 = 26; y83 = 7; x83 = 26;
                y63 = 3; x63 = 27; y84 = 7; x84 = 27;
            }
        }
        public static void pereshkodaplus()
        {
            game_gr[y43, x43] = '*'; game_gr[y64, x64] = '*';
            game_gr[y44, x44] = '*'; game_gr[y65, x65] = '*';
            game_gr[y45, x45] = '*'; game_gr[y66, x66] = '*';
            game_gr[y46, x46] = '*'; game_gr[y67, x67] = '*';
            game_gr[y47, x47] = '*'; game_gr[y68, x68] = '*';
            game_gr[y48, x48] = '*'; game_gr[y69, x69] = '*';
 
            game_gr[y49, x49] = '*'; game_gr[y70, x70] = '*';
            game_gr[y50, x50] = '*'; game_gr[y71, x71] = '*';
            game_gr[y51, x51] = '*'; game_gr[y72, x72] = '*';
            game_gr[y52, x52] = '_'; game_gr[y73, x73] = '_';
            game_gr[y53, x53] = '_'; game_gr[y74, x74] = '_';
            game_gr[y54, x54] = '_'; game_gr[y75, x75] = '_';
            game_gr[y55, x55] = '*'; game_gr[y76, x76] = '*';
            game_gr[y56, x56] = '*'; game_gr[y77, x77] = '*';
            game_gr[y57, x57] = '*'; game_gr[y78, x78] = '*';
 
            game_gr[y58, x58] = '*'; game_gr[y79, x79] = '*';
            game_gr[y59, x59] = '*'; game_gr[y80, x80] = '*';
            game_gr[y60, x60] = '*'; game_gr[y81, x81] = '*';
            game_gr[y61, x61] = '*'; game_gr[y82, x82] = '*';
            game_gr[y62, x62] = '*'; game_gr[y83, x83] = '*';
            game_gr[y63, x63] = '*'; game_gr[y84, x84] = '*';
 
        }
        public static void ochPl()
        {
            game_grond[y1, x1] = ' '; game_grond[y22, x22] = ' ';
            game_grond[y2, x2] = ' '; game_grond[y23, x23] = ' ';
            game_grond[y3, x3] = ' '; game_grond[y24, x24] = ' ';
            game_grond[y4, x4] = ' '; game_grond[y25, x25] = ' ';
            game_grond[y5, x5] = ' '; game_grond[y26, x26] = ' ';
            game_grond[y6, x6] = ' '; game_grond[y27, x27] = ' ';
 
            game_grond[y7, x7] = ' '; game_grond[y28, x28] = ' ';
            game_grond[y8, x8] = ' '; game_grond[y29, x29] = ' ';
            game_grond[y9, x9] = ' '; game_grond[y30, x30] = ' ';
            game_grond[y10, x10] = ' '; game_grond[y31, x31] = ' ';
            game_grond[y11, x11] = ' '; game_grond[y32, x32] = ' ';
            game_grond[y12, x12] = ' '; game_grond[y33, x33] = ' ';
            game_grond[y13, x13] = ' '; game_grond[y34, x34] = ' ';
            game_grond[y14, x14] = ' '; game_grond[y35, x35] = ' ';
            game_grond[y15, x15] = ' '; game_grond[y36, x36] = ' ';
 
            game_grond[y16, x16] = ' '; game_grond[y37, x37] = ' ';
            game_grond[y17, x17] = ' '; game_grond[y38, x38] = ' ';
            game_grond[y18, x18] = ' '; game_grond[y39, x39] = ' ';
            game_grond[y19, x19] = ' '; game_grond[y40, x40] = ' ';
            game_grond[y20, x20] = ' '; game_grond[y41, x41] = ' ';
            game_grond[y21, x21] = ' '; game_grond[y42, x42] = ' ';
        }
        public static void pereshkodaoch()
        {
            game_gr[y43, x43] = ' '; game_gr[y64, x64] = ' ';
            game_gr[y44, x44] = ' '; game_gr[y65, x65] = ' ';
            game_gr[y45, x45] = ' '; game_gr[y66, x66] = ' ';
            game_gr[y46, x46] = ' '; game_gr[y67, x67] = ' ';
            game_gr[y47, x47] = ' '; game_gr[y68, x68] = ' ';
            game_gr[y48, x48] = ' '; game_gr[y69, x69] = ' ';
 
            game_gr[y49, x49] = ' '; game_gr[y70, x70] = ' ';
            game_gr[y50, x50] = ' '; game_gr[y71, x71] = ' ';
            game_gr[y51, x51] = ' '; game_gr[y72, x72] = ' ';
            game_gr[y52, x52] = ' '; game_gr[y73, x73] = ' ';
            game_gr[y53, x53] = ' '; game_gr[y74, x74] = ' ';
            game_gr[y54, x54] = ' '; game_gr[y75, x75] = ' ';
            game_gr[y55, x55] = ' '; game_gr[y76, x76] = ' ';
            game_gr[y56, x56] = ' '; game_gr[y77, x77] = ' ';
            game_gr[y57, x57] = ' '; game_gr[y78, x78] = ' ';
 
            game_gr[y58, x58] = ' '; game_gr[y79, x79] = ' ';
            game_gr[y59, x59] = ' '; game_gr[y80, x80] = ' ';
            game_gr[y60, x60] = ' '; game_gr[y81, x81] = ' ';
            game_gr[y61, x61] = ' '; game_gr[y82, x82] = ' ';
            game_gr[y62, x62] = ' '; game_gr[y83, x83] = ' ';
            game_gr[y63, x63] = ' '; game_gr[y84, x84] = ' ';
 
        }
 
        public static void rightArrowEvent()
        {
 
            if (x1 != 28 && x2 != 28 && x3 != 28 && x4 != 28 && x5 != 28 && x6 != 28 && x7 != 28 && x8 != 28 && x9 != 28 && x10 != 28 && x11 != 28 && x12 != 28 && x13 != 28 && x14 != 28 && x15 != 28 &&
                x16 != 28 && x17 != 28 && x18 != 28 && x19 != 28 && x20 != 28 && x21 != 28 && x22 != 28 && x23 != 28 && x24 != 28 && x25 != 28 && x26 != 28 && x27 != 28 && x28 != 28 && x29 != 28 && x30 != 28 &&
                x31 != 28 && x32 != 28 && x33 != 28 && x34 != 28 && x35 != 28 && x36 != 28 && x37 != 28 && x38 != 28 && x39 != 28 && x40 != 28 && x41 != 28 && x42 != 28)
            {
                ochPl();
                x1 += 9; x2 += 9; x3 += 9; x4 += 9; x5 += 9; x6 += 9; x7 += 9; x8 += 9; x9 += 9; x10 += 9;
                x11 += 9; x12 += 9; x13 += 9; x14 += 9; x15 += 9; x16 += 9; x17 += 9; x18 += 9; x19 += 9; x20 += 9;
                x21 += 9; x22 += 9; x23 += 9; x24 += 9; x25 += 9; x26 += 9; x27 += 9; x28 += 9; x29 += 9; x30 += 9;
                x31 += 9; x32 += 9; x33 += 9; x34 += 9; x35 += 9; x36 += 9; x37 += 9; x38 += 9; x39 += 9; x40 += 9;
                x41 += 9; x42 += 9;
                carplus();
                carview();
            }
 
        }
        public static void leftArrowEvent()
        {
 
            if (x1 != 0 && x2 != 0 && x3 != 0 && x4 != 0 && x5 != 0 && x6 != 0 && x7 != 0 && x8 != 0 && x9 != 0 && x10 != 0 && x11 != 0 && x12 != 0 && x13 != 0 && x14 != 0 && x15 != 0 &&
                x16 != 0 && x17 != 0 && x18 != 0 && x19 != 0 && x20 != 0 && x21 != 0 && x22 != 0 && x23 != 0 && x24 != 0 && x25 != 0 && x26 != 0 && x27 != 0 && x28 != 0 && x29 != 0 && x30 != 0 &&
                x31 != 0 && x32 != 0 && x33 != 0 && x34 != 0 && x35 != 0 && x36 != 0 && x37 != 0 && x38 != 0 && x39 != 0 && x40 != 0 && x41 != 0 && x42 != 0)
            {
                ochPl();
                x1 -= 9; x2 -= 9; x3 -= 9; x4 -= 9; x5 -= 9; x6 -= 9; x7 -= 9; x8 -= 9; x9 -= 9; x10 -= 9;
                x11 -= 9; x12 -= 9; x13 -= 9; x14 -= 9; x15 -= 9; x16 -= 9; x17 -= 9; x18 -= 9; x19 -= 9; x20 -= 9;
                x21 -= 9; x22 -= 9; x23 -= 9; x24 -= 9; x25 -= 9; x26 -= 9; x27 -= 9; x28 -= 9; x29 -= 9; x30 -= 9;
                x31 -= 9; x32 -= 9; x33 -= 9; x34 -= 9; x35 -= 9; x36 -= 9; x37 -= 9; x38 -= 9; x39 -= 9; x40 -= 9;
                x41 -= 9; x42 -= 9;
                carplus();
                carview();
            }
 
        }
        public static void gameover()
        {
            if ((y7 == y79 && x7 == x79) || (y15 == y79 && x15 == x79) || (y1 == y79 && x1 == x79) || (y3 == y79 && x3 == x79))
            {
                Console.WriteLine("Game over");
                Console.WriteLine("Again? y/n");
                if (Console.ReadKey(true).Key == ConsoleKey.Y) game_over = false;
                else game_over = true;
            }
        }
        public static void falling()
        {
            fix = false;
            pereshkoda();
            pereshkodaplus();
            perview();
            Thread.Sleep(1000);
            while (y79 != 34 && y80 != 34 && y81 != 34 && y82 != 34 && y83 != 34 && y84 != 34)
            {
                pereshkodaoch();
                y43++; y44++; y45++; y46++; y47++; y48++; y49++; y50++; y51++; y52++;
                y53++; y54++; y55++; y56++; y57++; y58++; y59++; y60++; y61++; y62++;
                y63++; y64++; y65++; y66++; y67++; y68++; y69++; y70++; y71++; y72++;
                y73++; y74++; y75++; y76++; y77++; y78++; y79++; y80++; y81++; y82++;
                y83++; y84++;
                pereshkodaplus();
                perview();
            }
            fix = true;
            pereshkodaoch();
        }
        public static void backgroundCars()
        {
           
                carplins();
                carplus();
                carview();
                falling();
          
        }
        public static void Game()
        {
            RisovPole();
            background.Start();            
            background.IsBackground = true;
            while (!game_over)
            {
                key_info = Console.ReadKey(true);
                if (key_info.Key == ConsoleKey.LeftArrow) leftArrowEvent();
                else if (key_info.Key == ConsoleKey.RightArrow) rightArrowEvent();
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
 
            Car.Game();
        }
    }
}
Добавлено через 9 минут
Переменные с y1,x1 по y42,x42 отвечают за машинку игрока, y43,x43 по y84,x84 за машинку, которая падает вниз сверху.
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
06.01.2018, 04:10
Ответы с готовыми решениями:

Автомобильные гонки в консоли - как задать разную скорость для каждого из них
Задача следующая: Автомобили двигаются по экрану консоли от левого края к правому с переменной скоростью. Победителем гонки считается...

2D гонки
Всем доброго времени суток, форумчане. Долго гадал, в какой же раздел форума мне писать, но в Mono все очень тихо, поэтому я пришел к вам....

задание на курсовую игра гонки
вообщем задание написать игру гонки хочу реализовать с использованием openTK using System; using System.Drawing; using...

14
06.01.2018, 07:31

Не по теме:

глядя на твой код, я сразу вспомнил мем

0
44 / 45 / 41
Регистрация: 28.06.2017
Сообщений: 133
06.01.2018, 16:13

Не по теме:

My eyes are bleeding



У Вас не возникало чувства, что сама архитектура "немного в принципе неправильная"?
0
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6
06.01.2018, 16:33  [ТС]
Возникало. Так подскажите в каком направлении мне двигаться. Какую архитектуру подобрать "правильную"? Я же написал, что только учусь. Пока я так вижу.
Если убрать метод падения, то машина игрока реагирует на управление стрелочками. А если все вместе запустить, начинается салют. Помогите пожалуйста.

Добавлено через 2 минуты
Я думаю, что проблема с массивами или неправильной передачи в поток.
0
Wanna be serious
 Аватар для Bespridelschic
587 / 474 / 186
Регистрация: 31.07.2013
Сообщений: 1,693
06.01.2018, 17:21
Ручной труд ныне не в моде.
Бесконечные:
C#
1
2
3
4
5
6
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,
                            x11, x12, x13, x14, x15, x16, x17, x18, x19, x20,
                            x21, x22, x23, x24, x25, x26, x27, x28, x29, x30,
                            x31, x32, x33, x34, x35, x36, x37, x38, x39, x40,
                            x41, x42, x43, x44, x45, x46, x47, x48, x49, x50,
                            x51, x52, x53, x54 ...
Стоит заменит массивами:
C#
1
2
int[] x = new int[84];
int[] y = new int[84];
C#
1
2
3
4
5
6
7
WriteAt("|*|", 29, 0);
            WriteAt("|*|", 29, 1);
            WriteAt("|*|", 29, 2);
            WriteAt("|*|", 29, 3);
            WriteAt("|*|", 29, 4);
            WriteAt("|*|", 29, 5);
...
Заменить простым циклом:
C#
1
2
3
4
for (int i = 0; i < 35; i++)
{
    WriteAt("|*|", 29, i);
}
В остальных методах аналогично, необходимо ужать весь этот объем кода. А пока, даже не понятно что этот код должен выполнять.
Примените пока циклы и массивы, там где это нужно, а там видно будет.
1
06.01.2018, 17:58

Не по теме:

Меня поражает ваше трудолюбие...

0
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6
06.01.2018, 19:10  [ТС]
Метод carplins-устанавливает координаты машины игрока внизу поля
Метод carplus-рисует машину игрока задаными символами
Метод carview-выводит на экран машину игрока
Метод pereshkoda-устанавливает координаты машины препятствия
Метод pereshkodaplus-рисует машину препятствие
Метод perview-выводит на экран машину препятствие
Метод leftarrowevent и right-перезатирает машину игрока при нажатии стрелки влево или вправо
Метод falling-отвечает за движение машины препятствия

Bespridelschic, спасибо за совет. Буду пробовать.
0
10 / 10 / 7
Регистрация: 27.12.2017
Сообщений: 72
07.01.2018, 02:00
Цитата Сообщение от Pavlbab Посмотреть сообщение
подскажите в каком направлении мне двигаться
В направлении курения мануалов. Бедный препод там...
0
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6
07.01.2018, 04:33  [ТС]
Можно подумать, что все форумчане сразу начали писать идеальный код без ошибок и родились профессионалами. Такие сообщения и я могу написать. А вот дать дельный совет может не каждый. Легко унизить человека. А вот дать дельный совет не каждый может. Это все таки раздел для начинающих.
0
Эксперт .NET
 Аватар для Wolfdp
3790 / 1767 / 371
Регистрация: 15.06.2012
Сообщений: 6,543
Записей в блоге: 3
07.01.2018, 05:13
Pavlbab,
не, ну ты сам напросился...

1. отсутствие использование массивов. Хотя для char определить додумались, значит о их существовании знаете.
2. отсутствие циклов. Местами есть, но добрая часть кода унылая копипаста.
3. полное отсутствие обьектов. То что вы все обернули в статичесткий класс за ООП не считается.
4. У вас используется дополнительный поток, но по синхронизации полный ноль. Что будет, если после отрисовки 50% "фрейма" прилетит сдвиг от юзера?
5. "я так вижу" в программировании не катит, вы не художник.
6. >>проблема с массивами или неправильной передачи в поток.
Проблема в (цитата): что сама архитектура "немного в принципе неправильная". Вам нужно отдельно определить class Машинка с ее позицией и методами управления, отдельно -- class Препятствие. По таймеру/циклу -- смещать все это добро и проверять, не столкнулась ли машина с препятствием. Читаем про lock. И уже отдельный метод, которы будет тупо отрисовывать все.
7. Даный форум -- не клуб подержки начинающих неумех, особенно студентов, которые вместо консультации с преподователем, ищут легкие пути в интернете. Не нравится что плохо отзываются про ваш код? Велком ту риал ворлд. Мне и сейчас в лицо говорят, что "это хрень", не вижу смысла обижатся.
8. Вообще, сама идея гоночек на консоле -- унылая задача. Тот кто додумался до даной "задачи", откровенно говоря фигово придумывает образовательные задачи: ни тебе работы с БД, ни с файлами, ни с удалеными методами, ни с модульностью. Многопоточность тоже используется так-себе.
9. И повторю вышесказаное мной -- у вас отличное трудолюбие. Лично я, при написании первой "игры", заметив копипасту одного обработчика на 36 кнопок, полез в гугл. Про растановку их "вручную" даже и не думал, т.к. про циклы знал еще с лицея. И подозреваю что все остальные форумчанены ищут решения, а не городят код.
1
07.01.2018, 06:47

Не по теме:

Pavlbab, не обижайтесь на форумчан. Люди начали воспринимать в штыки подобные вопросы, потому что их большая часть от общей массы. Каждый напишет хрен пойми что, и свято уверен, что другие это тоже понимают, или будут разбираться в писанине. А в реальности, при виде такой вот портянки, не хочется даже смотреть что там ниже, и как оно все работает.

Если вы обучаетесь в ВУЗе, и C# вам интересен, подыщите хорошую литературу для изучения, благо на форуме есть специальная тема со списком (вот здесь)

0
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6
07.01.2018, 17:26  [ТС]
Все спасибо за советы. Я пытаюсь переделать свою программу. Пока написал наново. Возможно так будет лучше? Посмотрите пожалуйста.

C#
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace TetrisCar
{
    public class RisovPole
    {
 
        protected static int p;
        protected static int z;
        protected static void WriteAt(string s, int x, int y)
        {
            try
            {
                Console.SetCursorPosition(p + x, z + y);
                Console.Write(s);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
        public void Pole()
        {
            RisovCars v = new RisovCars();
            p = Console.CursorTop;
            z = Console.CursorLeft;
            Console.ForegroundColor = ConsoleColor.Cyan;
            WriteAt("+-------------------------------+", 0, 0);
            WriteAt("|*******************************|", 0, 1);
            WriteAt("|*+---------------------------+*|", 0, 2);
            for (int i = 3; i < 34; i++)
            {
                WriteAt("|*|", 0, i); WriteAt("|*|", 30, i);
            }            
            WriteAt("|*+---------------------------+*|", 0, 34);
            WriteAt("|*******************************|", 0, 35);
            WriteAt("+-------------------------------+\n\n\n\n\n\n\n\n\n\n\n", 0, 36);
            Console.ResetColor();
            //RisovCars.RisovPlCar();
            Console.ReadKey();
        }
    }
    public class Cars
    {
        List<string> CarPlayer = new List<string>();
        List<string> CarPereshkoda = new List<string>();
        public string St { get; set; }
        public string St1 { get; set; }
        public string St2 { get; set; }
        public string St3 { get; set; }
        public string St4 { get; set; }
        public string St5 { get; set; }
        public string St6 { get; set; }
        public string St7 { get; set; }
        public override string ToString()
        {
            return St + "\n" + St1 + "\n" + St2 + "\n" + St3 + "\n" + St4 + "\n" + St5 + "\n" + St6 + "\n" + St7;
        }  
    }
    public class RisovCars
    {
        //List<Cars> Car=new List<Cars>()
        public static ConsoleKeyInfo key = new ConsoleKeyInfo();
        public static Thread background = new Thread(backgroundCars);
        public static List<Cars> CarPl = new List<Cars>();
        public static int x = 6;
        public static int x1 = 3;
        public static void RisovPlCar()
        {
                        
            CarPl.Add(new Cars()
            {
                St =     "***",
                St1 =    "***",
                St2 = "***___***",
                St3 = "***   ***",
                St4 =    "***",
                St5 =    "***",
                St6 = "***___***",
                St7 = "***   ***"
            });
            foreach (Cars car in CarPl)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.SetCursorPosition(x, 26);
                Console.WriteLine(car.St);
                Console.SetCursorPosition(x, 27);
                Console.WriteLine(car.St1);
                Console.SetCursorPosition(x1, 28);
                Console.WriteLine(car.St2);
                Console.SetCursorPosition(x1, 29);
                Console.WriteLine(car.St3);
                Console.SetCursorPosition(x, 30);
                Console.WriteLine(car.St4);
                Console.SetCursorPosition(x, 31);
                Console.WriteLine(car.St5);
                Console.SetCursorPosition(x1, 32);
                Console.WriteLine(car.St6);
                Console.SetCursorPosition(x1, 33);
                Console.WriteLine(car.St7);
                Console.ResetColor();
            }
        }
        public static void RightArrow()
        {
            if (x != 22 && x1 != 22)
            {
                CarPl.Clear();
                x += 9; x1 += 9;
                CarPl.Add(new Cars()
                {
                    St = "***",
                    St1 = "***",
                    St2 = "***___***",
                    St3 = "***   ***",
                    St4 = "***",
                    St5 = "***",
                    St6 = "***___***",
                    St7 = "***   ***"
                });
                foreach (Cars car in CarPl)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(x, 26);
                    Console.WriteLine(car.St);
                    Console.SetCursorPosition(x, 27);
                    Console.WriteLine(car.St1);
                    Console.SetCursorPosition(x1, 28);
                    Console.WriteLine(car.St2);
                    Console.SetCursorPosition(x1, 29);
                    Console.WriteLine(car.St3);
                    Console.SetCursorPosition(x, 30);
                    Console.WriteLine(car.St4);
                    Console.SetCursorPosition(x, 31);
                    Console.WriteLine(car.St5);
                    Console.SetCursorPosition(x1, 32);
                    Console.WriteLine(car.St6);
                    Console.SetCursorPosition(x1, 33);
                    Console.WriteLine(car.St7);
                    Console.ResetColor();
                }
            }
        }
        public static void LeftArrow()
        {
            if (x != 2 && x1 != 2)
            {
                CarPl.Clear();
                x += 9; x1 += 9;
                CarPl.Add(new Cars()
                {
                    St = "***",
                    St1 = "***",
                    St2 = "***___***",
                    St3 = "***   ***",
                    St4 = "***",
                    St5 = "***",
                    St6 = "***___***",
                    St7 = "***   ***"
                });
                foreach (Cars car in CarPl)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(x, 26);
                    Console.WriteLine(car.St);
                    Console.SetCursorPosition(x, 27);
                    Console.WriteLine(car.St1);
                    Console.SetCursorPosition(x1, 28);
                    Console.WriteLine(car.St2);
                    Console.SetCursorPosition(x1, 29);
                    Console.WriteLine(car.St3);
                    Console.SetCursorPosition(x, 30);
                    Console.WriteLine(car.St4);
                    Console.SetCursorPosition(x, 31);
                    Console.WriteLine(car.St5);
                    Console.SetCursorPosition(x1, 32);
                    Console.WriteLine(car.St6);
                    Console.SetCursorPosition(x1, 33);
                    Console.WriteLine(car.St7);
                    Console.ResetColor();
                }
            }
        }
        public static void backgroundCars()
        {
            RisovCars.RisovPlCar();
        }
        public static void Game()
        {
            
            background.Start();
            background.IsBackground = true;
            
                        
                key = Console.ReadKey(true);
                if (key.Key = ConsoleKey.LeftArrow) LeftArrow();
                else if (key.Key == ConsoleKey.RightArrow) RightArrow();
            
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            RisovPole f = new RisovPole();
            f.Pole();
            RisovCars.Game();
            
        }
    }
}
Добавлено через 1 минуту
Я не обижаюсь на форумчан. Если бы я был обидчивым, я бы не написал и не попросил бы помощи. Я готов к критике. Ведь я хочу научиться правильно программировать. Еще раз спасибо за помощь и советы.
0
Wanna be serious
 Аватар для Bespridelschic
587 / 474 / 186
Регистрация: 31.07.2013
Сообщений: 1,693
07.01.2018, 18:03
Теперь гораздо лучше. Но можно сделать ещё лучше. Например класс Cars:
C#
1
2
3
4
5
6
7
8
public string St { get; set; }
public string St1 { get; set; }
public string St2 { get; set; }
public string St3 { get; set; }
public string St4 { get; set; }
public string St5 { get; set; }
public string St6 { get; set; }
public string St7 { get; set; }
Можно заменить на:
C#
1
public string[] St { get; set; }
C#
1
2
List<string> CarPlayer = new List<string>();
List<string> CarPereshkoda = new List<string>();
Стоит выделять память в конструкторе класса:
C#
1
2
3
4
5
public Cars
{
    CarPlayer = new List<string>();
    CarPereshkoda = new List<string>();
}
0
0 / 0 / 0
Регистрация: 21.08.2017
Сообщений: 6
21.01.2018, 14:19  [ТС]
Вообщем долго разбирался. И вот что получилось.
C#
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
//Created by Babik
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace TetrisCar
{
    public class RisovPole
    {
        
        protected static int p;
        protected static int z;
        protected static void WriteAt(string s, int x, int y)
        {
            try
            {
                Console.SetCursorPosition(p + x, z + y);
                Console.Write(s);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
        public void Pole()
        {
            RisovCars v = new RisovCars();
            p = Console.CursorTop;
            z = Console.CursorLeft;
            Console.ForegroundColor = ConsoleColor.Cyan;
            WriteAt("+-------------------------------+", 0, 0);
            WriteAt("|*******************************|", 0, 1);
            WriteAt("|*+---------------------------+*|", 0, 2);
            for (int i = 3; i < 34; i++)
            {
                WriteAt("|*|", 0, i); WriteAt("|*|", 30, i);
            }
            WriteAt("|*+---------------------------+*|", 0, 34);
            WriteAt("|*******************************|", 0, 35);
            WriteAt("+-------------------------------+\n\n\n\n\n\n\n\n\n\n\n", 0, 36);
            
            Console.ResetColor();
            Console.ReadKey();
        }
        public void Privet()
        {
            Console.SetCursorPosition(5, 10);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("******                      ****");
            Console.SetCursorPosition(5, 11);
            Console.WriteLine("******                     ******");
            Console.SetCursorPosition(5, 12);
            Console.WriteLine("  **                       **  **");
            Console.SetCursorPosition(5, 13);
            Console.WriteLine("  **  *** ***** **   * *** **     **  ** ");
            Console.SetCursorPosition(5, 14);
            Console.WriteLine("  **  *     *   * *    *   **       * * *");
            Console.SetCursorPosition(5, 15);
            Console.WriteLine("  **  **    *   **   * *** **  ** *** ** ");
            Console.SetCursorPosition(5, 16);
            Console.WriteLine("  **  *     *   * *  *   * ****** * * * *");
            Console.SetCursorPosition(5, 17);
            Console.WriteLine("  **  ***   *   *  * * ***  ****  *** *  *");
            Thread.Sleep(5000);
            Console.Clear();
            Console.ResetColor();
        }
    }
    public class Cars
    {
        List<string> CarPlayer = new List<string>();
        List<string> CarPereshkoda = new List<string>();
        public string St { get; set; }
        public string St1 { get; set; }
        public string St2 { get; set; }
        public string St3 { get; set; }
        public string St4 { get; set; }
        public string St5 { get; set; }
        public string St6 { get; set; }
        public string St7 { get; set; }
        public override string ToString()
        {
            return St + "\n" + St1 + "\n" + St2 + "\n" + St3 + "\n" + St4 + "\n" + St5 + "\n" + St6 + "\n" + St7;
        }
    }
    public class CarPer
    {
 
        List<string> CarPereshkoda = new List<string>();
        public string S { get; set; }
        public string S1 { get; set; }
        public string S2 { get; set; }
        public string S3 { get; set; }
        public string S4 { get; set; }
        public string S5 { get; set; }
        public string S6 { get; set; }
        public string S7 { get; set; }
        public override string ToString()
        {
            return S + "\n" + S1 + "\n" + S2 + "\n" + S3 + "\n" + S4 + "\n" + S5 + "\n" + S6 + "\n" + S7;
        }
    }
    public class RisovCars:RisovPole
    {
        public static ConsoleKeyInfo key = new ConsoleKeyInfo();
        public static Thread background = new Thread(backgroundCars);
        public static List<Cars> CarPl = new List<Cars>();
        public static List<CarPer> CarPer = new List<CarPer>();
        public static bool gameov = false;
        public static bool fix = true;
        public static int Score = 0;
        public static int x = 6;
        public static int x1 = 3;
        public static int x2, x3;
        public static int y = 3;
        public static int y1 = 4;
        public static int y2 = 5;
        public static int y3 = 6;
        public static int y4 = 7;
        public static int y5 = 8;
        public static int y6 = 9;
        public static int y7 = 10;
        public static void RisovPlCar()
        {
 
            CarPl.Add(new Cars()
            {
                St = "***",
                St1 = "***",
                St2 = "***___***",
                St3 = "***   ***",
                St4 = "***",
                St5 = "***",
                St6 = "***___***",
                St7 = "***   ***"
            });
            foreach (Cars car in CarPl)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.SetCursorPosition(x, 26);
                Console.WriteLine(car.St);
                Console.SetCursorPosition(x, 27);
                Console.WriteLine(car.St1);
                Console.SetCursorPosition(x1, 28);
                Console.WriteLine(car.St2);
                Console.SetCursorPosition(x1, 29);
                Console.WriteLine(car.St3);
                Console.SetCursorPosition(x, 30);
                Console.WriteLine(car.St4);
                Console.SetCursorPosition(x, 31);
                Console.WriteLine(car.St5);
                Console.SetCursorPosition(x1, 32);
                Console.WriteLine(car.St6);
                Console.SetCursorPosition(x1, 33);
                Console.WriteLine(car.St7);
                Console.ResetColor();
            }
        }
        public static void RisovCarPer()
        {
 
            CarPer.Add(new CarPer()
            {
                S = "***",
                S1 = "***",
                S2 = "***___***",
                S3 = "***   ***",
                S4 = "***",
                S5 = "***",
                S6 = "***___***",
                S7 = "***   ***"
            });
            foreach (CarPer car in CarPer)
            {
                Random r = new Random();
                int h = r.Next(1, 4);
                if (h == 1)
                {
                    x2 = 6; x3 = 3;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.SetCursorPosition(x2, y);
                    Console.WriteLine(car.S);
                    Console.SetCursorPosition(x2, y1);
                    Console.WriteLine(car.S1);
                    Console.SetCursorPosition(x3, y2);
                    Console.WriteLine(car.S2);
                    Console.SetCursorPosition(x3, y3);
                    Console.WriteLine(car.S3);
                    Console.SetCursorPosition(x2, y4);
                    Console.WriteLine(car.S4);
                    Console.SetCursorPosition(x2, y5);
                    Console.WriteLine(car.S5);
                    Console.SetCursorPosition(x3, y6);
                    Console.WriteLine(car.S6);
                    Console.SetCursorPosition(x3, y7);
                    Console.WriteLine(car.S7);
                    Console.ResetColor();
                }
                if (h == 2)
                {
                    x2 = 15; x3 = 12;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.SetCursorPosition(x2, y);
                    Console.WriteLine(car.S);
                    Console.SetCursorPosition(x2, y1);
                    Console.WriteLine(car.S1);
                    Console.SetCursorPosition(x3, y2);
                    Console.WriteLine(car.S2);
                    Console.SetCursorPosition(x3, y3);
                    Console.WriteLine(car.S3);
                    Console.SetCursorPosition(x2, y4);
                    Console.WriteLine(car.S4);
                    Console.SetCursorPosition(x2, y5);
                    Console.WriteLine(car.S5);
                    Console.SetCursorPosition(x3, y6);
                    Console.WriteLine(car.S6);
                    Console.SetCursorPosition(x3, y7);
                    Console.WriteLine(car.S7);
                    Console.ResetColor();
                }
                if (h == 3)
                {
                    x2 = 24; x3 = 21;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.SetCursorPosition(x2, y);
                    Console.WriteLine(car.S);
                    Console.SetCursorPosition(x2, y1);
                    Console.WriteLine(car.S1);
                    Console.SetCursorPosition(x3, y2);
                    Console.WriteLine(car.S2);
                    Console.SetCursorPosition(x3, y3);
                    Console.WriteLine(car.S3);
                    Console.SetCursorPosition(x2, y4);
                    Console.WriteLine(car.S4);
                    Console.SetCursorPosition(x2, y5);
                    Console.WriteLine(car.S5);
                    Console.SetCursorPosition(x3, y6);
                    Console.WriteLine(car.S6);
                    Console.SetCursorPosition(x3, y7);
                    Console.WriteLine(car.S7);
                    Console.ResetColor();
                }
            }
        }
        public static void OchPlCar()
        {
 
            CarPl.Add(new Cars()
            {
                St = "   ",
                St1 = "   ",
                St2 = "         ",
                St3 = "         ",
                St4 = "   ",
                St5 = "   ",
                St6 = "         ",
                St7 = "         "
            });
            foreach (Cars car in CarPl)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.SetCursorPosition(x, 26);
                Console.WriteLine(car.St);
                Console.SetCursorPosition(x, 27);
                Console.WriteLine(car.St1);
                Console.SetCursorPosition(x1, 28);
                Console.WriteLine(car.St2);
                Console.SetCursorPosition(x1, 29);
                Console.WriteLine(car.St3);
                Console.SetCursorPosition(x, 30);
                Console.WriteLine(car.St4);
                Console.SetCursorPosition(x, 31);
                Console.WriteLine(car.St5);
                Console.SetCursorPosition(x1, 32);
                Console.WriteLine(car.St6);
                Console.SetCursorPosition(x1, 33);
                Console.WriteLine(car.St7);
                Console.ResetColor();
            }
        }
        public static void OchPerCar()
        {
 
            CarPer.Add(new CarPer()
            {
                S = "   ",
                S1 = "   ",
                S2 = "         ",
                S3 = "         ",
                S4 = "   ",
                S5 = "   ",
                S6 = "         ",
                S7 = "         "
            });
            foreach (CarPer car in CarPer)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.SetCursorPosition(x2, y);
                Console.WriteLine(car.S);
                Console.SetCursorPosition(x2, y1);
                Console.WriteLine(car.S1);
                Console.SetCursorPosition(x3, y2);
                Console.WriteLine(car.S2);
                Console.SetCursorPosition(x3, y3);
                Console.WriteLine(car.S3);
                Console.SetCursorPosition(x2, y4);
                Console.WriteLine(car.S4);
                Console.SetCursorPosition(x2, y5);
                Console.WriteLine(car.S5);
                Console.SetCursorPosition(x3, y6);
                Console.WriteLine(car.S6);
                Console.SetCursorPosition(x3, y7);
                Console.WriteLine(car.S7);
                Console.ResetColor();
            }
        }
        public static void Falling()
        {
            fix = false;
            RisovCarPer();
            while (y7 != 33)
            {
                CarPer.Clear();
                Thread.Sleep(200);
                OchPerCar();
                y ++; y1 ++; y2 ++; y3 ++; y4 ++; y5 ++; y6 ++; y7 ++;
                CarPer.Add(new CarPer()
                {
                    S =     "***",
                    S1 =    "***",
                    S2 = "***___***",
                    S3 = "***   ***",
                    S4 = "***",
                    S5 = "***",
                    S6 = "***___***",
                    S7 = "***   ***"
                });
                foreach (CarPer car in CarPer)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.SetCursorPosition(x2, y);
                    Console.WriteLine(car.S);
                    Console.SetCursorPosition(x2, y1);
                    Console.WriteLine(car.S1);
                    Console.SetCursorPosition(x3, y2);
                    Console.WriteLine(car.S2);
                    Console.SetCursorPosition(x3, y3);
                    Console.WriteLine(car.S3);
                    Console.SetCursorPosition(x2, y4);
                    Console.WriteLine(car.S4);
                    Console.SetCursorPosition(x2, y5);
                    Console.WriteLine(car.S5);
                    Console.SetCursorPosition(x3, y6);
                    Console.WriteLine(car.S6);
                    Console.SetCursorPosition(x3, y7);
                    Console.WriteLine(car.S7);
                    Console.ResetColor();
                }
                fix = true;
                if (y7 == 33)
                {
                    Score += 5;
                }
                if ((y7 == 26 || y7 == 28) && (x2 == x || x2 + 9 == x + 9 || x2 == x1 || x2 + 9 == x1 + 9 || x3 == x || x3 + 9 == x + 9 || x3 == x1 || x3 + 9 == x1 + 9))
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.SetCursorPosition(6, 15);
                    Console.WriteLine("Game Over!!!\n");
                    Console.ResetColor();                    
                    gameov = true;
                }
            }
            y = 3; y1 = 4; y2 = 5; y3 = 6; y4 = 7; y5 = 8; y6 = 9; y7 = 10;
            
        }
        public static void RightArrow()
        {
            if (x != 25 && x1 != 21)
            {
                CarPl.Clear();
                OchPlCar();
                x += 9; x1 += 9;
                CarPl.Add(new Cars()
                {
                    St = "***",
                    St1 = "***",
                    St2 = "***___***",
                    St3 = "***   ***",
                    St4 = "***",
                    St5 = "***",
                    St6 = "***___***",
                    St7 = "***   ***"
                });
                foreach (Cars car in CarPl)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(x, 26);
                    Console.WriteLine(car.St);
                    Console.SetCursorPosition(x, 27);
                    Console.WriteLine(car.St1);
                    Console.SetCursorPosition(x1, 28);
                    Console.WriteLine(car.St2);
                    Console.SetCursorPosition(x1, 29);
                    Console.WriteLine(car.St3);
                    Console.SetCursorPosition(x, 30);
                    Console.WriteLine(car.St4);
                    Console.SetCursorPosition(x, 31);
                    Console.WriteLine(car.St5);
                    Console.SetCursorPosition(x1, 32);
                    Console.WriteLine(car.St6);
                    Console.SetCursorPosition(x1, 33);
                    Console.WriteLine(car.St7);
                    Console.ResetColor();
                }
            }
        }
        public static void LeftArrow()
        {
            if (x != 5 && x1 != 3)
            {
                CarPl.Clear();
                OchPlCar();
                x -= 9; x1 -= 9;
                CarPl.Add(new Cars()
                {
                    St = "***",
                    St1 = "***",
                    St2 = "***___***",
                    St3 = "***   ***",
                    St4 = "***",
                    St5 = "***",
                    St6 = "***___***",
                    St7 = "***   ***"
                });
                foreach (Cars car in CarPl)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(x, 26);
                    Console.WriteLine(car.St);
                    Console.SetCursorPosition(x, 27);
                    Console.WriteLine(car.St1);
                    Console.SetCursorPosition(x1, 28);
                    Console.WriteLine(car.St2);
                    Console.SetCursorPosition(x1, 29);
                    Console.WriteLine(car.St3);
                    Console.SetCursorPosition(x, 30);
                    Console.WriteLine(car.St4);
                    Console.SetCursorPosition(x, 31);
                    Console.WriteLine(car.St5);
                    Console.SetCursorPosition(x1, 32);
                    Console.WriteLine(car.St6);
                    Console.SetCursorPosition(x1, 33);
                    Console.WriteLine(car.St7);
                    Console.ResetColor();
                }
            }
        }
        public static void score()
        {
            Console.SetCursorPosition(35, 5);
            Console.WriteLine("SCORE: " + Score);
            
        }
        public static void GAMEOVER()
        {
            Console.Clear();
            Console.WriteLine("Nice Game!");
            Console.WriteLine("Again? Y/N");
        }
        public static void backgroundCars()
        {
            while (!gameov)
            {
                RisovPole f = new RisovPole();               
                Console.Clear();
                f.Pole();
                if (fix == true)
                {
                    score();
                    RisovCars.RisovPlCar();
                }
                Falling();
            }
            if (gameov) GAMEOVER();
        }
        public static void Game()
        {
            //RisovCars.RisovPlCar();
            //score();
            background.Start();
            background.IsBackground = true;
            while (!gameov)
            {
                key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.LeftArrow) LeftArrow();
                else if (key.Key == ConsoleKey.RightArrow) RightArrow();
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            RisovPole b = new RisovPole();
            b.Privet();
            RisovCars.Game();
        }
    }
}
Прошу прокоментировать и подсказать что можно было бы упростить. Спасибо всем за советы и за помощь.
0
Wanna be serious
 Аватар для Bespridelschic
587 / 474 / 186
Регистрация: 31.07.2013
Сообщений: 1,693
21.01.2018, 15:40
Pavlbab, большую часть. Все те же проблемы - отсутствие циклов и массивов.
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
21.01.2018, 15:40
Помогаю со студенческими работами здесь

Гонки в 2Д
Всем привет. Итак ребят у меня тут проект - написать гонки в 2Д на С++... Возникли проблемы при написании класса... нужно написать класс;...

Гонки
У меня курсовая - гонки. Все есть и все довольно неплохо работает, НО при старте машина срывается с места без плавного разгона и едет на...

Гонки
Пишу курсовик, есть много вопросов. 1. Какими человеческими способами можно релизовать выполнение функций через промежутки времени для...

Гонки
Доброй ночи! Помогите решить задачу. Гонки проводятся 2-мя группами по 10 человек. Результаты соревнований показаны списками участников по...

Гонки
помогите плиз с курсовой по програмированию срочна нужна на тему гонки!!!!!!! мое мыло vetalii_galkin@mail.ru


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

Или воспользуйтесь поиском по форуму:
15
Ответ Создать тему
Новые блоги и статьи
SDL3 для Web (WebAssembly): Обработчик клика мыши в браузере ПК и касания экрана в браузере на мобильном устройстве
8Observer8 02.02.2026
Содержание блога Для начала пошагово создадим рабочий пример для подготовки к экспериментам в браузере ПК и в браузере мобильного устройства. Потом напишем обработчик клика мыши и обработчик. . .
Философия технологии
iceja 01.02.2026
На мой взгляд у человека в технических проектах остается роль генерального директора. Все остальное нейронки делают уже лучше человека. Они не могут нести предпринимательские риски, не могут. . .
SDL3 для Web (WebAssembly): Вывод текста со шрифтом TTF с помощью SDL3_ttf
8Observer8 01.02.2026
Содержание блога В этой пошаговой инструкции создадим с нуля веб-приложение, которое выводит текст в окне браузера. Запустим на Android на локальном сервере. Загрузим Release на бесплатный. . .
SDL3 для Web (WebAssembly): Сборка C/C++ проекта из консоли
8Observer8 30.01.2026
Содержание блога Если вы откроете примеры для начинающих на официальном репозитории SDL3 в папке: examples, то вы увидите, что все примеры используют следующие четыре обязательные функции, а. . .
SDL3 для Web (WebAssembly): Установка Emscripten SDK (emsdk) и CMake для сборки C и C++ приложений в Wasm
8Observer8 30.01.2026
Содержание блога Для того чтобы скачать Emscripten SDK (emsdk) необходимо сначало скачать и уставить Git: Install for Windows. Следуйте стандартной процедуре установки Git через установщик. . . .
SDL3 для Android: Подключение Box2D v3, физика и отрисовка коллайдеров
8Observer8 29.01.2026
Содержание блога Box2D - это библиотека для 2D физики для анимаций и игр. С её помощью можно определять были ли коллизии между конкретными объектами. Версия v3 была полностью переписана на Си, в. . .
Инструменты COM: Сохранение данный из VARIANT в файл и загрузка из файла в VARIANT
bedvit 28.01.2026
Сохранение базовых типов COM и массивов (одномерных или двухмерных) любой вложенности (деревья) в файл, с возможностью выбора алгоритмов сжатия и шифрования. Часть библиотеки BedvitCOM Использованы. . .
SDL3 для Android: Загрузка PNG с альфа-каналом с помощью SDL_LoadPNG (без SDL3_image)
8Observer8 28.01.2026
Содержание блога SDL3 имеет собственные средства для загрузки и отображения PNG-файлов с альфа-каналом и базовой работы с ними. В этой инструкции используется функция SDL_LoadPNG(), которая. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru