forked from freudenreichan/info2Praktikum-Wortsalat
Format Project
This commit is contained in:
4 files changed
+32
-38
No files matched your search
+4
-19
@@ -1,45 +1,30 @@
|
|||||||
# clang-format-Konfiguration, abgeleitet aus dem bestehenden Wortsalat-Code
|
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
|
|
||||||
# Einrückung: 4 Leerzeichen, keine Tabs
|
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
|
|
||||||
# Allman-Stil: geschweifte Klammern für Funktionen, Schleifen, if/else stehen in eigenen Zeilen
|
|
||||||
BreakBeforeBraces: Allman
|
BreakBeforeBraces: Allman
|
||||||
|
|
||||||
# Keine automatischen Zeilenumbrüche, der Code bricht lange Zeilen bereits selbst um
|
|
||||||
ColumnLimit: 0
|
ColumnLimit: 0
|
||||||
ReflowComments: false
|
ReflowComments: false
|
||||||
|
|
||||||
# Zeiger-Sternchen rechts: char *word, SearchWord *words
|
|
||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: false
|
||||||
|
|
||||||
# Kein Leerzeichen vor der Klammer bei if/for/while und bei Funktionsaufrufen
|
|
||||||
SpaceBeforeParens: Custom
|
|
||||||
SpaceBeforeParensOptions:
|
|
||||||
AfterControlStatements: false
|
|
||||||
AfterFunctionDeclarationName: false
|
|
||||||
AfterFunctionDefinitionName: false
|
|
||||||
SpaceAfterCStyleCast: false
|
|
||||||
|
|
||||||
# Kurze Konstrukte bleiben mehrzeilig
|
|
||||||
AllowShortIfStatementsOnASingleLine: Never
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
|
||||||
# Geschweifte Initialisierer: {0, 0}
|
InsertBraces: true
|
||||||
|
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
|
|
||||||
# Includes nicht umsortieren (Reihenfolge ist teils bewusst gewählt)
|
SortIncludes: CaseSensitive
|
||||||
SortIncludes: Never
|
IncludeBlocks: Regroup
|
||||||
IncludeBlocks: Preserve
|
|
||||||
|
|
||||||
# Leerzeilen
|
|
||||||
MaxEmptyLinesToKeep: 2
|
MaxEmptyLinesToKeep: 2
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
+15
-6
@@ -1,14 +1,15 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include <time.h>
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
|
|
||||||
int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||||
int searchFieldLen, int column, int row, int axis);
|
int searchFieldLen, int column, int row, int axis);
|
||||||
|
|
||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// Creates the word salad by placing words randomly and filling empty spaces
|
||||||
@@ -19,7 +20,9 @@ int createWordSalad(
|
|||||||
unsigned int wordCount)
|
unsigned int wordCount)
|
||||||
{
|
{
|
||||||
if (searchFieldLen == 0 || searchFieldLen > MAX_SEARCH_FIELD_LEN)
|
if (searchFieldLen == 0 || searchFieldLen > MAX_SEARCH_FIELD_LEN)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int placedWords = 0;
|
int placedWords = 0;
|
||||||
|
|
||||||
@@ -27,8 +30,12 @@ int createWordSalad(
|
|||||||
|
|
||||||
// Spielfeld leeren:
|
// Spielfeld leeren:
|
||||||
for (int x = 0; x < searchFieldLen; x++)
|
for (int x = 0; x < searchFieldLen; x++)
|
||||||
|
{
|
||||||
for (int y = 0; y < searchFieldLen; y++)
|
for (int y = 0; y < searchFieldLen; y++)
|
||||||
|
{
|
||||||
salad[x][y] = EMPTY_CHAR;
|
salad[x][y] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Wörter platzieren
|
// Wörter platzieren
|
||||||
@@ -37,7 +44,9 @@ int createWordSalad(
|
|||||||
int wordlenght = strlen(words[w]); // Wortlänge festgelegt
|
int wordlenght = strlen(words[w]); // Wortlänge festgelegt
|
||||||
|
|
||||||
if (wordlenght == 0 || wordlenght > searchFieldLen)
|
if (wordlenght == 0 || wordlenght > searchFieldLen)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (int attempts = 0;
|
for (int attempts = 0;
|
||||||
attempts < MAX_RAND_TRIES_PER_WORD;
|
attempts < MAX_RAND_TRIES_PER_WORD;
|
||||||
@@ -48,7 +57,7 @@ int createWordSalad(
|
|||||||
int row = rand() % searchFieldLen;
|
int row = rand() % searchFieldLen;
|
||||||
int column = rand() % searchFieldLen;
|
int column = rand() % searchFieldLen;
|
||||||
|
|
||||||
int success = placeWord( words[w],wordlenght, salad, searchFieldLen, column, row, axis);
|
int success = placeWord(words[w], wordlenght, salad, searchFieldLen, column, row, axis);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -69,12 +78,12 @@ int createWordSalad(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%d placed" ,placedWords);
|
printf("%d placed", placedWords);
|
||||||
return placedWords;
|
return placedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||||
int searchFieldLen, int column, int row, int axis)
|
int searchFieldLen, int column, int row, int axis)
|
||||||
{
|
{
|
||||||
// Available space check & word collision avoidance
|
// Available space check & word collision avoidance
|
||||||
|
|||||||
+5
-6
@@ -1,14 +1,17 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count);
|
int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count);
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) {
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
{
|
||||||
char buffer[MAX_LINE_LEN];
|
char buffer[MAX_LINE_LEN];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *divisor = " ,;.\n";
|
char *divisor = " ,;.\n";
|
||||||
|
|
||||||
while (fgets(buffer, MAX_LINE_LEN, file) != NULL) {
|
while (fgets(buffer, MAX_LINE_LEN, file) != NULL)
|
||||||
|
{
|
||||||
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
|
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
|
||||||
{
|
{
|
||||||
strncpy(words[count], word, MAX_WORD_LEN);
|
strncpy(words[count], word, MAX_WORD_LEN);
|
||||||
@@ -17,7 +20,3 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+8
-7
@@ -1,8 +1,9 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "input.h"
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "graphicalGame.h"
|
#include "graphicalGame.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// Check if the correct number of arguments is provided
|
// Check if the correct number of arguments is provided
|
||||||
if(argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -21,7 +22,7 @@ int main(int argc, char *argv[])
|
|||||||
unsigned int wordCount = 0;
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
if(file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
// Print error message if file couldn't be opened
|
// Print error message if file couldn't be opened
|
||||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||||
@@ -35,7 +36,7 @@ int main(int argc, char *argv[])
|
|||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
if(wordCount == 0)
|
if (wordCount == 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "No words found...\n");
|
fprintf(stderr, "No words found...\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -44,7 +45,7 @@ int main(int argc, char *argv[])
|
|||||||
// Create the word salad by placing words into grid
|
// Create the word salad by placing words into grid
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||||
|
|
||||||
if(placedWords != wordCount)
|
if (placedWords != wordCount)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Could not place %u out of %u words ...\n", wordCount - placedWords, wordCount);
|
fprintf(stderr, "Could not place %u out of %u words ...\n", wordCount - placedWords, wordCount);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Reference in new issue
Block a user