// Country6a.h // This will hold the class definitions for countries // Copyright (c) 1998 Forest J. Handford ///////////////////////////////////////////////////// #ifndef Country6a_h #define Country6a_h #include #include #define TRUE 1 #define FALSE 0 int Total = 1; // A global count of the total players int AddArmies = 5; // A global count of the number of armies to win after a kill class CCountries { class CPlayer { friend CCountries; private: CPlayer *Link; CPlayer *Previous; int Armies; int Money; int Territory; int Technology; int UpgradeCost; char Name[15]; // This will check for to many territories void CountryLoss() { if(Armies < Territory) { cout<<"Sorry "< 0) { Money -= 1; Territory += 1; cout<<"You now have "<>YorN; } // If they are out of money tell them and exit else { cout<<"You are out of money!"<= UpgradeCost) { Money -= UpgradeCost; UpgradeCost *= 2; Technology += 1; cout<<"You now have "<>YorN; } } // This will sell land back /////////////////////////// void Shrink() { char YorN = 'y'; while(tolower(YorN) == 'y') { if(Territory > 0) { Money += 1; Territory -= 1; cout<<"You now have "<>YorN; } else { cout<<"You are out of money!"<>Exit; } } //The destructor that deletes any nodes on the queue //////////////////////////////////////////////////// ~CCountries() { CPlayer *Current; //The current node to delete CPlayer *Next; //The next node to delete Current = Front; //start Current in the front //Until the list is empty delete the nodes while(Current!=0) { Next = Current->Link; //setup the next node delete Current; //delete the current node Current = Next; //prepare for the next loop run } } // This will let the player attack ////////////////////////////////// bool Attack() { char Exit = 'Y'; CPlayer *Victim; char VictimName[15]; // This will hold the victim's name bool Flag; // True or flase value bool DeathFlag = FALSE; // True or false value bool Win = FALSE; while (toupper(Exit) == 'Y') { Victim = Front; Flag = FALSE; cout<<"What Player do you want to attack? "; cin>>VictimName; if ( strcmp(VictimName,Front->Name) == 0) { cout<<"If you want to fight your self be my guest!"<Link != 0) Victim = Victim->Link; else { Flag = FALSE; break; } if (strcmp(VictimName,Victim->Name) == 0) { Flag = TRUE; break; } } if (Flag == FALSE) { cout<<"No such player, Try again."<Armies - 1 - (Victim->Armies * Victim->Technology / 5); VictimArmies = Victim->Armies - 1 - (Front->Armies * Front->Technology / 5); Front->Armies = AttackerArmies; Victim->Armies = VictimArmies; if(Victim->Armies < 1) { Win = Dead(Victim); End(); DeathFlag = TRUE; if(Front->Armies > 1) { Front->Armies += AddArmies; AddArmies *= 2; cout<Name<<" you now have "<Armies<<" armies for your kill." <Armies += AddArmies; AddArmies *= 2; cout<Name<<" you now have "<Armies<<" armies for your kill." <Armies < 1) { Win = Dead(Front); End(); if(DeathFlag == FALSE) { Victim->Armies += AddArmies; AddArmies *= 2; cout<Name<<" you now have "<Armies<<" armies for your kill." <CountryLoss(); Front->CountryLoss(); cout<Name<<" now has "<Armies<<" armies."<Name<<" now has "<Armies<<" armies."<Name<<", Would you like to attack again ((Y)es or (N)o)? "; cin>>YorN; } } if(End() == FALSE) { cout<<"Would you like to attack another Player ((Y)es or (N)o)? "; cin>>Exit; } else break; } return (TRUE); // Flag success } //Inserts a Player at the rear ///////////////////////////// void Enqueue(CPlayer Player) { CPlayer *Ptr; //Make a Ptr for the new node Ptr = new CPlayer; // create a queuenode and point to it with Ptr *Ptr = Player; Ptr->Link = 0; //start the pointer at 0 Ptr->Previous = Rear; //point to the previous player //If the node isn't empty set the last link to point to the new node if (Front != 0) Rear->Link = Ptr; //else make the Front point to it. else Front = Ptr; //Make the rear point to the new node Rear = Ptr; } //Delete the first player and return the data ///////////////////////////////////////////// CPlayer Dequeue() { CPlayer Player; //the return value CPlayer *Ptr; //Will point to the first node //If there are nodes delete the first one if (Front != 0) { Ptr = Front; //Have the Pointer aim at the Front Player = *Ptr; //Copy the player Front = Ptr->Link; //Make Front point to the next node in line delete Ptr; //delete the node Front->Previous = 0; // set to 0 if (Front==0) //If the list is empty make the rear point to 0 Rear = 0; } //else print an error else cout<<"Hey man, there aren't any Players here!"<Name<<" You are the Winner!!!!!" <Name<<" you are dead!"<Previous != 0) { Current = Victim->Previous; Current->Link = Victim->Link; } else // else change the rear { Front = Victim->Link; } // Check to make sure it is not the last entry if(Victim->Link != 0) { Current = Victim->Link; Current->Previous = Victim->Previous; } else // else change the Rear { Rear = Victim->Previous; } delete Victim; return (FALSE); } // This adds a player void AddPlayer(int Total) { CPlayer *Ptr; //Make a Ptr for the new node Ptr = new CPlayer; // create a queuenode and point to it with Ptr Ptr->Armies = 5; Ptr->Money = 5; Ptr->Territory = 5; Ptr->Technology = 1; Ptr->UpgradeCost = 5; cout<<"Player "<>Ptr->Name; Ptr->Link = 0; //start the pointer at 0 //If the node isn't empty, set the last link to point to the new node if (Front != 0) { Ptr->Previous = Rear; Rear->Link = Ptr; } //else make the Front point to it. else { Ptr->Previous = 0; Front = Ptr; } //Make the rear point to the new node Rear = Ptr; } }; #endif