Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include<iostream>
  2. #include"World.h"
  3. #include"Goat.h"
  4. #include"Creature.h"
  5. #include"RandomNum.h"
  6.  
  7. Goat::Goat(World & Fate,RandomNum & Random):Creature(Fate,Random){
  8. foodPoints = 20;
  9.  
  10.  
  11. }
  12. Goat::~Goat(){
  13.  
  14. }
  15. void Goat::move(int X,int Y){
  16. int direction = Creature::Random();
  17.  
  18. if(direction == 0){
  19. Creature::FATE.land[Y][X+1] = Creature::FATE.land[Y][X];
  20. Creature::FATE.land[Y][X] = NULL;
  21. }else if(direction == 1){
  22. Creature::FATE.land[Y-1][X] = Creature::FATE.land[Y][X];
  23. Creature::FATE.land[Y][X] = NULL;
  24. }else if(direction == 2){
  25. Creature::FATE.land[Y][X-1] = Creature::FATE.land[Y][X];
  26. Creature::FATE.land[Y][X] = NULL;
  27. }else{
  28. Creature::FATE.land[Y+1][X] = Creature::FATE.land[Y][X];
  29. Creature::FATE.land[Y][X] = NULL;
  30. }
  31.  
  32. }
  33. void Goat::act() {
  34. int AGE = Creature::getAge();
  35. int X = Creature::getX();
  36. int Y = Creature::getY();
  37.  
  38. if(AGE>=50 && AGE<=55){
  39. breed(X,Y);
  40. Creature::aging();
  41. }else if(AGE == 70)
  42. Creature::FATE.die(Creature::getX(),Creature::getY());
  43. else{
  44. Creature::aging();
  45. move(X,Y);
  46. }
  47.  
  48. Creature::RoundOver();
  49. }
  50. void Goat::breed(int X,int Y){
  51. int direction = Creature::Random();
  52.  
  53. if(direction == 0){
  54. if(Creature::FATE.land[Y][X+1]!= NULL){
  55. if(Creature::FATE.land[Y][X+1]->CreatureIs() == 0)
  56. Creature::aging();
  57. else{
  58. Creature::FATE.die(X+1,Y);
  59. foodPoints += 5;
  60. Creature::FATE.land[Y][X+1] = new Goat(Creature::FATE,Creature::RANDOM);
  61. }
  62. }else
  63. Creature::FATE.land[Y][X+1] = new Goat(Creature::FATE,Creature::RANDOM);
  64. }else if(direction == 1){
  65. if(Creature::FATE.land[Y-1][X]!= NULL){
  66. if(Creature::FATE.land[Y-1][X]->CreatureIs() == 0)
  67. Creature::aging();
  68. else{
  69. Creature::FATE.die(X,Y-1);
  70. foodPoints += 5;
  71. Creature::FATE.land[Y-1][X] = new Goat(Creature::FATE,Creature::RANDOM);
  72. }
  73. }else
  74. Creature::FATE.land[Y-1][X] = new Goat(Creature::FATE,Creature::RANDOM);
  75. }else if(direction == 2){
  76. if(Creature::FATE.land[Y][X-1]!= NULL){
  77. if(Creature::FATE.land[Y][X-1]->CreatureIs() == 0)
  78. Creature::aging();
  79. else{
  80. Creature::FATE.die(X-1,Y);
  81. foodPoints += 5;
  82. Creature::FATE.land[Y][X-1] = new Goat(Creature::FATE,Creature::RANDOM);
  83. }
  84. }else
  85. Creature::FATE.land[Y][X-1] = new Goat(Creature::FATE,Creature::RANDOM);
  86. }else{
  87. if(Creature::FATE.land[Y+1][X]!= NULL){
  88. if(Creature::FATE.land[Y+1][X]->CreatureIs() == 0)
  89. Creature::aging();
  90. else{
  91. Creature::FATE.die(X,Y+1);
  92. foodPoints += 5;
  93. Creature::FATE.land[Y+1][X] = new Goat(Creature::FATE,Creature::RANDOM);
  94. }
  95. }else
  96. FATE.land[Y+1][X] = new Goat(Creature::FATE,Creature::RANDOM);
  97. }
  98.  
  99. }
  100. CreatureType Goat::CreatureIs() const{
  101. return GOAT;
  102. }
Add Comment
Please, Sign In to add comment