Gra – Szubienica.

Popularna gra: Szubienica! Polega na tym, że komputer losuje wyraz z puli wyraz wpisanych w program. My podając litery odgadujemy ten wyraz, zaś kiedy nie ma danej literki w wyrazie to jest to błąd i buduje się szubienica. Koniec gry jest wtedy, gdy odgadniemy wyraz lub zbudujemy całą szubienicę. Można rozbudować program o kategorię (poziomy) zgadywanych wyrazów, np. pierwszy poziom wyrazy 3-literowe, następny poziom 4-literowe, itd.


C++


#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <time.h>

using namespace std;

void error0() {
  cout << endl << endl << endl << endl << endl << endl << endl << endl << endl;
}

void error1() {
  cout << endl << endl << endl << endl << endl << endl << endl << endl;
  cout << "----------------" << endl;
}

void error2() {
  cout << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << "----------------" << endl;
}

void error3() {
  cout << " --------------" << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << "----------------" << endl;
}

void error4() {
  cout << " --------------" << endl;
  cout << " | |" << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << " | " << endl;
  cout << "----------------" << endl;
}

void error5() {
  cout << " -------------- " << endl;
  cout << " | | " << endl;
  cout << " | ( ) " << endl;
  cout << " | | " << endl;
  cout << " | /|\\ " << endl;
  cout << " | | " << endl;
  cout << " | / \\ " << endl;
  cout << " | " << endl;
  cout << "---------------- " << endl;
}

void start(int i) {
  cout << " GRA SZUBIENICA" << endl;
  cout << " POZIOM " << i+1 << endl << endl;
}

void koniec(int i) {
  cout << " KONIEC GRY. " << endl;
  cout << " POZIOM: " << i << endl;
}

int main()
{
  // baza wyrazow do gry
  string level[4][3] = {
    {"los", "dom", "raz"},
    {"kran", "gram", "stop"},
    {"hamak", "klasa", "obraz"},
    {"garnek","rozkaz","krawat"}
  };
  // losowanie wyrazu
  int poziom = 0;
  int error = 0;
  do {
    srand(time(NULL));
    int los = rand()%3;
    string wyraz = level[poziom][los];
    string szukany_wyraz;
    for (int i=0; i<level[poziom][los].length(); i++)
      szukany_wyraz += "-";
    do {
      system("cls");
      start(poziom);
      if (error==0) error0();
      if (error==1) error1();
      if (error==2) error2();
      if (error==3) error3();
      if (error==4) error4();
      if (error==5) {
        error5();
        break;
      }
      bool zmienna = true;
      cout << szukany_wyraz << endl;
      cout << "podaj litere: ";
      char litera;
      cin >> litera;  
      for (int x=0; x<wyraz.length(); x++)
        if (litera == wyraz[x]) {
        szukany_wyraz[x] = litera;
        zmienna = false;
      }
      if (zmienna) error++;
      cout << szukany_wyraz << endl;
    } while (szukany_wyraz!=wyraz);
    if (szukany_wyraz==wyraz) {
      system("cls");
      cout << " WYGRANA!!!" << endl;
      poziom++;
      if (poziom == 4) {
        koniec(poziom);
        break;
      }
    } else {
      system("cls");
      koniec(poziom);
      error5();
      cout << " PRZEGRANA!!!" << endl;
      break;
    }
  } while (poziom < 5);
  return 0;
}

JAVA


 

Leave a Reply

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>