Форум программистов, компьютерный форум CyberForum.ru

Движение шайбы в хоккее на С++ (DOS) - C++

Восстановить пароль Регистрация
 
Tep4k111
0 / 0 / 0
Регистрация: 25.11.2013
Сообщений: 18
07.06.2014, 19:17     Движение шайбы в хоккее на С++ (DOS) #1
У меня есть код программы, всё готово: меню, help, прорисовано поле и всё что необходимо.
Подскажите как реализовать движение шайбы.. Я вообще не представляю. Заранее большое спасибо!

Вот мой код:

C++ (Qt)
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#include <graphics.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
#include <math.h>
//______________________________GLOBAL CONSTANTS______________________________
int x_player1 = 10;
int y_player1 = 10;
 
int x_player2 = 10;
int y_player2 = 10;
 
int x_field = 10;
int y_field = 10;
 
int x_washer = 10;
int y_washer = 10;
 
int x_menu = 10;
int y_menu = 10;
 
int count_menu = 0;
int count = 3;
 
int x_old_washer = 0;
int y_old_washer = 0;
 
int dx = 1;
int dy = -1;
 
struct help
{
 unsigned char *movie;
} helps1 [4], helps2 [4];
 
//______________________________INITGRAPH______________________________________
void init_graph ()
{
 int gdriver = DETECT;
 int gmode;
 
// initgraph (&gdriver, &gmode, "c:\\turboc3\\bgi");
 initgraph (&gdriver, &gmode, "c:\\tc\\bgi");
}
 
//______________________________MENU BACKGROUND_______________________________
void Background_menu (int x_field, int y_field)
{
  setbkcolor (15);
  setcolor (4);
  arc (x_field - 10, y_field + 230, 210, 160, 75);    //1
  arc (x_field + 630, y_field + 230, 90, 280, 75);    //2
 
  setfillstyle (8, 1);
  bar (x_field - 12, y_field - 10, x_field - 2, y_field + 160);    //leviy bok 1
  bar (x_field - 12, y_field + 461, x_field - 2, y_field + 300);   // 2
  bar (x_field - 10, y_field - 12, x_field + 640, y_field - 2);    //vverh
  bar (x_field - 10, y_field + 461, x_field + 640, y_field + 640); //niz
  bar (x_field + 621, y_field - 10, x_field + 640, y_field + 160); // praviy bok
  bar (x_field + 621, y_field + 465, x_field + 640, y_field + 300);// 2
 }
 
//______________________________GAME MENU_____________________________________
//______________________________PAINT RECTANGLE_______________________________
void Rectangle_menu (int x_menu, int y_menu)
{
 rectangle (x_menu + 30, y_menu + 30, x_menu + 150, y_menu + 80);
}
 
void Paint_menu_rectangle (int x_menu, int y_menu, int &count)
{
 for (int i = 0; i < count; i++)
 {
  Rectangle_menu (x_menu + i * 100, y_menu - 100);
 }
}
 
//____________________________PAINT NAME GAME_________________________________
void Paint_menu_name_game (int x_menu, int y_menu, char *name_game[])
{
 setcolor (9);
 settextstyle (1, 0, 8);
 
 for (int i = 0; i < 1; i++)
 {
  outtextxy (x_menu + i * 100 + 40, y_menu, name_game[i]);
 }
}
 
void Paint_menu_text (int x_menu, int y_menu, char *start[], char *help[], char *exit[])
{
 setcolor (1);
 settextstyle (1, 0, 5);
 
 for (int i = 0; i < 1; i++)
 {
  outtextxy (x_menu + i * 100 + 265, y_menu + 120, start[i]);
  outtextxy (x_menu + i * 120 + 265, y_menu + 220, help[i]);
  outtextxy (x_menu + i * 140 + 265, y_menu + 320, exit[i]);
 }
}
 
