Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ProgramKarol.cpp : Defines the entry point for the console application.
- //
- #include<iostream>
- #include <string>
- #include<string.h>
- #include<stdio.h>
- #include<stdlib.h>
- using namespace std;
- void startGry();
- char* wprowadzSlowo()
- {
- string slowo1;
- cout << "Podaj slowo: " << endl;
- cin>>slowo1;
- char* slowo=new char[slowo1.size() + 1];
- copy(slowo1.begin(), slowo1.end(), slowo);
- slowo[slowo1.size()] = '\0';
- return slowo;
- }
- void wyswietlanieSlowa(string slowo)
- {
- cout<<slowo<<endl;
- }
- bool sprawdzIstnienie(char* slowo, char znak, char* zgadujacego)
- {
- int dlugosc=strlen(slowo);
- bool zgadniecie=false;
- for (int i = 0; i < dlugosc; i++)
- {
- if (znak == slowo[i])
- {
- zgadujacego[i] = znak;
- zgadniecie=true;
- }
- }
- return zgadniecie;
- }
- bool zgadniecieWszystkiego(char* slowo)
- {
- bool wynik=true;
- int dlugosc=strlen(slowo);
- for(int i=0;i<dlugosc;i++)
- {
- if(slowo[i]=='*')
- {
- wynik=false;
- }
- }
- return wynik;
- }
- void zgadywanie(int length, char* slowoKlucz)
- {
- char litera;
- int dlugosc=length, szanse=5;
- char slowoPuste[dlugosc];
- for (int i=1; i < dlugosc-1; i++)
- {
- slowoPuste[i] = '*';
- }
- slowoPuste[0]=slowoKlucz[0];
- slowoPuste[dlugosc-1]=slowoKlucz[dlugosc-1];
- slowoPuste[dlugosc]='\0';
- while(!(zgadniecieWszystkiego(slowoPuste)))
- {
- wyswietlanieSlowa(slowoPuste);
- cout<<"Podaj litere: "<<endl;
- cin>>litera;
- system("cls");
- if(!(sprawdzIstnienie(slowoKlucz, litera, slowoPuste))){
- szanse-=1;
- cout<<"Nie zgadles litery! Ilosc pozostałych szans: "<<szanse<<endl;
- }else{
- cout<<"Brawo, udalo Ci sie odgadnac litere! Ilosc pozostałych szans: "<<szanse<<endl;
- }
- if(szanse==0)
- {
- do{
- system("cls");
- cout<<"Niestety przegrales... :("<<endl<<"Wybierz jedna z czynnosci: "<<endl<<"1- od nowa"<<endl<<"2- wyjscie"<<endl;
- cin>>litera;
- }while(litera!='1'&&litera!='2');
- if(litera=='1')
- {
- system("cls");
- startGry();
- }else{
- system("exit");
- }
- break;
- }
- }
- if(zgadniecieWszystkiego(slowoPuste)){
- do{
- system("cls");
- cout<<"Brawo wygrales gre!"<<endl<<"Wybierz jedna z czynnosci: "<<endl<<"1- od nowa"<<endl<<"2- wyjscie"<<endl;
- cin>>litera;
- }while(litera!='1'&&litera!='2');
- if(litera=='1')
- {
- system("cls");
- startGry();
- }else{
- system("exit");
- }
- }
- }
- void startGry(){
- char* slowoKlucz=wprowadzSlowo();
- int length = strlen(slowoKlucz);
- zgadywanie(length, slowoKlucz);
- }
- int main(int argc, char** argv)
- {
- startGry();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement