Форум программистов, компьютерный форум, киберфорум
C для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/6: Рейтинг темы: голосов - 6, средняя оценка - 5.00
14 / 14 / 4
Регистрация: 08.11.2010
Сообщений: 172
1

Тетрис - исправить ошибки Undefined reference

21.05.2011, 09:59. Показов 1112. Ответов 7
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
перевёл тетрис с ооп на простой си, и выпадают ошибки линковщика, помогите пожалуйста, и объясните некоторые ф-ии прораммы
компилятор dev-cpp
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
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<time.h>
#include<string.h>
#include<windows.h>
#define EMPTY 0
#define STATIC 2
#define DYNAMIC 1
#define RIGHT 77
#define DOWN 80
#define LEFT 75
#define ENTER 32
#define ENTER1 13
#define UP 72
#define ESC 27
 
typedef struct
{
        int **mpt;
        int size_i;
        int size_j;
        int vert;
        /*Matr();
        ~Matr();
        friend void ReadStdFile(Matr*,int);
        friend void Vert(Matr&);
        friend Matr** Preobr(Matr*,int);*/
}Matr;
typedef struct
{
        int x,y;
        int type;
        int pol;
}Figure;
typedef struct
{
    Matr **p;
    int **ar_old;
    int **color_ar_old;
    int **ar;
    int **color_ar;
    int size_i;
    int size_j;
    int unsigned lines;
    unsigned long score;
    unsigned long record;
    unsigned long lastres;
        Figure a;
        int level;
        /*Glass(){};
        Glass(Matr**);
        ~Glass();
        int Fall();
        int Move(int);
        int Rotate();
        int Do(int);
        void Draw(void**);
        int Create(int,int,int,int,int);
        void Destr();
        void CopyMas();
        void LeftPanel();
        void Score(int);*/
}Glass;
void gotoxy(int xpos, int ypos);
void CreateGlass(Glass *it,Matr** p);
void DeleteGlass(Glass *it);
int CreateGlass(Glass *it);
void DestrGlass(Glass *it);
int Do(Glass *it,int type);
int Fall(Glass *it);
int Move(Glass *it,int key);
void Draw(Glass *it,void **sd);
void InitMatr(Matr *it);
void DeleteMatr(Matr *it);
void ReadStdFile(Matr *p,int N);
void** PreobrGraph(int N);
void Vert(Matr &p);
Matr** Preobr(Matr *p,int N);
void CopyMas(Glass *it);
void LeftPanel(Glass *it);
void DrawFut(int *type,void **gp,Matr *p);
void Score(Glass *it,int d);
void Menu(char *str1);
 
void gotoxy(int xpos, int ypos)
{
  COORD scrn;    
 
  HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
 
  scrn.X = xpos; scrn.Y = ypos;
 
  SetConsoleCursorPosition(hOuput,scrn);
}
void CreateGlass(Glass *it, Matr** p_)
{
    int i;
    FILE *f=fopen("Tetris.rec","r");
    if (f)
    {
        fscanf(f,"%li\n",&(it->record));
        fscanf(f,"%li\n",&(it->lastres));
        fclose(f);
    }
    it->p=p_;
    it->size_i=20;
    it->size_j=10;
    it->lines=0;
    it->level=1;
    it->score=0;
    it->ar=(int**)malloc(sizeof(int*)*it->size_i);
    for (int i=0;i<it->size_i;i++)
    {
        it->ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->ar[i][j]=EMPTY;
    }
    it->ar_old=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->ar_old[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->ar_old[i][j]=STATIC;
    }
    it->color_ar=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->color_ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->color_ar[i][j]=EMPTY;
    }
    it->color_ar_old=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->color_ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->color_ar_old[i][j]=EMPTY;
    }
};
void DeleteGlass(Glass *it)
{
    for (int i=0;i<it->size_i;i++)
    {
        free(it->ar[i]);
        free(it->color_ar[i]);
        free(it->ar_old[i]);
        free(it->color_ar_old[i]);
 
    }
    free(it->ar);
    free(it->color_ar);
    free(it->ar_old);
    free(it->color_ar_old);
}
int CreateGlass(Glass *it,int x_,int y_,int type_,int pol_,int d)
{
    int flag=1;
    for (int i=0;i<it->p[type_][pol_].size_i;i++)
        for (int j=0;j<it->p[type_][pol_].size_j;j++)
        {
            if ((y_+j<0 || y_+j>=it->size_j) || ((it->p[type_][pol_].mpt[i][j]==1 && it->ar[x_+i][y_+j]==2) && (d==LEFT || d==RIGHT || d==0 || d==ENTER)))
                flag=2;
            if ((it->p[type_][pol_].mpt[i][j]==1 && it->ar[x_+i][y_+j]==2 && d==DOWN) || x_+i==it->size_i)
                flag=0;
        }
    if (flag==2 && d==0)
    {
            for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=STATIC;
                    it->color_ar[i][j]=it->a.type;
                }
            }
            return 0;
    }
    if (flag==1)
    {
        for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=EMPTY;
                    it->color_ar[i][j]=type_;
                }
            }
        for (int i=0;i<it->p[type_][pol_].size_i;i++)
            for (int j=0;j<it->p[type_][pol_].size_j;j++)
                if (it->ar[x_+i][y_+j]!=2)
                if (it->p[type_][pol_].mpt[i][j]==1)
                {
                    it->ar[x_+i][y_+j]=1;
                    it->color_ar[x_+i][y_+j]=type_;
                }
        it->a.x=x_;
        it->a.y=y_;
        it->a.type=type_;
        it->a.pol=pol_;
    }
    else if (flag==0)
    {
        for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=STATIC;
                    it->color_ar[i][j]=it->a.type;
                }
            }
        DestrGlass(it);
    }
    else if (flag==2) return 0;
    return flag;
}
void DestrGlass(Glass *it)
{
    int flag;
    for (int i=it->size_i-1;i>=0;i--)
    {
        flag=1;
        for (int j=0;j<it->size_j;j++)
        {
            if (it->ar[i][j]!=STATIC)
            {
                flag=0;
            }
        }
        if (flag)
        {
            for (int i_=i;i_>0;i_--)
            {
                for (int j_=0;j_<it->size_j;j_++)
                {
                    it->ar[i_][j_]=it->ar[i_-1][j_];
                    it->color_ar[i_][j_]=it->color_ar[i_-1][j_];
                }
            }
            for (int j_=0;j_<it->size_j;j_++)
            {
                it->ar[0][j_]=0;
                it->color_ar[0][j_]=0;
            }
            it->lines++;
            Score(it,100);
            LeftPanel(it);
            if (1+it->lines/10>it->level)
            {
                gotoxy(1,3);
                it->level=1+it->lines/10;
            }
            DestrGlass(it);
        }
    }
}
 
int Do(Glass *it,int type)
{
    if (!CreateGlass(it,0,(it->size_j-it->p[type][0].size_j)/2,type,0,0)) return 0;
    else return 1;
}
 
int Fall(Glass *it)
{
    if (!CreateGlass(it,it->a.x+1,it->a.y,it->a.type,it->a.pol,DOWN)) return 0;
    else return 1;
}
 
int Move(Glass *it,int key)
{
    switch(key)
    {
        case RIGHT:
        {
            if (!CreateGlass(it,it->a.x,it->a.y+1,it->a.type,it->a.pol,RIGHT)) return 0;
            else return 1;
        }
        case LEFT:
        {
            if (!CreateGlass(it,it->a.x,it->a.y-1,it->a.type,it->a.pol,LEFT)) return 0;
            else return 1;
        }
        case DOWN:
        {
            Score(it,1);
            if (!CreateGlass(it,it->a.x+1,it->a.y,it->a.type,it->a.pol,DOWN)) return 0;
            else return 1;
        }
        case ENTER:
        {
            if (!CreateGlass(it,it->a.x,it->a.y,it->a.type,(it->a.pol+1)%it->p[it->a.type][0].vert,ENTER)) return 0;
            else return 1;
        }
    }
}
 
void Draw(Glass *it,void **sd)
{
    int pos_x=(getmaxx()-it->size_j*20)/2,pos_y=(getmaxy()-it->size_i*20)/2;
    setcolor(WHITE);
    rectangle(pos_x,pos_y,pos_x+it->size_j*20+1,pos_y+it->size_i*20+1);
    for(int i=0;i<it->size_i;i++)
    {
        for (int j=0;j<it->size_j;j++)
        {
            if(it->ar_old[i][j]!=it->ar[i][j] || it->color_ar_old[i][j]!=it->color_ar[i][j])
            {
                switch(it->ar[i][j])
                {
                    case STATIC:
                    {
                        setfillstyle(SOLID_FILL,DARKGRAY);
                        putimage(pos_x+j*20+1,pos_y+i*20+1,sd[it->color_ar[i][j]],0);
                        break;
                    }
                    case DYNAMIC:
                    {
                        putimage(pos_x+j*20+1,pos_y+i*20+1,sd[it->a.type],0);
                        break;
                    }
                    case EMPTY:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(pos_x+j*20+1,pos_y+i*20+1,pos_x+(j+1)*20,pos_y+(i+1)*20);
                        //setfillstyle(SOLID_FILL,WHITE);
                        //fillellipse(pos_x+j*20+10,pos_y+i*20+10,1,1);
                        //bar(pos_x+j*20+1,pos_y+i*20+1,pos_x+(j+1)*20,pos_y+(i+1)*20);
                        break;
                    }
                }
            }
        }
    }
    CopyMas(it);
}
 
void InitMatr(Matr *it)
{
    it->vert=0;
    it->size_i=0;
    it->size_j=0;
    it->mpt=NULL;
}
 
void DeleteMatr(Matr *it)
{
    int i;
    for (i=0;i<it->size_i;i++)
    {
        free(it->mpt[i]);
    }
    free(it->mpt);
}
 
void ReadStdFile(Matr *p,int N)
{
    FILE *f=NULL;
    f=fopen("std.fig","r");
    if (f)
    {
        int i,u,v;
        char h[2];
        h[1]='\0';
        for (i=0;i<N;i++)
        {
            h[0]=fgetc(f);
            p[i].size_i=atoi(h);
            h[0]=fgetc(f);
            p[i].size_j=atoi(h);
            p[i].mpt=new int*[p[i].size_i];
            getc(f);
            for (u=0;u<p[i].size_i;u++)
            {
                p[i].mpt[u]=new int[p[i].size_j];
                for (v=0;v<p[i].size_j;v++)
                {
                    h[0]=fgetc(f);
                    p[i].mpt[u][v]=atoi(h);
                }
                getc(f);
            }
        }
    }
    else
    {
        cout << "\nfile 'std.fig' not found!\n";
        getch();
    }
    fclose(f);
}
 
void** PreobrGraph(int N)
{
    cleardevice();
    int mas[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    unsigned int size=imagesize(1,1,20,20);
    void **sd=(void **)malloc(7*sizeof(void*));
    for (int i=0;i<N;i++)
    {
        sd[i]=malloc(size);
        /*setfillstyle(SOLID_FILL,mas[i]);
        bar(1,1,20,20);*/
        setfillstyle(SOLID_FILL,BLACK);
        bar(1,1,20,20);
        setcolor(WHITE);
        line(1,4,1,16);
        line(20,4,20,16);
        line(4,1,16,1);
        line(4,20,16,20);
        line(1,4,4,1);
        line(1,16,4,20);
        line(16,1,20,4);
        line(16,20,20,16);
        /*setfillstyle(SOLID_FILL,mas[i]);
        floodfill(10,10,WHITE);*/
        setfillstyle(SOLID_FILL,mas[i+8]);
        bar(4,4,17,17);
        setcolor(BLACK);
        rectangle(4,4,17,17);
        getimage(1,1,20,20,sd[i]);
    }
    return sd;
}
 
void Vert(Matr &p)
{
    int flag=0;
    for (int i=0;i<p.size_i;i++)
    {
        for (int j=0;j<p.size_j;j++)
        {
            if (p.mpt[i][j]!=p.mpt[p.size_i-i-1][p.size_j-j-1]) flag=1;
        }
    }
    if (flag) p.vert=4;
    else if (p.size_i==p.size_j) p.vert=1;
    else p.vert=2;
}
 
Matr** Preobr(Matr *p,int N)
{
    Matr **p1=(Matr**)malloc(sizeof(Matr*)*N);
    for (int i=0;i<N;i++)
    {
        Vert(p[i]);
        p1[i]=(Matr*)malloc(sizeof(Matr)*p[i].vert);
        for (int j=0;j<p[i].vert;j++)
        {
            if (j%2!=0)
            {
                p1[i][j].size_i=p[i].size_j;
                p1[i][j].size_j=p[i].size_i;
            }
            else
            {
                p1[i][j].size_i=p[i].size_i;
                p1[i][j].size_j=p[i].size_j;
            }
            p1[i][j].vert=p[i].vert;
            p1[i][j].mpt=(int**)malloc(sizeof(int*)*p1[i][j].size_i);
            for (int k=0;k<p1[i][j].size_i;k++)
            {
                p1[i][j].mpt[k]=(int*)malloc(sizeof(int)*p1[i][j].size_j);
                for (int l=0;l<p1[i][j].size_j;l++)
                {
                    if (j==0)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[k][l];
                    }
                    else if (j==1)
                    {
                        p1[i][j].mpt[k][p1[i][j].size_j-l-1]=p[i].mpt[l][k];
                    }
                    else if (j==2)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[p[i].size_i-k-1][p[i].size_j-l-1];
                    }
                    else if (j==3)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[l][p[i].size_i-k];
                    }
                }
            }
        }
    }
    return p1;
}
 
