UNKNOWN //************************************** // Name: Snake Game // Description:Trying to improve algorithm creation and development. Its my first try making a game. Even though it has lots of problems i feel it is a easy way to improve your skills. I hope people more experienced than me can send me their opinions and what they would have changed. // By: Victor Chavauty // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.13847/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include <stdio.h> #include <stdlib.h> #include <time.h> #include <windows.h> #define TRUE 1 #define FALSE 0 char map[20][20] = {{'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}}; char map2[20][20] = {{'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}}; char map3[20][20] = {{'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'}, {'-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'}}; struct pessoa { char name[50]; int points; int Size; } person; int difficulty = 300; int difficulty_config = 0; int seg = 0; int x, y; int Direction; void restaura(); /*restore map*/ void crear_punto(); /*create point*/ void imprime(int ax, int bx, char MESSAGE[50]) /*show map*/ { int a, b; system("cls"); printf("NAME: %sPOINTS: %d\n", person.name, person.points); /* MUDA */ if(MESSAGE != NULL) { printf("%s5n\n", MESSAGE); /* MUDA */ } map[ax][bx] = '0'; for(a = 0;a < 20;a++) { for(b = 0;b < 20;b++) { printf("%c", map[a][b]); /* MUDA */ } printf("\n"); /* MUDA */ } } void move() { int stat = TRUE; restaura(); printf("A"); if(Direction == 5) { if(map[x - 1][y] == '-' || map[x - 1][y] == '|') { system("CLS"); printf("GAME OVER 1"); /* MUDA */ exit(0); } if(map[x - 1][y] == 'x') { printf("A"); if(difficulty_config == 5) { printf("A"); difficulty_config = 0; if(difficulty > 100) difficulty = difficulty - 35; } printf("A"); eliminar_punto(x-1, y); person.points = person.points + 1; difficulty_config = difficulty_config + 1; } printf("A"); x = x - 1; } else if(Direction == 2) { if(map[x + 1][y] == '-' || map[x + 1][y] == '|' ) { system("CLS"); printf("GAME OVER"); /* MUDA */ exit(0); } if(map[x + 1][y] == 'x') { if(map[x + 1][y] == 'x') { if(difficulty_config == 5) { difficulty_config = 0; if(difficulty > 100) difficulty = difficulty - 35; } eliminar_punto(x + 1, y); person.points = person.points + 1; difficulty_config = difficulty_config + 1; } } x = x + 1; } else if(Direction == 3) { printf("C"); if(map[x][y + 1] == '-' || map[x][y + 1] == '|') { system("CLS"); printf("GAME OVER 3"); exit(0); } printf("C"); if(map[x][y + 1] == 'x') { if(difficulty_config == 5) { difficulty_config = 0; if(difficulty > 100) difficulty = difficulty - 35; printf("C"); } printf("C"); eliminar_punto(x, y +1 ); person.points = person.points + 1; difficulty_config = difficulty_config + 1; } printf("C"); y = y + 1; } else if(Direction == 1) { if(map[x][y - 1] == '-' || map[x][y - 1] == '|') { system("CLS"); printf("GAME OVER 4"); exit(0); } if(map[x][y - 1] == 'x') { if(difficulty_config == 5) { difficulty_config = 0; if(difficulty > 100) difficulty = difficulty - 35; } eliminar_punto(x, y - 1); person.points = person.points + 1; difficulty_config = difficulty_config + 1; } y = y - 1; } if(stat == TRUE) { imprime(x, y, NULL); } } void relojo( int seconds ) /*clock*/ { clock_t tempo; tempo = clock () + seconds * 300; while (clock() < tempo) {} seg++; } int main() { x = 10; y = 10; crear_punto(); Direction = 3; printf("Qual o seu nome: >"); scanf("%s", &person.name); person.points = 0; person.Size = 2; int i; char ch = 'a'; printf("Z1"); for(i = 0;i < 5;i++) { printf("Z2"); do { if(GetAsyncKeyState(VK_ESCAPE) & 1) { printf("Z3"); system("cls"); printf("JOGO TERMINADO..."); exit(0); } else if(GetAsyncKeyState(VK_UP) & 1) { printf("Z3b"); Direction = 5; } else if(GetAsyncKeyState(VK_LEFT) & 1) { printf("Z3c"); Direction = 1; } else if(GetAsyncKeyState(VK_DOWN) & 1) { printf("Z3d"); Direction = 2; } else if(GetAsyncKeyState(VK_RIGHT) & 1) { printf("Z3e"); Direction = 3; } printf("Z"); move(); relojo(1); printf("Z"); i = 0; }while(ch != 'e'); } } void restaura() { int a, b; for(a = 0;a < 20; a++) { for(b = 0;b < 20;b++) { map[a][b] = map2[a][b]; } } } void eliminar_punto(int a, int b) { map2[a][b] = map3[a][b]; map[a][b] = map3[a][b]; crear_punto(); } void crear_punto() { int random1, random2; random1 = rand() % 19 + 0; random2 = rand() % 19 + 0; map[random1][random2] = 'x'; map2[random1][random2] = 'x'; }