All pastes #286747 Raw Edit

Unnamed

public text v1 · immutable
#286747 ·published 2006-12-20 22:02 UTC
rendered paste body
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;

const char u='\x81';
const char o='\x94';
short controller=1;
short gambler=0;
short croupier=0;
string cardname;

//funktionen


int question(void);
int hint(void);
int winner(void);
int won(short a);
int AI(void);
int menu(void);
int karte(short a,short b=0);
long rnd(long a=0,long b=2147483647);
int kartenwert(void);
int decision(void);

int main (void)
{
    srand(time(0));
    rand();
        
    short quietus=0;
    
    do
    {
          
                  

          
          //menü
          if (controller==1) 
          {
                         menu();
                         }
                         
          //eigentlicher Spielbeginn
          if (controller==2)
          {
                            karte(0);
                            karte(1);
                            karte(0);
                            if (controller!=1)
                            {
                                              karte(1,1);
                                              controller=5;
                                              }
                            }
          if (controller==3)
          {
                            hint();
                            }
          //beenden 
          if (controller==4)
          {
                            quietus=1;
                            }
          //will Spieler noch eine Karte ?                  
          if (controller==5)
          {
                            decision();
                            if (controller==5)
                            karte(0);
                            if (controller==6)
                            karte(1,2);
                            }
          //muss Croupier noch eine Karte nehmen ?
          if (controller==6)
          {
                            AI();
                            }
        }while (quietus==0);
    
    
    return 0;
}

//menü
int menu(void)
{
    short choice;
    gambler=0;
    croupier=0;
    cout << "Neues Spiel starten  (1)" << endl;
    cout << "Anleitung            (2)" << endl;
    cout << "Beenden              (3)" << endl;
    cin >> choice;
    if (choice==1)
    {
                  controller=2;
                  }
    if (choice==2)
    {
                  controller=3;
                  }
    if (choice==3)
    {
                  controller=4;
                  }
                  
    system ("cls");    
 
}

//neue karte austeilen
// (0) = Spieler Karte ; (1) = Croupier Karte ; (1,1) = Croupier Karte verdeckt ; (1,2) Croupier deckt auf
int karte(short a,short b)
{
    short buffer;
    short no=0;
    
    //zufällige karte errechnen und an den Gesamtwert des Spielers bzw. croupiers übergeben
    if (a==0)
    {
             buffer=gambler;
             gambler=gambler+kartenwert();
             if ((gambler-11)==buffer)
             {
                                     question();
                                     no=1;
                                     }
             }
    
    
    if ((a==1) && (b==0)) 
    {
               buffer=croupier;
               croupier=croupier+kartenwert();
               if (croupier>21)
               {
                               if ((croupier-11)==buffer)
                               croupier=croupier-10;
                               }
                }
    
    if ((a==1) && (b==2))
    {
               buffer=croupier;
               croupier=croupier+kartenwert();
               if (croupier>21)
               {
                               if ((croupier-11)==buffer)
                               croupier=croupier-10;
                               }
               }

    
    //spieler bekommt karte
    if (a==0)
    {
             if (no==0)
             cout << "Sie haben " << cardname << "." << endl;
             no=0;
             }
    if ((a==1) && (b==0))
    {
             cout << "Der Croupier hat " << cardname << "." << endl;
             if ((controller==6) && (croupier<17))
               {
                                   cout << "Dealer must stand on 17 and must draw to 16 !" << endl;
                                   cout << "\n";
                                   }
             if ((croupier>=17) && (croupier<=21))
             {
                                 cout << "Dealer stands on soft 17." << endl;
                                 cout << "\n";
                                 }
             }
    if ((a==1) && (b==1))
    {
              cout << "Karte des Croupier verdeckt." << endl;
              }
    if ((a==1) && (b==2))
    {
               cout << "Der Croupier deckt auf. Der Croupier hat " << cardname << "." << endl;
               if ((controller==6) && (croupier<17))
               {
                                   cout << "Dealer must stand on 17 and must draw to 16 !" << endl;
                                   cout << "\n";
                                   }
               if ((croupier>=17) && (croupier<=21))
               {
                                 cout << "Dealer stands on soft 17." << endl;
                                 cout << "\n";
                                 }
               }
    if (a==0)    
    {      
           cout << "Ihr Gesamtwert: " << gambler << endl;
           if (gambler>21)
           {
                          cout << "Sie sind " << u << "ber 21. Sie haben leider verloren !" << endl;
                          controller=1;
                          }
           }
    if (((a==1) && (b==0)) || ((a==1) && (b==2)))
    {
                cout << "Croupier Gesamzwert: " << croupier << endl;
                if (croupier>21)
                {
                                cout << "Der Croupier ist " << u << "ber 21. Sie haben gewonnen !" << endl;
                                controller=1;
                                }
                }
                
    cout << "\n";
    system("pause");
    system("cls");
}

//zufall
long rnd(long a,long b)
{
     return (rand() % (b-a+1)) + a;
     }
     
//was für eine karte man bzw. der croupier bekommt    
int kartenwert(void)
{
    short wert;
    wert=rnd(2,14); 
      
    if (wert==2)
    cardname="einen Zweier";
    if (wert==3)
    cardname="einen Dreier";
    if (wert==4)
    cardname="einen Vierer";
    if (wert==5)
    cardname="einen F\x81nfer";
    if (wert==6)
    cardname="einen Sechser";
    if (wert==7)
    cardname="einen Siebner";
    if (wert==8)
    cardname="einen Achter";
    if (wert==9)
    cardname="einen Neuner";
    if (wert==10)
    cardname="einen Zehner";
    if (wert==11) 
    cardname="ein Ass";
    if (wert==12)
    cardname="einen Buben";
    if (wert==13)
    cardname="eine Dame";
    if (wert==14)
    cardname="einen K\x94nig";
    
    if ((wert>=12) && (wert<=14))
    {
                   wert=10;
                   }               
    return wert;
}
        
//will der spieler noch eine karte ?
int decision(void)
{
    short yn;
    cout << "Wollen sie noch eine Karte ?" << endl;
    cout << "JA (1)         NEIN (2)" << endl;
    cin >> yn;
    
    if (yn==2)
    controller=6;
    
    system("cls");
}
    
//bekommt(muss) croupier noch eine Karte
int AI(void)
{
    if(croupier<=16)
    karte(1);
    if((croupier>=17) && (croupier<=21)) 
    {
                      winner();
                      if(croupier==gambler)
                      {
                                           won(2);
                                           }
                                           }
}
    
//wer hat gewonnen ?
int winner(void)
{
    if(gambler<=21)
    {
                   if(gambler>croupier)
                   {
                                       won(0);
                                       }
                                       }
    if(croupier<=21)
    {
                    if(croupier>gambler)
                    {
                                        won(1);
                                        }
                                        }
}

//gewinner auf den bildschirm schreiben und zum hauptmenü gehen
int won(short a)
{
    if (a==0)
    {
             cout << "Herzlichen Gl" << u << "ckwunsch sie haben das Spiel gewonnen." << endl;
             cout << "Ihr      Gesamtwert: " << gambler << endl;
             cout << "Croupier Gesamtwert: " << croupier << endl;
             }
    if (a==1)
    {
             cout << "Sie haben das Spiel leider verloren." << endl;
             cout << "Ihr      Gesamtwert: " << gambler << endl;
             cout << "Croupier Gesamtwert: " << croupier << endl;
             }
    if (a==2)
    {
             cout << "Das Spiel ist unentschieden. Egalite." << endl;
             cout << "Ihr      Gesamtwert: " << gambler << endl;
             cout << "Croupier Gesamtwert: " << croupier << endl;
             }
             
    cout << "\n";
    system("pause");
    system("cls");
    controller=1;
}