Hangman
-
Hallo bin noch relativ neu im programmier geschäft und daher noch relativ unerfahren. Volgendes problem ich muss in der schule das Hangmanspiel das vermutlich jeder kennt programmiren, das hab ich auch soweit feddich und hab schon ein paar spielerreien eingebaut usw. Jeztz will mein lehrer das ich die eigabe von dem wort verschlüssel also das anstatt des wortes sternchen kommen wie wen ich ein passwort eigebe. kann mir da jemand helfen ich hab so garkeine idee. und könnt ihr mir vielleicht auch erklären wie ich sounds einfüge das wäre klasse.
Hier mein bissheriger qelltext:
// Hangman1.cpp : Defines the entry point for the console application.
//#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h> //Biliotheken//
#include <windows.h>
#include <stdlib.h>void farbe(WORD color)
{
SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void einlesen();
void lang();
void menue();
void ratenB(); //Funktionsprototypen//
void ratenW();
void losen();
void figur();
void prufen();
void buchstaben();
void lose();
void win();char wort[100],antwort[100];
int lange,x=1,z=0,j; //Globale variablen//int main()
{char repeat;
int i;
x=1;
z=0;
Sleep(2000);
system("CLS");printf("Wollen sie starten?\nJa \t=J \nNein \t=N\n \t=");
cin>>repeat;
repeat=toupper(repeat); //abfrage ob Beginnen//
while(repeat=='J')
{
system("CLS");
einlesen();lang();
for(i=0;i<lange;i++)
{
antwort[i]='*';
}system("CLS");
for(z=0;z!=1;z=z+0)
{
prufen(); //Spielschleife//
system("CLS");
printf("%s\n\n",bs);
menue();}
Sleep(1500);
system("CLS");
printf("Wollen sie Nochmal?\nJa \t=J \n Nein \t=N\n \t=");
cin>>repeat; //Neustart//
repeat=toupper(repeat);
}return 0;
}void einlesen()
{printf("Bitte geben sie ein Wort ein(Maximal 100 zeichen)\n");
gets(wort);}
void lang()
{int i=0;
while(wort[i]!='\0')
{
i++;
} //Überprüfung der wortlänge//
lange=i;}
void menue()
{int wahl;
printf("\n%s ",antwort);
figur();
printf("\nBuchstaben raten \t=1");
printf("\nWort raten \t\t=2");
printf("\nL\x94 \bsung zeigen \t\t=3\n\n\t\t\t=");
cin>>wahl;switch(wahl)
{
case 1:
ratenB();
break;case 2:
ratenW();
break;case 3:
losen();
break;}
}void ratenB()
{int i,y;
char buch;printf("\nBitte geben sie einen buchstaben ein \t= ");
cin>>buch;
j++;
bs[j]=buch;for(i=0;i<lange;i++)
{
if(wort[i]==buch)
{
antwort[i]=buch;
y=0; //'X' durch richtige buchstaben ersetzen//
}}
if(y!=0)
{
x=x+1; //hangman ein weiter zeichnen//
j++;
bs[j]=buch;}
}
void ratenW()
{char losung[100];
int y;printf("\nBitte geben sie das wort ein \t=");
cin>>losung; //vermutliches wort eingeben//if(strcmp(losung,wort)==0)
{
y=0;
z=1; //speileschleife beenden//
win();}
if(y!=0)
x=x+1; //hangman ein weiter zeichnen//}
void losen()
{
system("CLS");
printf("\ndas Wort war \t= %s \n",wort);
lose();
Sleep(600);
z=1; //Spielschleife sofort beenden//
}void prufen()
{if(strcmp(antwort,wort)==0)
{
z=1; //Spielschleife beenden//win();
main();
}if(x==8)
{printf("Das wart war \t= %s",wort);
z=1; //Spielschleife beenden//
lose();main();
}}
void lose()
{
int i;
system("CLS");
x=11;
for(i=0;i<10;i++)
{
if(x==11)
{figur();
printf("\nSie haben das Spiel Verloren \nDas Wort war \t= %s",wort);
x=8;
Sleep(200);
system("CLS");
}if(x==8)
{
figur();
printf("\nSie haben das Spiel Verloren \nDas Wort war \t= %s",wort);
x=12;
Sleep(160);
system("CLS");
}if(x==12)
{
figur();
printf("\nSie haben das Spiel Verloren \nDas Wort war \t= %s",wort);
x=13;
Sleep(200);
system("CLS");
}if(x==13)
{
figur();
printf("\nSie haben das Spiel Verloren \nDas Wort war \t= %s",wort);
x=11;
Sleep(160);
system("CLS");
}
}
main();
}void win()
{int i;
x=9;
for(i=0;i<50;i++)
{
if(x==9)
{figur();
printf("\nDas Wort war \t= %s",wort);
printf("\nSie haben gewonnen!!!");
x=10;
Sleep(150);
system("CLS");
}if(x==10)
{
figur();
printf("\nDas Wort war \t= %s",wort);
printf("\nSie haben gewonnen!!!");
x=9;
Sleep(150);
system("CLS");
}
}
main();}
void figur()
{if(x==13)
{
farbe(6); printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
farbe(12);
printf("YOU ");
farbe(4);
printf("O ");
farbe(6);
printf("\n |");
farbe(12);
printf(" ARE ");
farbe(4);
printf("/|\\ ");
farbe(6);
printf("\n |");
farbe(12);
printf(" DEAD ");
farbe(4);
printf("/ \\ ");
farbe(6);
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==12)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | \\ ");
printf("\n | ");
farbe(4);
printf("O- ");
farbe(6);
printf("\n | ");
farbe(4);
printf("|\- ");
farbe(6);
printf("\n | ");
farbe(4);
printf("|");
farbe(6);
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}
if(x==11)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | / ");
printf("\n | ");
farbe(4);
printf("-O ");
farbe(6);
printf("\n |");
farbe(4);
printf(" -/| ");
farbe(6);
printf("\n | ");
farbe(4);
printf("| ");
farbe(6);
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==10)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
farbe(4);
printf(" \\O/ ");
farbe(6);
printf("\n | ");
farbe(4);
printf(" | ");
farbe(6);
printf("\n+-------+ ");
farbe(4);
printf(" / \\ ");
farbe(6);
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);}
if(x==9)
{farbe(6);
printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
farbe(10);
printf("YOU ");
farbe(6);
printf("\n | ");
farbe(10);
printf("WIN ");
farbe(6);
printf("\n | ");
printf("\n | ");
farbe(4);
printf("\\O/ ");
farbe(6);
printf("\n+-------+ ");
farbe(4);
printf("|");
farbe(6);
printf("\n| | ");
farbe(4);
printf("/ \\ ");
farbe(2);
printf("\n-----------------");
farbe(7);}
if(x==8)
{
farbe(6); printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
farbe(12);
printf("YOU ");
farbe(4);
printf("O ");
farbe(6);
printf("\n |");
farbe(12);
printf(" ARE ");
farbe(4);
printf("/|\\ ");
farbe(6);
printf("\n |");
farbe(12);
printf(" DEAD ");
farbe(4);
printf("/ \\ ");
farbe(6);
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==7)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
farbe(4);
printf("O ");
farbe(6);
printf("\n | ");
farbe(4); printf("/|\\ ");
farbe(6);
printf("\n | ");
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==6)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | | ");
printf("\n |");
farbe(4); printf(" O ");
farbe(6);
printf("\n |");
farbe(4);
printf(" | ");
farbe(6);
printf("\n | ");
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n----------------- ");
farbe(7);
}if(x==5)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | | ");
printf("\n | ");
farbe(4);
printf(" O ");
farbe(6);
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n----------------- ");
farbe(7);
}if(x==4)
{
farbe(6);
printf("\n +--------+ ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==3)
{
printf("\n ");
farbe(6);
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n | ");
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n-----------------");
farbe(7);
}if(x==2)
{
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
farbe(6);
printf("\n+-------+ ");
printf("\n| | ");
farbe(2);
printf("\n----------------- ");
farbe(7);
}if(x==1)
{
farbe(2);
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n ");
printf("\n----------------- ");
farbe(7);
}}
-
alls erstes ma
#include <stdio.h> #include <conio.h> #include <iostream.h> #include <string.h> //Biliotheken// #include <windows.h> #include <stdlib.h>
durch
#include <stdio.h> #include <conio.h> #include <iostream> #include <string> //Biliotheken// #include <windows.h> #include <cstdlib>
ersetzen und
warum nimmst immer printf() statt cout ?
man kan zeichen mit z.B mit '\b' löschen
-
cout hab ich noch nich drauf . Kann man den ein \b in ein cin einbauen???
-
warum machst du nach dem du das word eingegeben hast nicht einfach wieder
system("CLS");
bevor du cout benutzen kannst musst
using namespace std;
oder std::cout
-
string str; int c = 0; while(c = getch(), c != '\n' && c != '\r') { c = getch(); cout.put('*'); str += c; } cout << endl;
-
gibt es den auch ne methode nur mit den sachen die auch im restlichen programm schon vorkommen also printf,while,for,switch/case,if,usw ??? weil ich das in der schule auch nacher noch alles erklären muss
-
klar, es gibt viele lösungswege zum ziel. ich schieb dich mal in die c abteilung, weil das wohl eher ein grundlegendes programmierproblem ist, kein spiele/graphic relevantes.
-
Dieser Thread wurde von Moderator/in rapso aus dem Forum Spiele-/Grafikprogrammierung in das Forum ANSI C verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.