Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cat.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- const int KK=0;
- const int KVK=1;
- char* nafnbanki[]={"kottur1","kottur2","kottur3","kottur4","kottur5","kottur6","kottur7","kottur8","kottur9","kottur10","kottur11","kottur12"};
- class cat
- {
- public:
- cat(); //smidur1
- cat(char* nafn, int kyn, int styrkur, int skap);
- void prenta();
- void getname()
- {
- cout << nafn << endl;
- }
- cat* Attack(cat* k1);
- private:
- char* nafn;
- int kyn, styrkur, skap; //hér er kyn notað sem integer, KK=0 og KVK=1
- };
- void cat::prenta()
- {
- cout << "Nafn: " << nafn << endl;
- cout << "kyn: " << kyn << endl;
- cout << "Styrkur: " << styrkur << endl;
- cout << "Skapstyrkur: " << skap << endl << endl;
- }
- cat::cat()
- {
- int i=rand()%12;
- nafn=nafnbanki[i];
- kyn=rand()%2;
- styrkur=rand()%6;
- skap=rand()%6;
- }
- cat::cat(char* inafn, int ikyn, int istyrkur, int iskap)
- {
- this->nafn=inafn;
- this->kyn=ikyn;
- this->styrkur=istyrkur;
- this->skap=iskap;
- }
- cat* cat::Attack(cat *opponent)
- {
- if(this->kyn != opponent->kyn)
- {
- cout << "Ekki sama kyn" << endl;
- return NULL;
- }
- 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%
- double tala2 = (opponent->styrkur / 5.0) * 0.7 + (opponent->skap / 5.0) * 0.2 + ((rand() % 100) + 1) / 100.0;
- cat *sigurvegari = NULL;
- if(tala1 == tala2)
- {
- cout << "Jafntefli" << endl;
- sigurvegari = NULL;
- }
- if(tala1 > tala2)
- {
- sigurvegari = this;
- // cout << "Kotturinn: " << this->getname() << " Vann" << endl;
- }
- else
- {
- sigurvegari = opponent;
- opponent->getname();
- cout << "Motherji vann" << endl;
- }
- return sigurvegari;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- srand(time(0)); //býr til random með hjálp tíma
- cat c,c1;
- // c.prenta(); //prentar út cat::cat()
- cat *kottur1 = new cat();
- cat *kottur2 = new cat ("kottur2", 0 ,1,4); // ?
- cat* sigurvegari = kottur1->Attack(kottur2);
- if(sigurvegari != NULL)
- {
- sigurvegari->prenta();
- cout << "Vinningstexti" << endl;
- }
- delete kottur1;
- kottur1 = NULL;
- delete kottur2;
- kottur2 = NULL;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment