Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- using namespace std;
- class CreatureCaretaker
- {
- private:
- int creaturePow;
- int creatureLife;
- string creatureName;
- int creatureNum;
- int nodeNum;
- int creatureList[11];
- string listSortName[11];
- int listSortPow[11];
- int listSortLife[11];
- int arrayAccess;
- void swapName(string *element1, string *element2)
- {
- string temp;
- temp = *element1;
- *element1 = *element2;
- *element2 = temp;
- }
- void swap(int *element1, int *element2)
- {
- int temp = 0;
- temp = *element1;
- *element1 = *element2;
- *element2 = temp;
- }
- CreatureCaretaker *head, *tail, *right, *left, *newNode;
- public:
- CreatureCaretaker()
- {
- creaturePow = 0;
- creatureLife = 0;
- creatureNum = 0;
- creatureName = "Default Slot";
- arrayAccess = 0;
- }
- CreatureCaretaker(int givenPow, int givenLife, string givenName)
- {
- this->creaturePow = givenPow;
- this->creatureLife = givenLife;
- this->creatureName = givenName;
- }
- void addCreature(int creaturePow, int creatureLife, string creatureName);
- void showCreature();
- void removeCreature();
- void exchangeSortPow(int givenPow[], int givenLife[], string givenName[], int size);
- void exchangeSortLife(int givenPow[], int givenLife[], string givenName[], int size);
- void showPow();
- void showLife();
- }; CreatureCaretaker ooo;
- void CreatureCaretaker::addCreature(int creaturePow, int creatureLife, string creatureName)
- {
- if(head == NULL)
- {
- head = new CreatureCaretaker(creaturePow, creatureLife, creatureName);
- tail = head;
- head->left = NULL;
- head->right = newNode;
- listSortPow[arrayAccess] = creaturePow;
- listSortLife[arrayAccess] = creatureLife;
- listSortName[arrayAccess] = creatureName;
- }
- else
- {
- arrayAccess += 1;
- if(arrayAccess > 0)
- {
- newNode = new CreatureCaretaker(creaturePow, creatureLife, creatureName);
- tail->right = newNode;
- newNode->left = tail;
- tail = tail->right;
- tail->right = NULL;
- listSortPow[arrayAccess] = creaturePow;
- listSortLife[arrayAccess] = creatureLife;
- listSortName[arrayAccess] = creatureName;
- }
- }
- }
- void CreatureCaretaker::showCreature()
- {
- CreatureCaretaker *tmp;
- tmp = head;
- if(tmp == NULL)
- cout << "head is NULL";
- for(creatureNum = 1; tmp != NULL; creatureNum++)
- {
- if(creatureNum < 11)
- {
- cout << "Creature Number - " << creatureNum << endl;
- cout << "Name - " << tmp->creatureName << endl;
- cout << "Power - " << tmp->creaturePow << endl;
- cout << "Life Points - " << tmp->creatureLife << endl << endl;
- tmp = tmp->right;
- this->creatureNum = creatureNum;
- creatureList[creatureNum];
- }
- }
- }
- void CreatureCaretaker::removeCreature()
- {
- cout << "Remove which creature number?" << endl;
- cin >> nodeNum;
- CreatureCaretaker *tmp, *oldTmp, *frontTmp;
- tmp = head;
- if(nodeNum > tmp->creatureNum)
- return;
- if(nodeNum == 1)
- {
- frontTmp = head;
- head = frontTmp->right;
- free(frontTmp);
- }
- else
- {
- oldTmp = tmp;
- for(int counter = 2; counter <= nodeNum; counter++)
- {
- oldTmp = tmp;
- tmp = tmp->right;
- }
- oldTmp->right = tmp->right;
- free(tmp);
- }
- }
- void CreatureCaretaker::exchangeSortPow(int givenPow[], int givenLife[], string givenName[], int size)
- {
- int counter1, counter2;
- for(counter1 = 0; counter1 < size - 1; counter1++)
- {
- for(counter2 = counter1 + 1; counter2 < size; counter2++)
- {
- if(givenPow[counter1] > givenPow[counter2])
- {
- swap(&givenPow[counter1], &givenPow[counter2]);
- swap(&givenLife[counter1], &givenLife[counter2]);
- swapName(&givenName[counter1], &givenName[counter2]);
- }
- }
- }
- }
- void CreatureCaretaker::exchangeSortLife(int givenPow[], int givenLife[], string givenName[], int size)
- {
- int counter1, counter2;
- for(counter1 = 0; counter1 < size - 1; counter1++)
- {
- for(counter2 = counter1 + 1; counter2 < size; counter2++)
- {
- if(givenLife[counter1] > givenLife[counter2])
- {
- swap(&givenPow[counter1], &givenPow[counter2]);
- swap(&givenLife[counter1], &givenLife[counter2]);
- swapName(&givenName[counter1], &givenName[counter2]);
- }
- }
- }
- }
- void CreatureCaretaker::showPow()
- {
- exchangeSortPow(listSortPow, listSortLife, listSortName, creatureNum);
- int counter;
- counter = 1;
- while(counter < creatureNum)
- {
- cout << "Creature Number - " << counter << endl;
- cout << "Name - " << listSortName[counter] << endl;
- cout << "Power - " << listSortPow[counter] << endl;
- cout << "Life Points - " << listSortLife[counter] << endl << endl;
- counter++;
- }
- }
- void CreatureCaretaker::showLife()
- {
- exchangeSortLife(listSortPow, listSortLife, listSortName, creatureNum);
- int count;
- int counter = creatureNum - 1;
- for(count = 1; counter > 0; count++)
- {
- cout << "Creature Number - " << count << endl;
- cout << "Name - " << listSortName[counter] << endl;
- cout << "Power - " << listSortPow[counter] << endl;
- cout << "Life Points - " << listSortLife[counter] << endl << endl;
- counter--;
- }
- }
- int main()
- {
- CreatureCaretaker *head;
- int selectNumber;
- int creaturePow = 10;
- int creatureLife = 11;
- int creatureSlot = 10;
- string creatureName = "asd asd";
- cout << "Welcome to the Creature Caretaker!" << endl;
- cout << "What would you like to do?" << endl << endl;
- cout << "1 - Add a creature" << endl;
- cout << "2 - Remove a creature" << endl;
- cout << "3 - Show game creatures" << endl;
- cout << "4 - Sort creatures by power" << endl;
- cout << "5 - Sort creatures by life points" << endl;
- cout << "6 - Exit the Program" << endl;
- cout << "\nEnter chosen option: ";
- cin >> selectNumber;
- if (selectNumber == '1')
- {
- cout << "\nAdding a creature in now." << endl;
- cout << "\nEnter creature name as text." << endl;
- cin >> creatureName;
- cout << "\nEnter card power as number." << endl;
- cin >> creaturePow;
- cout << "\nEnter card life points as number." << endl;
- cin >> creatureLife;
- if((creaturePow >= 1 && creaturePow <= 20) && (creatureLife >= 1 && creatureLife <= 20))
- {
- ooo.addCreature(creaturePow, creatureLife, creatureName);
- }
- else
- {
- cout << endl << "Invalid Input!" << endl;
- }
- }
- /*ooo.addCreature(1, 12, "a");
- /*ooo.addCreature(2, 32, "b");
- ooo.addCreature(3, 67, "c");
- ooo.addCreature(4, 43, "d");
- ooo.addCreature(5, 14, "e");
- ooo.addCreature(6, 11, "f");
- ooo.addCreature(7, 12, "g");
- ooo.addCreature(8, 13, "h");
- ooo.addCreature(9, 14, "i");
- ooo.addCreature(10, 11, "j");*/
- ooo.showCreature();
- cout << "Ascending Order (Power)" << endl;
- ooo.showPow();
- cout << "Descending Order (Life)" << endl;
- ooo.showLife();
- getch();
- }
Add Comment
Please, Sign In to add comment