示例#1
0
/**A função executaCriaJog recebe os argumentos da linha de comando, vai verificar se tem os argumentos, certos se tal ocorre, executa criarJogo com o nome do argumento no formato ".ltr".
 * @param args Recebe uma string com os argumentos associados ao comando em questão ("cr").
 * @param Tab Tabuleiro do jogo
 * @param DIM dimensão do tabuleiro
 * @returns torna um inteiro que verifica se foi ou não bem sucedida a função.
 */
int executaCriaJogo(char *args,int *DIM,Elem **Tab) {
	char buf[1024];
	char nome[256];

	int nargs = sscanf(args, "%s %[^\n]", nome, buf);


  if(nargs != 1) {
      return mensagem_de_erro(E_INVARGS);
  }
	
	strcat(nome,".ltr");
	criarTabuleiro(nome,DIM,Tab);

return 0;
}
示例#2
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      MAT_tpCondRet CondRetObtido   = MAT_CondRetOK ;
      MAT_tpCondRet CondRetEsperada = MAT_CondRetFaltouMemoria ;
                                      /* inicializa para qualquer coisa */

	  char   StringDado[  DIM_VALOR ] ;
	  int i ,
				valor;
	  int numColuna,
				numLinha;
      int  NumLidos      = -1 ;
      int  inxMatriz     = -1 ;
	  numColuna = -1;
	  numLinha = -1;
	  valor = -1;

	  StringDado[ 0 ] = 0 ;     

      #ifdef _DEBUG
         int  IntEsperado   = -1 ;
      #endif

      /* Tratar: inicializar contexto */

         if ( strcmp( ComandoTeste , RESET_CMD ) == 0 )
         {

            if ( estaInicializado )
            {
               for( i = 0 ; i < DIM_VT_MATRIZES ; i++ )
               {
                  destruirMatriz( ( vtRefMatriz[ i ] )) ;
               } /* for */
            } /* if */

            for( i = 0 ; i < DIM_VT_MATRIZES ; i++ )
            {
               vtRefMatriz[ i ] = 0 ;
            } /* for */

            estaInicializado = 1 ;

         } /* fim ativa: Tratar: inicializar contexto */

      /* Testar MAT Criar matriz */

   //      else if ( strcmp( ComandoTeste , CRIAR_MAT_CMD ) == 0 )
   //      {

   //         NumLidos = LER_LerParametros( "ii" ,
   //                            &inxMatriz , &CondRetEsperada ) ;
   //         if ( ( NumLidos != 2 )
   //           || !VerificarInx( inxMatriz ))
   //         {
   //            return TST_CondRetParm ;
   //         } /* if */

			//CondRetObtido = criarMatriz( &(vtRefMatriz[inxMatriz] ));

   //         return TST_CompararInt( CondRetEsperada , CondRetObtido ,
   //                                 "Retorno errado ao criar matriz." );

   //      } /* fim ativa: Testar MAT Criar matriz */

      /* Testar MAT Adicionar linha à matriz */

   //      else if ( strcmp( ComandoTeste , INS_LIN_CMD ) == 0 )
   //      {

   //         NumLidos = LER_LerParametros( "ii" ,
   //                            &inxMatriz , &CondRetEsperada ) ;
   //         if ( ( NumLidos != 2 )
   //           || !VerificarInx( inxMatriz ))
   //         {
   //            return TST_CondRetParm ;
   //         } /* if */

			//CondRetObtido = inserirLinha(*vtRefMatriz[inxMatriz]);

   //         return TST_CompararInt( CondRetEsperada , CondRetObtido ,
   //                                 "Retorno errado inserir à direita." );

   //      } /* fim ativa: Testar MAT Adicionar linha à matriz */

   //   /* Testar MAT Adicionar coluna à matriz */

   //      else if ( strcmp( ComandoTeste , INS_COL_CMD ) == 0 )
   //      {

   //         NumLidos = LER_LerParametros( "ii" ,
   //                            &inxMatriz , &CondRetEsperada ) ;
   //         if ( ( NumLidos != 2 )
   //           || !VerificarInx( inxMatriz ))
   //         {
   //            return TST_CondRetParm ;
   //         } /* if */

			//CondRetObtido = inserirColuna(*vtRefMatriz[inxMatriz]);

   //         return TST_CompararInt( CondRetEsperada , CondRetObtido ,
   //                                 "Retorno errado ao inserir à esquerda." );

   //      } /* fim ativa: Testar MAT Adicionar coluna à matriz */

      /* Testar MAT Criar tabuleiro */

         else if ( strcmp( ComandoTeste , CRIAR_TAB_CMD ) == 0 )
         {

            NumLidos = LER_LerParametros( "iiii" ,
                               &inxMatriz , &numLinha, &numColuna, &CondRetEsperada ) ;
            if ( ( NumLidos != 4 )
              || !VerificarInx( inxMatriz ))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRetObtido = criarTabuleiro(&(vtRefMatriz[inxMatriz]), numLinha, numColuna);

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao criar tabuleiro." );

         } /* fim ativa: Testar MAT Criar tabuleiro */

      /* Testar MAT Empilhar valor */

         else if ( strcmp( ComandoTeste , EMP_VAL_CMD ) == 0 )
         {
			 printf("Entrou no empilhar");

            NumLidos = LER_LerParametros( "iiiii" ,
                               &inxMatriz , &valor, &numLinha, &numColuna, &CondRetEsperada ) ;
            if ( ( NumLidos != 5 )
              || !VerificarInx( inxMatriz ))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRetObtido = 
				empilharValor(vtRefMatriz[0], 1,
				numLinha, numColuna ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao empilhar valor." );

         } /* fim ativa: Testar MAT Empilhar valor */

      /* Testar MAT Desempilhar valor */

         else if ( strcmp( ComandoTeste , DESEMP_VAL_CMD ) == 0 )
         {

            NumLidos = LER_LerParametros( "iiii" ,
				&inxMatriz , &numLinha, &numColuna, &CondRetEsperada ) ;
            if ( ( NumLidos != 4 )
              || !VerificarInx( inxMatriz ))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRetObtido = desempilharValor( vtRefMatriz[ inxMatriz ], numLinha, numColuna);			

			return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                   "Retorno errado ao desempilhar valor." );						
			
			
         } /* fim ativa: Testar MAT Desempilhar valor */

		  /* Testar MAT Destruir matriz */
		 else if( strcmp( ComandoTeste, DESTRUIR_MAT_CMD) == 0)
		 {
			 NumLidos = LER_LerParametros( "ii" ,
                               &inxMatriz, &CondRetEsperada  ) ;
            if ( ( NumLidos != 2 )
              || !VerificarInx( inxMatriz ))
            {
               return TST_CondRetParm ;
            
			} /* if */

			CondRetObtido = destruirMatriz( vtRefMatriz[ inxMatriz ] );				

			return TST_CompararInt(CondRetEsperada, CondRetObtido,
				"Retorno errado destruir matriz.");

		 }/* fim ativa: Testar MAT Destruir matriz */


      
      return TST_CondRetNaoConhec ;

   } /* Fim função: TMAT &Efetuar operações específicas */
示例#3
0
文件: Damas_C.cpp 项目: TaynaCT/damaC
int main()
{
	criarTabuleiro();
	mostrarTabuleiro();

	Player jogo = NULL;

	int turno = 1;
	int fim = 0;
	int x0, y0, xf, yf, jAtual = 0;
	char jogador1[10], jogador2[10], jogadorAtual[10];


	puts(" ");
	do
	{
		if (turno == 1) {
			printf("=== JOGADOR 1 insira o nome ===\n");
			scanf("%s", jogador1);
			printf("=== JOGADOR 2 insira o nome ===\n");
			scanf("%s", jogador2);
			
			system("cls");
			fflush(stdin);
		}

		strcpy(jogadorAtual, jogador1);

		if (jAtual > 2) {
			strcpy(jogadorAtual, jogador1);
			jAtual = 0;
		}
		if (jAtual == 1)
			strcpy(jogadorAtual, jogador2);

		printf("======================================================\n");
		printf("TURNO: %d\nJOGADOR: %s", turno, jogadorAtual);
		puts(" ");
		mostrarTabuleiro();

		printf("==== Insira um movimento ===\n");
		printf("\t ESCOLHA A CORDENADA DA PEÇA A MOVIMENTAR [x0, y0]\n");
		printf("\t x0 = \n");
		scanf("%d", &x0);
		printf("\t y0 = \n");
		scanf("%d", &y0);
		printf("\t ESCOLHA A CORDENADA O DESTINO DA PEÇA [xf, yf]");

		scanf("%d %d", &xf, &yf);
		fflush(stdin);

		//fazerMovimento(x0)
		turno++;

		mostrarTabuleiro();
		printf("FIM DE JOGADA ? [1-sim, 0-não]\n");
		scanf("%d", &fim);

		fflush(stdin);
		jAtual++;

		if (vencerPartida() == 1)
		{
			system("cls");
			printf("PARABéNS O JOGADOR 1 VENCEU A PARTIDA!!!");
			break;
		}
		if (vencerPartida() == 2)
		{
			system("cls");
			printf("PARABéNS O JOGADOR 2 VENCEU A PARTIDA!!!");
			break;
		}

	} while (vencerPartida() == 0);


	getchar();
	return 0;
}