/* Dackral Phillips CSE 3700 September 27, 2K */ /******************************************************************************************************** The game of life part 2: For this assignment, the original game of life is used with the rules utilized in the first assignment. In addition, some added functionality is included whic ls allowing the user to change the initial state of the board, add an additional 6 nodes to the board, and delete up to 6 nodes on the board. ********************************************************************************************************/ #include #include class Node; class Cell { public: Cell() { nwptr = NULL; nptr = NULL; neptr = NULL; wptr = NULL; eptr = NULL; swptr = NULL; sptr = NULL; septr = NULL; }; ~Cell() { delete nwptr; delete nptr; delete neptr; delete wptr; delete eptr; delete swptr; delete sptr; delete septr; }; void SetNextState() { int counter = 0; if (nwptr->GetState() == 1) { counter += 1; } if (nptr->GetState() == 1) { counter += 1; } if (neptr->GetState() == 1) { counter += 1; } if (wptr->GetState() == 1) { counter += 1; } if (eptr->GetState() == 1) { counter += 1; } if (swptr->GetState() == 1) { counter += 1; } if (sptr->GetState() == 1) { counter += 1; } if (septr->GetState() == 1) { counter += 1; } }; void UpdateState() { state = nextState; }; int GetState() { return state; }; void PrintState() { cout << state; }; private: int state, nextState; //pointers Node *nwptr; Node *nptr; Node *neprt; Node *wptr; Node *eptr; Node *swptr; Node *sptr; Node *septr; }; class Node { public: Node() { east = NULL; south = NULL; }; ~Node() { delete east; delete south; }; void SetCoords(int Row, int Col) { row = Row; col = Col; }; Node* Next() { if (east == NULL) { return south; } else { return east; } }; void SetNext(Node* nextPtr, char direction) { switch (direction) { case 'e': east = nextPtr; break; case 's': south = nextPtr; break; } }; void RecPrint() { cell.PrintState(); if (next != NULL) { next->RecPrint(); } }; private: int row, col; // keeps track of the postion in the list. Useful for keeping track of neighbors Cell cell; Node* east; Node* south; }; class List { public: List() { items = 0; first = NULL; }; ~List() { Node* temp; while (first != NULL) { temp = first; first = first->Next(); delete temp; temp = NULL; } }; void AddNode() { Node* temp; items++; temp = new Node(); temp->SetNext(first); first = temp; }; void PrintList() { Node* temp = first; while (temp != NULL) { temp->print(); temp = temp->Next(); } }; void RecPrintList() { first->RecPrint(); }; private: int items; Node* first; }; int main() { int ans = 0; while (ans != 5) { cout << endl << endl << "Game of life Master Menu" << endl << "________________________" << endl << endl << "1) Add a node to the board" << endl << "2) Delete a node from the board" << endl << "3) Change the initial board state" << endl << "4) Print the board state" << endl << "5) Exit the program" << endl << endl << "Please enter your choice: "; cin >> ans; cout << endl; switch (ans) { case 1: createNode(); break; case 2: deleteNode(); break; case 3: editBoard(); break; case 4: printMenu(); break; case 5: break; default: cout << endl << "I'm sorry, but I didn't understand your keystroke. Please enter an integer from 1 to 5" << endl; break; } } return 0; } void createNode() { } void deleteNode() { } void editBoard() { } void printMenu() { int ans = 0; while ((ans != 1)) cout << endl << endl << "Print Menu" << endl << "__________" << endl << "1) Print the list iteratively" << endl << "2) Print the list recursively" << endl << endl << "Please enter your choice: "; cin >> ans; cout << endl; switch (ans) { case 1: PrintList(); break; case 2: RecPrintList(); break; default: cout << endl << "I'm sorry, but I didn't understand your keystroke. Please enter 1 or 2" << endl; break; } }