验证中...
7.21 杭州源创会火热报名中,一起来看看移动开发如何紧跟浪潮?
语言: C/C++
分类: 其他
最后更新于 2018-04-17 18:35
片段 1 片段 2 片段 3
main.cpp
原始数据 复制代码
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
#include"Zoo.h"
using namespace std;
int main()
{
Zoo forest;
system("pause");
}
Zoo.cpp
原始数据 复制代码
#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;
}
Zoo.h
原始数据 复制代码
#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
using namespace std;
#ifndef ZOO_H
#define ZOO_H
class Money //魂币
{
public:
Money();
~Money();
friend Money operator+(Money&, Money&);
friend Money operator-(Money&, Money&);
friend void operator+=(Money&, Money&);
friend void operator-=(Money&, Money&);
int get_dollars();
int get_cents();
int all_money; //魂币
};
class AnimalFood //动物的食物
{
public:
AnimalFood();
~AnimalFood();
double peanuts_amount;//10,000点爆裂花生米
double carrots_amount;//7,000点鬼影胡萝卜
double bananas_amount;//4,000点黄金圣龙蕉
};
class AnimalEnclosure //魂兽圈地
{
public:
AnimalEnclosure();
~AnimalEnclosure();
int get_closed_days();
void clean(); //关门打扫
void open();
bool get_open_or_not(); //看开门没
int dirty_shit; //脏乱度
private:
bool enclosure_open; //是否开门
int closed_days;
};
class Animal
{
public:
Animal();
~Animal();
int amount_eaten; //魂兽吃掉的食物点数
int food_capacity;//食量
AnimalEnclosure enclosure;
int animal_amount;
};
class Elephant :virtual public Animal //猛犸巨象
{
public:
Elephant();
~Elephant();
private:
int trunk_length;//可以吃750点食物
};
class Giraffe :virtual public Animal //远古暗影大角鹿
{
public:
Giraffe();
~Giraffe();
private:
int neck_length;//可以吃500点食物
};
class Monkey :virtual public Animal //史诗泰坦
{
public:
Monkey();
~Monkey();
private:
int arm_length;//可以吃300点食物
};
class Person
{
public:
Person();
~Person();
char name[6];//随机 名字和年龄
int age;
};
class ZooKeeper :private Person //执法修罗
{
public:
ZooKeeper();
~ZooKeeper();
bool cleaning_or_not;
int cleaning_days;//执勤10天返回神界
};
class FoodSeller :private Person //魂器贩卖者
{
public:
FoodSeller();
~FoodSeller();
AnimalFood animal_food; //剩余食物量
Money money_from_foodsold; //卖吃的赚了多少
Money peanuts_prices;
Money carrots_prices;
Money bananas_prices; //食物价格
};
class Visitor :private Person //魂环掠夺者
{
public:
Visitor();
~Visitor();
private:
int IDnumber[10];
};
class Child :private Visitor //魂士
{
public:
Child();
~Child();
int elephant_food_amount; //魂士持有的食物数量
int giraffe_food_amount;
int monkey_food_amount;
};
class Adult :private Visitor//斗帝强者
{ //20-40个,1-3个小孩,10-20刀
public: //大人门票1刀,小孩40分
Adult();
~Adult();
Money get_money_owned();
int get_children_amount();
void buy_food();
Child *childs_array;
void seller_contact(FoodSeller*);
private:
Money money_owned; //斗帝带的魂币
int children_amount; //带魂士数量
FoodSeller *contact_seller;
};
class Zoo //星斗大森林
{ //1 elephant,2 giraffe,3 monkey
public:
Zoo();
~Zoo();
void feed();
void dirty_check();
private:
int adults_amount_everyday; //斗帝强者数量
ZooKeeper* cleaner_ptr;
FoodSeller* seller_ptr;
Adult *adults_array; //斗帝名单指针
int total_adults; //斗帝总数
int total_children; //魂士总数
int elephant_amount;
int giraffe_amount;
int monkey_amount;
Elephant* elephant_ptr;
Giraffe* giraffe_ptr;
Monkey* monkey_ptr;
};
#endif

评论列表( 0 )

你可以在登录后,发表评论

11_float_left_people 11_float_left_close