//____________________________MOVE RACTANGLE MENU_____________________________
int Move_menu (int x_menu, int y_menu, int count)
{
 int count_menu = 0;
 char c = 0;
 count--;
 
 setcolor(4);
 Rectangle_menu (x_menu + 225, y_menu + 95);
 
 while (c != 13)
 {
  c = getch();
 
  if (!c) c += getch();
  switch (c)
  {
   case 80:
   {
    if (count_menu == count) count_menu = 0;
     else count_menu++;
 
     setcolor (15);
     Rectangle_menu (x_menu + 225, y_menu + 95);
 
     setcolor (4);
     y_menu = count_menu * 100 + 10;
     Rectangle_menu (x_menu + 225, y_menu + 95);
 
     if (count_menu > 0)
     {
      setcolor (0);
      Rectangle_menu (x_menu + 225, y_menu - 5);
     }
     else
      {
       setcolor (0);
       Rectangle_menu (x_menu + 225, y_menu + 295);
      }
   break;
  } // move down
 
  case 72:
  {
   if (count_menu < 0) count_menu = 1;
    else count_menu--;
 
    setcolor(0);
    Rectangle_menu (x_menu + 225, y_menu + 95);
 
    if (y_menu + 95 <= 105) y_menu = 210;
    else y_menu -= 100;
 
    setcolor (4);
    Rectangle_menu (x_menu + 225, y_menu + 95);
    break;
   } // move up
  }
 }
 return count_menu;
}
//____________________________FIGURE MENU_____________________________________
void Figure (int count_menu)
{
 setcolor (4);
 settextstyle (1, 0, 3);
 char *s;
 sprintf (s, "%d", count_menu);
 outtextxy (200, 200, s);
 setcolor (6);
}
//___________________________BACKGROUND HELP_________________________________
void Background_help (int x_field, int y_field)
{
  setbkcolor (15);
  setcolor (4);
  arc (x_field - 10, y_field + 230, 210, 160, 75);    //1
  arc (x_field + 630, y_field + 230, 90, 280, 75);    //2
 
  setcolor (4);
  setfillstyle (1, 4);
  circle (x_field + 308, y_field + 230, 80);
  circle (x_field + 308, y_field + 230, 75);
  floodfill (x_field + 384, y_field + 230, 4);
 
  setfillstyle (1, 4);
  bar (x_field + 312, y_field - 10, x_field + 308, y_field + 480);  //srednya liniya
 
  setfillstyle (8, 1);
  bar (x_field - 12, y_field - 10, x_field - 2, y_field + 160);     //leviy bok 1
  bar (x_field - 12, y_field + 461, x_field - 2, y_field + 300);    // 2
  bar (x_field - 10, y_field - 12, x_field + 640, y_field - 2);     //vverh
  bar (x_field - 10, y_field + 461, x_field + 640, y_field + 640);  //niz
  bar (x_field + 621, y_field - 10, x_field + 640, y_field + 160);  // praviy bok
  bar (x_field + 621, y_field + 465, x_field + 640, y_field + 300); // 2
}
//____________________________BACKGROUND GAME_________________________________
void Background()
{
 setbkcolor (15);
}
 
void Arc_left (int x_field, int y_field)
{
 setcolor (4);
 arc (x_field - 10, y_field + 230, 210, 160, 75);    //1
}
 
void Arc_right (int x_field, int y_field)
{
 setcolor (4);
 arc (x_field + 630, y_field + 230, 90, 280, 75);
}
 
void Center_circle (int x_field, int y_field)
{
 setcolor (4);
 setfillstyle (1, 4);
 circle (x_field + 308, y_field + 230, 80);
 circle (x_field + 308, y_field + 230, 75);
 floodfill (x_field + 384, y_field + 230, 4);
}
 
void Center_line (int x_field, int y_field)
{
 setfillstyle (1, 4);
 bar (x_field + 312, y_field - 10, x_field + 308, y_field + 480);  //srednya liniya
}
//____________________________PAINT FIELD_____________________________________
void Paint_field (int x_field, int y_field)
{
 Arc_left (x_field, y_field);
 Arc_right (x_field, y_field);
 
 Center_circle (x_field, y_field);
 Center_line (x_field, y_field);
 
 setfillstyle (8, 1);
 bar (x_field - 12, y_field - 10, x_field - 2, y_field + 160); //leviy bok 1
 bar (x_field - 12, y_field + 461, x_field - 2, y_field + 300); // 2
 bar (x_field - 10, y_field - 12, x_field + 640, y_field - 2); //vverh
 bar (x_field - 10, y_field + 461, x_field + 640, y_field + 640);//niz
 bar (x_field + 621, y_field - 10, x_field + 640, y_field + 160);// praviy bok
 bar (x_field + 621, y_field + 465, x_field + 640, y_field + 300);// 2
}
 
//____________________________PLAYER 1________________________________________
void Player1 (int x_player1, int y_player1)
{
 setcolor (5);
 setfillstyle (1, 5);                // 1 player
 circle (x_player1, y_player1, 30);
 circle (x_player1, y_player1, 20);
 floodfill (x_player1 + 15 , y_player1 + 15, 5);
}
 
//____________________________PLAYER 2________________________________________
void Player2 (int x_player2, int y_player2)
{
 setcolor (6);
 setfillstyle (1, 6);
 circle (x_player2, y_player2, 30);
 circle (x_player2, y_player2, 20);
// floodfill (x1, y1, 5);
}
 
//____________________________Washer__________________________________________
void Washer (int x_washer, int y_washer)
{
 setcolor (8);
 setfillstyle (1, 8);
 circle (x_washer, y_washer, 15);
 floodfill (x_washer, y_washer, 8);
}
 
//____________________________MAIN FUNCTION MENU________________________________
void Main_field (int x_field, int y_field)
{
 Background();
 Paint_field (x_field, y_field);
}
 
//____________________________CLEAR MOVE PLAYER 1________________________________________
void Clear_move_player1 (int x_player1, int y_player1)
{
 setcolor (15);
 setfillstyle (1, 15);
 circle (x_player1, y_player1, 30);
 circle (x_player1, y_player1, 20);
 floodfill (x_player1 + 15, y_player1 + 15, 15);
}
 
//____________________________CLEAR MOVE PLAYER 2________________________________________
void Clear_move_player2 (int x_player2, int y_player2)
{
 setcolor (15);
 setfillstyle (1, 15);
 circle (x_player2, y_player2, 30);
 circle (x_player2, y_player2, 20);
 floodfill (x_player2 + 15, y_player2 + 15, 15);
}
 
void Clear_move_washer (int x_washer, int y_washer)
{
 setcolor (15);
 setfillstyle (1, 15);
 circle (x_washer, y_washer, 15);
 floodfill (x_washer, y_washer, 15);
}
//____________________________MOVE PLAYERS________________________________________
void Move_Players (int &x_player1, int &y_player1, int &x_player2, int &y_player2, int x_field, int y_field, int x_washer, int y_washer)
{
 x_player1 += 30;
 y_player1 += 230;
 x_player2 += 590;
 y_player2 += 230;
 x_washer += 210;
 y_washer += 230;
 
 while (1)
 {
  Player1 (x_player1, y_player1);
  Player2 (x_player2, y_player2);
  Washer (x_washer, y_washer);
 
  int dx1 = 20;
  int dy1 = 20;
 
  int dx2 = 20;
  int dy2 = 20;
 
  x_old_washer = x_washer;
  y_old_washer = y_washer;
 
  if ((x_player1 + 40 == x_washer) || (y_player1 + 40 == y_washer))
  {
   while (1)
   {
    delay (1);
    Clear_move_washer (x_washer, y_washer);
    x_washer += dx;
    y_washer += dy;
   }
  }
  if ((x_washer == 30) || (x_washer == 610) || (y_washer == 30) || (y_washer == 450))
  {
   x_washer -= dx;
   y_washer -= dy;
  }
//  if (x + 5 == x2) Shayba (x2 + 100, y2 * atan (30));
 
  if (kbhit() )
   {
    int a;
    a = getch();
 
    if (a == 'x') { exit (1); }
 
//____________________________MOVE PLAYER 1________________________________________
 
    if (a == 'd') //move right
     {
      if (x_player1 > 280) continue;
 
      if (x_player1 + dx1 > 280) dx1 = 280 - x_player1;
 
      Clear_move_player1 (x_player1, y_player1);
 
      Arc_left (x_field, y_field);
 
      Center_circle (x_field, y_field);
      x_player1 += dx1;
 
      Player1 (x_player1, y_player1);
      dx1 = 20;
     }
 
     if (a == 'a') //move left
     {
      if (x_player1 < 60) continue;
 
      if (x_player1 + dx1 < 60) dx1 = 60 - x_player1;
 
      Clear_move_player1 (x_player1, y_player1);
 
      Arc_left (x_field, y_field);
      Center_circle (x_field, y_field);
 
      x_player1 -= dx1;
 
      Player1 (x_player1, y_player1);
      dx1 = 20;
    }
 
      if (a == 'w') //move up
     {
      if (y_player1 < 60) continue;
 
      if (y_player1 + dy1 < 60) dy1 = 60 - y_player1;
 
      Clear_move_player1 (x_player1, y_player1);
 
      Arc_left (x_field, y_field);
      Center_circle (x_field, y_field);
 
      y_player1 -= dy1;
      Player1 (x_player1, y_player1);
      dy1 = 20;
     }
 
      if (a == 's') //move down
     {
      if (y_player1 > 440) continue;
 
      if (y_player1 + dy1 > 440) dy1 = 440 - y_player1;
 
      Clear_move_player1 (x_player1, y_player1);
 
      Arc_left (x_field, y_field);
      Center_circle (x_field, y_field);
 
      y_player1 += dy1;
      Player1 (x_player1, y_player1);
      dy1 = 20;
     }
 
//____________________________MOVE PLAYER 2________________________________________
 
     if (a == 'l') //move right
     {
      if (x_player2 > 600) continue;
 
      if (x_player2 + dx2 > 600) dx2 = 600 - x_player2;
 
      Clear_move_player2 (x_player2, y_player2);
 
      Arc_right (x_field, y_field);
      Center_circle (x_field, y_field);
 
      x_player2 += dx2;
      Player2 (x_player2, y_player2);
      dx2 = 20;
     }
 
     if (a == 'j') //move left
     {
      if (x_player2 < 380) continue;
 
      if (x_player2 + dx2 < 380) dx2 = 380 - x_player2;
 
      Clear_move_player2 (x_player2, y_player2);
 
      Arc_right (x_field, y_field);
      Center_circle (x_field, y_field);
 
      x_player2 -= dx2;
      Player2 (x_player2, y_player2);
      dx2 = 20;
     }
 
     if (a == 'i') //move up
     {
      if (y_player2 < 60) continue;
 
      if (y_player2 + dy2 < 60) dy2 = 60 - y_player2;
 
      Clear_move_player2 (x_player2, y_player2);
 
      Arc_right (x_field, y_field);
      Center_circle (x_field, y_field);
 
      y_player2 -= dy2;
      Player2 (x_player2, y_player2);
      dy2 = 20;
     }
 
     if (a == 'k') //move down
     {
      if (y_player2 > 440) continue;
 
      if (y_player2 + dy2 > 440) dy2 = 440 - y_player2;
 
      Clear_move_player2 (x_player2, y_player2);
 
      Arc_right (x_field, y_field);
      Center_circle (x_field, y_field);
 
      y_player2 += dy2;
      Player2 (x_player2, y_player2);
      dy2 = 20;
     }
 
     char str2[10];
 
     setcolor (15);
     outtextxy (550, 50, str2);
 
     itoa (x_washer, str2, 10);
      setcolor (4);
      outtextxy (550, 50, str2);
 
       char str1[10];
 
     setcolor (15);
     outtextxy (150, 50, str1);
 
     itoa (x_player1, str1, 10);
      setcolor (5);
      outtextxy (150, 50, str1);
 
 
     }
 }
}
 
