[PATCH] Hangman: Kevins Verbesserungen umgesetzt=0A=
DoBi ·
=0A= + Lizenz=0A= + stdbool.h benutzt.=0A= + Codestil=0A= ! Max 80 Zeichen pro Zeile.=0A= ! switch anstatt mehrere if-Abfragen.=0A= Signed-off-by: Dominik Bittner <DoBi-tyndur at gmx.net>=0A= ---=0A= src/modules/c/hangman/Makefile.all | 8 +=0A= src/modules/c/hangman/main.c | 315 = ++++++++++++++++++++++++++++++++++++=0A= 2 files changed, 323 insertions(+), 0 deletions(-)=0A= create mode 100755 src/modules/c/hangman/Makefile.all=0A= create mode 100755 src/modules/c/hangman/main.c=0A= =0A= diff --git a/src/modules/c/hangman/Makefile.all = b/src/modules/c/hangman/Makefile.all=0A= new file mode 100755=0A= index 0000000..0ae2b38=0A= --- /dev/null=0A= +++ b/src/modules/c/hangman/Makefile.all=0A= @@ -0,0 +1,8 @@=0A= +shopt -s extglob=0A= +source $LOST_BUILDMK_ROOT/config.sh=0A= +=0A= +echo "LD $1/apps/hangman"=0A= +=0A= +$LOST_TOOLS_LD -ohangman $LDSCRIPT --start-group *.o $2 --end-group=0A= +=0A= +$LOST_TOOLS_STRIP -s hangman -o $1/apps/hangman=0A= diff --git a/src/modules/c/hangman/main.c b/src/modules/c/hangman/main.c=0A= new file mode 100755=0A= index 0000000..e45f342=0A= --- /dev/null=0A= +++ b/src/modules/c/hangman/main.c=0A= @@ -0,0 +1,315 @@=0A= +/*=0A= + * Copyright (c) 2011 The tyndur Project. All rights reserved.=0A= + *=0A= + * This code is derived from software contributed to the tyndur Project=0A= + * by Dominik Bittner.=0A= + *=0A= + * Redistribution and use in source and binary forms, with or without=0A= + * modification, are permitted provided that the following conditions=0A= + * are met:=0A= + * 1. Redistributions of source code must retain the above copyright=0A= + * notice, this list of conditions and the following disclaimer.=0A= + * 2. Redistributions in binary form must reproduce the above copyright=0A= + * notice, this list of conditions and the following disclaimer in = the=0A= + * documentation and/or other materials provided with the = distribution.=0A= + * 3. All advertising materials mentioning features or use of this = software=0A= + * must display the following acknowledgement:=0A= + * This product includes software developed by the tyndur Project=0A= + * and its contributors.=0A= + * 4. Neither the name of the tyndur Project nor the names of its=0A= + * contributors may be used to endorse or promote products derived=0A= + * from this software without specific prior written permission.=0A= + *=0A= + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0A= + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT = LIMITED=0A= + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR=0A= + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0A= + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=0A= + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0A= + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR = PROFITS;=0A= + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF = LIABILITY,=0A= + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE = OR=0A= + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN = IF=0A= + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A= + */=0A= +=0A= +#include <stdio.h>=0A= +#include <unistd.h>=0A= +#include <stdlib.h>=0A= +#include <string.h>=0A= +#include <readline/readline.h>=0A= +#include <wchar.h>=0A= +#include <ctype.h>=0A= +#include <stdbool.h>=0A= +=0A= +void ausgabe (int,bool);=0A= +=0A= +char* loesung;=0A= +=0A= +int main(int argc, char** argv)=0A= +{=0A= + /*=0A= + * Variabeln=0A= + */=0A= + char striche[100];=0A= + char* eing;=0A= + int versuch =3D 11;=0A= + int i =3D 0;=0A= + int z;=0A= + int k;=0A= + int c =3D 0;=0A= + int l;=0A= + bool treffer;=0A= + ////////////////////=0A= +=0A= + /*=0A= + * Regeln ausgeben=0A= + */=0A= + printf("Hangman!\n");=0A= + printf("Regeln:\n- keine Zeichen z.B. Ausrufezeichen\n");=0A= + printf("- nicht mehr als 20 Buchstaben\n");=0A= + printf("- Beim raten immer nur einen Buchstaben eingeben\n");=0A= + printf("- Keine Umlaute!\n");=0A= +=0A= + /*=0A= + * Wort einlesen, ueberpruefen ob ueberhaupt ein Wort eingegeben = wurde=0A= + * gegebenenfalls das Programm beenden (kann noch verbessert werden = :-))=0A= + * Wort in Kleinbuchstaben umwandeln=0A= + */=0A= + loesung =3D readline("Bitte ein Wort eingeben: ");=0A= +=0A= + l =3D strlen(loesung);=0A= +=0A= + if(loesung =3D=3D NULL || l < 1) {=0A= + printf("Sie muessen ein Wort eingeben!\n");=0A= + return 1;=0A= + }=0A= +=0A= + while(c < l + 1) {=0A= + loesung[c]=3Dtolower(loesung[c]);=0A= + c++;=0A= + }=0A= + //////////////////////////////////=0A= +=0A= + /*=0A= + * Bildschirm leeren.=0A= + */=0A= +=0A= + puts("\33[2J\33[H");=0A= +=0A= + /*=0A= + * Das Wort 'verschluesseln'=0A= + */=0A= +=0A= + while (i<=3Dstrlen(loesung)) { =0A= + striche[i]=3D45;=0A= + i++;=0A= + }=0A= +=0A= + striche[strlen(loesung)]=3D'\0';=0A= +=0A= + /////////////////////////////////=0A= +=0A= + printf("Du hast 11 Versuche!\n");=0A= + printf("Auf das Raten fertig los!\n\n");=0A= + printf(striche);=0A= + printf("\n");=0A= +=0A= + /*=0A= + * Schleife, die 11 mal durchlaufen wird --> 11 Versuche=0A= + */=0A= +=0A= + for(z=3D1; z < 12;) {=0A= + /*=0A= + * Methode 'ausgabe(int versuch1, bool a)' ausf=FChren=0A= + */=0A= + ausgabe(versuch,0);=0A= +=0A= + treffer =3D false;=0A= +=0A= + /*=0A= + * Versuch einlesen und ueberpruefen ob etwas eingegeben wurde=0A= + * und ob die Eingabe =3D der Loesung ist.=0A= + * Sonst wird der eingegebene Buchstabe 'entschluesselt'=0A= + * und spaeter auch angezeigt.=0A= + */=0A= + eing =3D readline("Dein Versuch: ");=0A= +=0A= + k =3D strlen(eing);=0A= +=0A= + if ((k > 1 && strcmp(loesung,eing) !=3D 0) || eing =3D=3D NULL) = {=0A= + printf("Ungueltige Eingabe\n\n");=0A= + return 1;=0A= + }=0A= + else {=0A= + printf("\n");=0A= +=0A= + for(i=3D0; i<=3Dl; i++) {=0A= + for(k=3D0; k<strlen(eing); k++) {=0A= + if (loesung[i]=3D=3Deing[k]) {=0A= + striche[i]=3Dloesung[i];=0A= + treffer=3Dtrue;=0A= + }=0A= + }=0A= + }=0A= + }=0A= +=0A= + /*=0A= + * Wenn man nicht richtig liegt hat man einen Versuch weniger.=0A= + */=0A= +=0A= + if (treffer=3D=3Dfalse) {=0A= + z++;=0A= + versuch--;=0A= + }=0A= +=0A= + /*=0A= + * Ausgabe des 'verschluesselten' bzw. teilweise = 'entschluesselten' Wortes=0A= + */=0A= + printf("\n");=0A= + printf(striche);=0A= + printf("\n\n");=0A= +=0A= + /*=0A= + * Bei Erfolg wird die Schleife unterbrochen und eine sch=F6ne = Nachricht ausgegeben.=0A= + */=0A= +=0A= + if (strcmp (loesung,striche)=3D=3D0 || = strcmp(loesung,eing)=3D=3D0 ) {=0A= + printf("Glueckwunsch\n\n");=0A= + printf(striche);=0A= + printf(" war die Loesung\n\n");=0A= + break;=0A= + }=0A= + }=0A= +=0A= + /*=0A= + * Funktion 'ausgabe' ein letztes Mal aufgerufen.=0A= + * 'eing' und 'loesung' freigegeben.=0A= + */=0A= + ausgabe(versuch,1);=0A= + free(eing);=0A= + free(loesung);=0A= +=0A= + // Programm erfolgreich beenden.=0A= + return 0;=0A= +}=0A= +=0A= +void ausgabe(int versuch1, bool a)=0A= +{=0A= + /*=0A= + * Anzahl der Versuche ueberpruefen + Hangman ausgeben=0A= + */=0A= + if(a =3D=3D 0)=0A= + {=0A= + switch (versuch1)=0A= + {=0A= + case 11:=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + break;=0A= + case 10:=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 9:=0A= + printf(" \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 8:=0A= + printf(" _______ \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 7:=0A= + printf(" _______ \n");=0A= + printf(" |/ \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 6:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 5:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O \n");=0A= + printf(" | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 4:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O \n");=0A= + printf(" | | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 3:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O/ \n");=0A= + printf(" | | \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 2:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O/ \n");=0A= + printf(" | /| \n");=0A= + printf(" | \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 1:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O/ \n");=0A= + printf(" | /| \n");=0A= + printf(" | / \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + case 0:=0A= + printf(" _______ \n");=0A= + printf(" |/ | \n");=0A= + printf(" | O/ \n");=0A= + printf(" | /| \n");=0A= + printf(" | / L \n");=0A= + printf(" _|_ \n");=0A= + break;=0A= + }=0A= + }=0A= + /*=0A= + * Loesung anzeigen wenn man es nicht in 11 Versuche geschafft hat. = Sonst 'Glueckwunsch!'=0A= + */=0A= + if(versuch1 > 0 && a =3D=3D 1) {=0A= + printf("Glueckwunsch!\n");=0A= + }=0A= + if(versuch1 <=3D 0) {=0A= + printf("Du Idiot das waere die Loesung gewesen: ");=0A= + printf(loesung);=0A= + printf("\n");=0A= + }=0A= +}=0A= \ No newline at end of file=0A= -- =0A= 1.7.1=0A= =0A= ------=_NextPart_000_0009_01CBDCFA.88C61A10--