Guest User

Untitled

a guest
Jun 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include<iostream>
  2. #include"Creature.h"
  3. #include"Grass.h"
  4. #include"World.h"
  5.  
  6. Grass::Grass(World & Fate,RandomNum & Random):Creature(Fate,Random){
  7.  
  8. }
  9. Grass::~Grass(){
  10.  
  11. }
  12. void Grass::act(){
  13. int AGE = Creature::getAge();
  14. int X = Creature::getX();
  15. int Y = Creature::getY();
  16.  
  17. if(AGE >=3 && AGE<=5){
  18. breed(X,Y);
  19. Creature::aging();
  20. }else if(AGE == 6){
  21. Creature::FATE.die(Creature::getX(),Creature::getY());
  22. Creature::aging();
  23. }else
  24. Creature::aging();
  25.  
  26. Creature::RoundOver();
  27. }
  28.  
  29. void Grass::breed(int X,int Y){
  30. int direction = Creature::Random();
  31.  
  32. if(direction == 0){
  33. if(Creature::FATE.land[Y][X+1]!= NULL)
  34. Creature::aging();
  35. else{
  36. Creature::FATE.land[Y][X+1] = new Grass(Creature::FATE,Creature::RANDOM);
  37. Creature::aging();
  38. }
  39. }else if(direction == 1){
  40. if(Creature::FATE.land[Y-1][X] != NULL)
  41. Creature::aging();
  42. else{
  43. Creature::FATE.land[Y-1][X] = new Grass(Creature::FATE,Creature::RANDOM);
  44. Creature::aging();
  45. }
  46. }else if(direction == 2){
  47. if(Creature::FATE.land[Y][X-1]!= NULL)
  48. Creature::aging();
  49. else{
  50. Creature::FATE.land[Y][X-1] = new Grass(Creature::FATE,Creature::RANDOM);
  51. Creature::aging();
  52. }
  53. }else{
  54. if(Creature::FATE.land[Y+1][X]!=NULL)
  55. Creature::aging();
  56. else{
  57. Creature::FATE.land[Y+1][X] = new Grass(Creature::FATE,Creature::RANDOM);
  58. Creature::aging();
  59. }
  60. }
  61. }
  62.  
  63. CreatureType Grass::CreatureIs() const{
  64. return GRASS;
  65. }
Add Comment
Please, Sign In to add comment