void CopyMas(Glass *it)
{
    for (int i=0;i<it->size_i;i++)
        for (int j=0;j<it->size_j;j++)
        {
            it->ar_old[i][j]=it->ar[i][j];
            it->color_ar_old[i][j]=it->color_ar[i][j];
        }
}
 
void LeftPanel(Glass *it)
{
    int i;
    int x=20,y=40;
    char str[]="Score:";
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,4);
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y,str);
    char scorestr[7];
    itoa(it->score,scorestr,10);
    int dif=6-strlen(scorestr);
    scorestr[6]='\0';
    int len=strlen(scorestr);
    for (int i=0;i<len;i++)
    {
        scorestr[5-i]=scorestr[len-i-1];
    }
    for (i=0;i<dif;i++)
    {
        scorestr[i]='0';
    }
    setfillstyle(SOLID_FILL,BLACK);
    bar(x,y+textheight(str)*1.1,x+textwidth(str),y+2*textheight(str)*1.1);
    outtextxy(x,y+textheight(str)*1.1,scorestr);
    settextstyle(5,HORIZ_DIR,4);
    char str2[]="Lines:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y+3*textheight(str)*1.1,str2);
    char linestr[5];
    itoa(it->lines,linestr,10);
    bar(x+textwidth(str2),y+3*textheight(str)*1.1,x+textwidth(str2)+50,y+3*textheight(str)*1.1+textheight(linestr));
    outtextxy(x+textwidth(str2),y+3*textheight(str)*1.1,linestr);
    char str1[]="Level:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    char levelstr[5];
    outtextxy(x,y+4*textheight(str)*1.1,str1);
    itoa(it->level,levelstr,10);
    bar(x+textwidth(str1),y+4*textheight(str)*1.1,x+textwidth(str1)+50,y+4*textheight(str)*1.1+textwidth(str1));
    outtextxy(x+textwidth(str1),y+4*textheight(str)*1.1,levelstr);
 
    settextstyle(3,HORIZ_DIR,1);
    char str3[]="Record:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y+3*textheight(str2)*1.1,str3);
    char recordstr[10];
    sprintf(recordstr,"%li",it->record);
    outtextxy(x+textwidth(str3),y+3*textheight(str)*1.1,recordstr);
    char str4[]="Last result:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    char lastresstr[10];
    outtextxy(x,y+4*textheight(str)*1.1,str4);
    sprintf(lastresstr,"%li",it->lastres);
    outtextxy(x+textwidth(str4),y+4*textheight(str)*1.1,lastresstr);
}
 
void DrawFut(int *type,void **gp,Matr *p)
{
    setfillstyle(SOLID_FILL,BLACK);
    int x=500,y=50;
    setfillstyle(LTSLASH_FILL,DARKGRAY);
    bar(x-10,y-10,x+100+10,y+400+10);
    setcolor(WHITE);
    rectangle(x,y,x+100,y+400);
    settextstyle(TRIPLEX_FONT,VERT_DIR,3);
    char str1[]="NEXT";
    settextjustify(RIGHT_TEXT,TOP_TEXT);
    outtextxy(x-3,y+10,str1);
    char str2[]="1";
    settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
    settextjustify(RIGHT_TEXT,TOP_TEXT);
    outtextxy(x,y+130,str2);
    char str3[]="2";
    outtextxy(x,y+230,str3);
    char str4[]="3";
    outtextxy(x,y+330,str4);
    for (int i=0;i<4;i++)
    {
        if (i==0)
        {
            setfillstyle(SOLID_FILL,BLACK);
            bar(x,y,x+100,y+100);
            setcolor(WHITE);
            rectangle(x,y,x+100,y+100);
        }
        for (int j=0;j<p[type[i]].size_i;j++)
            for (int k=0;k<p[type[i]].size_j;k++)
            {
                if (p[type[i]].mpt[j][k]==1)
                    putimage(x+(100-p[type[i]].size_j*20)/2+20*k,y+i*100+(100-p[type[i]].size_i*20)/2+20*j,gp[type[i]],0);
            }
    }
}
 
void Score(Glass *it,int d)
{
    it->score+=d;
    LeftPanel(it);
}
 
void Menu(char *str1)
{
    int x=20,y=300;
    int old_choice=0;
    int choice=0;
    int ch;
    char str2[]="Control";
    char str3[]="Exit";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    settextstyle(7,HORIZ_DIR,3);
    setfillstyle(SOLID_FILL,DARKGRAY);
    setcolor(WHITE);
    outtextxy(x,y,str1);
    setcolor(DARKGRAY);
    outtextxy(x,y+textheight(str1),str2);
    outtextxy(x,y+textheight(str1)+textheight(str2),str3);
    while(1)
    {
        ch=getch();
        switch(ch)
        {
            case DOWN:
            {
                old_choice=choice;
                if (choice==2) choice=0;
                else choice++;
                break;
            }
            case UP:
            {
                old_choice=choice;
                if (choice==0) choice=2;
                else choice--;
                break;
            }
            case ENTER1:
            {
                switch(choice)
                {
                    case 0:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(x,y,x+180,y+3*textheight(str1));
                        return;
                    }
                    case 1:
                    {
                        settextstyle(2,HORIZ_DIR,5);
                        setcolor(WHITE);
                        setfillstyle(SOLID_FILL,BLACK);
                        outtextxy(x+15,y+80,"BACKSPACE - ROTATE");
                        outtextxy(x+15,y+80+10,"ESC - EXIT");
                        outtextxy(x+15,y+80+10+10,"ARROWS - MOVE");
                        getch();
                        setcolor(DARKGRAY);
                        settextstyle(7,HORIZ_DIR,3);
                        bar(x+15,y+80,x+180,y+80+50);
                        break;
                    }
                    case 2:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(x,y,x+180,y+3*textheight(str1));
                        exit(1);
                    }
                }
            }
            default:
            {
                continue;
            }
        }
        setcolor(WHITE);
        switch(choice)
        {
            case 0:
            {
                outtextxy(x,y,str1);
                break;
            }
            case 1:
            {
                outtextxy(x,y+textheight(str1),str2);
                break;
            }
            case 2:
            {
                outtextxy(x,y+textheight(str1)+textheight(str2),str3);
                break;
            }
        }
        setcolor(DARKGRAY);
        switch(old_choice)
        {
            case 0:
            {
                outtextxy(x,y,str1);
                break;
            }
            case 1:
            {
                outtextxy(x,y+textheight(str1),str2);
                break;
            }
            case 2:
            {
                outtextxy(x,y+textheight(str1)+textheight(str2),str3);
                break;
            }
        }
 
    }
}
main()
{
    int i;
    cleardevice();
    //randomize();
    Matr *p=(Matr*)malloc(sizeof(Matr)*7);
    for (int i=0;i<7;i++)
        InitMatr(&p[i]);
    ReadStdFile(p,7);
    Matr **p1;
    p1=Preobr(p,7);
    int gd=0,gmode=0;
    initgraph(&gd,&gmode,"");
    cleardevice();
    void **gp=PreobrGraph(7);
    Glass field;
    CreateGlass(&field,p1);
    clock_t mark;
    double step=0.5;
    cleardevice();
    setfillstyle(XHATCH_FILL,WHITE);
    bar(0,0,getmaxx(),20);
    bar(0,getmaxy()-20,getmaxx(),getmaxy());
    setlinestyle(SOLID_LINE, 0, 2);
    setcolor(WHITE);
    line(0,20,getmaxx(),20);
    line(0,getmaxy()-20,getmaxx(),getmaxy()-20);
    setlinestyle(SOLID_LINE, 0, 1);
    int esc_flag=0;
    int type[4];
    for(i=0;i<4;i++)
    {
        type[i]=rand()%7;
    }
    LeftPanel(&field);
    while(Do(&field,type[0]))
    {
        for (i=0;i<3;i++)
        {
            type[i]=type[i+1];
        }
        type[3]=rand()%7;
        DrawFut(type,gp,p);
        Draw(&field,gp);
        do
        {
            mark=clock();
            Draw(&field,gp);
            while((double)(clock()-mark)/CLK_TCK<step/field.level)
            {
                if(kbhit())
                {
                    int ch=0;
                    ch=getch();
                    if(ch==RIGHT || ch==LEFT || ch==DOWN || ch==ENTER)
                    {
                        if (Move(&field,ch))
                        {
                            Draw(&field,gp);
                        }
                    }
                    else if (ch==UP)
                    {
                        Score(&field,10);
                        while(Fall(&field));
                    }
                    else if (ch==ESC)
                    {
                        Menu("Resume Game");
                        esc_flag=1;
                        break;
                    }
                }
            }
            //if (esc_flag) break;
        }
        while(Fall(&field));
        //if (esc_flag) break;
    }
    settextstyle(4,0,5);
    setcolor(WHITE);
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(10,360,"Game Over");
    if (field.score>field.record)
    {
        settextstyle(5,0,3);
        setcolor(WHITE);
        settextjustify(LEFT_TEXT,TOP_TEXT);
        outtextxy(20,400,"New record!");
        FILE *f=fopen("Tetris.rec","w");
        if (f)
        {
            fprintf(f,"%li\n%li\n",field.score,field.score);
            fclose(f);
        }
    }
    else
    {
        FILE *f=fopen("Tetris.rec","w");
        if (f)
        {
            fprintf(f,"%li\n%li\n",field.record,field.score);
            fclose(f);
        }
    }
    int ch;
    do
    {
        ch=getch();
    }
    while(ch!=ESC);
 
    closegraph();
    for (i=0;i<7;i++)
    {
        free(p1[i]);
        DeleteMatr(&p[7]);
    }
    free(p1);
    free(p);
    DeleteGlass(&field);
}
tetrisW.rar
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
21.05.2011, 09:59
Ответы с готовыми решениями:

Ошибки "undefined reference to". Что нужно исправить?
Ошибки.Что нужно исправить?

Undefined reference
Доброго времени суток! Создаю проект на С для ARM, для этого использую Eclipse for DS-5 на...

