Advertisement
davsank

Untitled

Apr 29th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.20 KB | None | 0 0
  1. #include "Team.h"
  2. #include "Defender.h"
  3. #include "Goalkeeper.h"
  4. #include "Striker.h"
  5. #include <iostream>
  6. #include <assert.h>
  7. using namespace std;
  8.  
  9. bool isNameAvailable(string name,Rabbid **players,int size)
  10. {
  11.     for (int i=0;i<size;i++)
  12.     {
  13.         if(name.compare(players[i]->getName()))
  14.             return false;
  15.     }
  16.     return true;
  17. }
  18.  
  19. Rabbid** addPlayer(Rabbid **players,int size)
  20. {
  21.     int playerType,buildType,reaction,kick,tackle;
  22.     string name;
  23.     Rabbid **temp= new Rabbid*[size];
  24.     assert(temp!=NULL);
  25.     for (int i=0;i<size;i++)
  26.     {
  27.         temp[i]=players[i];
  28.     }
  29.     players = new Rabbid*[size+1];
  30.     assert(players!=NULL);
  31.     for (int i=0;i<size;i++)
  32.     {
  33.         players[i]=temp[i];
  34.     }
  35.     for (int i=0;i<size;i++)
  36.     {
  37.         delete temp[i];
  38.     }
  39.     delete []temp;
  40.     do
  41.     {
  42.         system("cls");
  43.         cout<<"Please select the type of player you want to create:"<<endl<<"1)\tGoalkeeper"<<endl<<"2)\tStriker"<<endl<<"3) \tDefender"<<endl;
  44.         cin>>playerType;
  45.     }while(!(playerType==1 || playerType==2 ||playerType==3));
  46.     switch (playerType)
  47.     {
  48.     case 1:
  49.         do
  50.         {
  51.             cout<<"Would you like to build a random Goalkeeper (0) or set his name and reaction yourself (1)?"<<endl;
  52.             cin>>buildType;
  53.         }while (!(buildType==0 || buildType==1));
  54.         switch (buildType)
  55.         {
  56.         case 0:
  57.             players[size]=new Goalkeeper();
  58.             assert(players[size]!=NULL);
  59.             break;
  60.         case 1:
  61.             do
  62.             {
  63.                 cout<<"Please enter the name of the Goalkeeper you would like to create:"<<endl;
  64.                 cin>>name;
  65.             }while (!(isNameAvailable(name,players,size)));
  66.             cout<<"Please enter the reaction for the Goalkeeper you would like to create:"<<endl;
  67.             cin>>reaction;
  68.             players[size]=new Goalkeeper(name,reaction);
  69.             assert(players[size]!=NULL);
  70.             break;
  71.         }
  72.         break;
  73.     case 2:
  74.         do
  75.         {
  76.             cout<<"Would you like to build a random Striker (0) or set his name and kick yourself (1)?"<<endl;
  77.             cin>>buildType;
  78.         }while (!(buildType==0 || buildType==1));
  79.         switch (buildType)
  80.         {
  81.         case 0:
  82.             players[size]=new Striker();
  83.             assert(players[size]!=NULL);
  84.             break;
  85.         case 1:
  86.             do
  87.             {
  88.                 cout<<"Please enter the name of the Striker you would like to create:"<<endl;
  89.                 cin>>name;
  90.             }while (!(isNameAvailable(name,players,size)));
  91.             cout<<"Please enter the kick for the Striker you would like to create:"<<endl;
  92.             cin>>kick;
  93.             players[size]=new Striker(name,kick);
  94.             assert(players[size]!=NULL);
  95.             break;
  96.         }
  97.         break;
  98.     case 3:
  99.         do
  100.         {
  101.             cout<<"Would you like to build a random Defender (0) or set his name and tackle yourself (1)?"<<endl;
  102.             cin>>buildType;
  103.         }while (!(buildType==0 || buildType==1));
  104.         switch (buildType)
  105.         {
  106.         case 0:
  107.             players[size]=new Defender();
  108.             assert(players[size]!=NULL);
  109.             break;
  110.         case 1:
  111.             do
  112.             {
  113.                 cout<<"Please enter the name of the Defender you would like to create:"<<endl;
  114.                 cin>>name;
  115.             }while (!(isNameAvailable(name,players,size)));
  116.             cout<<"Please enter the tackle for the Defender you would like to create:"<<endl;
  117.             cin>>tackle;
  118.             players[size]=new Striker(name,tackle);
  119.             assert(players[size]!=NULL);
  120.             break;
  121.         }
  122.         break;
  123.     }
  124.  
  125.  
  126.     return players;
  127. }
  128.  
  129. int main (void)
  130. {
  131.     srand(time(NULL));
  132.     int numOfPlayers=0;
  133.     Rabbid **players= new Rabbid* [0];
  134.     assert(players!=NULL);
  135.    
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement