Buscar

Torre de hanoi feito em c

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
#include <math.h>
#define linha 7
#define coluna 73
#define tam 100
FILE *Movimentos;
FILE *relatorio;
FILE *relatGeral;
typedef struct
 {
 char Nome[tam];
 char pontos[tam];
 }tscore;
int min=0,seg=0;
int origem, destino,cont=0;
int dia=0,mes=0,ano=0,horas=0,minutos=0,segundos=0;
char str[100]={ };
char nomeArq[20] = "Relatorio.txt",op;
tscore Dados;
char menu();
char menu2();
char menu3();
void parabens();
void menu_tela();
void limpa_str();
void Limpe_list();
char menu_escolha();
void List_jogador();
void torre_de_hanoi();
void menu_tela_teste();
void perfil();
int analisamovimento(int);
void Time_and_Date_system();
void altera_caracter(int m);
void cronometro(int x,int y);
void imprime_torre(int mat[7][3]);
void novorelatorio(char nomeArq[]);
void gera_matriz(int mat[7][3], int *disco);
void mat_interface(char discos[linha][coluna]);
void imprime_pilar(int mat[7][3],char discos[linha][coluna]);
void MoveDisco(int Orig,int Dest,int mat[7][3] ,char discos[linha][coluna]);
void ImprimeRelatorio(char nomeArq[],int mat[7][3],char discos[linha][coluna]);
void movemat(int destino2,int origem2,char discos[linha][coluna],int i,int j,int p);
void movimenta_torre(int mat[7][3] ,int destino2,int origem2,char discos[linha][coluna]);
void MoveTorre(int n, int Orig,int Dest, int Aux,int mat[7][3] ,char discos[linha][coluna]);
int main()
{
 int mat[7][3]={0};
 int Orig=1, Dest=3,Aux=2;
 int i,j=1,k,disco=0,centro=9,n,origem2,destino2,Num_min;;
 char discos[linha][coluna] = {0},opcao,opcao2,relat;
 char text[100]={ },escolha,ori_conv,des_conv,escolha_menu;
 FILE *jogadores;
 FILE *historia;
 FILE *treino;
 system("color 70");
 opcao = menu();
 switch(opcao)
 {
 case'I':
 system("color 70");
 opcao2 = menu2();
 switch (opcao2)
 {
 case'J':
 jogadores = fopen("jogadores.txt","a");
 if(jogadores==NULL)
 {
 printf("nao foi possivel acessar o arquivo");
 exit(1);
 }
 do{
 escolha = menu_escolha();
 system("cls");
 switch(escolha)
 {
 case (49):
 perfil();
 break;
 case (50):
 List_jogador();
 break;
 case (51):
 Limpe_list();
 break;
 default:
 printf("\n Opcao Invalida Tente Novamente !\n\n\n");
 }
 }while(escolha != 49 && escolha != 50 && escolha != 51);
 system("cls");
 fprintf(jogadores,"%s %d-%d-%d %d-%d-%d\n",Dados.Nome,dia,mes,ano,horas,minutos,segundos);
 fclose(jogadores);
 gera_matriz(mat,&disco);
 imprime_pilar(mat,discos);
 for (i=7-disco,k=0;i<linha;i++,k++)
 {
 for (j=centro-k-3;j<=centro+k+3;j++)
 { system("color 70");
 discos[i][j]=205;
 }
 }
 mat_interface(discos);
 menu_tela();
 do{
 do{
 while(!kbhit())
 {
 gotoxy(1,22);
 printf("informe a sua origem :\t");
 cronometro(24,22);
 }
 ori_conv = getche();
 origem = ori_conv - 48;
 fflush(stdin);
 if(origem == 29 || origem == 61)
 {
 escolha_menu = menu3();
 switch(escolha_menu)
 {
 case'P':
 printf("pausa aki");
 break;
 case'C':
 printf("em breve aki");
 break;
 case'L':
 printf("lista aki");
 break;
 case'R':
 printf("reiniciar aki");
 break;
 case'A':
 printf("abandonar aki");
 break;
 }
 }
 while(!kbhit())
 {
 gotoxy(1,24);
 printf("informe o seu destino para o disco :\t");
 cronometro(37,24);
 }
 des_conv = getche();
 destino = des_conv - 48;
 fflush(stdin);
 if( destino == 29 || destino == 29)
 {
 escolha_menu = menu3();
 }
 system("cls");
 mat_interface (discos);
 imprime_pilar(mat,discos);
 menu_tela();
 }while(origem<1 || origem >3 || destino <1 || destino>3 || origem == destino);
 fprintf(Movimentos,"%d -> %d \n",origem ,destino);
 origem2 = analisamovimento(origem);
 destino2 = analisamovimento(destino);
 system("cls");
 imprime_pilar(mat,discos);
 movimenta_torre(mat,destino2,origem2,discos);
 menu_tela();
 cronometro(2,25);
 }while(mat[7-disco][2]!=1);
 system("color 71");
 parabens();
 Sleep(100);
 system("color 72");
 Sleep(100);
 system("color 83");
 Sleep(100);
 system("color c4");
 Sleep(100);
 system("color 45");
 Sleep(100);
 system("color f6");
 gotoxy(2,24);
 printf("PARABENS VOCE GANHOU !!!\n\n");
 cronometro(2,25);
 cont = 0;
 min = 0;
 seg = 0;
 gotoxy(2,26);
 system("pause");
 system("cls");
 main();
 break;
 case'T':
 treino = fopen("treino.txt","w");
 for(i=0;i<100;i++)
 {
 text[i] = ' ';
 }
 disco = 0;
 cont = 0;
 gera_matriz(mat,&disco);
 imprime_pilar(mat,discos);
 Num_min = pow(2,disco)-1;
 for
(i=7-disco,k=0;i<linha;i++,k++)
 {
 for (j=centro-k-3;j<=centro+k+3;j++)
 { system("color 70");
 discos[i][j]=205;
 }
 }
 mat_interface(discos);
 menu_tela_teste();
 do{
 do{
 gotoxy(1,22);
 printf("informe a sua origem :\t");
 gotoxy(24,22);
 ori_conv = getche();
 origem = ori_conv - 48;
 fflush(stdin);
 if(origem == 20 || origem == 52)
 {
 system("cls");
 main();
 }
 if(origem == 37 || origem == 69)
 {
 }
 gotoxy(1,24);
 printf("informe o seu destino para o disco :\t");
 des_conv = getche();
 destino = des_conv - 48;
 fflush(stdin);
 if( destino == 20 || destino == 52)
 {
 system("cls");
 main();
 }
 if(destino == 37 || destino == 69)
 {
 }
 system("cls");
 gera_matriz(mat,&disco);
 imprime_pilar(mat,discos);
 mat_interface (discos);
 //imprime_pilar(mat,discos);
 menu_tela_teste();
 }while(origem<1 || origem >3 || destino <1 || destino>3 || origem == destino);
 fprintf(treino,"%d -> %d \n",origem ,destino);
 origem2 = analisamovimento(origem);
 destino2 = analisamovimento(destino);
 system("cls");
 imprime_pilar(mat,discos);
 movimenta_torre(mat,destino2,origem2,discos);
 menu_tela_teste();
 }while(mat[7-disco][2]!=1);
 if(cont == Num_min)
 {
 fprintf(treino,"Parabens o Numero De Movimentos foi Minino");
 }
 fclose(treino);
 system("color 71");
 parabens();
 Sleep(100);
 system("color 72");
 Sleep(100);
 system("color 83");
 Sleep(100);
 system("color c4");
 Sleep(100);
 system("color 45");
 Sleep(100);
 system("color f6");
 gotoxy(2,24);
 printf("PARABENS VOCE GANHOU !!!\n\n");
 gotoxy(2,26);
 system("pause");
 system("cls");
 treino = fopen("treino.txt","r");
 if(treino == NULL)
 {
 printf("Nao foi possivel abrir o arquivo!");
 system("pause");
 exit(1);
 }
 while(fgets(text,100,treino)!=NULL)
 {
 printf("\n %s",text);
 }
 printf("\n\n");
 fclose(treino);
 system("pause");
 system("cls");
 main();
 break;
 case'R':
 gera_matriz(mat,&disco);
 imprime_pilar(mat,discos);
 for (i=7-disco,k=0;i<linha;i++,k++)
 {
 for (j=centro-k-3;j<=centro+k+3;j++)
 {
 discos[i][j]=205;
 }
 }
 MoveTorre(disco,Orig,Dest,Aux,mat,discos);
 printf("\n\n");
 system("pause");
 system("cls");
 main();
 break;
 case'S':
 exit(1);
 break;
 }
 break;
 case'C':
 printf("Em breve");
 system("pause");
 main();
 break;
 case'A':
 {
 historia = fopen("historia_hanoi.txt","r");
 if(historia == NULL)
 {
 printf("Nao foi possivel abrir o arquivo!");
 system("pause");
 exit(1);
 }
 while(fgets(text,100,historia)!=NULL)
 {
 printf("\n %s",text);
 }
 printf("\n\n");
 fclose(historia);
 system("pause");
 system("cls");
 main();
 }
 break;
 case'S':
 exit(1);
 break;
 }
 return 0;
}
void imprime_torre(int mat[7][3])
{
 int i,j;
 for (i=0;i<7;i++)
 {
 for (j=0;j<3;j++)
 {
 printf("%2d",mat[i][j]);
 }
 printf("\n");
 }
}
void gera_matriz(int mat[7][3],int *disco)
{
int i,j=1;
do{
 printf("\n\n\n\n\t\t\tInforme a quantidade de disco (1->7) :\t");
 scanf("%d",disco);
 fflush(stdin);
 system("cls");
 }while(*disco<1 || *disco>7);
 for (i=7-*disco;i<7;i++)
 {
 mat[i][0] = j;
 j=j+1;
 }
}
void mat_interface(char discos[linha][coluna] )
{
int i,j;
torre_de_hanoi();
printf("\n\n");
 for(i=0;i<linha;i++)
 {
 for(j=0;j<coluna;j++)
 {
 printf("%c",discos[i][j]);
 }
 printf("\n");
 }
 gotoxy(0,18);
 for(i=0;i<80;i++)
 printf("%c",205);
 gotoxy(9,16);
 printf("<I>");
 gotoxy(35,16);
 printf("<II>");
 gotoxy(62,16);
 printf("<III>");
}
int analisamovimento(int n)
{
 if(n==1)
 {
 return 9;
 }
 else if(n==2)
 {
 return 36;
 }
 else if(n==3)
 {
 return 63;
 }
}
void movemat(int destino2,int origem2,char discos[linha][coluna],int i,int j, int p)
{
 int k;
 for(k=destino2-2-i;k<=destino2+2+i;k++)
 {
 discos[j][k]=205;
 }
 for(k=origem2-2-i;k<=origem2+2+i;k++)
 {
 discos[p][k]=' ';
 }
}
char menu()
{
 char opcao;
 do{
 gotoxy(32,14);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(32,15);
 printf(" %c INICIAR : (I) %c\n ",186,186);
 gotoxy(32,16);
 printf(" %c %c\n",186,186);
 gotoxy(32,17);
 printf(" %c SOBRE : (A) %c\n",186,186);
 gotoxy(32,18);
 printf(" %c %c\n",186,186);
 gotoxy(32,19);
 printf(" %c SAIR : (S) %c\n",186,186);
 gotoxy(32,20);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 printf("\n\n\n\t\t\t\t O que deseja fazer ? ");
 opcao = getche();
 opcao = toupper(opcao);
 system("cls");
 }while(opcao!='I'&& opcao!='C'&&opcao!='A'&&opcao!='S');
 return opcao;
}
char menu2()
{
 char opcao2;
 do{
 gotoxy(32,12);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(32,13);
 printf(" %c JOGAR : (J) %c\n ",186,186);
 gotoxy(32,14);
 printf(" %c %c\n",186,186);
 gotoxy(32,15);
 printf(" %c TREINO : (T) %c\n ",186,186);
 gotoxy(32,16);
 printf(" %c %c\n",186,186);
 gotoxy(32,17);
 printf(" %c RESOLUCAO : (R) %c",186,186);
 gotoxy(32,18);
 printf(" %c %c\n",186,186);
 gotoxy(32,19);
 printf(" %c SAIR : (S) %c\n",186,186,186);
 gotoxy(32,20);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 printf("\n\n\n\t\t\t\tO que deseja fazer ? ");
 opcao2 = getche();
 opcao2=toupper(opcao2);
 system("cls");
 }while(opcao2!='J'&&opcao2!='R'&&opcao2!='S'&&opcao2!='T');
 return opcao2;
}
void imprime_pilar(int mat[7][3],char discos[linha][coluna])
{
 int i,j,cont=0,cont1=0,cont2=0;
 for (i=0;i<7;i++)
 {
 if(mat[i][0]==0)
 {
 cont++;
 }
 }
 for (i=0;i<cont;i++)
 {
 discos[i][9]=186;
 }
 for (i=0;i<7;i++)
 {
 if(mat[i][1]==0)
 {
 cont1++;
 }
 }
 for (i=0;i<cont1;i++)
 {
 discos[i][36]=186;
 }
 for (i=0;i<7;i++)
 {
 if(mat[i][2]==0)
 {
 cont2++;
 }
 }
 for (i=0;i<cont2;i++)
 {
 discos[i][63]=186;
 }
}
void torre_de_hanoi()
{
gotoxy(2,1);
printf("\t _____ _ _ _ _ \n");
gotoxy(2,2);
printf("\t|_ _| | | | | | | (_)\n");
gotoxy(2,3);
printf("\t | | ___ _ __ _ __ ___ __| | ___ | |_| | __ _ _ __ ___ _ \n");
gotoxy(2,4);
printf("\t | |/ _ \\| '__| '__/ _ \\ / _` |/ _ \\ | _ |/ _` | '_ \\ / _ \\| |\n");
gotoxy(2,5);
printf("\t | | (_) | | | | | __/ | (_| | __/ | | | | (_| | | | | (_) | |\n");
gotoxy(2,6);
printf("\t \\_/\\___/|_| |_| \\___| \\__,_|\\___| \\_| |_/\\__,_|_| |_|\\___/|_|\n");
}
void movimenta_torre (int mat[7][3],int destino2,int origem2,char discos[linha][coluna])
{
int i , j, aux=0;
for (i=0;i<7;i++)
 {
 if(mat[6][origem-1]!=0 && mat[i][origem-1]!=0 && aux!=1)
 {
 if(mat[6][destino-1]==0 && aux!=1)
 {
 mat[6][destino-1] = mat[i][origem-1];
 cont++;
 movemat(destino2,origem2,discos,mat[i][origem-1],6,i);
 mat[i][origem-1]=0;
 aux = 1;
 }
 else
 {
 for (j=0;j<7;j++)
 {
 if(mat[j][destino-1]!=0 && mat[i][origem-1]<mat[j][destino-1]&& aux!=1)
 {
 mat[j-1][destino-1] = mat[i][origem-1];
 cont ++;
 movemat(destino2,origem2,discos,mat[i][origem-1],j-1,i);
 mat[i][origem-1] = 0;
 aux =1;
 }
 else if(mat[j][destino-1]!=0 && mat[i][origem-1]>mat[j][destino-1]&& aux!=1)
 aux=1;
 }
 }
 }
 }
 imprime_pilar(mat,discos);
 mat_interface(discos);
//mat_interface (disco ,centro,discos);
Sleep(300);
aux = 0;
}
void MoveTorre(int n, int Orig,int Dest, int Aux,int mat[7][3],char discos[linha][coluna])
{
 if(n==1)
 {
 MoveDisco(Orig,Dest,mat,discos);
 }else
 {
 MoveTorre(n-1,Orig,Aux,Dest,mat,discos);
 MoveDisco(Orig, Dest,mat,discos);
 MoveTorre(n-1, Aux, Dest, Orig,mat,discos);
 }
}
void MoveDisco(int Orig,int Dest,int mat[7][3],char discos[linha][coluna])
{
 int origem2;
 int destino2;
 origem = Orig;
 destino = Dest;
 origem2 = analisamovimento(Orig);
 destino2 = analisamovimento(Dest);
 movimenta_torre(mat,destino2,origem2,discos);
}
void perfil()
{
 char arquivo[1000];
 int ved;
 do{
 printf("\nInforme o Nome Do Jogador : ");
 gets(Dados.Nome);
 system("cls");
 }while(strcmp(Dados.Nome,"\n")==-1);
 strcpy(arquivo,Dados.Nome);
 Time_and_Date_system();
 limpa_str();
 altera_caracter(dia);
 strcat(arquivo," ");
 strcat(arquivo,str);
 limpa_str();
 altera_caracter(mes);
 strcat(arquivo,"-");
 strcat(arquivo,str);
 limpa_str();
 altera_caracter(ano);
 strcat(arquivo,"-");
 strcat(arquivo,str);
 limpa_str();
 altera_caracter(horas);
 strcat(arquivo," ");
 strcat(arquivo,str);
 limpa_str();
 altera_caracter(minutos);
 strcat(arquivo,"-");
 strcat(arquivo,str);
 limpa_str();
 altera_caracter(segundos);
 strcat(arquivo,"-");
 strcat(arquivo,str);
 strcat(arquivo,".txt");
 Movimentos = fopen(arquivo , "a");
}
void altera_caracter(int m)
{
 int n,i=0;
 n=m;
 while((n/10)>10)
 {
 i++;
 n = n/10;
 }
 if((n/10)!=0)
 i++;
 while((m/10)>0)
 {
 str[i] = 48+(m%10);
 m = m/10;
 i--;
 }
 str[i] = 48 + (m%10);
 //printf("%s\n",str);
}
void Time_and_Date_system()
{
struct tm *local;
time_t t;
t= time(NULL);
local=localtime(&t);
dia=local->tm_mday;
mes=local->tm_mon+1;
ano = ((local->tm_year+1900)%2000);
segundos = local->tm_sec;
minutos = local->tm_min;
horas = local->tm_hour;
}
char menu_escolha()
{
 char escolha;
 gotoxy(25,12);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(25,13);
 printf(" %cCriar Uma Novo jogador : (1) %c\n ",186,186,186);
 gotoxy(25,14);
 printf(" %c %c\n",186,186);
 gotoxy(25,15);
 printf(" %cListar Jogadores : (2) %c\n",186,186,186);
 gotoxy(25,16);
 printf(" %c %c\n",186,186);
 gotoxy(25,17);
 printf(" %cLimpar Lista de jogadores : (3) %c\n",186,186,186);
 gotoxy(25,18);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 printf("\n\n\n\t\t\t Selecione a Opcao Desejada : ");
 escolha = getch();
 return escolha;
}
void parabens()
{
gotoxy(2,1);
printf(" ______ _ \n");
Sleep(200);
gotoxy(2,2);
printf(" | ___ \\ | | \n");
Sleep(200);
gotoxy(2,3);
printf(" | |_/ /_ _ _ __ __ _| |__ ___ _ __ ___ \n");
Sleep(200);
gotoxy(2,4);
printf(" | __/ _` | '__/ _` | '_ \\ / _ \\ '_ \\/ __| \n");
Sleep(200);
gotoxy(2,5);
printf("
| | | (_| | | | (_| | |_) | __/ | | \\__ \\ \n");
Sleep(200);
gotoxy(2,6);
printf(" \\_| \\__,_|_| \\__,_|_.__/ \\___|_| |_|___/ \n");
Sleep(200);
}
void List_jogador()
{
 FILE *jogadores;
 jogadores = fopen("jogadores.txt","r");
 char jogador[1000];
 if (jogadores == NULL)
 {
 printf("Nao Foi Possivel Abrir o Arquivo");
 exit(1);
 }
 while(fgets(jogador,1000,jogadores)!=NULL)
 {
 printf("\n %s",jogador);
 }
 printf("\n\n");
 fclose(jogadores);
 system("pause");
 system("cls");
 main();
}
void Limpe_list()
{
 int i;
 FILE *jogadores;
 jogadores = fopen("jogadores.txt","w");
 fclose(jogadores);
 gotoxy(12,3);
 system("cls");
 printf(" \n\n\t\t\tExcluido Aguarde......");// funcao de abertura a loainding ...
 gotoxy(1,10);
 for(i=1;i<14;i++)
 {
 Sleep(200); //retarda em 100 milisegundos
 printf("_______");
 }
 system("cls");//limpamdo a tela
 printf("\n\n\n\t\t\tO Arquivo Excluido Com Sucesso !\n\n\n\n");
 Sleep(100);
 system("pause");
 system("cls");
 main();
}
char menu3()
{
 char opcao;
 do{
 gotoxy(29,12);
 Sleep(100);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(29,13);
 Sleep(100);
 printf(" %c %c\n ",186,186);
 gotoxy(29,14);
 Sleep(100);
 printf(" %c %c\n",186,186);
 gotoxy(29,15);
 printf(" %c VOLTAR AO JOGO : (V) %c\n",186,186);
 gotoxy(29,16);
 Sleep(100);
 printf(" %c %c\n",186,186);
 gotoxy(29,17);
 Sleep(100);
 printf(" %c LISTAR JOGADAS : (L) %c\n",186,186);
 gotoxy(29,18);
 Sleep(100);
 printf(" %c %c\n",186,186);
 gotoxy(29,19);
 printf(" %c REINICIAR GAME : (R) %c\n",186,186);
 gotoxy(29,20);
 printf(" %c %c\n",186,186);
 gotoxy(29,21);
 Sleep(100);
 printf(" %c ABANDONAR PARTIDA : (A) %c\n",186,186);
 gotoxy(29,22);
 Sleep(100);
 printf(" %c %c\n",186,186);
 gotoxy(29,23);
 Sleep(100);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 Sleep(100);
 printf("\n\n\n\t\t\t\t O que deseja fazer ? ");
 opcao = getche();
 opcao = toupper(opcao);
 system("cls");
 }while(opcao!='P'&& opcao!='C'&&opcao!='L'&&opcao!='R'&&opcao!='A');
 return opcao;
}
void limpa_str()
{
 int i;
 for (i=0;i<100;i++)
 {
 str[i] = 0;
 }
}
void cronometro(int c,int l)
{
 gotoxy(76,24);
 printf("%d:%d",min,seg);
 gotoxy(c,l);
 Sleep(1000);
 seg++;
 if(seg == 60)
 {
 seg = 0;
 min++;
 }
 if(min == 60)
 {
 min = 0;
 }
}
void menu_tela()
{
 gotoxy(55,19);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(55,20);
 printf(" %c MENU/PAUSA : (M) %c\n",186,186);
 gotoxy(55,21);
 printf(" %c %c\n",186,186);
 gotoxy(55,22);
 printf(" %c MOVIMENTOS : %c\n",186,186);
 gotoxy(55,23);
 printf(" %c %c\n",186,186);
 gotoxy(55,24);
 printf(" %c TEMPO: %c\n",186,186);
 gotoxy(55,25);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 printf("\n\n");
 gotoxy(76,22);
 printf("%d",cont);
}
void menu_tela_teste()
{
 gotoxy(55,19);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
 gotoxy(55,20);
 printf(" %c DESISITIR : (D) %c\n",186,186);
 gotoxy(55,21);
 printf(" %c %c\n",186,186);
 gotoxy(55,22);
 printf(" %c DESFAZER : (U) %c\n",186,186);
 gotoxy(55,23);
 printf(" %c %c\n",186,186);
 gotoxy(55,24);
 printf(" %c MOVIMENTOS : %c\n",186,186);
 gotoxy(55,25);
 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
 printf("\n\n");
 gotoxy(76,24);
 printf("%d",cont);
}
void novorelatorio(char nomeArq[])
{
 FILE *relatorio;
 FILE *nrelatorio;
 int cont2=0,a,b;
 relatorio = fopen(nomeArq,"r");
 nrelatorio = fopen("nrelatorio.txt","w");
 if(relatorio==NULL || nrelatorio==NULL)
 {
 printf("Nao foi possivel abrir seu arquivo...\n");
 exit(1);
 }
 fclose(nrelatorio);
 rewind(relatorio);
 nrelatorio = fopen("nrelatorio.txt","a");
 while(!feof(relatorio))
 {
 cont2++;
 fscanf(relatorio,"%d -> %d\n",&a,&b);
 fprintf(nrelatorio,"%d -> %d\n", a,b);
 if(cont2==cont)
 break;
 }
 fclose(nrelatorio);
 fclose(relatorio);
 relatorio = fopen(nomeArq,"w");
 fclose(relatorio);
 nrelatorio = fopen("nrelatorio.txt","r");
 relatorio = fopen(nomeArq,"a");
 rewind(nrelatorio);
 while(!feof(nrelatorio))
 {
 fscanf(nrelatorio,"%c -> %c\n",&a,&b);
 fprintf(relatorio,"%c -> %c\n", a,b);
 }
 fclose(relatorio);
 nrelatorio = fopen("nrelatorio.txt","w");
 fclose(nrelatorio);
}
void ImprimeRelatorio(char nomeArq[],int mat[7][3],char discos[linha][coluna])
{
 FILE * relatorio;
 int cont2=0;
 int a,b,c;
 relatorio = fopen(nomeArq,"r");
 if(relatorio==NULL)
 {
 printf("Nao foi possivel abrir seu arquivo...\n");
 exit(1);
 }
 while(!feof(relatorio))
 {
 fscanf(relatorio,"%d -> %d\n",&a,&b);
 cont2++;
 if(cont2==cont)
 {
 origem = b;
 destino = a;
 a = analisamovimento(a);
 b = analisamovimento(b);
 movimenta_torre(mat,a,b,discos);
 }
 }
 fclose(relatorio);
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais

Materiais relacionados

Perguntas relacionadas

Perguntas Recentes