|
|
#include "quizduell.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int pruefeAntwort(QuizFrage frage, char antwort) { return (frage.korrekteAntwort == antwort); }
QuizFrage erstelleFrage(const char* frage, const char* antwortA, const char* antwortB, const char* antwortC, const char* antwortD, char korrekteAntwort) { QuizFrage neueFrage; strcpy(neueFrage.frage, frage); strcpy(neueFrage.antwortA, antwortA); strcpy(neueFrage.antwortB, antwortB); strcpy(neueFrage.antwortC, antwortC); strcpy(neueFrage.antwortD, antwortD); neueFrage.korrekteAntwort = korrekteAntwort; return neueFrage;
}
int spieleKategorie(Kategorie* kategorie) {
for (int i = 0; i < kategorie->anzahlFragen; i++) { char benutzerAntwort[10];
printf("\nQuestion %d:\n%s", i + 1, kategorie->fragen[i].frage); } }
void zeigeVerfuegbareKategorien(Kategorie kategorien[]) { printf("\nChoose a Category:\n"); if (kategorien[0].fragen != NULL) printf("Mountains\n"); if (kategorien[1].fragen != NULL) printf("Cooking\n"); if (kategorien[2].fragen != NULL) printf("Sports\n"); }
void befreieKategorie(Kategorie* kategorie) { free(kategorie->fragen); kategorie->fragen = NULL; kategorie->anzahlFragen = 0; kategorie->joker = 0; }
void quizduell() { printf("Welcome to the singleplayer quizduell!\n");
Kategorie kategorien[MAX_CATEGORIES]; kategorien[0].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage)); kategorien[0].fragen[0] = erstelleFrage("Whats the height of the Zugspitze?", "2482 Meter", "2867 Meter", "2962 Meter", "3173 Meter", 'C'); kategorien[0].fragen[1] = erstelleFrage("In which Federal State is the Zugspitze?", "Bayern", "Baden-Wuerttemberg", "Hessen", "Thueringen", 'A'); kategorien[0].fragen[2] = erstelleFrage("Which Mountain is the highest following after the Zugspitze?", "Grossglockner", "Watzmann", "Feldberg", "Meissner", 'B'); kategorien[0].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY; kategorien[0].joker = 1;
kategorien[1].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage)); kategorien[1].fragen[0] = erstelleFrage("Which Ingredient is used traditionally for Pesto?", "Tomatoes", "Basil", "Spinach", "Oregano", 'B'); kategorien[1].fragen[1] = erstelleFrage("Which meal is known for its usage of rice?", "Lasagna", "Sushi", "Pizza", "Hamburger", 'B'); kategorien[1].fragen[2] = erstelleFrage("Which color has a ripe banana?", "Red", "Green", "Yellow", "Orange", 'C'); kategorien[1].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY; kategorien[1].joker = 1;
kategorien[2].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage)); kategorien[2].fragen[0] = erstelleFrage("In which sport is the term 'home run' used?", "Soccer/Football", "Baseball", "Tennis", "Golf", 'B'); kategorien[2].fragen[1] = erstelleFrage("How many players are there normally on the pitch in a soccer/football team?", "9", "11", "7", "5", 'B'); kategorien[2].fragen[2] = erstelleFrage("What sport is played on a pitch and has a 'wicket'?", "Rugby", "Cricket", "American Football", "Hockey", 'B'); kategorien[2].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY; kategorien[2].joker = 1;
while (1) { char auswahl[50];
zeigeVerfuegbareKategorien(kategorien);
printf("Your selection: "); scanf("%s", auswahl);
int auswahlIndex = -1;
for (int i = 0; i < MAX_CATEGORIES; i++) { if (kategorien[i].fragen != NULL && strcmp(auswahl, "Mountains") == 0) { auswahlIndex = 0; break; } else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Cooking") == 0) { auswahlIndex = 1; break; } else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Sports") == 0) { auswahlIndex = 2; break; } }
if (auswahlIndex != -1 && kategorien[auswahlIndex].fragen != NULL) { int punkte = spieleKategorie(&kategorien[auswahlIndex]); printf("\nPoints in this category: %d\n", punkte);
befreieKategorie(&kategorien[auswahlIndex]); }
return;
} }
|