Guest User

Untitled

a guest
Jun 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. // Cat.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <time.h>
  8. using namespace std;
  9.  
  10. const int KK=0;
  11. const int KVK=1;
  12.  
  13. char* nafnbanki[]={"kottur1","kottur2","kottur3","kottur4","kottur5","kottur6","kottur7","kottur8","kottur9","kottur10","kottur11","kottur12"};
  14.  
  15. class cat
  16. {
  17. public:
  18. cat(); //smidur1
  19. cat(char* nafn, int kyn, int styrkur, int skap);
  20. void prenta();
  21. void getname()
  22. {
  23. cout << nafn << endl;
  24. }
  25. cat* Attack(cat* k1);
  26.  
  27.  
  28. private:
  29. char* nafn;
  30. int kyn, styrkur, skap; //hér er kyn notað sem integer, KK=0 og KVK=1
  31. };
  32.  
  33. void cat::prenta()
  34. {
  35. cout << "Nafn: " << nafn << endl;
  36. cout << "kyn: " << kyn << endl;
  37. cout << "Styrkur: " << styrkur << endl;
  38. cout << "Skapstyrkur: " << skap << endl << endl;
  39. }
  40.  
  41. cat::cat()
  42. {
  43. int i=rand()%12;
  44. nafn=nafnbanki[i];
  45. kyn=rand()%2;
  46. styrkur=rand()%6;
  47. skap=rand()%6;
  48. }
  49.  
  50. cat::cat(char* inafn, int ikyn, int istyrkur, int iskap)
  51. {
  52. this->nafn=inafn;
  53. this->kyn=ikyn;
  54. this->styrkur=istyrkur;
  55. this->skap=iskap;
  56. }
  57.  
  58. cat* cat::Attack(cat *opponent)
  59. {
  60. if(this->kyn != opponent->kyn)
  61. {
  62. cout << "Ekki sama kyn" << endl;
  63. return NULL;
  64.  
  65. }
  66. double tala1 = (this->styrkur / 5.0) * 0.7 + (this->skap / 5.0) * 0.2 + ((rand() % 100) + 1) / 100.0; // styrkur hefur 70%, skap 20% og random er 10%
  67. double tala2 = (opponent->styrkur / 5.0) * 0.7 + (opponent->skap / 5.0) * 0.2 + ((rand() % 100) + 1) / 100.0;
  68. cat *sigurvegari = NULL;
  69. if(tala1 == tala2)
  70. {
  71. cout << "Jafntefli" << endl;
  72. sigurvegari = NULL;
  73. }
  74. if(tala1 > tala2)
  75. {
  76. sigurvegari = this;
  77. // cout << "Kotturinn: " << this->getname() << " Vann" << endl;
  78.  
  79. }
  80. else
  81. {
  82. sigurvegari = opponent;
  83. opponent->getname();
  84. cout << "Motherji vann" << endl;
  85. }
  86. return sigurvegari;
  87. }
  88.  
  89.  
  90. int _tmain(int argc, _TCHAR* argv[])
  91. {
  92. srand(time(0)); //býr til random með hjálp tíma
  93.  
  94.  
  95. cat c,c1;
  96. // c.prenta(); //prentar út cat::cat()
  97. cat *kottur1 = new cat();
  98. cat *kottur2 = new cat ("kottur2", 0 ,1,4); // ?
  99.  
  100. cat* sigurvegari = kottur1->Attack(kottur2);
  101. if(sigurvegari != NULL)
  102. {
  103. sigurvegari->prenta();
  104. cout << "Vinningstexti" << endl;
  105. }
  106.  
  107. delete kottur1;
  108. kottur1 = NULL;
  109.  
  110. delete kottur2;
  111. kottur2 = NULL;
  112.  
  113. system("pause");
  114. return 0;
  115. }
Add Comment
Please, Sign In to add comment