Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <fstream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <iostream>
- #include <string>
- #define KOLORY 4
- #define FIGURY 13
- #define AVAILABLE 134
- #define TAKEN 1
- #define TRUE 1
- #define FALSE 0
- #define NUM_RANKS 13
- /* external variables */
- using namespace std;
- int Strit, Kolor, Kareta, Trojka;
- int Para = 0;
- void menu()
- {
- system("cls");
- cout << "Menu"<< endl<<endl;
- cout << "1. Rozpocznij gre"<<endl;
- cout << "2. Zasady gry"<<endl;
- cout << "3. Zakoncz gre" << endl << endl;
- }
- bool wyswietlZawartoscPliku( string Zasady )
- {
- ifstream plik;
- plik.open( Zasady.c_str() );
- if( !plik.good() )
- return false;
- string wiersz;
- while( getline( plik, wiersz ) )
- cout << wiersz << endl;
- plik.close();
- return true;
- }
- void tasowanie( int talia[][ 13 ] )
- {
- int wiersz; /* represents suit value of card */
- int kolumna; /* represents face value of card */
- int karta; /* loop counter */
- /* for each of the 52 cards, choose a slot of the deck randomly */
- for ( karta = 1; karta <= 52; karta++ )
- {
- do /* choose a new random location until unoccupied slot is found */
- {
- wiersz = rand() % 4; /* randomly select the row */
- kolumna = rand() % 13; /* randomly select the column */
- } while( talia[ wiersz ][ kolumna ] != 0 ); /* end do...while */
- /* place card number in chosen slot of deck */
- talia[ wiersz ][ kolumna ] = karta;
- } /* end for */
- } /* end function shuffle */
- void rozdanieKart(int koloryWRece[], int figuryWRece[],char *kolory[], char *figury[], int talia[][FIGURY])
- {
- int kolorIndex, figuraIndex;
- kolorIndex = rand() % 4;
- figuraIndex = rand() %13;
- while( talia[kolorIndex][figuraIndex] == TAKEN ){
- kolorIndex = rand() % 4;
- figuraIndex = rand() %13;
- }
- talia[kolorIndex][figuraIndex] = TAKEN;
- figuryWRece[figuraIndex]++;
- koloryWRece[kolorIndex]++;
- printf("%s %s \n", figury[figuraIndex], kolory[kolorIndex]);
- }
- void rozdanieReki(int koloryWRece[], int figuryWRece[], char *kolory[], char *figury[], int talia[][FIGURY])
- {
- int i;
- for(i = 0; i < 5; i++)
- rozdanieKart(koloryWRece, figuryWRece, kolory, figury, talia);
- cout << "\n";
- }
- void sprawdzanieReki(int koloryWRece[], int figuryWRece[])
- {
- int kolejne_figury = 0;
- int rank, kolor;
- Strit = FALSE;
- Kolor = FALSE;
- Kareta = FALSE;
- Trojka = FALSE;
- Para = 0;
- for (kolor = 0; kolor < KOLORY; kolor++)
- if (koloryWRece[kolor] == 5)
- Kolor = TRUE;
- rank = 0;
- while (figuryWRece[rank] == 0)
- rank++;
- for (; rank < FIGURY && figuryWRece[rank]; rank++)
- kolejne_figury++;
- if (kolejne_figury == 5) {
- Strit = TRUE;
- return;
- }
- for (rank = 0; rank < NUM_RANKS; rank++) {
- if (figuryWRece[rank] == 4)
- Kareta = TRUE;
- if (figuryWRece[rank] == 3)
- Trojka = TRUE;
- if (figuryWRece[rank] == 2)
- Para++;
- }
- }
- void wyswietlanieWynikow(int koloryWRece[], int figuryWRece[], int *wartosc)
- {
- sprawdzanieReki(koloryWRece, figuryWRece);
- if (Strit && Kolor) {
- cout << "POKER\n\n";
- *wartosc = 9;
- }
- else if (Kareta) {
- cout << "KARETA\n\n";
- *wartosc = 8;
- }
- else if (Trojka && Para == 1) {
- cout << "FUL\n\n";
- *wartosc = 7;
- }
- else if (Kolor) {
- cout << "KOLOR\n\n";
- *wartosc = 6;
- }
- else if (Strit) {
- cout << "STRIT\n\n";
- *wartosc = 5;
- }
- else if (Trojka) {
- cout << "Trojka\n\n";
- *wartosc = 4;
- }
- else if (
- Para == 2) {
- cout << "DWIE PARY\n\n";
- *wartosc = 3;
- }
- else if (Para == 1) {
- cout << "PARA\n\n";
- *wartosc = 2;
- }
- else
- cout << "WYSOKA KARTA\n\n";
- *wartosc = 1;
- }
- int Gra()
- {
- char *kolory[4] = { "Serce", "Karo", "Pik", "Trefl" };
- char *figury[13] = { "2", "3", "4", "5", "6", "7",
- "8", "9", "10", "Walet", "Dama", "Krol", "As" };
- int talia[4][13] = { { AVAILABLE } };
- int koloryWRece[4] = {0} ;
- int figuryWRece[13] = {0};
- int koloryWRece2[4] = {0};
- int figuryWRece2[13] = {0};
- int punkty1gracza;
- int punkty2gracza;
- srand( time( NULL ) );
- /* shuffle the deck */
- tasowanie( talia );
- cout << "Gracz wylosowal:\n\n";
- rozdanieReki(koloryWRece, figuryWRece, kolory, figury, talia);
- sprawdzanieReki(koloryWRece, figuryWRece);
- wyswietlanieWynikow(koloryWRece, figuryWRece, &punkty1gracza);
- cout << "Komputer wylosowal:\n\n";
- rozdanieReki(koloryWRece2, figuryWRece2, kolory, figury, talia);
- sprawdzanieReki(koloryWRece2, figuryWRece2);
- wyswietlanieWynikow(koloryWRece2, figuryWRece2, &punkty2gracza);
- if(punkty1gracza > punkty2gracza) {
- cout << "Gratulacje, wygrales to rozdanie!\n\n" ;
- }
- else if(punkty1gracza< punkty2gracza) {
- cout << "Niestety przegrales ta runde...\n\n" ;
- }
- else
- cout << "Remis\n\n";
- cout << "\n";
- system("pause");
- void tasowanie( int talia[][ 13 ] );
- void rozdanieReki(int koloryWRece[], int figuryWRece[], char *kolory[], char *figury[], int talia[][FIGURY]);
- void rozdanieKart(int koloryWRece[], int figuryWRece[], char *kolory[], char *figury[], int talia[][FIGURY]);
- void sprawdzanieReki(int koloryWRece[], int figuryWRece[]);
- /* assign value to hand and print results */
- void wyswietlanieWynikow(int koloryWRece[], int figuryWRece[], int *wartosc);
- return 0;
- }
- int main()
- {
- int wybor;
- while(1)
- {
- menu();
- cin>>wybor;
- system("cls");
- switch (wybor)
- {
- case 1:
- Gra();
- system("PAUSE");
- break;
- case 2:
- if( !wyswietlZawartoscPliku( "Zasady.txt" ) )
- cout << "Nie udalo sie otworzyc pliku o podanej nazwie." << endl;
- cout << endl << endl;
- system("PAUSE");
- break;
- case 3:
- return 0;
- break;
- default:
- cout << "Zla opcja";
- cout << endl << endl;
- system("PAUSE");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement