Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <windows.h>
- #include <string.h>
- #define UP 72
- #define DOWN 80
- #define LEFT 75
- #define RIGHT 77
- #define gspeed 5
- #define jspeed 50
- void delay(unsigned int);
- typedef struct eredmeny{ //Struktúra az eredmény listához.
- char nev[100];
- int score;
- }ERED;
- void SetPosition(int X, int Y)
- {
- HANDLE Screen;
- Screen = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD Position = { X, Y };
- SetConsoleCursorPosition(Screen, Position);
- }
- int getline(char s[], int n)
- {
- int c, i;
- for (i = 0; i<n && (c = getchar()) != EOF&&c != '\n'; ++i)
- s[i] = c;
- s[i] = '\0';
- while (c != EOF&&c != '\n') c = getchar();
- return(i);
- }
- int main()
- {
- char matrix[23][27] =
- { "------------------------",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |",
- " |", };
- int i, j, n = 0, score = 0, bszam = 200, a = 1, s = 2, seged = 1, b = 1, eltolas = 0, l = 0, temp = 1;
- int px = 22, py = 10, key = 0, bx = 21, by = py, k = 0, f = 0, pont, ok = 1, x = 17, sor = 5, masik = 17, w;
- int masol, masolas, torol, ell, c = 1, e = 17, msor = 8;
- int szamlalo = 3;
- int g = 50;
- char ures = ' ';
- char player = 'A';
- char bullet = '^';
- char alian = 'V';
- matrix[px][py] = 'A';
- char nev[32];
- FILE *fp;
- int index4 = 0;
- ERED *tomb;
- char line[32];
- int jatekszam = 0;
- matrix[5][1] = alian;
- matrix[5][3] = alian;
- matrix[5][5] = alian;
- matrix[5][7] = alian;
- matrix[5][9] = alian;
- matrix[5][11] = alian;
- matrix[5][13] = alian;
- matrix[5][15] = alian;
- matrix[8][1] = alian;
- matrix[8][3] = alian;
- matrix[8][5] = alian;
- matrix[8][7] = alian;
- matrix[8][9] = alian;
- matrix[8][11] = alian;
- matrix[8][13] = alian;
- matrix[8][15] = alian;
- matrix[4][1] = alian;
- matrix[4][3] = alian;
- matrix[4][5] = alian;
- matrix[4][7] = alian;
- matrix[4][9] = alian;
- matrix[4][11] = alian;
- matrix[4][13] = alian;
- matrix[4][15] = alian;
- matrix[4][17] = alian;
- matrix[4][19] = alian;
- matrix[4][21] = alian;
- matrix[3][2] = alian;
- matrix[3][5] = alian;
- matrix[3][8] = alian;
- matrix[3][11] = alian;
- matrix[3][14] = alian;
- matrix[3][17] = alian;
- matrix[3][20] = alian;
- nevbe:
- printf("Felhasznalonev (max 30 karakter, angol ABC betui, esetleg szokoz): ");
- if (!getline(nev, 31))
- {
- printf("HIBA: Hianyzo adat.\n\n");
- goto nevbe;
- }
- if (strlen(nev) > 30)
- {
- printf("HIBA: A megadott nev tul hosszu!\nKerem adjon meg ujat!\n\n");
- goto nevbe;
- }
- for (w = 0; w < strlen(nev); w++)
- {
- if (!isalpha(nev[w]) && !isspace(nev[w]))
- {
- printf("HIBA: A felhasznalonev csak az angol ABC betuit tartalmazhatja!\nKerem adjon meg ujat!\n\n");
- goto nevbe;
- }
- }
- system("cls");
- a--;
- do
- {
- if (g == 50)
- {
- a++;
- if (a < 8)
- {
- for (; b < x; b = b + 2)
- {
- /* if (matrix[sor][b + 1] == bullet)
- {
- matrix[sor][b + 1] = ures;
- matrix[sor][b] = ures;
- bx = 21;
- f = 0;
- ok = 1;
- score = score + 50;
- eltolas = eltolas + 1;
- }*/
- matrix[sor][b + 1] = matrix[sor][b];
- matrix[sor][b] = ures;
- }
- b = b - 16;
- b++;
- x++;
- for (; c < e; c = c + 2)
- {
- if (matrix[msor][c + 1] == bullet)
- {
- matrix[msor][c + 1] = ures;
- matrix[msor][c] = ures;
- bx = 21;
- f = 0;
- ok = 1;
- score = score + 50;
- eltolas = eltolas + 1;
- }
- matrix[msor][c + 1] = matrix[msor][c];
- matrix[msor][c] = ures;
- }
- c = c - 16;
- c++;
- e++;
- }
- g = 0;
- }
- if (a == 7)
- {
- masolas = 1;
- for (masol = 8; masol < 24; masol++, masolas++)
- {
- matrix[sor + 1][masolas] = matrix[sor][masol];
- }
- masolas = 1;
- for (masol = 8; masol < 24; masol++, masolas++)
- {
- matrix[msor + 1][masolas] = matrix[msor][masol];
- }
- for (torol = 0; torol < 24; torol++)
- {
- matrix[sor][torol] = ures;
- matrix[msor][torol] = ures;
- }
- sor = sor + 1;
- a = 0;
- b = 1;
- x = 17;
- msor = msor + 1;
- e = 17;
- c = 1;
- }
- for (ell = 0; ell < 24; ell++)
- {
- if (matrix[sor][ell] == '^')
- {
- matrix[sor][ell] = ures;
- }
- if (matrix[msor][ell] == '^')
- {
- matrix[msor][ell] = ures;
- }
- }
- if (_kbhit())
- {
- key = _getch();
- if (key == RIGHT)
- {
- py = py + 1;
- if (py > 0 && py < 22)
- {
- matrix[px][py] = player;
- matrix[px][py - 1] = ures;
- }
- else
- {
- py = py - 1;
- }
- }
- if (key == LEFT)
- {
- py = py - 1;
- if (py>-1 && py < 24)
- {
- matrix[px][py] = player;
- matrix[px][py + 1] = ures;
- }
- else
- {
- py = py + 1;
- }
- }
- if (key == UP)
- {
- f = 1;
- if (ok > 0)
- {
- pont = py;
- }
- bszam = bszam - 1;
- }
- }
- if (f > 0 && szamlalo > 2)
- {
- szamlalo = 0;
- ok = 0;
- bx = bx - 1;
- if (bx > 0)
- {
- if (matrix[bx][pont] == alian)
- {
- matrix[bx][pont] = ures;
- matrix[bx + 1][pont] = ures;
- bx = 21;
- f = 0;
- ok = 1;
- eltolas = eltolas + 1;
- score = score + 50;
- }
- else
- {
- if (matrix[bx + 1][pont] != alian)
- {
- matrix[bx][pont] = bullet;
- matrix[bx + 1][pont] = ures;
- }
- else
- {
- matrix[bx][pont] = bullet;
- }
- }
- }
- if (bx == 1)
- {
- matrix[bx][pont] = ures;
- }
- if (bx < 2)
- {
- bx = 21;
- f = 0;
- ok = 1;
- }
- }
- if (bszam == 0 || msor == 20 || eltolas == 34)
- {
- key = 'e';
- }
- for (i = 0; i < 23; i++)
- {
- for (j = 0; j < 27; j++)
- {
- printf("%c", matrix[i][j]);
- }
- printf("\n");
- }
- printf("%d %d/14", score, (sor - 4));
- /*gotoxy(0, 0);*/
- SetPosition(0, 0);
- g = g + 1;
- szamlalo = szamlalo + 1;
- } while (key != 'e');
- system("cls");
- printf("SCORE:%d \n\n", score);
- if (eltolas == 34)
- printf("YOU WIN!!!\n\n");
- else
- printf("GAME OVER!!!!\n\n");
- fp = fopen("top.txt", "at");
- fprintf(fp, "%s %d\n", nev, score);
- fclose(fp);
- fp = fopen("top.txt", "r");
- fclose(fp);
- tomb = (ERED*)malloc(sizeof(ERED) * 10);
- fp = fopen("top.txt", "r");
- while (!feof(fp))
- {
- fscanf(fp, "%s %d\n", line, &pont);
- strcpy(tomb[index4].nev, line);
- tomb[index4].score = pont;
- index4++;
- }
- fclose(fp);
- for (n = 0; n < index4; n++){
- for (i = n + 1; i < index4; i++)
- if (tomb[n].score < tomb[i].score)
- {
- temp = tomb[n].score;
- tomb[n].score = tomb[i].score;
- tomb[i].score = temp;
- strcpy(line, tomb[n].nev);
- strcpy(tomb[n].nev, tomb[i].nev);
- strcpy(tomb[i].nev, line);
- }
- }
- fp = fopen("top.txt", "w");
- for(i = 0; i < 5; i++ )
- {
- fprintf(fp, "%s %d\n", tomb[i].nev, tomb[i].score);
- }
- fclose(fp);
- fp = fopen("top.txt", "r");
- i = 0;
- do
- {
- fgets(line, 100, fp);
- puts(line);
- i++;
- } while (!feof(fp));
- fclose(fp);
- free(tomb);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement