Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <iostream>
- //Definindo as teclas usadas
- #define Cima '8'
- #define Baixo '2'
- #define Esquerda '4'
- #define Direita '6'
- //Definindo as notas sonoras
- #define Do 1046
- #define Re 1174
- #define Re6 2349
- #define Mi 1318
- #define Sol 1567
- #define Fa 1396
- #define CIMA 1
- #define BAIXO 2
- #define ESQUERDA 3
- #define DIREITA 4
- #define BT_MEIO '5'
- #define NIVEL1 2
- #define NIVEL2 3
- #define NIVEL3 4
- #define NIVEL4 5
- #define NIVEL5 6
- #define NIVEL6 7
- #define NIVEL7 8
- #define NIVEL8 9
- #define NIVEL9 10
- #define NIVEL10 11
- #define NIVEL11 12
- #define NIVEL12 13
- #define NIVEL13 14
- #define NIVEL14 15
- #define NIVEL15 16
- #define NIVEL16 17
- #define NIVEL17 18
- #define NIVEL18 19
- #define NIVEL19 20
- #define NIVEL20 21
- #define NIVEIS 20
- int pontos = 0;
- int score = 0;
- struct {
- const int fases_ID[NIVEIS] ={NIVEL1,NIVEL2,NIVEL3,NIVEL4,NIVEL5,
- NIVEL6,NIVEL7,NIVEL8,NIVEL9,NIVEL10,
- NIVEL11,NIVEL12,NIVEL13,NIVEL14,NIVEL15,
- NIVEL16,NIVEL17,NIVEL18,NIVEL19,NIVEL20};
- }Fases_ID;
- /*Definindo os niveis*/
- struct {
- int Ordem[NIVEL1];
- }Fase1;
- struct {
- int Ordem[NIVEL2];
- }Fase2;
- struct {
- int Ordem[NIVEL3];
- }Fase3;
- struct {
- int Ordem[NIVEL4];
- }Fase4;
- struct {
- int Ordem[NIVEL5];
- }Fase5;
- struct {
- int Ordem[NIVEL6];
- }Fase6;
- struct {
- int Ordem[NIVEL7];
- }Fase7;
- struct {
- int Ordem[NIVEL8];
- }Fase8;
- struct {
- int Ordem[NIVEL9];
- }Fase9;
- struct {
- int Ordem[NIVEL10];
- }Fase10;
- struct {
- int Ordem[NIVEL11];
- }Fase11;
- struct {
- int Ordem[NIVEL12];
- }Fase12;
- struct {
- int Ordem[NIVEL13];
- }Fase13;
- struct {
- int Ordem[NIVEL14];
- }Fase14;
- struct {
- int Ordem[NIVEL15];
- }Fase15;
- struct {
- int Ordem[NIVEL16];
- }Fase16;
- struct {
- int Ordem[NIVEL17];
- }Fase17;
- struct {
- int Ordem[NIVEL18];
- }Fase18;
- struct {
- int Ordem[NIVEL19];
- }Fase19;
- struct {
- int Ordem[NIVEL20];
- }Fase20;
- int Nome[5][28]={{1,1,1,1,0,1,1,1,1,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,1,1,1},
- {1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0},
- {1,0,1,1,0,1,1,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,1,0},
- {1,0,0,1,0,1,0,0,0,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,1},
- {1,1,1,1,0,1,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,1,1,0,1,1,1,0}};
- //Desenhos das telas
- int Zero[19][20] = {{0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
- {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
- {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
- {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
- {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0},
- {0,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,0},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,1,1,1,1},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,1,1,1,1},
- {1,1,1,1,0,0,1,0,0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,1,1,1,0,0,0,0},
- {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0},
- {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0},
- {0,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,2,2,2,0},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,2,2,2,2},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,2,2,2,2},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,2,2,2,2},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,2,2,2,2},
- {1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,2,2,2,2},
- {0,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,2,2,2,0},
- {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0},
- {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0},
- {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
- {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
- {0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0},
- };
- void posX(int num){
- for(int i = 0;i < num; i++)
- printf("\t");
- }
- void posY(int num){
- for(int i = 0;i < num; i++)
- printf("\n");
- }
- void tela(char x){
- printf("Pontos: %d Score: %d",pontos, score);
- posY(1);
- for(int i = 0; i < 5; i++){
- posX(5);
- for(int y = 0; y < 28; y++){
- switch(Nome[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- switch(x){
- case 0:
- posY(1);
- for(int i = 0; i < 19; i++){
- posX(6);
- for(int y = 0; y < 20; y++){
- switch(Zero[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",176);
- break;
- case 2:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- break;
- case Cima:
- posY(1);
- for(int i = 0; i < 19; i++){
- posX(6);
- for(int y = 0; y < 20; y++){
- switch(cima[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",176);
- break;
- case 2:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- break;
- case Baixo:
- posY(1);
- for(int i = 0; i < 19; i++){
- posX(6);
- for(int y = 0; y < 20; y++){
- switch(baixo[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",176);
- break;
- case 2:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- break;
- case Esquerda:
- posY(1);
- for(int i = 0; i < 19; i++){
- posX(6);
- for(int y = 0; y < 20; y++){
- switch(esquerda[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",176);
- break;
- case 2:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- break;
- case Direita:
- posY(1);
- for(int i = 0; i < 19; i++){
- posX(6);
- for(int y = 0; y < 20; y++){
- switch(direita[i][y]){
- case 0:
- printf(" ");
- break;
- case 1:
- printf("%c",176);
- break;
- case 2:
- printf("%c",178);
- break;
- }
- }
- printf("\n");
- }
- break;
- }
- }
- void Beep_seq(int index){
- switch(index){
- case CIMA:
- tela(Cima);
- Beep(Do, 500);
- break;
- case BAIXO:
- tela(Baixo);
- Beep(Re, 500);
- break;
- case ESQUERDA:
- tela(Esquerda);
- Beep(Mi, 500);
- break;
- case DIREITA:
- tela(Direita);
- Beep(Fa, 500);
- break;
- }
- }
- void indexFase(int index, int idVal, int val){
- switch(index){
- case 0:
- Fase1.Ordem[idVal] = val;
- break;
- case 1:
- Fase2.Ordem[idVal] = val;
- break;
- case 2:
- Fase3.Ordem[idVal] = val;
- break;
- case 3:
- Fase4.Ordem[idVal] = val;
- break;
- case 4:
- Fase5.Ordem[idVal] = val;
- break;
- case 5:
- Fase6.Ordem[idVal] = val;
- break;
- case 6:
- Fase7.Ordem[idVal] = val;
- break;
- case 7:
- Fase8.Ordem[idVal] = val;
- break;
- case 8:
- Fase9.Ordem[idVal] = val;
- break;
- case 9:
- Fase10.Ordem[idVal] = val;
- break;
- case 10:
- Fase11.Ordem[idVal] = val;
- break;
- case 11:
- Fase12.Ordem[idVal] = val;
- break;
- case 12:
- Fase13.Ordem[idVal] = val;
- break;
- case 13:
- Fase14.Ordem[idVal] = val;
- break;
- case 14:
- Fase15.Ordem[idVal] = val;
- break;
- case 15:
- Fase16.Ordem[idVal] = val;
- break;
- case 16:
- Fase17.Ordem[idVal] = val;
- break;
- case 17:
- Fase18.Ordem[idVal] = val;
- break;
- case 18:
- Fase19.Ordem[idVal] = val;
- break;
- case 19:
- Fase20.Ordem[idVal] = val;
- break;
- }
- }
- int ReturnIndexFase(int nivel, int idVal){
- int valor;
- switch(nivel){
- case 0:
- valor = Fase1.Ordem[idVal];
- break;
- case 1:
- valor = Fase2.Ordem[idVal];
- break;
- case 2:
- valor = Fase3.Ordem[idVal];
- break;
- case 3:
- valor = Fase4.Ordem[idVal];
- break;
- case 4:
- valor = Fase5.Ordem[idVal];
- break;
- case 5:
- valor = Fase6.Ordem[idVal];
- break;
- case 6:
- valor = Fase7.Ordem[idVal];
- break;
- case 7:
- valor = Fase8.Ordem[idVal];
- break;
- case 8:
- valor = Fase9.Ordem[idVal];
- break;
- case 9:
- valor = Fase10.Ordem[idVal];
- break;
- case 10:
- valor = Fase11.Ordem[idVal];
- break;
- case 11:
- valor = Fase12.Ordem[idVal];
- break;
- case 12:
- valor = Fase13.Ordem[idVal];
- break;
- case 13:
- valor = Fase14.Ordem[idVal];
- break;
- case 14:
- valor = Fase15.Ordem[idVal];
- break;
- case 15:
- valor = Fase16.Ordem[idVal];
- break;
- case 16:
- valor = Fase17.Ordem[idVal];
- break;
- case 17:
- valor = Fase18.Ordem[idVal];
- break;
- case 18:
- valor = Fase19.Ordem[idVal];
- break;
- case 19:
- valor = Fase20.Ordem[idVal];
- break;
- }
- return valor;
- }
- void sequencia(int nivel){
- for(int i = 0; i < Fases_ID.fases_ID[nivel]; i++){
- Beep_seq(ReturnIndexFase(nivel, i));
- system("cls");
- tela(0);
- Sleep(200);
- system("cls");
- }
- }
- void Salvar_Arquivo(int valor){
- FILE *fp;
- char Valor[10];
- fp = fopen("Score.dll", "w");
- if(fp == NULL)
- printf("Erro ao criar arquivo!");
- else{
- sprintf(Valor, "%d", valor);
- fputs(Valor,fp);
- fclose(fp);
- }
- }
- int Abrir_Arquivo(){
- int valor = 0;
- char Valor[10];
- FILE *fp;
- fp = fopen("Score.dll", "r");
- if(fp == NULL)
- printf("Erro ao abrir arquivo");
- else{
- fgets(Valor,sizeof(Valor),fp);
- valor = atoi(Valor);
- }
- return valor;
- }
- int main()
- {
- char com;
- bool sair = false;
- bool Play_Game = true;
- int Nivel = 0;
- int incremento_Nivel = 0;
- srand((unsigned)time(NULL));
- int valoresOrdem[20];
- char *Valor;
- while(Play_Game){
- score = Abrir_Arquivo();
- //zerando as variaveis;
- for(int i = 0; i < 8; i++)
- valoresOrdem[i] = 0;
- /*definindo valores alatórios para as sequencias e repetições*/
- for(int i = 0;i < Fases_ID.fases_ID[Nivel]; i++){
- valoresOrdem[i] = (rand() % 4) + 1;
- }
- for(int i = 0; i < Fases_ID.fases_ID[Nivel]; i++){
- indexFase(Nivel, i, valoresOrdem[i]);
- }
- sequencia(Nivel);
- tela(0);
- for(int i = 0; i < Fases_ID.fases_ID[Nivel]; i++){
- switch(getch()){
- case Cima:
- system("cls");
- if(ReturnIndexFase(Nivel, i) != CIMA)sair = true;
- else{
- Beep_seq(ReturnIndexFase(Nivel, i));
- system("cls");
- tela(0);
- }
- break;
- case Baixo:
- system("cls");
- if(ReturnIndexFase(Nivel, i) != BAIXO)sair = true;
- else{
- Beep_seq(ReturnIndexFase(Nivel, i));
- system("cls");
- tela(0);
- }
- break;
- case Esquerda:
- system("cls");
- if(ReturnIndexFase(Nivel, i) != ESQUERDA)sair = true;
- else{
- Beep_seq(ReturnIndexFase(Nivel, i));
- system("cls");
- tela(0);
- }
- break;
- case Direita:
- system("cls");
- if(ReturnIndexFase(Nivel, i) != DIREITA)sair = true;
- else{
- Beep_seq(ReturnIndexFase(Nivel, i));
- system("cls");
- tela(0);
- }
- break;
- }
- if(sair)break;
- }
- if(sair){
- Beep(200, 100);
- Beep(100, 100);
- pontos = 0;
- incremento_Nivel = 0;
- Nivel = 0;
- printf("Voce perdeu!\n\n");
- sair = false;
- printf("Deseja continuar? <S> <N>");
- switch(getch()){
- case 'n':
- case 'N':
- Play_Game = false;
- break;
- }
- }
- else {
- pontos++;
- incremento_Nivel++;
- if(incremento_Nivel >= 2){
- if(Nivel<NIVEIS)Nivel++;
- incremento_Nivel = 0;
- }
- Beep(700, 100);
- Beep(800, 100);
- if(pontos>score){
- printf("salvando score...");
- Salvar_Arquivo(pontos);
- }
- }
- system("cls");
- tela(0);
- Sleep(800);
- system("cls");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment