Новичок
Профиль
Группа: Участник
Сообщений: 1
Регистрация: 25.4.2012
Репутация: нет Всего: нет
|
| Код | #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <math.h> //Рисуем спички int Show(int sp[100][4], int all) { int i; //Затираем setcolor(0); for(i=0;i<100;i++) { line(150+sp[i][0],70+sp[i][1],150+sp[i][2],70+sp[i][3]); } //рисуем setcolor(7); for(i=0;i<all;i++) { line(150+sp[i][0],70+sp[i][1],150+sp[i][2],70+sp[i][3]); } return 0; } int main(void) { //============переменные int sp[100][4];//спичек 100 int Pl,Comp,All=100;//взято спичек int A,i,j; float a;//угол наклона спичек char ch;//vvod int Win=0,//победа 1 игрок 2 комп Esc=0,//выход P;//чей ход 0 комп 1 игрок randomize(); //очищаем спички for(i=0;i<100;i++) { sp[i][0]=0;sp[i][1]=0;sp[i][2]=0;sp[i][3]=0; } //задаем расположение спичек случайно for(i=0;i<100;i++) { sp[i][0]=random(300);sp[i][1]=random(150); A=random(360); a=3.14*A/180; sp[i][2]=sp[i][0]+50*sin(a); sp[i][3]=sp[i][1]+50*cos(a); } /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int xmax, ymax; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); } //Кто ходит setcolor(5); outtextxy(200,20,"KTO hodit pervim 1 - Igrok 2 - Computer"); Xod: ch=getch(); if(ch=='2')P=0;else if(ch=='1')P=1;else goto Xod; setcolor(0); outtextxy(200,20,"KTO hodit pervim 1 - Igrok 2 - Computer"); setcolor(5); outtextxy(310,400,"Igra"); Show(sp,All); //==================================== char buffer[5]; //Игра while((Win==0)&&(Esc==0)) { //============================================= //ход игрока if(P==1) { setcolor(0); sprintf(buffer, "%d",All); outtextxy(200,20,"Spichek ostalos ");outtextxy(350,20,buffer); setcolor(5); outtextxy(100,420,"Skolko spichek berem? (1-10 jmem ot 1 do 0, 0 eto 10)"); sprintf(buffer, "%d",All); outtextxy(200,20,"Spichek ostalos ");outtextxy(350,20,buffer); Pl_P: ch=getch(); setcolor(0); sprintf(buffer, "%d",All); outtextxy(200,20,"Spichek ostalos ");outtextxy(350,20,buffer); if(ch=='1')Pl=1;else if(ch=='2')Pl=2;else if(ch=='3')Pl=3;else if(ch=='4')Pl=4;else if(ch=='5')Pl=5;else if(ch=='6')Pl=6;else if(ch=='7')Pl=7;else if(ch=='8')Pl=8;else if(ch=='9')Pl=9;else if(ch=='0')Pl=10;else if(ch==27){Esc=1;goto end;}//Выход else { goto Pl_P; } //проверка на победу All=All-Pl; if(All<=0){Win=2;goto end;} P=0; }//конец хода игрока //============================================= //ход компа else { setcolor(0); outtextxy(100,420,"Skolko spichek berem? (1-10 jmem ot 1 do 0, 0 eto 10)"); sprintf(buffer, "%d",All); outtextxy(200,20,"‘Spichek ostalos ");outtextxy(350,20,buffer); if( All >12 )//если спичек больше 12 { for( i=1; i<10; i++ ) if( i*11+1 <All ) Comp=All-(i*11+1); if( Comp >10 )Comp=1; } else if( All >10 ) Comp=10; else if( All <=10 && All >1 ) Comp=All-1; else Comp=All;
} //Вывод хода компа //проверка на победу All=All-Comp; setcolor(5); sprintf(buffer, "%d",Comp); outtextxy(250,420,"Comp vzial");outtextxy(350,420,buffer); sprintf(buffer, "%d",All); outtextxy(200,20,"Spichek ostalos ");outtextxy(350,20,buffer); if(All<=0){Win=1;goto end;} P=1; outtextxy(200,460,"Najmite Space dlia prodoljenia"); getch(); setcolor(0); sprintf(buffer, "%d",Comp); outtextxy(250,420,"Comp vzial ");outtextxy(350,420,buffer); sprintf(buffer, "%d",All); outtextxy(200,20,"Spichek ostalos ");outtextxy(350,20,buffer); outtextxy(200,460,"Najmite Space dlia prodoljenia"); } //======================конец хода компа Show(sp,All); end: }//============================================ //Конец игры setcolor(0); outtextxy(100,420,"Skolko spichek berem? (1-10 jmem ot 1 do 0, 0 eto 10)"); if(Win==1) { setcolor(5); outtextxy(290,420,"Pobedil Igrok"); outtextxy(200,460,"Najmite Space dlia Vihoda"); } if(Win==2) { setcolor(5); outtextxy(280,420,"Pobedil computer"); outtextxy(200,440,"Najmite Space dlia Vihoda "); } getch(); /* vihod */ closegraph(); return 0; }
|
Это сообщение отредактировал(а) bsa - 27.4.2012, 22:49
|