forked from freudenreichan/info2Praktikum-Wortsalat
Format Project
This commit is contained in:
4 files changed
+33
-39
No files matched your search
+4
-19
@@ -1,45 +1,30 @@
|
||||
# clang-format-Konfiguration, abgeleitet aus dem bestehenden Wortsalat-Code
|
||||
BasedOnStyle: LLVM
|
||||
|
||||
# Einrückung: 4 Leerzeichen, keine Tabs
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
ContinuationIndentWidth: 4
|
||||
|
||||
# Allman-Stil: geschweifte Klammern für Funktionen, Schleifen, if/else stehen in eigenen Zeilen
|
||||
BreakBeforeBraces: Allman
|
||||
|
||||
# Keine automatischen Zeilenumbrüche, der Code bricht lange Zeilen bereits selbst um
|
||||
ColumnLimit: 0
|
||||
ReflowComments: false
|
||||
|
||||
# Zeiger-Sternchen rechts: char *word, SearchWord *words
|
||||
PointerAlignment: Right
|
||||
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
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
|
||||
# Geschweifte Initialisierer: {0, 0}
|
||||
InsertBraces: true
|
||||
|
||||
Cpp11BracedListStyle: true
|
||||
|
||||
# Includes nicht umsortieren (Reihenfolge ist teils bewusst gewählt)
|
||||
SortIncludes: Never
|
||||
IncludeBlocks: Preserve
|
||||
SortIncludes: CaseSensitive
|
||||
IncludeBlocks: Regroup
|
||||
|
||||
# Leerzeilen
|
||||
MaxEmptyLinesToKeep: 2
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
+16
-7
@@ -1,14 +1,15 @@
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#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);
|
||||
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
@@ -19,7 +20,9 @@ int createWordSalad(
|
||||
unsigned int wordCount)
|
||||
{
|
||||
if (searchFieldLen == 0 || searchFieldLen > MAX_SEARCH_FIELD_LEN)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int placedWords = 0;
|
||||
|
||||
@@ -27,8 +30,12 @@ int createWordSalad(
|
||||
|
||||
// Spielfeld leeren:
|
||||
for (int x = 0; x < searchFieldLen; x++)
|
||||
{
|
||||
for (int y = 0; y < searchFieldLen; y++)
|
||||
{
|
||||
salad[x][y] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wörter platzieren
|
||||
@@ -37,7 +44,9 @@ int createWordSalad(
|
||||
int wordlenght = strlen(words[w]); // Wortlänge festgelegt
|
||||
|
||||
if (wordlenght == 0 || wordlenght > searchFieldLen)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int attempts = 0;
|
||||
attempts < MAX_RAND_TRIES_PER_WORD;
|
||||
@@ -48,7 +57,7 @@ int createWordSalad(
|
||||
int row = 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)
|
||||
{
|
||||
@@ -69,12 +78,12 @@ int createWordSalad(
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d placed" ,placedWords);
|
||||
printf("%d placed", 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)
|
||||
{
|
||||
// Available space check & word collision avoidance
|
||||
@@ -112,4 +121,4 @@ int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN]
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -1,14 +1,17 @@
|
||||
#include "input.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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];
|
||||
int count = 0;
|
||||
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))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+8
-7
@@ -1,8 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "input.h"
|
||||
#include "game.h"
|
||||
#include "graphicalGame.h"
|
||||
#include "input.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
@@ -11,7 +12,7 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 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]);
|
||||
return EXIT_FAILURE;
|
||||
@@ -21,7 +22,7 @@ int main(int argc, char *argv[])
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
if(file == NULL)
|
||||
if (file == NULL)
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
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);
|
||||
fclose(file);
|
||||
|
||||
if(wordCount == 0)
|
||||
if (wordCount == 0)
|
||||
{
|
||||
fprintf(stderr, "No words found...\n");
|
||||
return EXIT_FAILURE;
|
||||
@@ -44,7 +45,7 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
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);
|
||||
return EXIT_FAILURE;
|
||||
|
||||
Reference in new issue
Block a user