#include<iostream>
#include<string>
#include"Zoo.h"
#include<ctime>
#include<cstdlib>
using namespace std;
/***********************星斗大森林***********************/
Zoo::Zoo()
{
srand((unsigned)time(NULL));
elephant_amount = 1;
giraffe_amount = 2;
monkey_amount = 3;
Elephant mammoth_elephant; // ↘
Giraffe *ancient_giraffe = new Giraffe[giraffe_amount];// →·→投放百万年魂兽
Monkey *epic_titanic = new Monkey[monkey_amount]; // ↗
elephant_ptr = &mammoth_elephant;
giraffe_ptr = ancient_giraffe;
monkey_ptr = epic_titanic;
elephant_ptr->animal_amount = elephant_amount;
giraffe_ptr[0].animal_amount = giraffe_amount;
monkey_ptr[0].animal_amount = monkey_amount;
ZooKeeper king;
FoodSeller seller;
cleaner_ptr = &king;
seller_ptr = &seller;
total_adults = 0;
total_children = 0; //置零
for (int i = 1;; i++) //星斗大森林毁灭前每天都有斗帝带着小魂士历练
{
adults_amount_everyday = rand() % 21 + 20; //随机进入斗帝
total_adults += adults_amount_everyday;
Adult *adults = new Adult[adults_amount_everyday]; //创建斗帝名单
adults_array = adults;
for (int j = 0; j < adults_amount_everyday; j++)
{
adults[j].seller_contact(seller_ptr);
adults[j].buy_food();
for (int k = 0; k < adults[j].get_children_amount(); k++)
{
int peanuts = adults[j].childs_array[k].elephant_food_amount;
int carrots = adults[j].childs_array[k].giraffe_food_amount;
int bananas = adults[j].childs_array[k].monkey_food_amount;
seller.animal_food.peanuts_amount -= peanuts;
seller.animal_food.carrots_amount -= carrots;
seller.animal_food.bananas_amount -= bananas;
seller.money_from_foodsold.all_money += (peanuts * seller.peanuts_prices.all_money);
seller.money_from_foodsold.all_money += (carrots * seller.carrots_prices.all_money);
seller.money_from_foodsold.all_money += (bananas * seller.bananas_prices.all_money);
}
total_children += adults[j].get_children_amount(); //统计小魂士数量
}
feed();
if (!elephant_ptr->enclosure.get_open_or_not())
elephant_ptr->enclosure.open();
else if (!giraffe_ptr->enclosure.get_open_or_not())
giraffe_ptr->enclosure.open();
else if (!monkey_ptr->enclosure.get_open_or_not())
monkey_ptr->enclosure.open();
dirty_check();
if (king.cleaning_days >= 10)
{
cout << "动物园开了" << i << "天" << endl << "清洁工辞职了" << endl;
break;
}
else if (seller.animal_food.peanuts_amount <= 0)
{
cout << "动物园开了" << i << "天" << endl << "花生卖光了" << endl;
break;
}
else if (seller.animal_food.bananas_amount <= 0)
{
cout << "动物园开了" << i << "天" << endl << "香蕉卖光了" << endl;
break;
}
else if (seller.animal_food.carrots_amount <= 0)
{
cout << "动物园开了" << i << "天" << endl << "胡萝卜卖光了" << endl;
break;
}
}
cout << "总共招待了" << total_adults << "个大人," << total_children << "个小孩" << endl;
cout << "卖食物赚了" << seller.money_from_foodsold.get_dollars() << "刀" << seller.money_from_foodsold.get_cents() << "分" << endl;
cout << "清洁工总共打扫了" << king.cleaning_days << "天" << endl;
cout << "大象圈地关了 " << mammoth_elephant.enclosure.get_closed_days() << "天" << endl;
cout << "长颈鹿圈地关了" << ancient_giraffe->enclosure.get_closed_days() << "天" << endl;
cout << "猴子圈地关了 " << epic_titanic->enclosure.get_closed_days() << "天" << endl;
}
void Zoo::feed()
{
for (int j = 0; j < adults_amount_everyday; j++) //遍历每一位斗帝
{
/*************************培养猛犸象************************/
if (elephant_ptr->enclosure.get_open_or_not())
{
for (int i = 0; i < adults_array[j].get_children_amount(); i++)
{
elephant_ptr->amount_eaten += adults_array[j].childs_array[i].elephant_food_amount;
if (elephant_ptr->amount_eaten >= elephant_ptr->food_capacity)
{
elephant_ptr->enclosure.dirty_shit += elephant_ptr->food_capacity;//吃饱拉翔
elephant_ptr->amount_eaten -= elephant_ptr->food_capacity;
}
}
}
/*************************培养大角鹿************************/
if (giraffe_ptr[0].enclosure.get_open_or_not())
{
for (int i = 0; i < adults_array[j].get_children_amount(); i++)
{
int random = rand() % giraffe_amount;
giraffe_ptr[random].amount_eaten += adults_array[j].childs_array[i].giraffe_food_amount;
if (giraffe_ptr[random].amount_eaten >= giraffe_ptr->food_capacity)
{
giraffe_ptr[0].enclosure.dirty_shit += giraffe_ptr->food_capacity;
giraffe_ptr[random].amount_eaten -= giraffe_ptr->food_capacity;
}
}
}
/*************************培养大泰坦************************/
if (monkey_ptr[0].enclosure.get_open_or_not())
{
for (int i = 0; i < adults_array[j].get_children_amount(); i++)
{
int random = rand() % monkey_amount;
monkey_ptr[random].amount_eaten += adults_array[j].childs_array[i].monkey_food_amount;
if (monkey_ptr[random].amount_eaten >= monkey_ptr->food_capacity)
{
monkey_ptr[0].enclosure.dirty_shit += monkey_ptr->food_capacity;
monkey_ptr[random].amount_eaten -= monkey_ptr->food_capacity;
}
}
}
}
}
void Zoo::dirty_check() //清场检测
{
if (elephant_ptr->enclosure.dirty_shit >= 2000)
{
elephant_ptr->enclosure.clean();
cleaner_ptr->cleaning_or_not = true;
cleaner_ptr->cleaning_days++;
}
if (giraffe_ptr[0].enclosure.dirty_shit >= 2000)
{
giraffe_ptr[0].enclosure.clean();
cleaner_ptr->cleaning_or_not = true;
cleaner_ptr->cleaning_days++;
}
if (monkey_ptr[0].enclosure.dirty_shit >= 2000)
{
monkey_ptr[0].enclosure.clean();
cleaner_ptr->cleaning_or_not = true;
cleaner_ptr->cleaning_days++;
}
}
Zoo::~Zoo()
{
}
/***********************魂兽***************************/
Animal::Animal()
{
amount_eaten = 0;
}
Animal::~Animal()
{
}
/***********************猛犸巨象***********************/
Elephant::Elephant()
{
trunk_length = rand() % 501 + 500;
food_capacity = 750;
}
Elephant::~Elephant()
{
}
/********************远古暗影大角鹿********************/
Giraffe::Giraffe()
{
neck_length = rand() % 201 + 600;
food_capacity = 500;
}
Giraffe::~Giraffe()
{
}
/***********************史诗泰坦***********************/
Monkey::Monkey()
{
arm_length = rand() % 101 + 500;
food_capacity = 300;
}
Monkey::~Monkey()
{
}
/*************************魂币*************************/
Money::Money()
{
all_money = 0;
}
int Money::get_dollars()
{
return all_money / 100;
}
int Money::get_cents()
{
return all_money - (all_money / 100) * 100;
}
Money::~Money()
{
}
/***********************魂兽饲料***********************/
AnimalFood::AnimalFood()
{
peanuts_amount = 10000;
carrots_amount = 7000;
bananas_amount = 4000;
}
AnimalFood::~AnimalFood()
{
}
/***********************魂兽领地***********************/
AnimalEnclosure::AnimalEnclosure()
{
dirty_shit = 0;
enclosure_open = true;
closed_days = 0;
}
int AnimalEnclosure::get_closed_days()
{
return closed_days;
}
void AnimalEnclosure::clean()
{
enclosure_open = false;
closed_days++;
dirty_shit = 0;
}
void AnimalEnclosure::open()
{
enclosure_open = true;
}
bool AnimalEnclosure::get_open_or_not()
{
return enclosure_open;
}
AnimalEnclosure::~AnimalEnclosure()
{
}
/***********************魂师属性***********************/
Person::Person()
{
//srand((unsigned)time(NULL));
name[0] = rand() % 26 + 'A';
for (int n = 1; n < 5; n++)
{
name[n] = rand() % 26 + 'a';
}
name[5] = '\0';
age = rand() % 100;
}
Person::~Person()
{
}
/***********************执法修罗***********************/
ZooKeeper::ZooKeeper()
{
cleaning_days = 0;
cleaning_or_not = false;
}
ZooKeeper::~ZooKeeper()
{
}
/**********************魂器贩卖者**********************/
FoodSeller::FoodSeller()
{
money_from_foodsold.all_money = 0;
peanuts_prices.all_money = 20;
carrots_prices.all_money = 30;
bananas_prices.all_money = 50;
}
FoodSeller::~FoodSeller()
{
}
/**********************魂环掠夺者**********************/
Visitor::Visitor()
{
//srand((unsigned)time(NULL));
for (int x = 0; x < 9; x++)
IDnumber[x] = rand() % 10;
IDnumber[9] = '\0';
}
Visitor::~Visitor()
{
}
/**********************随从小魂士**********************/
Child::Child()
{
elephant_food_amount = 0;
giraffe_food_amount = 0;
monkey_food_amount = 0;
}
Child::~Child()
{
}
/***********************斗帝强者***********************/
Adult::Adult()
{
//srand((unsigned)time(NULL));
children_amount = rand() % 3 + 1;
Child *children = new Child[children_amount];//随机分配小魂士
childs_array = children;
money_owned.all_money = (rand() % 11 + 10) * 100;
Money tickets;
tickets.all_money = 100 + children_amount * 40;
money_owned -= tickets; //买完票之后的余额
}
Money Adult::get_money_owned()
{
return money_owned;
}
int Adult::get_children_amount()
{
return children_amount;
}
void Adult::buy_food()
{
for (int i = 0; i < children_amount; i++)
{
childs_array[i].elephant_food_amount = (money_owned.all_money / (3 * children_amount * contact_seller->peanuts_prices.all_money));
childs_array[i].giraffe_food_amount = (money_owned.all_money / (3 * children_amount * contact_seller->carrots_prices.all_money));
childs_array[i].monkey_food_amount = (money_owned.all_money / (3 * children_amount * contact_seller->bananas_prices.all_money));
}
}
void Adult::seller_contact(FoodSeller* ptr)
{
contact_seller = ptr;
}
Adult::~Adult()
{
}
/***********************算币***********************/
Money operator+(Money&A, Money&B)
{
Money C;
C.all_money = A.all_money + B.all_money;
return C;
}
Money operator-(Money&A, Money&B)
{
Money C;
C.all_money = A.all_money - B.all_money;
return C;
}
void operator+=(Money&A, Money&B)
{
A.all_money += B.all_money;
}
void operator-=(Money&A, Money&B)
{
A.all_money -= B.all_money;
}
评论列表( 0 )
你可以在登录后,发表评论