int Menu (int x_menu, int y_menu, int &count_menu, char *name_game[], char *start[], char *exit[], char *help[], int count)
{
 cleardevice();
 Background_menu (x_menu, y_menu);
 Paint_menu_rectangle (x_menu, y_menu, count);
 Paint_menu_name_game (x_menu, y_menu, name_game);
 Paint_menu_text (x_menu, y_menu, start, help, exit);
 return count_menu = Move_menu (x_menu, y_menu, count);
}
//____________________________HELP____________________________________________
void Help (int x_field, int y_field, int x_menu, int y_menu, int &count_menu, char *name_game[], char *start[], char *exit[], char *help[], int count)
{
 Background_help (x_field, y_field);
 
 helps1[0].movie="        up         -  'w'";
 helps2[0].movie="        up         -  'i'";
 helps1[1].movie="       down        -  's'";
 helps2[1].movie="       down        -  'k'";
 helps1[2].movie="       left        -  'a'";
 helps2[2].movie="       left        -  'j'";
 helps1[3].movie="       right       -  'd'";
 helps2[3].movie="       right       -  'l'";
 
 setcolor (5);
 settextstyle (0, 0, 1);
 outtextxy (40, 70, "Control for the first player:");
 
 setcolor (5); //Player1
 settextstyle (0, 0, 1);
 outtextxy (15, 90, helps1[0].movie);
 outtextxy (15, 100, helps1[1].movie);
 outtextxy (15, 110, helps1[2].movie);
 outtextxy (15, 120, helps1[3].movie);
 
 setcolor (6);
 settextstyle (0, 0, 1);
 outtextxy (360, 70, "Control for the second player:");
 
 setcolor (6);   //Player
 settextstyle (0, 0, 1);
 outtextxy (335, 90, helps2[0].movie);
 outtextxy (335, 100, helps2[1].movie);
 outtextxy (335, 110, helps2[2].movie);
 outtextxy (335, 120, helps2[3].movie);
 
 setcolor(5);
 settextstyle (0, 0, 1);
 outtextxy (75, 320, "Meaning of the game:");
 outtextxy (15, 340, "Glow Hockey is a game involving two.");
 outtextxy (15, 355, "players. Goal of the game - to scrore");
 outtextxy (15, 370, "the puck into the opponent's goal.");
 
 setcolor (6);
 settextstyle (0, 0, 1);
 outtextxy (405, 320, "Rules of the game:");
 outtextxy (330, 340, "For every goal the puck into the op-");
 outtextxy (330, 355, "ponent goal is awarded one point. The");
 outtextxy (330, 370, "player who will score the first seven");
 outtextxy (330, 385, "points.");
 
 setcolor (4);
 settextstyle (0, 0, 1);
 outtextxy (415, 440, "Press 'C' to back the menu ");
 
 setcolor (4);
 settextstyle (0, 0, 1);
 outtextxy (392, 130, "exit        -  'x'");
 
 
 char a;
 while (a != 13)
 {
  a = getch ();
 
  if (!a) a += getch();
 
  if (a == 'c')
  {
   int count = 3;
   Menu (x_menu, y_menu, count_menu, name_game, start, exit, help, count);
   if (count_menu == 0)
   {
    cleardevice();
    Main_field (x_field, y_field);
    Move_Players (x_player1, y_player1, x_player2, y_player2, x_field, y_field, x_washer, y_washer);
   }
   if (count_menu > 0)
   {
    cleardevice();
    Help (x_field, y_field, x_menu, y_menu, count_menu, name_game, start, exit, help, count);
   }
 
 //  if (count_menu == 2) exit (1);
  }
 }
}
 
void Switch_menu (int x_player1, int y_player1, int x_player2, int y_player2, int x_field, int y_field, int count_menu, char *name_game[], char *start[], char *exit[], char *help[], int count)
{
 Menu (x_menu, y_menu, count_menu, name_game, start, exit, help, count);
 Figure (count_menu);
 if (count_menu == 0)
 {
  cleardevice();
  Main_field (x_field, y_field);
  Move_Players (x_player1, y_player1, x_player2, y_player2, x_field, y_field, x_washer, y_washer);
 }
 
 if (count_menu == 1)
 {
  cleardevice();
  Help (x_field, y_field, x_menu, y_menu, count_menu, name_game, start, exit, help, count);
 }
 
// if ((count_menu == 2) || (count_menu == -1)) exit (1);
}
 
int main()
{
 char *start[] = {"Start\0"};
 char *help[] = {"Help\0"};
 char *exit[] = {"Exit\0"};
 char *name_game[] = {"GLOW  HOCKEY\0"};
 
 init_graph();
 Switch_menu (x_player1, y_player1, x_player2, y_player2, x_field, y_field, count_menu, name_game, start, exit, help, count);
 getch();
 closegraph();
 return 0;
}
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
07.06.2014, 19:17     Движение шайбы в хоккее на С++ (DOS)
Посмотрите здесь:

БД в C++ for DOS C++
массив С++ for dos C++
C++ MS-DOS type
borland c++ 3.1 dos C++
DOS -> WIN C++
ООП в DOS C++
DOS приложения и C++ C++
C++ ms dos

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

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Ответ Создать тему
Опции темы

Текущее время: 21:23. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru