Jump to content

Jogo das Damas


nerd da computacao
 Share

Recommended Posts

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>

#define   debx   120


int h=20;
int x, y, i, j, i3, j3, c, e, k=1;
int x1, y1, x2, y2, x3, y3;
int indice, ind=1;
char msg[10],ch;
typedef struct { int c1,c2,c3;
       } tab;tab g[65];



void pion(int i2,int j2,int c) //{*************** funcao ****************}
{
  int d;
  if(c==12 || c==15) d=1;
    else if(c==13) { c=15; d=2; }
      else if(c==16) { c=12; d=2; }
  setcolor(c);
  setfillstyle(d,c);
  setlinestyle(0,1,1);
  j3=debx-50+i2*50; i3=40+j2*50;
  circle(j3+25,i3-50+24,17); floodfill(j3+24,i3-50+15,c);}



void Table() //{*********************procedimento************************}
  {
   for(i=1;i<=64;i++) { g.c1=BROWN; g.c2=0; g.c3=6; }
   for(j=2;j<=8;j+=2) for(i=2;i<=8;i+=2) g[i+(j-1)*8].c1=CYAN;
   for(j=1;j<=8;j+=2) for(i=1;i<=8;i+=2) g[i+(j-1)*8].c1=CYAN;

   cleardevice();
   setlinestyle(0,2,3);
   setfillstyle(1,GREEN);
   bar(0,0,getmaxx(),getmaxy()-5);
   setcolor(LIGHTRED);
   rectangle(0,0,getmaxx(),getmaxy()-5);

   x=debx; y=40;
   setfillstyle(0,BLACK);
   bar(x+20,y+20,x+420,y+420);
   rectangle(x,y,x+400,y+400);

   for (i=1;i<=8;i++) { x = debx;
   for (j=1;j<=8;j++) { setcolor(YELLOW);
         rectangle(x,y,x+50,y+50);
         setfillstyle(1,g[i+(j-1)*8].c1);
         bar(x+2,y+2,x+48,y+48);
         x+=50;
            } y+=50;
            }
  }

void Initialit() //{*********************procedimento************************}
  {
   for(i=1;i<=8;i+=2)
   { pion(i,1,WHITE); g[i+(1-1)*8].c2=1; g[i+(1-1)*8].c3=WHITE; }
   for(i=2;i<=8;i+=2)
   { pion(i,2,WHITE); g[i+(2-1)*8].c2=1; g[i+(2-1)*8].c3=WHITE; }
   for(i=1;i<=8;i+=2)
   { pion(i,3,WHITE); g[i+(3-1)*8].c2=1; g[i+(3-1)*8].c3=WHITE; }

   for(i=2;i<=8;i+=2)
   { pion(i,6,LIGHTRED); g[i+(6-1)*8].c2=1; g[i+(6-1)*8].c3=LIGHTRED; }
   for(i=1;i<=8;i+=2)
   { pion(i,7,LIGHTRED); g[i+(7-1)*8].c2=1; g[i+(7-1)*8].c3=LIGHTRED; }
   for(i=2;i<=8;i+=2)
   { pion(i,8,LIGHTRED); g[i+(8-1)*8].c2=1; g[i+(8-1)*8].c3=LIGHTRED; }

   settextstyle(1,HORIZ_DIR,3); // 1 ou 4 ou 7
   setcolor(WHITE);
   for(i=0;i<=7;i++) { sprintf(msg,"%c",i+65); outtextxy(debx+20+i*50,10,msg); }
   for(i=0;i<=7;i++) { sprintf(msg,"%d",i+1 ); outtextxy(debx-20,50+i*50,msg); }

  }

void Select(int i,int j) //{*************** funcao ****************}
  {
   setfillstyle(1,LIGHTMAGENTA);
   bar(debx-48+i*50,j*50-8,debx-2+i*50,j*50+38);
   if(g[i+(j-1)*8].c2) pion(i,j,g[i+(j-1)*8].c3);
  }

void Bare(int i,int j) //{***************funcao ****************}
  {
   setfillstyle(1,g[i+(j-1)*8].c1);
   bar(debx-48+i*50,j*50-8,debx-2+i*50,j*50+38);
   if(g[i+(j-1)*8].c2) pion(i,j,g[i+(j-1)*8].c3);
  }

int Eguale(int x3,int y3,int i,int j) //{*************** funcao***************}
{
   if(g[x3+(y3-1)*8].c3==13 && ( g[i+(j-1)*8].c3==13 || g[i+(j-1)*8].c3==15 ) ) return(1);
    else if(g[x3+(y3-1)*8].c3==16 && ( g[i+(j-1)*8].c3==16 || g[i+(j-1)*8].c3==12 ) ) return(1);
     else return(0);
}

void deplacer() //{*********************procedimento************************}
  {
   if( g[x2+(y2-1)*8].c2==1  || g[x2+(y2-1)*8].c1==BROWN  || abs(x3-x2)==0 || abs(y3-y2)==0)
      { sound(310); delay(300); nosound(); goto ET; }

   if( (g[x3+(y3-1)*8].c3==12 && y2-y3>0) || (g[x3+(y3-1)*8].c3==15 && y2-y3<0) )
      { sound(310); delay(300); nosound(); goto ET; }

   if(g[x3+(y3-1)*8].c3!=13 && g[x3+(y3-1)*8].c3!=16)
   if(abs(x3-x2)>2||abs(y3-y2)>2) { sound(310); delay(300); nosound(); goto ET; }




  int pax, pay;
  if(g[x3+(y3-1)*8].c3==13 || g[x3+(y3-1)*8].c3==16)
  { if(abs(x3-x2)!=abs(y3-y2)) { sound(310); delay(300); nosound(); goto ET; }
    pax=(x2-x3)/abs(x2-x3); pay=(y2-y3)/abs(y2-y3); i=x3+pax; j=y3+pay;

    while(abs(i-x2)!=0) { if( g[i+(j-1)*8].c2==1 && (Eguale(x3,y3,i,j) || g[i+pax+(j-1+pay)*8].c2!=0) ) { sound(310); delay(300); nosound(); goto ET; }
           else { i+=pax; j+=pay; }
         }
    i=x3+pax; j=y3+pay;
    while(abs(i-x2)!=0) { if(g[i+(j-1)*8].c2==1) { g[i+(j-1)*8].c2=0; Bare(i,j); }
           i+=pax; j+=pay;
         }
  }

  else if((abs(x3-x2)==2||abs(y3-y2)==2))
   {
    if(x3-2==x2 && y3-2==y2) e=1;
    else if(x3+2==x2 && y3-2==y2) e=2;
    else if(x3-2==x2 && y3+2==y2) e=3;
    else if(x3+2==x2 && y3+2==y2) e=4;

   switch(e)
   {
   case 1 : { if(g[x2+1+y2*8].c2==1 && g[x2+1+y2*8].c3!=g[x3+(y3-1)*8].c3) { g[x2+1+y2*8].c2=0; Bare(x2+1,y2+1); } else { sound(310); delay(300); nosound(); goto ET; } } break;
   case 2 : { if(g[x2-1+y2*8].c2==1 && g[x2-1+y2*8].c3!=g[x3+(y3-1)*8].c3) { g[x2-1+y2*8].c2=0; Bare(x2-1,y2+1); } else { sound(310); delay(300); nosound(); goto ET; } } break;
   case 3 : { if(g[x2+1+(y2-2)*8].c2==1 && g[x2+1+(y2-2)*8].c3!=g[x3+(y3-1)*8].c3) { g[x2+1+(y2-2)*8].c2=0; Bare(x2+1,y2-1); } else { sound(310); delay(300); nosound(); goto ET; } } break;
   case 4 : { if(g[x2-1+(y2-2)*8].c2==1 && g[x2-1+(y2-2)*8].c3!=g[x3+(y3-1)*8].c3) { g[x2-1+(y2-2)*8].c2=0; Bare(x2-1,y2-1); } else { sound(310); delay(300); nosound(); goto ET; } } break;
   }
   }
   g[x2+(y2-1)*8].c2 = 1;
   g[x3+(y3-1)*8].c2 = 0;

   g[x2+(y2-1)*8].c3 = g[x3+(y3-1)*8].c3;
   g[x3+(y3-1)*8].c3 = 6;

   if(y2==8 && g[x2+(y2-1)*8].c3==15) g[x2+(y2-1)*8].c3=13;
    else if(y2==1 && g[x2+(y2-1)*8].c3==12) g[x2+(y2-1)*8].c3=16;

   Base(x3,y3);
   Base(x2,y2);
ET:  ind = 1;

  }

void Dama()  //{*********************procedimento************************}
  {
   x1=x2=1; y1=y2=1;
   Select(x1,y1);

while (ch!=27) {

   x2=x1; y2=y1;

TQ:ch=getch();

   if(ch==13) if(ind) if(g[x2+(y2-1)*8].c2==0) goto TQ;
             else { x3=x2; y3=y2; indice=1; ind=0; ch=getch(); }
          else  deplacer();

   switch(ch)
   {
   case 53 :{ x1--; y1++; } break;
   case 54 :{ x1++; y1++; } break;
   case 56 :{ x1--; y1--; } break;
   case 57 :{ x1++; y1--; } break;
   }
    if(x1==0 && ch==56) { x1++; y1++; }
    else if(x1==0 && ch==53) { x1++; y1--; }

    else if(x1==9 && ch==57) { x1--; y1++; }
    else if(x1==9 && ch==54) { x1--; y1--; }
    else if(y1==0 && ch==56) { x1++; y1++; }
    else if(y1==9 && ch==53) { x1++; y1--; }
    else if(y1==0 && ch==57) { x1--; y1++; }
    else if(y1==9 && ch==54) { x1--; y1--; }

   if(!indice) if(x2!=x3 || y2!=y3 || ind==1) Bare(x2,y2);
   indice=0;
   Select(x1,y1);
        }
  }

int main(void)        /*****      programa principal    88888*****/

{
   /* d */
   int gdriver = DETECT, gmode, errorcode;

   /* inicializacao das variaveis */
   initgraph(&gdriver, &gmode, "");

   /* resultado  */
   errorcode = graphresult();
   

   Table();

   Initialit();

   Damma();

   /* clean up */
   closegraph();
   return 0;




}

o que tem de errado nesse codigoooooo? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ???

Link to comment
Share on other sites

nerd da computacao, se tu não sabes o que está errado com esse código não vamos ser nós, que estamos por fora, que vamos conseguir saber.

E muito menos vamos ser nós que vamos fazer o teu trabalho da escola...

Se queres ajuda coloca as tuas dúvidas de forma clara e concreta.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.