undefined reference to `sqrt'
Здравствуйте. Хочу корни квадратного уравнения найти. Из нижеследующего кода выходит ошибка:...

Undefined reference to 'WinMain@16'
Добрый день! У меня возникла проблема при написании кода. Сам код: #include &lt;stdio.h&gt; int...

7
14 / 14 / 4
Регистрация: 08.11.2010
Сообщений: 172
21.05.2011, 10:34  [ТС] 2
ошибки типо
[Linker error] undefined reference to `GetStockObject@4'
[Linker error] undefined reference to `SelectObject@8'
0
601 / 569 / 104
Регистрация: 07.11.2010
Сообщений: 2,004
21.05.2011, 10:41 3
какой компилятор то?
0
14 / 14 / 4
Регистрация: 08.11.2010
Сообщений: 172
21.05.2011, 17:58  [ТС] 4
там над листингом написано
dev cpp

Добавлено через 38 минут
ну что?

Добавлено через 36 минут
не много поправил, компилится
но выскакивает drawing operation was attempted when there was no current window
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
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<time.h>
#include<string.h>
#include<windows.h>
#define EMPTY 0
#define STATIC 2
#define DYNAMIC 1
#define RIGHT 77
#define DOWN 80
#define LEFT 75
#define ENTER 32
#define ENTER1 13
#define UP 72
#define ESC 27
 
typedef struct
{
        int **mpt;
        int size_i;
        int size_j;
        int vert;
        /*Matr();
        ~Matr();
        friend void ReadStdFile(Matr*,int);
        friend void Vert(Matr&);
        friend Matr** Preobr(Matr*,int);*/
}Matr;
typedef struct
{
        int x,y;
        int type;
        int pol;
}Figure;
typedef struct
{
    Matr **p;
    int **ar_old;
    int **color_ar_old;
    int **ar;
    int **color_ar;
    int size_i;
    int size_j;
    int unsigned lines;
    unsigned long score;
    unsigned long record;
    unsigned long lastres;
        Figure a;
        int level;
        /*Glass(){};
        Glass(Matr**);
        ~Glass();
        int Fall();
        int Move(int);
        int Rotate();
        int Do(int);
        void Draw(void**);
        int Create(int,int,int,int,int);
        void Destr();
        void CopyMas();
        void LeftPanel();
        void Score(int);*/
}Glass;
//void gotoxy(int xpos, int ypos);
void CreateGlass(Glass *it,Matr** p);
void DeleteGlass(Glass *it);
int CreateGlass(Glass *it);
void DestrGlass(Glass *it);
int Do(Glass *it,int type);
int Fall(Glass *it);
int Move(Glass *it,int key);
void Draw(Glass *it,void **sd);
void InitMatr(Matr *it);
void DeleteMatr(Matr *it);
void ReadStdFile(Matr *p,int N);
void** PreobrGraph(int N);
void Vert(Matr &p);
Matr** Preobr(Matr *p,int N);
void CopyMas(Glass *it);
void LeftPanel(Glass *it);
void DrawFut(int *type,void **gp,Matr *p);
void Score(Glass *it,int d);
void Menu(char *str1);
 
/*void gotoxy(int xpos, int ypos)
{
  COORD scrn;    
 
  HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
 
  scrn.X = xpos; scrn.Y = ypos;
 
  SetConsoleCursorPosition(hOuput,scrn);
}*/
void CreateGlass(Glass *it, Matr** p_)
{
    int i;
    FILE *f=fopen("Tetris.rec","r");
    if (f)
    {
        fscanf(f,"%li\n",&(it->record));
        fscanf(f,"%li\n",&(it->lastres));
        fclose(f);
    }
    it->p=p_;
    it->size_i=20;
    it->size_j=10;
    it->lines=0;
    it->level=1;
    it->score=0;
    it->ar=(int**)malloc(sizeof(int*)*it->size_i);
    for (int i=0;i<it->size_i;i++)
    {
        it->ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->ar[i][j]=EMPTY;
    }
    it->ar_old=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->ar_old[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->ar_old[i][j]=STATIC;
    }
    it->color_ar=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->color_ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->color_ar[i][j]=EMPTY;
    }
    it->color_ar_old=(int**)malloc(sizeof(int*)*it->size_i);
    for (i=0;i<it->size_i;i++)
    {
        it->color_ar[i]=(int*)malloc(sizeof(int)*it->size_j);
        for (int j=0;j<it->size_j;j++)
            it->color_ar_old[i][j]=EMPTY;
    }
};
void DeleteGlass(Glass *it)
{
    for (int i=0;i<it->size_i;i++)
    {
        free(it->ar[i]);
        free(it->color_ar[i]);
        free(it->ar_old[i]);
        free(it->color_ar_old[i]);
 
    }
    free(it->ar);
    free(it->color_ar);
    free(it->ar_old);
    free(it->color_ar_old);
}
int CreateGlass(Glass *it,int x_,int y_,int type_,int pol_,int d)
{
    int flag=1;
    for (int i=0;i<it->p[type_][pol_].size_i;i++)
        for (int j=0;j<it->p[type_][pol_].size_j;j++)
        {
            if ((y_+j<0 || y_+j>=it->size_j) || ((it->p[type_][pol_].mpt[i][j]==1 && it->ar[x_+i][y_+j]==2) && (d==LEFT || d==RIGHT || d==0 || d==ENTER)))
                flag=2;
            if ((it->p[type_][pol_].mpt[i][j]==1 && it->ar[x_+i][y_+j]==2 && d==DOWN) || x_+i==it->size_i)
                flag=0;
        }
    if (flag==2 && d==0)
    {
            for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=STATIC;
                    it->color_ar[i][j]=it->a.type;
                }
            }
            return 0;
    }
    if (flag==1)
    {
        for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=EMPTY;
                    it->color_ar[i][j]=type_;
                }
            }
        for (int i=0;i<it->p[type_][pol_].size_i;i++)
            for (int j=0;j<it->p[type_][pol_].size_j;j++)
                if (it->ar[x_+i][y_+j]!=2)
                if (it->p[type_][pol_].mpt[i][j]==1)
                {
                    it->ar[x_+i][y_+j]=1;
                    it->color_ar[x_+i][y_+j]=type_;
                }
        it->a.x=x_;
        it->a.y=y_;
        it->a.type=type_;
        it->a.pol=pol_;
    }
    else if (flag==0)
    {
        for (int i=0;i<it->size_i;i++)
            for (int j=0;j<it->size_j;j++)
            {
                if (it->ar[i][j]==1)
                {
                    it->ar[i][j]=STATIC;
                    it->color_ar[i][j]=it->a.type;
                }
            }
        DestrGlass(it);
    }
    else if (flag==2) return 0;
    return flag;
}
void DestrGlass(Glass *it)
{
    int flag;
    for (int i=it->size_i-1;i>=0;i--)
    {
        flag=1;
        for (int j=0;j<it->size_j;j++)
        {
            if (it->ar[i][j]!=STATIC)
            {
                flag=0;
            }
        }
        if (flag)
        {
            for (int i_=i;i_>0;i_--)
            {
                for (int j_=0;j_<it->size_j;j_++)
                {
                    it->ar[i_][j_]=it->ar[i_-1][j_];
                    it->color_ar[i_][j_]=it->color_ar[i_-1][j_];
                }
            }
            for (int j_=0;j_<it->size_j;j_++)
            {
                it->ar[0][j_]=0;
                it->color_ar[0][j_]=0;
            }
            it->lines++;
            Score(it,100);
            LeftPanel(it);
            if (1+it->lines/10>it->level)
            {
                //gotoxy(1,3);
                it->level=1+it->lines/10;
            }
            DestrGlass(it);
        }
    }
}
 
int Do(Glass *it,int type)
{
    if (!CreateGlass(it,0,(it->size_j-it->p[type][0].size_j)/2,type,0,0)) return 0;
    else return 1;
}
 
int Fall(Glass *it)
{
    if (!CreateGlass(it,it->a.x+1,it->a.y,it->a.type,it->a.pol,DOWN)) return 0;
    else return 1;
}
 
int Move(Glass *it,int key)
{
    switch(key)
    {
        case RIGHT:
        {
            if (!CreateGlass(it,it->a.x,it->a.y+1,it->a.type,it->a.pol,RIGHT)) return 0;
            else return 1;
        }
        case LEFT:
        {
            if (!CreateGlass(it,it->a.x,it->a.y-1,it->a.type,it->a.pol,LEFT)) return 0;
            else return 1;
        }
        case DOWN:
        {
            Score(it,1);
            if (!CreateGlass(it,it->a.x+1,it->a.y,it->a.type,it->a.pol,DOWN)) return 0;
            else return 1;
        }
        case ENTER:
        {
            if (!CreateGlass(it,it->a.x,it->a.y,it->a.type,(it->a.pol+1)%it->p[it->a.type][0].vert,ENTER)) return 0;
            else return 1;
        }
    }
}
 
void Draw(Glass *it,void **sd)
{
    int pos_x=(getmaxx()-it->size_j*20)/2,pos_y=(getmaxy()-it->size_i*20)/2;
    setcolor(WHITE);
    rectangle(pos_x,pos_y,pos_x+it->size_j*20+1,pos_y+it->size_i*20+1);
    for(int i=0;i<it->size_i;i++)
    {
        for (int j=0;j<it->size_j;j++)
        {
            if(it->ar_old[i][j]!=it->ar[i][j] || it->color_ar_old[i][j]!=it->color_ar[i][j])
            {
                switch(it->ar[i][j])
                {
                    case STATIC:
                    {
                        setfillstyle(SOLID_FILL,DARKGRAY);
                        putimage(pos_x+j*20+1,pos_y+i*20+1,sd[it->color_ar[i][j]],0);
                        break;
                    }
                    case DYNAMIC:
                    {
                        putimage(pos_x+j*20+1,pos_y+i*20+1,sd[it->a.type],0);
                        break;
                    }
                    case EMPTY:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(pos_x+j*20+1,pos_y+i*20+1,pos_x+(j+1)*20,pos_y+(i+1)*20);
                        //setfillstyle(SOLID_FILL,WHITE);
                        //fillellipse(pos_x+j*20+10,pos_y+i*20+10,1,1);
                        //bar(pos_x+j*20+1,pos_y+i*20+1,pos_x+(j+1)*20,pos_y+(i+1)*20);
                        break;
                    }
                }
            }
        }
    }
    CopyMas(it);
}
 
void InitMatr(Matr *it)
{
    it->vert=0;
    it->size_i=0;
    it->size_j=0;
    it->mpt=NULL;
}
 
void DeleteMatr(Matr *it)
{
    int i;
    for (i=0;i<it->size_i;i++)
    {
        free(it->mpt[i]);
    }
    free(it->mpt);
}
 
void ReadStdFile(Matr *p,int N)
{
    FILE *f=NULL;
    f=fopen("std.fig","r");
    if (f)
    {
        int i,u,v;
        char h[2];
        h[1]='\0';
        for (i=0;i<N;i++)
        {
            h[0]=fgetc(f);
            p[i].size_i=atoi(h);
            h[0]=fgetc(f);
            p[i].size_j=atoi(h);
            p[i].mpt=new int*[p[i].size_i];
            getc(f);
            for (u=0;u<p[i].size_i;u++)
            {
                p[i].mpt[u]=new int[p[i].size_j];
                for (v=0;v<p[i].size_j;v++)
                {
                    h[0]=fgetc(f);
                    p[i].mpt[u][v]=atoi(h);
                }
                getc(f);
            }
        }
    }
    else
    {
        printf("\nfile 'std.fig' not found!\n");
        getch();
    }
    fclose(f);
}
 
void** PreobrGraph(int N)
{
    cleardevice();
    int mas[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    unsigned int size=imagesize(1,1,20,20);
    void **sd=(void **)malloc(7*sizeof(void*));
    for (int i=0;i<N;i++)
    {
        sd[i]=malloc(size);
        /*setfillstyle(SOLID_FILL,mas[i]);
        bar(1,1,20,20);*/
        setfillstyle(SOLID_FILL,BLACK);
        bar(1,1,20,20);
        setcolor(WHITE);
        line(1,4,1,16);
        line(20,4,20,16);
        line(4,1,16,1);
        line(4,20,16,20);
        line(1,4,4,1);
        line(1,16,4,20);
        line(16,1,20,4);
        line(16,20,20,16);
        /*setfillstyle(SOLID_FILL,mas[i]);
        floodfill(10,10,WHITE);*/
        setfillstyle(SOLID_FILL,mas[i+8]);
        bar(4,4,17,17);
        setcolor(BLACK);
        rectangle(4,4,17,17);
        getimage(1,1,20,20,sd[i]);
    }
    return sd;
}
 
void Vert(Matr &p)
{
    int flag=0;
    for (int i=0;i<p.size_i;i++)
    {
        for (int j=0;j<p.size_j;j++)
        {
            if (p.mpt[i][j]!=p.mpt[p.size_i-i-1][p.size_j-j-1]) flag=1;
        }
    }
    if (flag) p.vert=4;
    else if (p.size_i==p.size_j) p.vert=1;
    else p.vert=2;
}
 
Matr** Preobr(Matr *p,int N)
{
    Matr **p1=(Matr**)malloc(sizeof(Matr*)*N);
    for (int i=0;i<N;i++)
    {
        Vert(p[i]);
        p1[i]=(Matr*)malloc(sizeof(Matr)*p[i].vert);
        for (int j=0;j<p[i].vert;j++)
        {
            if (j%2!=0)
            {
                p1[i][j].size_i=p[i].size_j;
                p1[i][j].size_j=p[i].size_i;
            }
            else
            {
                p1[i][j].size_i=p[i].size_i;
                p1[i][j].size_j=p[i].size_j;
            }
            p1[i][j].vert=p[i].vert;
            p1[i][j].mpt=(int**)malloc(sizeof(int*)*p1[i][j].size_i);
            for (int k=0;k<p1[i][j].size_i;k++)
            {
                p1[i][j].mpt[k]=(int*)malloc(sizeof(int)*p1[i][j].size_j);
                for (int l=0;l<p1[i][j].size_j;l++)
                {
                    if (j==0)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[k][l];
                    }
                    else if (j==1)
                    {
                        p1[i][j].mpt[k][p1[i][j].size_j-l-1]=p[i].mpt[l][k];
                    }
                    else if (j==2)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[p[i].size_i-k-1][p[i].size_j-l-1];
                    }
                    else if (j==3)
                    {
                        p1[i][j].mpt[k][l]=p[i].mpt[l][p[i].size_i-k];
                    }
                }
            }
        }
    }
    return p1;
}
 
void CopyMas(Glass *it)
{
    for (int i=0;i<it->size_i;i++)
        for (int j=0;j<it->size_j;j++)
        {
            it->ar_old[i][j]=it->ar[i][j];
            it->color_ar_old[i][j]=it->color_ar[i][j];
        }
}
 
void LeftPanel(Glass *it)
{
    int i;
    int x=20,y=40;
    char str[]="Score:";
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,4);
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y,str);
    char scorestr[7];
    itoa(it->score,scorestr,10);
    int dif=6-strlen(scorestr);
    scorestr[6]='\0';
    int len=strlen(scorestr);
    for (int i=0;i<len;i++)
    {
        scorestr[5-i]=scorestr[len-i-1];
    }
    for (i=0;i<dif;i++)
    {
        scorestr[i]='0';
    }
    setfillstyle(SOLID_FILL,BLACK);
    bar(x,y+textheight(str)*1.1,x+textwidth(str),y+2*textheight(str)*1.1);
    outtextxy(x,y+textheight(str)*1.1,scorestr);
    settextstyle(5,HORIZ_DIR,4);
    char str2[]="Lines:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y+3*textheight(str)*1.1,str2);
    char linestr[5];
    itoa(it->lines,linestr,10);
    bar(x+textwidth(str2),y+3*textheight(str)*1.1,x+textwidth(str2)+50,y+3*textheight(str)*1.1+textheight(linestr));
    outtextxy(x+textwidth(str2),y+3*textheight(str)*1.1,linestr);
    char str1[]="Level:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    char levelstr[5];
    outtextxy(x,y+4*textheight(str)*1.1,str1);
    itoa(it->level,levelstr,10);
    bar(x+textwidth(str1),y+4*textheight(str)*1.1,x+textwidth(str1)+50,y+4*textheight(str)*1.1+textwidth(str1));
    outtextxy(x+textwidth(str1),y+4*textheight(str)*1.1,levelstr);
 
    settextstyle(3,HORIZ_DIR,1);
    char str3[]="Record:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(x,y+3*textheight(str2)*1.1,str3);
    char recordstr[10];
    sprintf(recordstr,"%li",it->record);
    outtextxy(x+textwidth(str3),y+3*textheight(str)*1.1,recordstr);
    char str4[]="Last result:";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    char lastresstr[10];
    outtextxy(x,y+4*textheight(str)*1.1,str4);
    sprintf(lastresstr,"%li",it->lastres);
    outtextxy(x+textwidth(str4),y+4*textheight(str)*1.1,lastresstr);
}
 
void DrawFut(int *type,void **gp,Matr *p)
{
    setfillstyle(SOLID_FILL,BLACK);
    int x=500,y=50;
    setfillstyle(LTSLASH_FILL,DARKGRAY);
    bar(x-10,y-10,x+100+10,y+400+10);
    setcolor(WHITE);
    rectangle(x,y,x+100,y+400);
    settextstyle(TRIPLEX_FONT,VERT_DIR,3);
    char str1[]="NEXT";
    settextjustify(RIGHT_TEXT,TOP_TEXT);
    outtextxy(x-3,y+10,str1);
    char str2[]="1";
    settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
    settextjustify(RIGHT_TEXT,TOP_TEXT);
    outtextxy(x,y+130,str2);
    char str3[]="2";
    outtextxy(x,y+230,str3);
    char str4[]="3";
    outtextxy(x,y+330,str4);
    for (int i=0;i<4;i++)
    {
        if (i==0)
        {
            setfillstyle(SOLID_FILL,BLACK);
            bar(x,y,x+100,y+100);
            setcolor(WHITE);
            rectangle(x,y,x+100,y+100);
        }
        for (int j=0;j<p[type[i]].size_i;j++)
            for (int k=0;k<p[type[i]].size_j;k++)
            {
                if (p[type[i]].mpt[j][k]==1)
                    putimage(x+(100-p[type[i]].size_j*20)/2+20*k,y+i*100+(100-p[type[i]].size_i*20)/2+20*j,gp[type[i]],0);
            }
    }
}
 
void Score(Glass *it,int d)
{
    it->score+=d;
    LeftPanel(it);
}
 
void Menu(char *str1)
{
    int x=20,y=300;
    int old_choice=0;
    int choice=0;
    int ch;
    char str2[]="Control";
    char str3[]="Exit";
    settextjustify(LEFT_TEXT,TOP_TEXT);
    settextstyle(7,HORIZ_DIR,3);
    setfillstyle(SOLID_FILL,DARKGRAY);
    setcolor(WHITE);
    outtextxy(x,y,str1);
    setcolor(DARKGRAY);
    outtextxy(x,y+textheight(str1),str2);
    outtextxy(x,y+textheight(str1)+textheight(str2),str3);
    while(1)
    {
        ch=getch();
        switch(ch)
        {
            case DOWN:
            {
                old_choice=choice;
                if (choice==2) choice=0;
                else choice++;
                break;
            }
            case UP:
            {
                old_choice=choice;
                if (choice==0) choice=2;
                else choice--;
                break;
            }
            case ENTER1:
            {
                switch(choice)
                {
                    case 0:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(x,y,x+180,y+3*textheight(str1));
                        return;
                    }
                    case 1:
                    {
                        settextstyle(2,HORIZ_DIR,5);
                        setcolor(WHITE);
                        setfillstyle(SOLID_FILL,BLACK);
                        outtextxy(x+15,y+80,"BACKSPACE - ROTATE");
                        outtextxy(x+15,y+80+10,"ESC - EXIT");
                        outtextxy(x+15,y+80+10+10,"ARROWS - MOVE");
                        getch();
                        setcolor(DARKGRAY);
                        settextstyle(7,HORIZ_DIR,3);
                        bar(x+15,y+80,x+180,y+80+50);
                        break;
                    }
                    case 2:
                    {
                        setfillstyle(SOLID_FILL,BLACK);
                        bar(x,y,x+180,y+3*textheight(str1));
                        exit(1);
                    }
                }
            }
            default:
            {
                continue;
            }
        }
        setcolor(WHITE);
        switch(choice)
        {
            case 0:
            {
                outtextxy(x,y,str1);
                break;
            }
            case 1:
            {
                outtextxy(x,y+textheight(str1),str2);
                break;
            }
            case 2:
            {
                outtextxy(x,y+textheight(str1)+textheight(str2),str3);
                break;
            }
        }
        setcolor(DARKGRAY);
        switch(old_choice)
        {
            case 0:
            {
                outtextxy(x,y,str1);
                break;
            }
            case 1:
            {
                outtextxy(x,y+textheight(str1),str2);
                break;
            }
            case 2:
            {
                outtextxy(x,y+textheight(str1)+textheight(str2),str3);
                break;
            }
        }
 
    }
}
main()
{
    int i;
    cleardevice();
    //randomize();
    Matr *p=(Matr*)malloc(sizeof(Matr)*7);
    for (int i=0;i<7;i++)
        InitMatr(&p[i]);
    ReadStdFile(p,7);
    Matr **p1;
    p1=Preobr(p,7);
    int gd=0,gmode=0;
    initgraph(&gd,&gmode,"");
    cleardevice();
    void **gp=PreobrGraph(7);
    Glass field;
    CreateGlass(&field,p1);
    clock_t mark;
    double step=0.5;
    cleardevice();
    setfillstyle(XHATCH_FILL,WHITE);
    bar(0,0,getmaxx(),20);
    bar(0,getmaxy()-20,getmaxx(),getmaxy());
    setlinestyle(SOLID_LINE, 0, 2);
    setcolor(WHITE);
    line(0,20,getmaxx(),20);
    line(0,getmaxy()-20,getmaxx(),getmaxy()-20);
    setlinestyle(SOLID_LINE, 0, 1);
    int esc_flag=0;
    int type[4];
    for(i=0;i<4;i++)
    {
        type[i]=rand()%7;
    }
    LeftPanel(&field);
    while(Do(&field,type[0]))
    {
        for (i=0;i<3;i++)
        {
            type[i]=type[i+1];
        }
        type[3]=rand()%7;
        DrawFut(type,gp,p);
        Draw(&field,gp);
        do
        {
            mark=clock();
            Draw(&field,gp);
            while((double)(clock()-mark)/CLK_TCK<step/field.level)
            {
                if(kbhit())
                {
                    int ch=0;
                    ch=getch();
                    if(ch==RIGHT || ch==LEFT || ch==DOWN || ch==ENTER)
                    {
                        if (Move(&field,ch))
                        {
                            Draw(&field,gp);
                        }
                    }
                    else if (ch==UP)
                    {
                        Score(&field,10);
                        while(Fall(&field));
                    }
                    else if (ch==ESC)
                    {
                        Menu("Resume Game");
                        esc_flag=1;
                        break;
                    }
                }
            }
            //if (esc_flag) break;
        }
        while(Fall(&field));
        //if (esc_flag) break;
    }
    settextstyle(4,0,5);
    setcolor(WHITE);
    settextjustify(LEFT_TEXT,TOP_TEXT);
    outtextxy(10,360,"Game Over");
    if (field.score>field.record)
    {
        settextstyle(5,0,3);
        setcolor(WHITE);
        settextjustify(LEFT_TEXT,TOP_TEXT);
        outtextxy(20,400,"New record!");
        FILE *f=fopen("Tetris.rec","w");
        if (f)
        {
            fprintf(f,"%li\n%li\n",field.score,field.score);
            fclose(f);
        }
    }
    else
    {
        FILE *f=fopen("Tetris.rec","w");
        if (f)
        {
            fprintf(f,"%li\n%li\n",field.record,field.score);
            fclose(f);
        }
    }
    int ch;
    do
    {
        ch=getch();
    }
    while(ch!=ESC);
 
    closegraph();
    for (i=0;i<7;i++)
    {
        free(p1[i]);
        DeleteMatr(&p[7]);
    }
    free(p1);
    free(p);
    DeleteGlass(&field);
}
Добавлено через 5 часов 51 минуту
!!!!!
0
1563 / 1041 / 94
Регистрация: 17.04.2009
Сообщений: 2,995
21.05.2011, 18:23 5
......
0
14 / 14 / 4
Регистрация: 08.11.2010
Сообщений: 172
21.05.2011, 18:57  [ТС] 6
что это хоть за ошибка drawing operation was attempted when there was no current window?!?
0
1563 / 1041 / 94
Регистрация: 17.04.2009
Сообщений: 2,995
21.05.2011, 19:12 7
Попытка рисования, когда нет окна
0
14 / 14 / 4
Регистрация: 08.11.2010
Сообщений: 172
22.05.2011, 19:30  [ТС] 8
как исправить?
initgraph не работает?!?

Добавлено через 56 минут
ну так что?

Добавлено через 15 часов 19 минут
?????

Добавлено через 56 минут
в ф-ии void ReadStdFile(Matr *p,int N) память правильно выделяется?

Добавлено через 6 часов 55 минут
(((((
0
22.05.2011, 19:30
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
22.05.2011, 19:30
Помогаю со студенческими работами здесь

Ошибка:undefined reference to
Программа выдает ошибку: строки 11,13,13,14 undefined reference to &quot; имя соответствующей...

Ошибка undefined reference
Имеется программа. Представляет из себя поисковую систему. Пишу в dev-cpp. При компиляции вылезает...

Ошибка undefined reference to `getparam'
Прошу прощение за то что влез не в свою тему, но как то создавать отдельный топ не хочется. ...

Ошибка undefined reference to fcloseall
5 раз перепроверил. Стандартная же вроде функция. #include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include...


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

Или воспользуйтесь поиском по форуму:
8
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru