Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include"Creature.h"
- #include"Grass.h"
- #include"World.h"
- Grass::Grass(World & Fate,RandomNum & Random):Creature(Fate,Random){
- }
- Grass::~Grass(){
- }
- void Grass::act(){
- int AGE = Creature::getAge();
- int X = Creature::getX();
- int Y = Creature::getY();
- if(AGE >=3 && AGE<=5){
- breed(X,Y);
- Creature::aging();
- }else if(AGE == 6){
- Creature::FATE.die(Creature::getX(),Creature::getY());
- Creature::aging();
- }else
- Creature::aging();
- Creature::RoundOver();
- }
- void Grass::breed(int X,int Y){
- int direction = Creature::Random();
- if(direction == 0){
- if(Creature::FATE.land[Y][X+1]!= NULL)
- Creature::aging();
- else{
- Creature::FATE.land[Y][X+1] = new Grass(Creature::FATE,Creature::RANDOM);
- Creature::aging();
- }
- }else if(direction == 1){
- if(Creature::FATE.land[Y-1][X] != NULL)
- Creature::aging();
- else{
- Creature::FATE.land[Y-1][X] = new Grass(Creature::FATE,Creature::RANDOM);
- Creature::aging();
- }
- }else if(direction == 2){
- if(Creature::FATE.land[Y][X-1]!= NULL)
- Creature::aging();
- else{
- Creature::FATE.land[Y][X-1] = new Grass(Creature::FATE,Creature::RANDOM);
- Creature::aging();
- }
- }else{
- if(Creature::FATE.land[Y+1][X]!=NULL)
- Creature::aging();
- else{
- Creature::FATE.land[Y+1][X] = new Grass(Creature::FATE,Creature::RANDOM);
- Creature::aging();
- }
- }
- }
- CreatureType Grass::CreatureIs() const{
- return GRASS;
- }
Add Comment
Please, Sign In to add comment