generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
46
Commits
332bbc4a65
...
input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42a5143e9a | ||
|
|
acc14b49d8 | ||
|
|
6027c2a061 | ||
|
|
ed22736f68 | ||
|
|
7146174e78 | ||
|
|
d097819ef9 | ||
|
|
5e9132a48b | ||
|
|
5d1c8ac8a5 | ||
|
|
7414849901 | ||
|
|
46b6efbd69 | ||
|
|
1affb13041 | ||
|
|
63cafdbc0c | ||
|
|
543ba65b7e | ||
|
|
9747bc4530 | ||
|
|
30f601d4df | ||
|
|
f89019437f | ||
|
|
eb77a4d1b8 | ||
|
|
4ee5fd7648 | ||
|
|
4892e33b76 | ||
|
|
5442ecb0bc | ||
|
|
a5c1510745 | ||
|
|
d10fcd6db2 | ||
|
|
4fe7805c09 | ||
|
|
654aebac4d | ||
|
|
10598b0f8e | ||
|
|
a0ff1937bd | ||
|
|
ad8144ed08 | ||
|
|
6b89426f7f | ||
|
|
194636e728 | ||
|
|
c0b779f7fa | ||
|
|
6b887b60c4 | ||
|
|
7a1b9d6d24 | ||
|
|
7dc036df15 | ||
|
|
771cc1706f | ||
|
|
d1fd9b38ea | ||
|
|
2f625c98b9 | ||
|
|
f407d5a36f | ||
|
|
ea373b6bad | ||
|
|
b15fb04b88 | ||
|
|
7245877786 | ||
|
|
f7a6e56257 | ||
|
|
9e27997e44 | ||
|
|
20c957cb73 | ||
|
|
39d08d8609 | ||
|
|
5fe65f3210 | ||
|
|
5fc41568ad |
@@ -10,14 +10,182 @@
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
// enum to make it more clear what de current orientation is
|
||||
typedef enum
|
||||
{
|
||||
HORIZONTAL,
|
||||
VERTIKAL
|
||||
} orientation;
|
||||
|
||||
|
||||
// new struct for handing over the entire wordPosition
|
||||
// alignment is HORIZONTAL or VERTICAL
|
||||
// rowOrColumn is the int of the colum or row the word is suposed to be placed in
|
||||
// startingCell is the int of where in the row/colum the first leter of the word suposed to be placed
|
||||
typedef struct
|
||||
{
|
||||
orientation alignment;
|
||||
unsigned int rowOrColumn;
|
||||
unsigned int startingCell;
|
||||
} wordPosition;
|
||||
|
||||
|
||||
// Choses a random Position for the current Word
|
||||
wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength)
|
||||
{
|
||||
wordPosition position = {0, 0, 0};
|
||||
|
||||
srand(time(NULL));
|
||||
position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL;
|
||||
position.rowOrColumn = rand()%(searchFieldLen);
|
||||
position.startingCell = rand()%(searchFieldLen - wordLength);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
// Checks if the current Position is free
|
||||
// returns 1 if the Position is free
|
||||
// returns 0 if the Position is occupied
|
||||
int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position,unsigned int wordLength, unsigned int serchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int letterFound = 0;
|
||||
int positionfree = 0;
|
||||
|
||||
if (position.alignment == HORIZONTAL)
|
||||
{
|
||||
// checking to see if position is free
|
||||
// by scanning each column in the given row
|
||||
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
|
||||
{
|
||||
if ((salad[position.rowOrColumn][i] >= 'A') && (salad[position.rowOrColumn][i] <= 'z'))
|
||||
{
|
||||
letterFound = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (position.alignment == VERTIKAL)
|
||||
{
|
||||
// checking to see if position is free
|
||||
// by scanning each row in the given column
|
||||
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
|
||||
{
|
||||
if ((salad[i][position.rowOrColumn] >= 'A') && (salad[i][position.rowOrColumn] <= 'z'))
|
||||
{
|
||||
letterFound = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionfree = !letterFound;
|
||||
|
||||
return positionfree;
|
||||
}
|
||||
|
||||
|
||||
// Places the current word into the
|
||||
// selected position
|
||||
// returns 1 if sucessfull
|
||||
int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position, const char currentWord[], unsigned int currentWordLen, unsigned int serchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
if (position.alignment == HORIZONTAL)
|
||||
{
|
||||
|
||||
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++)
|
||||
{
|
||||
salad[position.rowOrColumn][i] = currentWord[i];
|
||||
}
|
||||
salad[position.rowOrColumn][i] = '\0';
|
||||
}
|
||||
else if (position.alignment == VERTIKAL)
|
||||
{
|
||||
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++)
|
||||
{
|
||||
salad[i][position.rowOrColumn] = currentWord[i];
|
||||
}
|
||||
salad[i][position.rowOrColumn] = '\0';
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Places random letters into the
|
||||
// empty fields of the wordSalad
|
||||
void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (j = 0; i < searchFieldLen; j++)
|
||||
{
|
||||
if ((salad[i][j] < 'A') && (salad[i][j] > 'z'))
|
||||
{
|
||||
salad[i][j] = rand()%('Z' - 'A' + 1) + 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
// returnes the number of sucessfully placed words
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int positionFound = 0;
|
||||
int placedWords = 0;
|
||||
char currentWord[MAX_WORD_LEN];
|
||||
wordPosition currentWordPosition = {0,0,0};
|
||||
|
||||
|
||||
for (i = 1; i <= wordCount; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
currentWordPosition = choserandomPosition(searchFieldLen, strlen(words[i]));
|
||||
positionFound = checkIfPositionIsFree(salad, currentWordPosition, strlen(words[i]), searchFieldLen);
|
||||
j++;
|
||||
} while ((j < MAX_RAND_TRIES_PER_WORD) && !(positionFound));
|
||||
|
||||
if (positionFound)
|
||||
{
|
||||
strcpy(currentWord, words[i-1]);
|
||||
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
|
||||
}
|
||||
}
|
||||
|
||||
placeRandomLetters(salad, searchFieldLen);
|
||||
|
||||
|
||||
return placedWords;
|
||||
}
|
||||
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
for (i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (j = 0; i < searchFieldLen; j++)
|
||||
{
|
||||
printf("%c", salad[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -403,6 +403,7 @@ static int allWordsFound(SearchWordPanel searchWordPanel)
|
||||
// Main game loop where game is run and updated
|
||||
static void gameLoop(const Vector2 screenSize, MouseSelection mouseSelection, CharSquarePanel squarePanel, SearchWordPanel searchWordPanel, const HelperMessage helperMsg, const WinMessage winMsg)
|
||||
{
|
||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||
InitWindow(screenSize.x, screenSize.y, "Word Salad"); // Initialize game window
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
@@ -2,11 +2,37 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define MAX_BUFFER_LEN 256
|
||||
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
int count = 0;
|
||||
char *teiler = ".,; !?\n";
|
||||
|
||||
if(file == NULL)
|
||||
{
|
||||
printf("Fehler beim Öffnen von words.txt!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(fgets(buffer, MAX_LINE_LEN, file))
|
||||
{
|
||||
const char *wort = strtok(buffer, teiler);
|
||||
|
||||
while(wort != NULL && count < maxWordCount)
|
||||
{
|
||||
strncpy(words[count], wort, MAX_WORD_LEN-1);
|
||||
words[count][MAX_WORD_LEN-1] = '\0';
|
||||
count++;
|
||||
|
||||
wort = strtok(NULL, teiler);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
+22
-1
@@ -7,6 +7,13 @@
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
|
||||
// selbstgeschriebene Definitionen:
|
||||
// annahmen ist das windowWidth in pixeln gegeben
|
||||
// werden muss, da auch andere funktionen wie
|
||||
// createCharSquarePanel in Pixeln arbeiten
|
||||
#define WINDOW_WIDTH 800
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
@@ -36,10 +43,24 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// DONE:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
if (placedWords != wordCount)
|
||||
{
|
||||
// selbe error message wird auch von wordsalad_inital.exe ausgegeben,
|
||||
// wenn diese einen fehler produziert
|
||||
printf("Could only place %d of %d words.", placedWords, wordCount);
|
||||
printf(" Possible solution is to choose a larger search field ...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// annahme: windowWidth wird in Pixeln gesucht,
|
||||
// da auch andere funktionen, wie createCharSquarePanel
|
||||
// in Pixeln arbeiten
|
||||
startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
+18
-11
@@ -1,22 +1,29 @@
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Cocoa -framework CoreVideo
|
||||
LDFLAGS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
|
||||
|
||||
# Architektur automatisch erkennen (arm64 oder x86_64)
|
||||
ARCH := $(shell uname -m)
|
||||
BINARIES = ./macos-$(ARCH)
|
||||
|
||||
ifeq ($(ARCH),arm64)
|
||||
BINARIES = ./macos-arm64
|
||||
else
|
||||
BINARIES = ./macos-x64
|
||||
endif
|
||||
|
||||
raylib_folder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
# --------------------------
|
||||
# initiales Spiel bauen
|
||||
# eigenes Spiel bauen
|
||||
# --------------------------
|
||||
wordsalad_initial:
|
||||
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.c graphicalGame.c $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
# --------------------------
|
||||
# Normales Spiel bauen
|
||||
# --------------------------
|
||||
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
main.o: main.c
|
||||
@@ -29,18 +36,18 @@ game.o: game.c
|
||||
$(CC) -c $(CFLAGS) game.c
|
||||
|
||||
graphicalGame.o: graphicalGame.c
|
||||
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
|
||||
|
||||
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
TEST_BIN = runTests
|
||||
|
||||
test: input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||
test: input.o game.o unit_tests.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
rm -f *.o wordsalad
|
||||
rm -f *.o wordsalad wordsalad_myversion $(TEST_BIN)
|
||||
+199
-2
@@ -6,20 +6,217 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
|
||||
//DONE: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
// enum to make it more clear what de current orientation is
|
||||
typedef enum
|
||||
{
|
||||
HORIZONTAL,
|
||||
VERTIKAL
|
||||
} orientation;
|
||||
|
||||
|
||||
// new struct for handing over the entire wordPosition
|
||||
// alignment is HORIZONTAL or VERTICAL
|
||||
// rowOrColumn is the int of the colum or row the word is suposed to be placed in
|
||||
// startingCell is the int of where in the row/colum the first leter of the word suposed to be placed
|
||||
typedef struct
|
||||
{
|
||||
orientation alignment;
|
||||
unsigned int rowOrColumn;
|
||||
unsigned int startingCell;
|
||||
} wordPosition;
|
||||
|
||||
|
||||
void initializeWordsalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
for (i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
salad[i][j] = '=';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Choses a random Position for the current Word
|
||||
wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength)
|
||||
{
|
||||
wordPosition position = {0, 0, 0};
|
||||
|
||||
|
||||
position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL;
|
||||
position.rowOrColumn = rand()%(searchFieldLen);
|
||||
position.startingCell = rand()%(searchFieldLen - wordLength);
|
||||
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
// Checks if the current Position is free
|
||||
// returns 1 if the Position is free
|
||||
// returns 0 if the Position is occupied
|
||||
int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position,unsigned int wordLength, unsigned int serchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int letterFound = 0;
|
||||
int positionfree = 0;
|
||||
|
||||
if (position.alignment == HORIZONTAL)
|
||||
{
|
||||
// checking to see if position is free
|
||||
// by scanning each column in the given row
|
||||
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
|
||||
{
|
||||
if (((salad[position.rowOrColumn][i] >= 'A') && (salad[position.rowOrColumn][i] <= 'Z')) || ((salad[position.rowOrColumn][i] >= 'a') && (salad[position.rowOrColumn][i] <= 'z')))
|
||||
{
|
||||
letterFound = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (position.alignment == VERTIKAL)
|
||||
{
|
||||
// checking to see if position is free
|
||||
// by scanning each row in the given column
|
||||
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
|
||||
{
|
||||
if (((salad[i][position.rowOrColumn] >= 'A') && (salad[i][position.rowOrColumn] <= 'z')) || ((salad[i][position.rowOrColumn] >= 'a') && (salad[i][position.rowOrColumn] <= 'z')))
|
||||
{
|
||||
letterFound = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionfree = !letterFound;
|
||||
|
||||
return positionfree;
|
||||
}
|
||||
|
||||
|
||||
// Places the current word into the
|
||||
// selected position
|
||||
// returns 1 if sucessfull
|
||||
int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position, const char currentWord[], unsigned int currentWordLen, unsigned int serchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
if (position.alignment == HORIZONTAL)
|
||||
{
|
||||
for (i = position.startingCell; (i < serchFieldLen) && (currentWord[j] != '\0'); i++)
|
||||
{
|
||||
salad[position.rowOrColumn][i] = currentWord[j];
|
||||
j++;
|
||||
}
|
||||
salad[position.rowOrColumn][i] = '\0';
|
||||
}
|
||||
else if (position.alignment == VERTIKAL)
|
||||
{
|
||||
for (i = position.startingCell; (i < serchFieldLen) && (currentWord[j] != '\0'); i++)
|
||||
{
|
||||
salad[i][position.rowOrColumn] = currentWord[j];
|
||||
j++;
|
||||
}
|
||||
salad[i][position.rowOrColumn] = '\0';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Places random letters into the
|
||||
// empty fields of the wordSalad
|
||||
void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
for (i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
if ((salad[i][j] < 'A') || (salad[i][j] > 'z') || ((salad[i][j] < 'a') && (salad[i][j] > 'Z')))
|
||||
{
|
||||
salad[i][j] = rand()%('Z' - 'A' + 1) + 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
// returnes the number of sucessfully placed words
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int positionFound = 0;
|
||||
int placedWords = 0;
|
||||
char nullWord[MAX_WORD_LEN];
|
||||
char currentWord[MAX_WORD_LEN];
|
||||
wordPosition currentWordPosition = {0,0,0};
|
||||
|
||||
|
||||
for (k = 0; k < MAX_WORD_LEN; k++)
|
||||
{
|
||||
nullWord[k] = '\0';
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
initializeWordsalad(salad, searchFieldLen);
|
||||
|
||||
for (i = 1; i <= wordCount; i++)
|
||||
{
|
||||
j = 0;
|
||||
|
||||
strcpy(currentWord, nullWord);
|
||||
strcpy(currentWord, words[i-1]);
|
||||
|
||||
do
|
||||
{
|
||||
currentWordPosition = choserandomPosition(searchFieldLen, strlen(currentWord));
|
||||
positionFound = checkIfPositionIsFree(salad, currentWordPosition, strlen(currentWord), searchFieldLen);
|
||||
j++;
|
||||
} while ((j < MAX_RAND_TRIES_PER_WORD) && !(positionFound));
|
||||
|
||||
if (positionFound)
|
||||
{
|
||||
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
|
||||
}
|
||||
}
|
||||
|
||||
placeRandomLetters(salad, searchFieldLen);
|
||||
|
||||
|
||||
return placedWords;
|
||||
}
|
||||
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
||||
for (i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
printf("%c", salad[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
//Kommentar
|
||||
Binary file not shown.
Binary file not shown.
+98
-1
@@ -2,11 +2,108 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
/*
|
||||
char *readSingleWord(FILE *file)
|
||||
{
|
||||
if (file == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
fgets(singleWordBuffer, MAX_LINE_LEN, file);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
int currentlyInWord = 0;
|
||||
int word = 0;
|
||||
int wordChar = 0;
|
||||
char currentChar = 0;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
currentChar = fgetc(file);
|
||||
|
||||
if ((currentChar >= 'A') && (currentChar <= 'Z'))
|
||||
{
|
||||
if (!currentlyInWord)
|
||||
{
|
||||
currentlyInWord = 1;
|
||||
}
|
||||
|
||||
words[word][wordChar] = currentChar;
|
||||
wordChar++;
|
||||
}
|
||||
else if ((currentChar >= 'a') && (currentChar <= 'z'))
|
||||
{
|
||||
if (!currentlyInWord)
|
||||
{
|
||||
currentlyInWord = 1;
|
||||
}
|
||||
|
||||
words[word][wordChar] = toupper(currentChar);
|
||||
wordChar++;
|
||||
}
|
||||
else if (currentlyInWord)
|
||||
{
|
||||
words[word][wordChar] = '\0';
|
||||
word++;
|
||||
wordChar = 0;
|
||||
currentlyInWord = 0;
|
||||
}
|
||||
|
||||
} while (((currentChar != EOF) && (word <= maxWordCount)));
|
||||
printf("wortzahl: %d\n", word);
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#define MAX_BUFFER_LEN 256
|
||||
|
||||
// TODO?
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
int count = 0;
|
||||
char *teiler = ".,; !?\n";
|
||||
|
||||
if(file == NULL)
|
||||
{
|
||||
printf("Fehler beim Öffnen von words.txt!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(fgets(buffer, MAX_LINE_LEN, file))
|
||||
{
|
||||
const char *wort = strtok(buffer, teiler);
|
||||
|
||||
while(wort != NULL && count < maxWordCount)
|
||||
{
|
||||
strncpy(words[count], wort, MAX_WORD_LEN-1);
|
||||
words[count][MAX_WORD_LEN-1] = '\0';
|
||||
count++;
|
||||
|
||||
wort = strtok(NULL, teiler);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
Binary file not shown.
+25
-1
@@ -7,6 +7,13 @@
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
|
||||
// selbstgeschriebene Definitionen:
|
||||
// annahmen ist das windowWidth in pixeln gegeben
|
||||
// werden muss, da auch andere funktionen wie
|
||||
// createCharSquarePanel in Pixeln arbeiten
|
||||
#define WINDOW_WIDTH 800
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
@@ -36,10 +43,27 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
printf("placed Words: %d\n", placedWords);
|
||||
printf("wordCount = %d\n", wordCount);
|
||||
// DONE:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
if (placedWords != wordCount)
|
||||
{
|
||||
// selbe error message wird auch von wordsalad_inital.exe ausgegeben,
|
||||
// wenn diese einen fehler produziert
|
||||
printf("Could only place %d of %d words.", placedWords, wordCount);
|
||||
printf(" Possible solution is to choose a larger search field ...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// annahme: windowWidth wird in Pixeln gesucht,
|
||||
// da auch andere funktionen, wie createCharSquarePanel
|
||||
// in Pixeln arbeiten
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
Binary file not shown.
+11
-4
@@ -1,5 +1,5 @@
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||
BINARIES = ./windows
|
||||
|
||||
@@ -9,8 +9,15 @@ unityfolder = ./unity
|
||||
# --------------------------
|
||||
# initiales Spiel bauen
|
||||
# --------------------------
|
||||
wordsalad_initial:
|
||||
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
#wordsalad_initial:
|
||||
# $(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
|
||||
# --------------------------
|
||||
# eigenes Spiel bauen
|
||||
# --------------------------
|
||||
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
|
||||
$(CC) -o wordsalad_myversion.exe main.c graphicalGame.c $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
|
||||
# --------------------------
|
||||
@@ -23,7 +30,7 @@ main.o: main.c
|
||||
$(CC) -c $(CFLAGS) main.c
|
||||
|
||||
input.o: input.c
|
||||
$(CC) -c $(CFLAGS)input.c
|
||||
$(CC) -c $(CFLAGS) input.c
|
||||
|
||||
game.o: game.c
|
||||
$(CC) -c $(CFLAGS) game.c
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user