Advertisement
TripleAlpha

Untitled

Dec 2nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4.  
  5. using namespace std;
  6.  
  7. const int SIZE = 10;
  8.  
  9. //prints header
  10. void printHeader() {
  11. cout << "\n+------------------------------------------------------+\n"
  12. << "| Computer Science and Engineering |\n"
  13. << "| CSCE 1030 - Computer Science I |\n"
  14. << "| [redacted] |\n"
  15. << "+--------------------------------------------------------+\n" << endl;
  16. }
  17.  
  18. //prints description of game
  19. void printIntro() {
  20. printf("\n%35s\n\n", "Welcome to Anthony's Battle!");
  21. printf("----------------------------------------------------------\n");
  22. cout << "Anthony the ant has decided that he wants to take over all\n"
  23. << "the adjacent ant colonies with his army of ants from colo-\n"
  24. << "ny \'A\'. To do this, Anthony's army will attempt to capture\n"
  25. << "ants from columns \'B\' through \'J\', with at least 1 ant re-\n"
  26. << "maining when the column \'J\' ant colony is found. Each col-\n"
  27. << "umn's ant colony is identified with a - in one of the rows\n"
  28. << "for that column, while patrols are represented by integers\n"
  29. << "between 1 and 10 for the number of ants in that particular\n"
  30. << "patrol. On the way to column \'J\' if Anthony's army encoun-\n"
  31. << "ters a patrol, the number in the patrol is subtracted from\n"
  32. << "Anthony's army total. Once his army finds the colony, how-\n"
  33. << "ever, any patrols not confronted will be added to his army\n"
  34. << "total. If Anthony makes really good decisions, then he can\n"
  35. << "take over all of the adjacent ant colonies; otherwise, his\n"
  36. << "army will be defeated!" << endl;
  37. printf("----------------------------------------------------------\n");
  38. }
  39.  
  40. //initializes colonies matrix
  41. void populateColonies(int** colonies, int patrolSize) {
  42. int colonyPos; //will hold random int representing position of colony
  43. //iterates through each column in the colonies matrix
  44. for(int col = 0; col < SIZE; col++) {
  45. //iterates through each position in each column
  46. for(int colPos = 0; colPos < SIZE; colPos++) {
  47. //assigns each patrol's size a to a number between 1 and 10 (inc.)
  48. patrolSize = rand() % 10 + 1;
  49. colonies[col][colPos] = patrolSize;
  50. }
  51. //randomly determines position of colony and sets to 0
  52. colonyPos = rand() % 10;
  53. colonies[col][colonyPos] = 0;
  54. }
  55. }
  56.  
  57. int main () {
  58. //prints header and introduction by calling corresponding functions
  59. printHeader();
  60. printIntro();
  61.  
  62. //dynamic colonies matrix declared
  63. int** colonies = new int*[SIZE];
  64. //arrays declared iteratively within matrix to eliminate null pointers
  65. for(int col = 0; col < SIZE; col++) {
  66. colonies[col] = new int[SIZE];
  67. }
  68.  
  69. int patrolSize; //int to hold number of ants in each cell
  70. //passes colony matrix by pointer to populate it
  71. populateColonies(&colonies, patrolSize);
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement