Objektorientēts stāsts


#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <iostream.h>
#include <string>
using namespace std;

class Story{
public:
Story(string titled,string location){
title=titled;
cout<<title<<endl<<endl;
cout<<"The story takes place in a "<<location<<endl;
}
void End(){
cout<<"This is the end of our story";
}
private:
string title;
};

class Hero{
public:
Hero(){}
Hero(string name1,string sex1,int money_sum){
name=name1;
sex=sex1;
money=money_sum;
drunk=0;
cout<<"Enters hero "<<name1<<" who is a "<<sex1<<endl;
}
Hero(string sex1){
sex=sex1;
name="";
cout<<"Enters a "<<sex1<<endl;
drunk=0;
}
void SetName(string name1){
name=name1;
}
void GiveMoney(Hero person,int amount){
cout<<Name()<<" gives "<<amount<< " piece(s) of money to "<<person.Name()<<endl;
money=money-amount;
}
int HasEnoughMoney(int amount){
if(money cout<<Name()<<" doesn`t have any money left"<<endl;
return 0;
}
else return 1;
}
int Drunk(){
return drunk;
}
void SetSex(int sex1){
sex=sex1;
}
void PassOut(){
cout<<Name()<<" passes out"<<endl;
}
void HitWithABrokenBottle(Hero victim){
cout<<Name()<<" hits "<<victim.Name()<<" with a broken bottle"<<endl;
}
void OrderBeer(Hero beer_from,int amount){
cout<<Name()<<" orders "<<amount<<" bottle(s) of beer from "<<beer_from.Name()<<endl;
}
void DrinkBeer(){
cout<<Name()<<" drinks beer"<<endl;
if(!drunk){
int a=rand()%50;
if(sex=="Woman"&&a>35) drunk=1;
if(sex=="Man"&&a>47) drunk=1;
if(drunk) cout<<"* "<<Name()<<" is now drunk"<<endl;
}
}
string Say(string content,Hero to_person){
cout<<Name()<<" says: `"<<content<<"` to "<< to_person.Name()<<endl;
return content;
}
void Ask(string question,Hero to_person){
cout<<Name()<<" asks "<<to_person.Name()<<": "<<question<<endl;
}
string Name(){
if(name!="") return name;
else return sex;
}
string Sex(){
return sex;
}
void Undress(Hero person){
cout<<Name()<<" undresses "<<person.Name()<<endl;
}
void MakeOutWith(Hero person){
cout<<Name()<<" has sex with "<<person.Name()<<endl;
}
void Notice(Hero person,string feeling){
cout<<Name()<<" notices "<<person.Sex()<<" and feels "<<feeling<<endl;
}
void WakeUp(){
cout<<Name()<<" wakes up"<<endl;
}
void TooDrunkToFuck(){
cout<<Name()<<" is too drunk to fuck"<<endl;
}
private:
string name;
string sex;
int drunk;
int money;
};
class Barman : public Hero{
public:
Barman(string name1){
SetName(name1);
cout<<"Appears barman "<<name1<<endl;
}
void GiveBeer(Hero beer_to,int amount){
cout<<Name()<<" gives "<<amount<<" bottle(s) of beer to "<<beer_to.Name()<<endl;
}
void CloseBar(){
cout<<Name()<<" closes the bar"<<endl;
}
};
int main(void)
{
srand(time(NULL));
Story NiceStory("A romantic tale of wine and roses","pub");
Hero Peter("Peter","Man",10);
Barman Barman("Barman John");
for(int i=1;i<4;i++){
Peter.OrderBeer(Barman,1);
Peter.GiveMoney(Barman,1);
Barman.GiveBeer(Peter,1);
Peter.DrinkBeer();
}
Hero Chick("Woman");
Peter.Notice(Chick,"lust");
Peter.Ask("What`s your name",Chick);
Chick.Say("Helena",Peter);
Chick.SetName("Helena");
Chick.Ask("And your name?",Peter);
Peter.Say("Peter.",Chick);
Peter.Ask("Do you want a beer?",Chick);
Chick.Say("Sure",Peter);
do{
Peter.OrderBeer(Barman,2);
Peter.GiveMoney(Barman,2);
Barman.GiveBeer(Peter,2);
Peter.DrinkBeer();
Chick.DrinkBeer();
}while(!Chick.Drunk()&&Peter.HasEnoughMoney(2));
Peter.Ask("Wanna have sex?",Chick);
if(Chick.Drunk()){
Chick.Say("Sure!",Peter);
Barman.Say("I have a room for 30 EUR an hour",Peter);
Peter.Say("I live next door, you money grabbing fucker!",Barman);
Barman.HitWithABrokenBottle(Peter);
Peter.PassOut();
}
else{
Chick.Say("No, you pervert!", Peter);
Chick.HitWithABrokenBottle(Peter);
Peter.PassOut();
Barman.Ask("Do you want another beer?",Chick);
Chick.Say("I always want a beer!",Barman);
while(!Chick.Drunk()){
Barman.GiveBeer(Chick,1);
Chick.DrinkBeer();
}
}
Barman.Ask("Wanna have sex?",Chick);
Chick.Say("I`m totally horny",Barman);
Barman.Say("I must close the bar in that case",Chick);
Barman.CloseBar();
Barman.Undress(Chick);
Barman.Undress(Barman);
Barman.MakeOutWith(Chick);
Peter.WakeUp();
Peter.Notice(Barman,"anger");
Peter.HitWithABrokenBottle(Barman);
Barman.PassOut();
Peter.Undress(Peter);
if(!Peter.Drunk()){
Peter.MakeOutWith(Chick);
Chick.Say("I`m tired that you both treat me like an object",Peter);
Chick.HitWithABrokenBottle(Peter);
Peter.PassOut();
}
else{
Peter.TooDrunkToFuck();
Peter.Ask("Shall we drink some more?",Chick);
Chick.Say("Sure!",Peter);
}
NiceStory.End();
getchar();
}