Created
July 23, 2013 16:27
-
-
Save viniciusjarina/6063853 to your computer and use it in GitHub Desktop.
Dama2001 - 15 yo checkers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <conio.h> | |
#include "allegro.h" | |
#include <math.h> | |
#include <conio.h> | |
#include <ctype.h> | |
#define NADA -10 | |
#define X1 ((xf-x0)/abs(xf-x0)) | |
#define Y1 ((yf-y0)/abs(yf-y0)) | |
#define D 10 // deslocamento do tabuleiro na tela | |
#define E 25 | |
#define COR_JOGADOR 0 | |
#define COR_MAQUINA 1 | |
#define COR_CASAPAR 2 | |
#define COR_CASAIMP 3 | |
#define COR_CONTORN 4 | |
/******** DECLARECAO DE VARIAVEIS E TIPOS DE VARIAVEIS ********/ | |
typedef char MATRIZ[8][8]; | |
typedef struct { | |
unsigned char CORES[5]; //cor da peca do usuario | |
unsigned char SOPRO,OPCAO,COMER_ATRAZ; | |
MATRIZ tabuleiro; | |
char total_comido,upecas,mpecas,sopradas,mtotal_comido; | |
}JOGO; | |
struct info_maq | |
{ | |
int delta; | |
char x0,xf,y0,yf; | |
}; | |
/************************ * ** ** * **********************/ | |
unsigned char TAM; // tamanho do tabuleiro // lucia - vitor sapiensa => tel: 3886-6763 | |
unsigned char SOPRO=TRUE,OPCAO=2,COMER_ATRAZ=1; | |
unsigned char TERMINA=FALSE; | |
unsigned char COR; //cor da peca do usuario | |
unsigned char COR_COMP; //cor da peca do computador | |
unsigned char COR_CASA1; //cor da casa da peca | |
unsigned char COR_CASA2; //cor da outra casa | |
unsigned char COR_LINHA; //cor da outra casa | |
char i,j,coluna[2],linha[2],sequencia=0,ja_jogou=FALSE;// 0-mouse 1-selecao | |
MATRIZ tabuleiro;//controle jogo | |
MATRIZ selecao;//controle selecao | |
MATRIZ posso_mover;//controle sequencia | |
DATAFILE *dados; // VARIAVEIS GLOBAIS // | |
char total_comido,upecas,mpecas,sopradas,mtotal_comido; | |
/********************************************************************/ | |
void copy_matriz(MATRIZ m,MATRIZ n) { | |
char a,b; | |
for(a=0;a<=7;a++) | |
for(b=0;b<=7;b++) | |
m[a][b]=n[a][b]; | |
} | |
/************************ CONTROLE de SALVAR/ CARREGAR JOGO******/ | |
JOGO zera_jogo(void) | |
{ | |
JOGO n_jogo; | |
n_jogo.CORES[0]=1; | |
n_jogo.CORES[1]=4; | |
n_jogo.CORES[2]=223; | |
n_jogo.CORES[3]=28; | |
n_jogo.CORES[5]=255; | |
n_jogo.OPCAO=OPCAO; | |
n_jogo.SOPRO=SOPRO; | |
n_jogo.COMER_ATRAZ=COMER_ATRAZ; | |
n_jogo.total_comido=0; n_jogo.upecas=12; n_jogo.mpecas=12; n_jogo.sopradas=0; n_jogo.mtotal_comido=0; | |
for(i=0;i<=7;i++) | |
for(j=0;j<=7;j++) { | |
n_jogo.tabuleiro[i][j]=0; // zerando tabuleiro | |
selecao[i][j]=FALSE ; // zerando matriz selecao | |
posso_mover[i][j]=FALSE ; // zerando matriz de checagem | |
if((i+j)%2==1 && i<3)n_jogo.tabuleiro[i][j]='v';//botando pedras v | |
if((i+j)%2==1 && i>4)n_jogo.tabuleiro[i][j]='a';// botando pedras*/ | |
} | |
return n_jogo; | |
} | |
JOGO load_game(void) | |
{ | |
FILE *file_save; | |
JOGO save; | |
if(fopen("dama.sav","r")==NULL) | |
{ | |
file_save=fopen("dama.sav","w"); | |
save=zera_jogo(); | |
fwrite(&save,sizeof(save),1,file_save); | |
fclose(file_save); | |
} | |
file_save=fopen("dama.sav","r+"); | |
fread(&save,sizeof(save),1,file_save); | |
fclose(file_save); | |
return save; | |
} | |
void save_jogo(void) | |
{ | |
JOGO save; | |
FILE *file_save; | |
save.CORES[COR_JOGADOR]=COR; | |
save.CORES[COR_MAQUINA]=COR_COMP; | |
save.CORES[COR_CASAPAR]=COR_CASA1; | |
save.CORES[COR_CASAIMP]=COR_CASA2; | |
save.CORES[COR_CONTORN]=COR_LINHA; | |
copy_matriz(save.tabuleiro,tabuleiro); | |
save.SOPRO=SOPRO; | |
save.OPCAO=OPCAO; | |
save.COMER_ATRAZ=COMER_ATRAZ; | |
save.total_comido=total_comido; | |
save.upecas=upecas; | |
save.mpecas=mpecas; | |
save.sopradas=sopradas;save.mtotal_comido=mtotal_comido; | |
if(fopen("dama.sav","r")==NULL) | |
{ | |
file_save=fopen("dama.sav","w");fclose(file_save); | |
} | |
file_save=fopen("dama.sav","r+"); | |
fwrite(&save,sizeof(save),1,file_save); | |
fclose(file_save); | |
} | |
/************ FUNCOES GRAFICAS ***************/ | |
int menu(void) | |
{ | |
unsigned char a=0; | |
set_color_conversion(COLORCONV_8_TO_16); | |
dados=load_datafile("dama.dat"); | |
set_gfx_mode(GFX_AUTODETECT,320,200, 0, 0); | |
set_pallete (dados[9].dat);clear(screen); | |
blit (dados[2].dat, screen, 0,0,0,0,640,480); | |
while(a!=27) | |
{ show_mouse(screen); | |
vsync(); | |
show_mouse(NULL); | |
if(mouse_x>102 && mouse_x <200 && mouse_y>62 && mouse_y<86) | |
{ | |
if(mouse_b){novo_jogo(zera_jogo());while(mouse_b==1){}return(1);} // novo jogo | |
else blit (dados[4].dat, screen, 0,0,102,61,320,200); | |
} | |
else | |
blit (dados[3].dat, screen, 0,0,102,61,320,200); | |
if(mouse_x>102 && mouse_x <200 && mouse_y>(62+25) && mouse_y<(86+25)) | |
{ | |
if(mouse_b){novo_jogo(load_game());while(mouse_b==1){}return(1);} // carregar | |
else blit (dados[1].dat, screen, 0,0,102,(61+25),320,200); | |
} | |
else | |
blit (dados[0].dat, screen, 0,0,102,(61+25),320,200); | |
if((mouse_x>102 && mouse_x <200)&&(mouse_y>(62+50) &&mouse_y<(86+50))) | |
{ | |
if(mouse_b){opcao();while(mouse_b==1){}return(1);} // opcoes | |
else blit (dados[6].dat, screen, 0,0,102,(61+50),320,200); | |
} | |
else | |
blit (dados[5].dat, screen, 0,0,102,(61+50),320,200); | |
if((mouse_x>102 && mouse_x <200)&&(mouse_y>(62+75) && mouse_y<(86+75))) | |
{ | |
if(mouse_b)return 0; //sair | |
else blit (dados[8].dat, screen, 0,0,102,(61+75),320,200); | |
} | |
else | |
blit (dados[7].dat, screen, 0,0,102,(61+75),320,200); | |
if(kbhit())a=getch(); | |
} | |
return 0; | |
} | |
void casa(int pos_x,int pos_y,int cor) | |
{ | |
drawing_mode(0,NULL,0,0); | |
rect(screen,(TAM*pos_x)+D,(TAM*pos_y)+E,((TAM*pos_x)+TAM)+D,((TAM*pos_y)+TAM)+E,COR_LINHA); | |
rectfill(screen,(TAM*pos_x)+1+D,(TAM*pos_y)+1+E,((TAM*pos_x)+TAM)-1+D,((TAM*pos_y)+TAM)-1+E,cor); | |
} | |
void peca(int pos_x,int pos_y,int cor,int fill,int size) | |
{ | |
drawing_mode(0,NULL,0,0); | |
circle(screen,pos_x+D,pos_y+E,size,(cor==COR_CASA1)?cor:makecol(0,0,0)); | |
if(fill) | |
{ | |
circlefill(screen,pos_x+D,pos_y+E,size-1,cor); | |
}else | |
{ | |
circlefill(screen,pos_x+D,pos_y+E,size-2,cor); | |
circlefill(screen,pos_x+D,pos_y+E,size-4,0); | |
circlefill(screen,pos_x+D,pos_y+E,size-6,cor); | |
circlefill(screen,pos_x+D,pos_y+E,size-8,0); | |
} | |
} | |
void come(int x0,int y0,int xf,int yf,char type) | |
{ | |
if(abs(x0-xf)>1) // logica de comida | |
{ | |
if(toupper(type)=='A' && toupper(tabuleiro[yf-Y1][xf-X1])=='V') | |
{total_comido++;mpecas--;} | |
if(toupper(type)=='V' && toupper(tabuleiro[yf-Y1][xf-X1])=='A') | |
{upecas--;mtotal_comido++;} | |
tabuleiro[yf-Y1][xf-X1]=0; | |
} | |
}// fim da fucao come; | |
void move_from_to(int x0,int y0,int xf,int yf,int cor,char type) { | |
int raio=TAM*0.4; | |
int x,y; //move minha pedra de uma dada posicao p/ outra | |
int fill;char aux; // arrastando-a pixel `a pixel | |
switch(type) | |
{ | |
case 'a' :{fill=1;break;} | |
case 'A' :{fill=0;break;} | |
case 'v' :{fill=1;break;} | |
case 'V' :{fill=0;break;} | |
} | |
show_mouse(screen); | |
if(x0==xf && y0==yf) | |
peca(TAM*(x0+0.5) ,TAM*(y0+0.5),cor,fill,raio); | |
else | |
{ | |
for(x=0;x<TAM*abs(x0-xf);x++) | |
{ | |
peca(TAM*(x0+0.5)+X1*x,TAM*(y0+0.5) + Y1*x,COR_CASA1,1,raio+2); | |
peca(TAM*(x0+0.5)+X1*(x+1),TAM*(y0+0.5) +Y1*(x+1),cor,fill,raio); | |
rest(7); | |
casa(x0+X1*(1+x/TAM),y0 + Y1*(x/TAM),COR_CASA2); | |
casa(x0+X1*(x/TAM) ,y0 + Y1*(1+x/TAM),COR_CASA2); | |
casa(x0+X1*(x/TAM),y0+Y1*(x/TAM),COR_CASA1); | |
} | |
come(x0,y0,xf,yf,type); | |
}//else | |
} | |
int menu_opcoes(void) | |
{ | |
do { | |
show_mouse(screen); | |
vsync(); | |
show_mouse(NULL); | |
rect(screen,1 ,0,100 ,20,9); | |
rect(screen,100 ,0,200 ,20,9); | |
rect(screen,200,0,300,20,9); | |
if(mouse_x<100 && mouse_x>1 && mouse_y<20 && mouse_y>0) | |
{ | |
textprintf(screen,font,36,8,12,"JOGO"); | |
if(mouse_b==1) | |
{ | |
rectfill(screen,1,20,100,100,17); | |
rect(screen,1,20,100,100,9); | |
while(mouse_x<100 && mouse_x>1 &&mouse_y<100 && mouse_y>1) | |
{ | |
if(mouse_y>20 && mouse_y<40) | |
{ | |
textprintf(screen,font,36,8+20,9,"Novo"); | |
if(mouse_b==1)novo_jogo(zera_jogo()); | |
} | |
else | |
textprintf(screen,font,36,8+20,15,"Novo"); | |
if(mouse_y>40 && mouse_y<60) | |
{ | |
textprintf(screen,font,22,8+40,9,"Carregar"); | |
if(mouse_b==1)novo_jogo(load_game()); | |
} | |
else | |
textprintf(screen,font,22,8+40,15,"Carregar"); | |
if(mouse_y>60 && mouse_y<80) | |
{ | |
textprintf(screen,font,30,8+60,9,"Salvar"); | |
if(mouse_b==1)save_jogo(); | |
} | |
else | |
textprintf(screen,font,30,8+60,15,"Salvar"); | |
if(mouse_y>80 && mouse_y<100) | |
{ | |
textprintf(screen,font,36,8+80,9,"Sair"); | |
if(mouse_b==1)return(0); | |
} | |
else | |
textprintf(screen,font,36,8+80,15,"Sair"); | |
show_mouse(screen); | |
vsync(); | |
show_mouse(NULL); | |
} | |
clear(screen);atualiza_tela();refresh_screen();refresh_quadro(); | |
} | |
} | |
else | |
textprintf(screen,font,36,8,15,"JOGO"); | |
if(mouse_x<200 && mouse_x>100 && mouse_y<20 && mouse_y>0) | |
{ | |
textprintf(screen,font,136,8,12,"SOM"); | |
if(mouse_b==1) | |
{ | |
rectfill(screen,100,20,200,60,17); | |
rect(screen,100,20,200,60,9); | |
while(mouse_x<200 && mouse_x>100 &&mouse_y<60 && mouse_y>1) | |
{ | |
if(mouse_y>20 && mouse_y<40) | |
{ | |
textprintf(screen,font,130,8+20,9,"Ligar"); | |
} | |
else | |
textprintf(screen,font,130,8+20,15,"Ligar"); | |
if(mouse_y>40 && mouse_y<60) | |
{ | |
textprintf(screen,font,122,8+40,9,"Desligar"); | |
} | |
else | |
textprintf(screen,font,122,8+40,15,"Desligar"); | |
show_mouse(screen); | |
vsync(); | |
show_mouse(NULL); | |
} //while_1 | |
clear(screen);atualiza_tela();refresh_screen();refresh_quadro(); | |
} | |
} | |
else | |
textprintf(screen,font,136,8,15,"SOM"); | |
if(mouse_x<300 && mouse_x>200 && mouse_y<20 && mouse_y>0) | |
{ | |
textprintf(screen,font,236,8,12,"VIDEO"); | |
if(mouse_b==1) | |
{ | |
rectfill(screen,200,20,300,60,17); | |
rect(screen,200,20,300,60,9); | |
while(mouse_x<300 && mouse_x>200 &&mouse_y<60 && mouse_y>1) | |
{ | |
if(mouse_y>20 && mouse_y<40) | |
{ | |
textprintf(screen,font,230,8+20,9,"800x600"); | |
if(mouse_b==1) | |
set_gfx_mode(GFX_AUTODETECT,800,600,0,0); | |
TAM=(sqrt(SCREEN_H*SCREEN_W)*0.75)/8; | |
} | |
else | |
textprintf(screen,font,230,8+20,15,"800x600"); | |
if(mouse_y>40 && mouse_y<60) | |
{ | |
textprintf(screen,font,230,8+40,9,"640x480"); | |
if(mouse_b==1) | |
set_gfx_mode(GFX_AUTODETECT,640,480,0,0); | |
TAM=(sqrt(SCREEN_H*SCREEN_W)*0.75)/8; | |
} | |
else | |
textprintf(screen,font,230,8+40,15,"640x480"); | |
show_mouse(screen); | |
vsync(); | |
show_mouse(NULL); | |
} | |
clear(screen);atualiza_tela();refresh_screen();refresh_quadro(); | |
} | |
} | |
else | |
textprintf(screen,font,236,8,15,"VIDEO"); | |
}while(mouse_x<300 && mouse_y<21); | |
return 1; | |
} | |
int refresh_screen(void) | |
{ | |
if(!(linha[0]==linha[1] && coluna[0]==coluna[1]))move_from_to(coluna[1],linha[1],coluna[1],linha[1],COR+8,tabuleiro[linha[1]][coluna[1]]); | |
for(i=0;i<=7;i++) | |
for(j=0;j<=7;j++){ | |
if(linha[1]!=i && coluna[1]!=j) | |
(!tabuleiro[i][j]) ? 0 : | |
move_from_to(j,i,j,i,(toupper(tabuleiro[i][j])=='A') ? COR :COR_COMP,tabuleiro[i][j]); | |
if(tabuleiro[i][j]==0 && (linha[0]!=i || coluna[0]!=j) && (i+j)%2==1)casa(j,i,COR_CASA1); | |
if((i+j)%2==0 && (linha[0]!=i || coluna[0]!=j))casa(j,i,COR_CASA2); | |
} | |
} | |
int atualiza_tela(void) | |
{ | |
for(i=0;i<8;i++) | |
for(j=!(i%2);j<=7;j+=2){ | |
casa(j,i,COR_CASA1); | |
(!tabuleiro[i][j])? 0 :move_from_to(j,i,j,i,(toupper(tabuleiro[i][j])=='A')?COR:COR_COMP,tabuleiro[i][j]); | |
} | |
} | |
int refresh_quadro(void){ | |
rect(screen,(TAM*8)+D+18,30,(TAM*8)+D+198,400,9); | |
textprintf(screen,font,(TAM*8)+D+48,50,9,"-= STATUS =-"); | |
rect(screen,(TAM*8)+D+28,70,(TAM*8)+D+188,220,COR_COMP); | |
textprintf(screen,font,(TAM*8)+D+58,80,COR_COMP,"MAQUINA"); | |
textprintf(screen,font,(TAM*8)+D+48,100,15,"Total Pedras: %d ",mpecas); | |
textprintf(screen,font,(TAM*8)+D+48,115,15,"Tomadas: %d",mtotal_comido); | |
textprintf(screen,font,(TAM*8)+D+48,130,(SOPRO)?15:8,"Sopradas: 0 "); | |
textprintf(screen,font,(TAM*8)+D+48,145,15,"Perdidas: %d ",12-mpecas); | |
rect(screen,(TAM*8)+D+28,225,(TAM*8)+D+188,380,COR); | |
textprintf(screen,font,(TAM*8)+D+58,240,COR,"JOGADOR"); | |
textprintf(screen,font,(TAM*8)+D+48,255,15,"Total Pedras: %d ",upecas); | |
textprintf(screen,font,(TAM*8)+D+48,270,15,"Tomadas: %d",total_comido); | |
textprintf(screen,font,(TAM*8)+D+48,285,(SOPRO)?15:8,"Sopradas: %d ",sopradas); | |
textprintf(screen,font,(TAM*8)+D+48,300,15,"Perdidas: %d",12-upecas-sopradas); | |
} | |
int opcao() | |
{ | |
char x; | |
dados=load_datafile("dama.dat"); | |
show_mouse(screen); | |
set_gfx_mode(GFX_AUTODETECT,320,200, 0, 0); | |
set_pallete (dados[9].dat); | |
blit (dados[2].dat, screen, 0,0,0,0,640,480); | |
blit (dados[5].dat, screen, 0,0,100,15,640,480); | |
rect (screen,9 ,45,111,60,21); | |
rectfill(screen,10,46,110,59, 0); | |
textprintf(screen,font,12,49,123,"Formar dama:"); | |
rect (screen,9,120,111,135,21); | |
rectfill(screen,10,121,110,134,0); | |
textprintf(screen,font,12,124,123,"Sopro :"); | |
rect (screen,9,147,141,161,21); | |
rectfill(screen,10,148,140,160,0); | |
textprintf(screen,font,11,152,123,"Comer para tr·s:"); | |
rect (screen,149 ,120,198,135,14); | |
rectfill(screen,150,121,197,134, 1); | |
rect (screen,149,147,198,161,14); | |
rectfill(screen,150,148,197,160, 1); | |
rect (screen,199 ,147,249,161,14); | |
rectfill(screen,200,148,248,160, 1); | |
rect (screen,199,120,249,135,14); | |
rectfill(screen,200,121,248,134, 1); | |
rect (screen,114,173,191,188,255); | |
rectfill(screen,115,174,190,187, 0); | |
for(x=15;x<=45;x+=15) | |
{ | |
rect (screen,2 ,48+x,318,60+x,14); | |
rectfill(screen,3,49+x,319,59+x, 1); | |
} | |
rest(2); | |
while(mouse_b==1); | |
do{ | |
show_mouse(NULL); | |
show_mouse(screen); | |
vsync(); | |
if(mouse_b==1) | |
{ | |
if(mouse_x>2 && mouse_y>63 && mouse_x<319 && mouse_y<75 ) OPCAO=2; | |
else if(mouse_x>2 && mouse_y>78 && mouse_x<319 && mouse_y<90 ) OPCAO=1; | |
else if(mouse_x>2 && mouse_y>93 && mouse_x<319 && mouse_y<105) OPCAO=0; | |
else if(mouse_x>150 && mouse_y>120 && mouse_x<198 && mouse_y<135) SOPRO=TRUE; | |
else if(mouse_x>200 && mouse_y>148 && mouse_x<249 && mouse_y<161) COMER_ATRAZ=FALSE; | |
else if(mouse_x>150 && mouse_y>148 && mouse_x<198 && mouse_y<161) COMER_ATRAZ=TRUE; | |
else if(mouse_x>200 && mouse_y>120 && mouse_x<249 && mouse_y<135) SOPRO=FALSE; | |
else if(mouse_x>115 && mouse_y>173 && mouse_x<191 && mouse_y<188) return(0); | |
} | |
textprintf(screen,font,205,152,(!COMER_ATRAZ)?255:35,"NAO"); | |
textprintf(screen,font,151,150,(COMER_ATRAZ)?255:35,"SIM"); | |
textprintf(screen,font,155,124,(SOPRO)?255:35,"SIM"); | |
textprintf(screen,font,205,123,(!SOPRO)?255:35,"NAO"); | |
textprintf(screen,font,5,65,(OPCAO==2)?255:35,"Somente ao acabar a rodada na 1™ linha"); | |
textprintf(screen,font,5,81,(OPCAO==1)?255:35,"Ao passar na 1™ linha (acaba rodada)"); | |
textprintf(screen,font,5,96,(OPCAO==0)?255:35,"Ao passar na 1™ linha (continua rodada)"); | |
textprintf(screen,font,118,177,(mouse_x>115 && mouse_y>173 && mouse_x<191 && mouse_y<188)?255:151," OK"); | |
if(kbhit())x=getch(); | |
}while(x!=27); | |
} | |
/****************************************************************/ | |
/******************* JOGADAS DA MAQUINA ***************************/ | |
/*********************************************************************/ | |
char mlinha[2],mcoluna[2],mposso_mover[8][8],msequencia; | |
MATRIZ back; | |
struct info_maq info[12];// 12 pois soh ha 12 pecas .. | |
#define MC1 (mcoluna[1]==mcoluna[0])?1:(mcoluna[0]-mcoluna[1])/abs(mcoluna[0]-mcoluna[1]) | |
#define ML1 (mlinha[1]==mlinha[0])?1:(mlinha[0]-mlinha[1])/abs(mlinha[0]-mlinha[1]) | |
#define mc1 (mcoluna[1]==col)?0:(col-mcoluna[1])/abs(col-mcoluna[1]) | |
#define ml1 (mlinha[1]==lin)?0:(lin-mlinha[1])/abs(lin-mlinha[1]) | |
//copy_matriz(back,tabuleiro);// salvo o meu tabuleiro em um backup | |
void mnao_move(void) | |
{ | |
msequencia=FALSE; | |
for(i=0;i<=7;i++) | |
for(j=0;j<=7;j++) | |
mposso_mover[i][j]=0; | |
} | |
char monde_pode_move(void) | |
{ | |
char pode=FALSE; | |
if(tabuleiro[mlinha[1]][mcoluna[1]]=='v')// se for pedra | |
{ | |
if( toupper(tabuleiro[mlinha[1]+1][mcoluna[1]+1])!='A') | |
{ | |
if(mlinha[1]<7 && mcoluna[1]<7 && toupper(tabuleiro[mlinha[1]+1][mcoluna[1]+1])!='V') | |
{ mposso_mover[mlinha[1]+1][mcoluna[1]+1]=1;pode=TRUE;} | |
} | |
else// | |
{ // | |
if(tabuleiro[mlinha[1]+2][mcoluna[1]+2]==0 && mcoluna[1]<6 && mlinha[1]<6) | |
{mposso_mover[mlinha[1]+2][mcoluna[1]+2]=3;msequencia=1;pode=TRUE;} | |
} | |
if(toupper(tabuleiro[mlinha[1]+1][mcoluna[1]-1])!='A') | |
{ | |
if(mlinha[1]<7 && mcoluna[1]>0 && toupper(tabuleiro[mlinha[1]+1][mcoluna[1]-1])!='V') | |
{mposso_mover[mlinha[1]+1][mcoluna[1]-1]=1;pode=TRUE;} | |
} | |
else | |
{ | |
if(mlinha[1]<6 && mcoluna[1]>1 && tabuleiro[mlinha[1]+2][mcoluna[1]-2]==0) | |
{mposso_mover[mlinha[1]+2][mcoluna[1]-2]=2;msequencia=1;pode=TRUE;} | |
} | |
if(mlinha[1]>1 && COMER_ATRAZ) | |
{ | |
if(mcoluna[1]<6 && toupper(tabuleiro[mlinha[1]-1][mcoluna[1]+1])=='A' && tabuleiro[mlinha[1]-2][mcoluna[1]+2]==0) | |
{mposso_mover[mlinha[1]-2][mcoluna[1]+2]=5;msequencia=1;pode=TRUE;} | |
if(mcoluna[1]>1 && toupper(tabuleiro[mlinha[1]-1][mcoluna[1]-1])=='A' && tabuleiro[mlinha[1]-2][mcoluna[1]-2]==0) | |
{mposso_mover[mlinha[1]-2][mcoluna[1]-2]=6;msequencia=1;pode=TRUE;} | |
} | |
} | |
else // se for dama | |
{ | |
i=1; j=1; | |
while(toupper(tabuleiro[mlinha[1]-i][mcoluna[1]-j])!='V' && (mlinha[1]-i)>=0 && (mcoluna[1]-j)>=0 && | |
!((toupper(tabuleiro[mlinha[1]-i][mcoluna[1]-j])=='A' && toupper(tabuleiro[mlinha[1]-i-1][mcoluna[1]-j-1])=='A')|| | |
(toupper(tabuleiro[mlinha[1]-i][mcoluna[1]-j])=='A' && toupper(tabuleiro[mlinha[1]-i-1][mcoluna[1]-j-1])=='V'))) { | |
if(toupper(tabuleiro[mlinha[1]-i][mcoluna[1]-j])=='A') | |
if(tabuleiro[mlinha[1]-i-1][mcoluna[1]-j-1]==0 && | |
(mlinha[1]-i)>=1 && (mcoluna[1]-j)>=1) | |
{ | |
mposso_mover[mlinha[1]-i-1][mcoluna[1]-j-1]=3; | |
msequencia=TRUE; | |
break; | |
}else break; | |
mposso_mover[mlinha[1]-i][mcoluna[1]-j]=1; | |
j++;i++;pode=TRUE; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[mlinha[1]-i][mcoluna[1]+j])!='V' && (mlinha[1]-i)>=0 && (mcoluna[1]+j)<=7 && | |
!(( toupper(tabuleiro[mlinha[1]-i][mcoluna[1]+j])=='A' && toupper(tabuleiro[mlinha[1]-i-1][mcoluna[1]+j+1])=='A') || | |
( toupper(tabuleiro[mlinha[1]-i][mcoluna[1]+j])=='A' && toupper(tabuleiro[mlinha[1]-i-1][mcoluna[1]+j+1])=='V'))) { | |
if(toupper(tabuleiro[mlinha[1]-i][mcoluna[1]+j])=='A') | |
if(tabuleiro[mlinha[1]-i-1][mcoluna[1]+j+1]==0 && | |
(mlinha[1]-i)>=1 && (mcoluna[1]+j)<=6) { | |
mposso_mover[mlinha[1]-i-1][mcoluna[1]+j+1]=2; | |
msequencia=TRUE;pode=TRUE; | |
break; | |
}else break; | |
mposso_mover[mlinha[1]-i][mcoluna[1]+j]=1; | |
j++;i++;pode=TRUE; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]+j])!='V' && (mlinha[1]+i)<=7 && (mcoluna[1]+j)<=7 && | |
!((toupper(tabuleiro[mlinha[1]+i][mcoluna[1]+j])=='A' && toupper(tabuleiro[mlinha[1]+i+1][mcoluna[1]+j+1])=='A')|| | |
(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]+j])=='A' && toupper(tabuleiro[mlinha[1]+i+1][mcoluna[1]+j+1])=='V'))) { | |
if(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]+j])=='A' ) | |
if(tabuleiro[mlinha[1]+i+1][mcoluna[1]+1+j]==0 && | |
(mlinha[1]+i)<=6 && (mcoluna[1]+j)<=6) { | |
mposso_mover[mlinha[1]+i+1][mcoluna[1]+j+1]=6; | |
msequencia=TRUE;pode=TRUE; | |
break; | |
} else break; | |
mposso_mover[mlinha[1]+i][mcoluna[1]+j]=1; | |
j++;i++;pode=TRUE; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]-j])!='V' && (mlinha[1]+i)<=7 && (mcoluna[1]-j)>=0 && | |
!((toupper(tabuleiro[mlinha[1]+i][mcoluna[1]-j])=='A' && toupper(tabuleiro[mlinha[1]+i+1][mcoluna[1]-j-1])=='A')|| | |
(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]-j])=='A' && toupper(tabuleiro[mlinha[1]+i+1][mcoluna[1]-j-1])=='V'))) { | |
if(toupper(tabuleiro[mlinha[1]+i][mcoluna[1]-j])=='A') | |
if(tabuleiro[mlinha[1]+i+1][mcoluna[1]-j-1]==0 && | |
(mlinha[1]+i)<=6 && (mcoluna[1]-j)>=1) { | |
mposso_mover[mlinha[1]+i+1][mcoluna[1]-j-1]=5; | |
msequencia=TRUE;pode=TRUE; | |
break; | |
}else break; | |
mposso_mover[mlinha[1]+i][mcoluna[1]-j]=1; | |
j++;i++;pode=TRUE; | |
} | |
} | |
return(pode); | |
} | |
void jogada_da_maquina(void) | |
{ | |
char lin,col,aux,aux2; | |
mnao_move(); | |
for(mlinha[1]=7;mlinha[1]>=0 && ja_jogou;mlinha[1]--) | |
{ | |
for(mcoluna[1]=7;mcoluna[1]>=0 && ja_jogou;mcoluna[1]--) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') | |
{ | |
if(msequencia) | |
{ | |
if(OPCAO==1) if(tabuleiro[mlinha[1]][mcoluna[1]]=='V')TERMINA=FALSE;else TERMINA=TRUE; | |
for(mlinha[0]=7;mlinha[0]>=0 && ja_jogou;mlinha[0]--) | |
for(mcoluna[0]=7;mcoluna[0]>=0 && ja_jogou;mcoluna[0]--) | |
if(mposso_mover[mlinha[0]][mcoluna[0]]>1) | |
if( | |
(toupper(tabuleiro[ mlinha[0]- ML1][mcoluna[0]-MC1])=='A' | |
&& | |
tabuleiro [ mlinha[0]- 2*ML1] | |
[ mcoluna[0]- 2*MC1]==0) || | |
(toupper(tabuleiro[ mlinha[0] + ML1] | |
[mcoluna[0] - MC1])=='A' | |
&& | |
tabuleiro[ mlinha[0] +2*ML1] | |
[mcoluna[0] -2*MC1]==0) || | |
(toupper(tabuleiro[ mlinha[0] - ML1] | |
[mcoluna[0] + MC1])=='A' | |
&& | |
tabuleiro[ mlinha[0] - 2*ML1] | |
[mcoluna[0] + 2*MC1]==0) | |
) | |
{ | |
aux=COMER_ATRAZ; | |
do{ | |
move_from_to(mcoluna[1],mlinha[1],mcoluna[0],mlinha[0],COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]);; | |
if(mlinha[0]==7 && tabuleiro[mlinha[1]][mcoluna[1]]=='v'&& (OPCAO==1 || OPCAO==0)) | |
tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
else | |
tabuleiro[mlinha[0]][mcoluna[0]]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
mnao_move(); | |
COMER_ATRAZ=TRUE; | |
mlinha[1]=mlinha[0]; | |
mcoluna[1]=mcoluna[0]; | |
monde_pode_move(); | |
while(!(!msequencia || (mlinha[1]==7 && TERMINA))) | |
{ | |
for(lin=7;lin>=0;lin--){ | |
for(col=0;col<=7;col++){ | |
if(mposso_mover[lin][col]>1) | |
{mlinha[0]=lin;mcoluna[0]=col; lin=0;col=7;} | |
} | |
} | |
break; | |
} | |
}while(!(!msequencia || (mlinha[1]==7 && TERMINA))); | |
if(mlinha[0]==7 && OPCAO==2)tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
ja_jogou=FALSE; | |
mnao_move(); | |
COMER_ATRAZ=aux; | |
} | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=7;mlinha[1]>=0 && ja_jogou;mlinha[1]--) | |
{ | |
for(mcoluna[1]=7;mcoluna[1]>=0 && ja_jogou;mcoluna[1]--) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') { | |
if(msequencia) | |
{ | |
if(OPCAO==1) if(tabuleiro[mlinha[1]][mcoluna[1]]=='V')TERMINA=FALSE;else TERMINA=TRUE; | |
for(mlinha[0]=7;mlinha[0]>=0 && ja_jogou;mlinha[0]--) | |
for(mcoluna[0]=0;mcoluna[0]<=7 && ja_jogou;mcoluna[0]++) | |
if(mposso_mover[mlinha[0]][mcoluna[0]]>1) | |
if(toupper(tabuleiro[ mlinha[0] + ML1] | |
[mcoluna[0] + MC1])!='A') | |
if | |
(!((toupper(tabuleiro[ mlinha[0] + ML1][mcoluna[0] - MC1])=='A' | |
&& tabuleiro[ mlinha[0] - ML1][mcoluna[0] + MC1]==0) | |
|| | |
(toupper(tabuleiro[ mlinha[0] - ML1][mcoluna[0] + MC1])=='A' | |
&& tabuleiro[ mlinha[0] + ML1][mcoluna[0] - MC1]==0))) | |
{ | |
aux=COMER_ATRAZ; | |
do{ | |
move_from_to(mcoluna[1],mlinha[1],mcoluna[0],mlinha[0],COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]);; | |
if(mlinha[0]==7 && tabuleiro[mlinha[1]][mcoluna[1]]=='v'&& (OPCAO==1 || OPCAO==0)) | |
tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
else | |
tabuleiro[mlinha[0]][mcoluna[0]]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
mnao_move(); | |
COMER_ATRAZ=TRUE; | |
mlinha[1]=mlinha[0]; | |
mcoluna[1]=mcoluna[0]; | |
monde_pode_move(); | |
while(!(!msequencia || (mlinha[1]==7 && TERMINA))) | |
{ | |
for(lin=7;lin>=0;lin--){ | |
for(col=0;col<=7;col++){ | |
if(mposso_mover[lin][col]>1) | |
{mlinha[0]=lin;mcoluna[0]=col; lin=0;col=7;} | |
} | |
} | |
break; | |
} | |
}while(!(!msequencia || (mlinha[1]==7 && TERMINA))); | |
if(mlinha[0]==7 && OPCAO==2)tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
ja_jogou=FALSE; | |
mnao_move(); | |
COMER_ATRAZ=aux; | |
} | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=7;mlinha[1]>=0 && ja_jogou;mlinha[1]--) | |
{ | |
for(mcoluna[1]=7;mcoluna[1]>=0 && ja_jogou;mcoluna[1]--) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') | |
{ | |
if(msequencia) | |
{ | |
if(OPCAO==1) | |
if(tabuleiro[mlinha[1]][mcoluna[1]]=='V')TERMINA=FALSE;else TERMINA=TRUE; | |
for(mlinha[0]=7;mlinha[0]>=0 && ja_jogou;mlinha[0]--) | |
for(mcoluna[0]=0;mcoluna[0]<=7 && ja_jogou;mcoluna[0]++) | |
if(mposso_mover[mlinha[0]][mcoluna[0]]>1) | |
{ | |
aux=COMER_ATRAZ; | |
do{ | |
move_from_to(mcoluna[1],mlinha[1],mcoluna[0],mlinha[0],COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]);; | |
if(mlinha[0]==7 && tabuleiro[mlinha[1]][mcoluna[1]]=='v'&& (OPCAO==1 || OPCAO==0)) | |
tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
else | |
tabuleiro[mlinha[0]][mcoluna[0]]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
mnao_move(); | |
COMER_ATRAZ=TRUE; | |
mlinha[1]=mlinha[0]; | |
mcoluna[1]=mcoluna[0]; | |
monde_pode_move(); | |
while(!(!msequencia || (mlinha[1]==7 && TERMINA))) | |
{ | |
for(lin=7;lin>=0;lin--){ | |
for(col=0;col<=7;col++){ | |
if(mposso_mover[lin][col]>1) | |
{mlinha[0]=lin;mcoluna[0]=col; lin=0;col=7;} | |
} | |
} | |
break; | |
} | |
}while(!(!msequencia || (mlinha[1]==7 && TERMINA))); | |
if(mlinha[0]==7 && OPCAO==2)tabuleiro[mlinha[0]][mcoluna[0]]='V'; | |
ja_jogou=FALSE; | |
mnao_move(); | |
COMER_ATRAZ=aux; | |
} | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=0;mlinha[1]<=7 && ja_jogou;mlinha[1]++) | |
{ | |
for(mcoluna[1]=7; mcoluna[1]<=0 && ja_jogou; mcoluna[1]-=1) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') | |
{ | |
for(lin=7;lin>=0 && ja_jogou;lin--) | |
for(col=0;col<=7 && ja_jogou;col++) | |
if(mposso_mover[lin][col]) | |
if(toupper(tabuleiro[lin + ml1][col + mc1])!='A') | |
if(!((toupper(tabuleiro[lin + ml1][col - mc1])=='A' | |
&& tabuleiro[lin- ml1][col + mc1]==0) | |
|| | |
(toupper(tabuleiro[ lin - ml1][col +mc1])=='A' | |
&& tabuleiro[ lin + ml1][col - mc1]==0))) | |
{ | |
move_from_to(mcoluna[1],mlinha[1],col,lin,COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]); | |
if(lin==7)tabuleiro[lin][col]='V'; | |
else tabuleiro[lin][col]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
ja_jogou=FALSE; | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=7;mlinha[1]<=0 && ja_jogou;mlinha[1]--) | |
{ | |
for(mcoluna[1]=0; mcoluna[1]<=7 && ja_jogou; mcoluna[1]+=1) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') | |
{ | |
for(lin=0;lin<=7 && ja_jogou;lin++) | |
for(col=7;col>=0 && ja_jogou;col--) | |
if(mposso_mover[lin][col]) | |
if(toupper(tabuleiro[lin - ml1][col + mc1])!='A') | |
{ | |
move_from_to(mcoluna[1],mlinha[1],col,lin,COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]); | |
if(lin==7)tabuleiro[lin][col]='V'; | |
else tabuleiro[lin][col]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
ja_jogou=FALSE; | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=0;mlinha[1]<=7 && ja_jogou;mlinha[1]++) | |
{ | |
for(mcoluna[1]=0; mcoluna[1]<=7 && ja_jogou; mcoluna[1]+=1) | |
{ | |
if(monde_pode_move() && toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V') | |
{ | |
for(lin=7;lin>=0 && ja_jogou;lin--) | |
for(col=7;col>=0 && ja_jogou;col--) | |
if(mposso_mover[lin][col]) | |
{ | |
move_from_to(mcoluna[1],mlinha[1],col,lin,COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]); | |
if(lin==7)tabuleiro[lin][col]='V'; | |
else tabuleiro[lin][col]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
ja_jogou=FALSE; | |
} | |
}else mnao_move(); | |
} | |
} | |
for(mlinha[1]=7;mlinha[1]>=0 && ja_jogou;mlinha[1]--) | |
{ | |
for(mcoluna[1]=0; mcoluna[1]<=7 && ja_jogou; mcoluna[1]+=1) | |
{ | |
if(toupper(tabuleiro[mlinha[1]][mcoluna[1]])=='V' && monde_pode_move()) | |
{ | |
for(lin=7;lin>=0 && ja_jogou;lin--) | |
for(col=7;col>=0 && ja_jogou;col--) | |
if(mposso_mover[lin][col]) | |
{ | |
move_from_to(mcoluna[1],mlinha[1],col,lin,COR_COMP,tabuleiro[mlinha[1]][mcoluna[1]]); | |
if(lin==7)tabuleiro[lin][col]='V'; | |
else tabuleiro[lin][col]=tabuleiro[mlinha[1]][mcoluna[1]]; | |
tabuleiro[mlinha[1]][mcoluna[1]]=0; | |
ja_jogou=FALSE; | |
} | |
}else mnao_move(); | |
} | |
} | |
}//fim da funcao | |
/******************* Funcoes de controle do jogo *************/ | |
void nao_move(void) | |
{ | |
sequencia=FALSE; | |
for(i=0;i<=7;i++) | |
for(j=0;j<=7;j++) | |
posso_mover[i][j]=0; | |
} | |
void apaga_selecao(void) | |
{ | |
for(i=0;i<=7;i++) { | |
for(j=0;j<=7;j++) { //apaga a outra pedra selecionada | |
if(selecao[i][j]) { | |
move_from_to(j,i,j,i,COR,tabuleiro[i][j]); | |
selecao[i][j]=FALSE; i=7;break; } | |
} | |
} | |
} | |
void onde_pode_move(void) { | |
if(tabuleiro[linha[1]][coluna[1]]=='a')// se for pedra | |
{ | |
if( toupper(tabuleiro[linha[1]-1][coluna[1]-1])!='V') | |
{ | |
if(linha[1]>0 && coluna[1]>0 && toupper(tabuleiro[linha[1]-1][coluna[1]-1])!='A') | |
{ posso_mover[linha[1]-1][coluna[1]-1]=1;} | |
} | |
else// | |
{ // | |
if(tabuleiro[linha[1]-2][coluna[1]-2]==0 && coluna[1]>1 && linha[1]>1) | |
{posso_mover[linha[1]-2][coluna[1]-2]=3;sequencia=1;} | |
} | |
if(toupper(tabuleiro[linha[1]-1][coluna[1]+1])!='V') | |
{ | |
if(linha[1]>0 && coluna[1]<7 && toupper(tabuleiro[linha[1]-1][coluna[1]+1])!='A') | |
{posso_mover[linha[1]-1][coluna[1]+1]=1;} | |
} | |
else | |
{ | |
if(linha[1]>1 && coluna[1]<6 && tabuleiro[linha[1]-2][coluna[1]+2]==0) | |
{posso_mover[linha[1]-2][coluna[1]+2]=2;sequencia=1;} | |
} | |
if(linha[1]<6 && COMER_ATRAZ) | |
{ | |
if(coluna[1]>1 && toupper(tabuleiro[linha[1]+1][coluna[1]-1])=='V' && tabuleiro[linha[1]+2][coluna[1]-2]==0) | |
{posso_mover[linha[1]+2][coluna[1]-2]=5;sequencia=1;} | |
if(coluna[1]<6 && toupper(tabuleiro[linha[1]+1][coluna[1]+1])=='V' && tabuleiro[linha[1]+2][coluna[1]+2]==0) | |
{posso_mover[linha[1]+2][coluna[1]+2]=6;sequencia=1;} | |
} | |
} | |
else // se for dama | |
{ | |
i=1; j=1; | |
while(toupper(tabuleiro[linha[1]-i][coluna[1]-j])!='A' && (linha[1]-i)>=0 && (coluna[1]-j)>=0 && | |
!((toupper(tabuleiro[linha[1]-i][coluna[1]-j])=='V' && toupper(tabuleiro[linha[1]-i-1][coluna[1]-j-1])=='V')|| | |
(toupper(tabuleiro[linha[1]-i][coluna[1]-j])=='V' && toupper(tabuleiro[linha[1]-i-1][coluna[1]-j-1])=='A'))) { | |
if(toupper(tabuleiro[linha[1]-i][coluna[1]-j])=='V') | |
if(tabuleiro[linha[1]-i-1][coluna[1]-j-1]==0 && | |
(linha[1]-i)>=1 && (coluna[1]-j)>=1) | |
{ | |
posso_mover[linha[1]-i-1][coluna[1]-j-1]=3; | |
sequencia=TRUE; | |
break; | |
} else break; | |
posso_mover[linha[1]-i][coluna[1]-j]=1; | |
j++;i++; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[linha[1]-i][coluna[1]+j])!='A' && (linha[1]-i)>=0 && (coluna[1]+j)<=7 && | |
!(( toupper(tabuleiro[linha[1]-i][coluna[1]+j])=='V' && toupper(tabuleiro[linha[1]-i-1][coluna[1]+j+1])=='V') || | |
( toupper(tabuleiro[linha[1]-i][coluna[1]+j])=='V' && toupper(tabuleiro[linha[1]-i-1][coluna[1]+j+1])=='A'))) { | |
if(toupper(tabuleiro[linha[1]-i][coluna[1]+j])=='V') | |
if(tabuleiro[linha[1]-i-1][coluna[1]+j+1]==0 && | |
(linha[1]-i)>=1 && (coluna[1]+j)<=6) | |
{ | |
posso_mover[linha[1]-i-1][coluna[1]+j+1]=2; | |
sequencia=TRUE; | |
break; | |
} else break; | |
posso_mover[linha[1]-i][coluna[1]+j]=1; | |
j++;i++; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[linha[1]+i][coluna[1]+j])!='A' && (linha[1]+i)<=7 && (coluna[1]+j)<=7 && | |
!((toupper(tabuleiro[linha[1]+i][coluna[1]+j])=='V' && toupper(tabuleiro[linha[1]+i+1][coluna[1]+j+1])=='V')|| | |
(toupper(tabuleiro[linha[1]+i][coluna[1]+j])=='V' && toupper(tabuleiro[linha[1]+i+1][coluna[1]+j+1])=='A'))) { | |
if(toupper(tabuleiro[linha[1]+i][coluna[1]+j])=='V') | |
if(tabuleiro[linha[1]+i+1][coluna[1]+1+j]==0 && | |
(linha[1]+i)<=6 && (coluna[1]+j)<=6) { | |
posso_mover[linha[1]+i+1][coluna[1]+j+1]=6; | |
sequencia=TRUE; | |
break; | |
}else break; | |
posso_mover[linha[1]+i][coluna[1]+j]=1; | |
j++;i++; | |
} | |
i=1; j=1; | |
while(toupper(tabuleiro[linha[1]+i][coluna[1]-j])!='A' && (linha[1]+i)<=7 && (coluna[1]-j)>=0 && | |
!((toupper(tabuleiro[linha[1]+i][coluna[1]-j])=='V' && toupper(tabuleiro[linha[1]+i+1][coluna[1]-j-1])=='V')|| | |
(toupper(tabuleiro[linha[1]+i][coluna[1]-j])=='V' && toupper(tabuleiro[linha[1]+i+1][coluna[1]-j-1])=='A'))) { | |
if(toupper(tabuleiro[linha[1]+i][coluna[1]-j])=='V') | |
if(tabuleiro[linha[1]+i+1][coluna[1]-j-1]==0 && | |
(linha[1]+i)<=6 && (coluna[1]-j)>=1) { | |
posso_mover[linha[1]+i+1][coluna[1]-j-1]=5; | |
sequencia=TRUE; | |
break; | |
} else break; | |
posso_mover[linha[1]+i][coluna[1]-j]=1; | |
j++;i++; | |
} | |
} | |
} | |
/********************* FUNCOES DO FUNCIONAMENTO DO JOGO ************/ | |
int novo_jogo(JOGO dado) | |
{ | |
int x,y,x1=1,y1; | |
PALLETE paleta; | |
coluna[1]=NADA; // nenhuma peca selecionada | |
linha[1]= NADA; | |
COR =dado.CORES[COR_JOGADOR]; | |
COR_COMP =dado.CORES[COR_MAQUINA]; | |
COR_CASA1 =dado.CORES[COR_CASAPAR]; | |
COR_CASA2 =dado.CORES[COR_CASAIMP]; | |
OPCAO =dado.OPCAO; | |
SOPRO =dado.SOPRO; | |
COMER_ATRAZ=dado.COMER_ATRAZ; | |
total_comido =dado.total_comido; | |
upecas =dado.upecas; | |
mpecas =dado.mpecas; | |
mtotal_comido=dado.mtotal_comido; | |
sopradas =dado.sopradas; | |
set_gfx_mode(GFX_AUTODETECT,640,480, 0, 0); | |
TAM=(sqrt(SCREEN_H*SCREEN_W)*0.75)/8; | |
show_mouse(screen); | |
for(x=0;x<=8*TAM;x+=TAM){ | |
for(y=0;y<=8*TAM;y++) { | |
putpixel(screen,y+D,x+E,2); //plota os pixels iniciais | |
putpixel(screen,x+D,y+E,10); | |
} | |
rest(100); | |
} | |
for(i=0;i<=7;i++) | |
for(j=0;j<=7;j++) { | |
tabuleiro[i][j]=dado.tabuleiro[i][j]; | |
selecao[i][j]=FALSE ; // zerando matriz selecao | |
posso_mover[i][j]= FALSE ; // zerando matriz de checagem | |
casa(j,i,(((i+j+1)%2)*COR_CASA2)+COR_CASA1*((i+j)%2)); | |
} | |
while(x1=menu_opcoes()) | |
{ | |
linha [0] = (mouse_y-E)/TAM; //lendo linha (mouse) | |
coluna[0] = (mouse_x-D)/TAM; //lendo coluna (mouse) | |
jogada_da_maquina(); | |
show_mouse(screen);vsync();show_mouse(NULL); | |
refresh_screen();refresh_quadro(); | |
if(posso_mover[linha[0]][coluna[0]] && coluna[0]<8 && linha[0]<8) | |
move_from_to(coluna[0],linha[0],coluna[0],linha[0],COR_CASA1-1,'v'); | |
if(kbhit()) | |
{ | |
rest(2); | |
show_mouse(NULL); | |
switch(toupper(getch())) | |
{ | |
case '1':COR++;break; | |
case '2':COR_CASA1++;break; | |
case '3':COR_CASA2++;break; | |
case '4':COR_COMP++ ;break; | |
case '5':COR_LINHA++;break; | |
case 'L':novo_jogo(load_game());break; | |
case 'S':save_jogo(); break; | |
case 'N':novo_jogo(zera_jogo());break; | |
case 27 :return(1); | |
case '-':if(TAM>10)TAM--;clear(screen);break; | |
case '+':if(TAM<SCREEN_H*0.15)TAM++;clear(screen);break; | |
} | |
atualiza_tela(); | |
refresh_screen(); | |
vsync(); | |
show_mouse(screen); | |
} | |
if(mouse_b==2) { //desistindo da selecao // clicando com o botao direito | |
nao_move(); | |
coluna[1]=NADA; | |
linha[1] =NADA; | |
} | |
if(mouse_b==1 && coluna[0]<=7 && linha[0]<=7) //clicou no tabuleiro ? | |
{ | |
if(toupper(tabuleiro[linha[0]][coluna[0]])=='A') //clicou em pedra a | |
{ | |
apaga_selecao();// apaga a outra pedra selecionada | |
linha[1]=linha[0]; coluna[1]=coluna[0]; //pega coord. da nova selecao ; | |
selecao[linha[1]][coluna[1]]=TRUE; // marca onde e' nova selecao; | |
move_from_to(coluna[1],linha[1],coluna[1],linha[1],COR+8,tabuleiro[linha[1]][coluna[1]]); | |
nao_move(); // <== zero minha matriz de onde posso mover | |
onde_pode_move(); // verifico onde eu posso mover | |
while(mouse_b==1); //para evitar arraste | |
} | |
else // clicou fora da pedra; | |
{ //LEMBRANDO Q linha[0] -> mouse | |
// verifica se ele pode mover para posicao que ele clicou | |
if(posso_mover[linha[0]][coluna[0]]) //posicao valida | |
{ | |
ja_jogou=TRUE;// tira a peca da selecao e move para o clique | |
if(OPCAO==1) // controle da formacao da dama | |
if(tabuleiro[linha[1]][coluna[1]]=='A')TERMINA=FALSE;else TERMINA=TRUE; | |
if(SOPRO) // se opcao sopro estiver ativa , ele puder soprar ... | |
{ | |
x=coluna[1];y=linha[1]; | |
for(linha[1]=0;linha[1]<=7;linha[1]++) | |
for(coluna[1]=0;coluna[1]<=7;coluna[1]++) { | |
nao_move(); | |
if(toupper(tabuleiro[linha[1]][coluna[1]])=='A') | |
{ | |
onde_pode_move(); | |
if(sequencia) // se o jogador podia ter comido | |
{ | |
y1=linha[1];x1=coluna[1]; | |
nao_move(); | |
linha[1]=y;coluna[1]=x; | |
onde_pode_move(); // mas preferiu fazer movimento simples | |
if(posso_mover[linha[0]][coluna[0]]==1) | |
{ | |
move_from_to(x1,y1,x1,y1,255,tabuleiro[y1][x1]);rest(1000); | |
tabuleiro[y1][x1]=0; | |
linha[1]=7;coluna[1]=7;sopradas++;upecas--;refresh_screen(); | |
break; | |
} | |
else {linha[1]=7;coluna[1]=7;break;} | |
} | |
} | |
} | |
nao_move(); | |
linha[1]=y;coluna[1]=x;onde_pode_move(); | |
} | |
y=COMER_ATRAZ; | |
if(tabuleiro[linha[1]][coluna[1]]) { | |
do{ | |
move_from_to(coluna[1],linha[1],coluna[0],linha[0],COR,tabuleiro[linha[1]][coluna[1]]); | |
if(linha[0]==0 && tabuleiro[linha[1]][coluna[1]]=='a'&& (OPCAO==1 || OPCAO==0)) | |
tabuleiro[linha[0]][coluna[0]]='A'; //formacao da dama*/ | |
else//else da formacao da dama | |
tabuleiro[linha[0]][coluna[0]]=tabuleiro[linha[1]][coluna[1]]; | |
tabuleiro[linha[1]][coluna[1]]=0;//<zera onde a peca ESTAVA | |
if(sequencia && posso_mover[linha[0]][coluna[0]]>1) | |
{ | |
nao_move(); | |
linha[1]=linha[0]; | |
coluna[1]=coluna[0]; | |
COMER_ATRAZ=TRUE; | |
onde_pode_move(); | |
} //a.b _ (_a+_b) | |
else nao_move(); | |
while(!(!sequencia || (!linha[1]&& TERMINA))) | |
{ | |
linha [0] = (mouse_y-E)/TAM; //lendo linha (mouse) | |
coluna[0] = (mouse_x-D)/TAM ; //lendo coluna (mouse) | |
if(posso_mover[linha[0]][coluna[0]]>1&&linha[0]<8&&coluna[0]<8)move_from_to(coluna[0],linha[0],coluna[0],linha[0],COR_CASA1-1,'v'); | |
show_mouse(screen);vsync();show_mouse(NULL);refresh_quadro(); | |
if(tabuleiro[linha[0]][coluna[0]]==0 && (linha[0]+coluna[0])%2==1&& coluna[0]<8 && linha[0]<8)casa(coluna[0],linha[0],COR_CASA1); | |
if(posso_mover[linha[0]][coluna[0]]>1 && mouse_b==1 && coluna[0]<8 && linha[0]<8)break; | |
} | |
}while(!(!sequencia || (!linha[1]&& TERMINA))); | |
if(!linha[0] && OPCAO==2)tabuleiro[linha[0]][coluna[0]]='A'; | |
} | |
selecao[linha[1]][coluna[1]]=0; //<zera matriz selecao | |
nao_move(); // zera matriz de onde se pode mover | |
linha[1]=NADA; // zera minha linha selecionada | |
coluna[1]=NADA; | |
COMER_ATRAZ=y; | |
} //fim (posso_mover) | |
} // fim do else | |
}// if clicou na tabua | |
}return(1);//while menu !=0 | |
}// funcao novo_jogo() | |
int main(void) { | |
allegro_init(); | |
install_timer(); | |
install_mouse(); | |
while(menu()); | |
allegro_exit(); | |
} | |
END_OF_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment