Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- const int SIZE = 10;
- //prints header
- void printHeader() {
- cout << "\n+------------------------------------------------------+\n"
- << "| Computer Science and Engineering |\n"
- << "| CSCE 1030 - Computer Science I |\n"
- << "| [redacted] |\n"
- << "+--------------------------------------------------------+\n" << endl;
- }
- //prints description of game
- void printIntro() {
- printf("\n%35s\n\n", "Welcome to Anthony's Battle!");
- printf("----------------------------------------------------------\n");
- cout << "Anthony the ant has decided that he wants to take over all\n"
- << "the adjacent ant colonies with his army of ants from colo-\n"
- << "ny \'A\'. To do this, Anthony's army will attempt to capture\n"
- << "ants from columns \'B\' through \'J\', with at least 1 ant re-\n"
- << "maining when the column \'J\' ant colony is found. Each col-\n"
- << "umn's ant colony is identified with a - in one of the rows\n"
- << "for that column, while patrols are represented by integers\n"
- << "between 1 and 10 for the number of ants in that particular\n"
- << "patrol. On the way to column \'J\' if Anthony's army encoun-\n"
- << "ters a patrol, the number in the patrol is subtracted from\n"
- << "Anthony's army total. Once his army finds the colony, how-\n"
- << "ever, any patrols not confronted will be added to his army\n"
- << "total. If Anthony makes really good decisions, then he can\n"
- << "take over all of the adjacent ant colonies; otherwise, his\n"
- << "army will be defeated!" << endl;
- printf("----------------------------------------------------------\n");
- }
- //initializes colonies matrix
- void populateColonies(int** colonies, int patrolSize) {
- int colonyPos; //will hold random int representing position of colony
- //iterates through each column in the colonies matrix
- for(int col = 0; col < SIZE; col++) {
- //iterates through each position in each column
- for(int colPos = 0; colPos < SIZE; colPos++) {
- //assigns each patrol's size a to a number between 1 and 10 (inc.)
- patrolSize = rand() % 10 + 1;
- colonies[col][colPos] = patrolSize;
- }
- //randomly determines position of colony and sets to 0
- colonyPos = rand() % 10;
- colonies[col][colonyPos] = 0;
- }
- }
- int main () {
- //prints header and introduction by calling corresponding functions
- printHeader();
- printIntro();
- //dynamic colonies matrix declared
- int** colonies = new int*[SIZE];
- //arrays declared iteratively within matrix to eliminate null pointers
- for(int col = 0; col < SIZE; col++) {
- colonies[col] = new int[SIZE];
- }
- int patrolSize; //int to hold number of ants in each cell
- //passes colony matrix by pointer to populate it
- populateColonies(&colonies, patrolSize);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement