You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
4.2 KiB
224 lines
4.2 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int BinX;
|
|
int BinY = 12;
|
|
|
|
char field[23][29];
|
|
|
|
int Ballx = -1;
|
|
int Bally = 27;
|
|
|
|
int fieldWidth = 25;
|
|
int fieldHeigth = 30;
|
|
|
|
struct Player
|
|
{
|
|
char Name[50];
|
|
int Points;
|
|
}playerlist[11];
|
|
|
|
|
|
void buildBin(int width, int heigth){
|
|
field[width][heigth] = 'V';
|
|
field[width+1][heigth+1] = '\\';
|
|
field[width+2][heigth+2] = '\\';
|
|
field[width-1][heigth+1] = '/';
|
|
field[width-2][heigth+2] = '/';
|
|
field[width][heigth+1] = ' ';
|
|
}
|
|
|
|
void loadLevel() {
|
|
int lvlnum;
|
|
clearField();
|
|
Ballx = -1;
|
|
Bally = 30;
|
|
|
|
int tmpX,tmpY;
|
|
|
|
switch (lvlnum)
|
|
{
|
|
case(1):
|
|
BinX = 12;
|
|
BinY = 10;
|
|
break;
|
|
case(2):
|
|
case(3):
|
|
case(4):
|
|
case(5):
|
|
|
|
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int ballX = 7;
|
|
int BallY = 23;
|
|
|
|
while (1)
|
|
{
|
|
system("clear");
|
|
|
|
for (int i = 0; i < 23; i++)
|
|
{
|
|
for (int j = 0; j < 29; j++)
|
|
{
|
|
field[i][j] = ' ';
|
|
}
|
|
}
|
|
|
|
field[ballX][BallY -= 1] = 'O';
|
|
|
|
|
|
buildBin(10,10);
|
|
|
|
for (int i = 0; i < 29; i++)
|
|
{
|
|
printf("|");
|
|
for (int j = 0; j < 23; j++)
|
|
{
|
|
if (i == 0 || i == 29 - 1 || i == 2)
|
|
printf("=");
|
|
else
|
|
printf("%c", field[j][i]);
|
|
}
|
|
printf("|");
|
|
printf("\n");
|
|
}
|
|
getStartPosition();
|
|
|
|
sleep(1);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
void getStartPosition()
|
|
{
|
|
|
|
while (Ballx == -1)
|
|
{
|
|
for (int i = 2, j = 0; i <= 20; i += 2, j++)
|
|
{
|
|
field[i][Bally] = j + '0';
|
|
}
|
|
Generatefield();
|
|
//printf("W\x84\hle die position des Balls (0-9):\n");
|
|
printf("W\x84\hle die position des Balls (0-9):\n");
|
|
|
|
scanf("%d", &Ballx);
|
|
|
|
if (Ballx < 0 || 9 < Ballx)
|
|
{
|
|
Ballx = -1;
|
|
continue;
|
|
}
|
|
Ballx = (Ballx + 1);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void clearField()
|
|
{
|
|
for (int i = 0; i <= fieldWidth; i++)
|
|
{
|
|
for (int j = 0; j <= fieldHeigth; j++)
|
|
{
|
|
field[i][j] = ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
void Generatefield() {
|
|
|
|
}
|
|
|
|
void addScoreboard()
|
|
{
|
|
int ScorePoints;
|
|
//Die txt wird geöffnet
|
|
FILE* fp = fopen("ScoreBoard.txt", "a+");
|
|
char name[255];
|
|
|
|
printf("Bitte gib deinen Namen ein:\n");
|
|
scanf("%s", name);
|
|
|
|
fprintf(fp, "%s %d\n", name, ScorePoints);
|
|
fclose(fp);
|
|
}
|
|
|
|
int checkBallPosition()
|
|
{
|
|
if (BinY + 24 == Bally && (Ballx == BinX || Ballx == BinX + 2 || Ballx == BinX - 2))
|
|
{
|
|
return 1;
|
|
}
|
|
else if (BinY > Bally || field[Ballx][Bally - 1] == '_' || Ballx > fieldWidth || Ballx < 0)
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
void sortScoreboard()
|
|
{
|
|
//Öffnet die Textdatei oder erstellt sie wenn keine existiert
|
|
FILE* fp;
|
|
fp = fopen("ScoreBoard.txt", "a+");
|
|
if (fp == NULL)
|
|
{
|
|
printf("Datei konnte nicht geoeffnet werden.\n");
|
|
}
|
|
else
|
|
{
|
|
system("clear");
|
|
FILE *file = fopen("ScoreBoard.txt", "r");
|
|
char line[1000];
|
|
int numberOfLines = 0;
|
|
//Die Textdatei wird Zeile für Zeile eingelesen und in die Strukturliste eingefügt
|
|
for (int j = 0; fgets(line, sizeof line, file) != NULL && j <= 10; j++)
|
|
{
|
|
char* playertmp = strtok(line, " ");
|
|
strcpy(playerlist[j].Name, playertmp);
|
|
|
|
playertmp = strtok(NULL, " ");
|
|
int playerPoints = atoi(playertmp);
|
|
|
|
playerlist[j].Points = playerPoints;
|
|
|
|
numberOfLines = j;
|
|
sleep(100);
|
|
}
|
|
|
|
struct Player temp;
|
|
for (int i = 0; i <= numberOfLines; i++)
|
|
{
|
|
for (int j = 0; j < (numberOfLines - i); j++)
|
|
{
|
|
if (playerlist[i].Points < playerlist[i + 1].Points)
|
|
{
|
|
temp = playerlist[i];
|
|
playerlist[i] = playerlist[i + 1];
|
|
playerlist[i + 1] = temp;
|
|
}
|
|
}
|
|
}
|
|
fclose(fp);
|
|
|
|
printf(" Scoreboard:\n\n");
|
|
for (int j = 0; j < numberOfLines; j++)
|
|
{
|
|
printf("%d. %s %s %d\n", j + 1, (j < 9) ? " " : " ", playerlist[j].Name, playerlist[j].Points);
|
|
sleep(500);
|
|
}
|
|
|
|
|
|
FILE* fp = fopen("ScoreBoard.txt", "w");
|
|
for (int i = 0; i < numberOfLines; i++)
|
|
{
|
|
fprintf(fp, "%s %d\n", playerlist[i].Name, playerlist[i].Points);
|
|
}
|
|
|
|
fclose(fp);
|
|
}
|
|
}
|