This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void saveMaze(string fileName) | |
| { | |
| cout << "Saving - Enter File Name" << endl; | |
| cin >> fileName; | |
| output.open(fileName+".txt"); | |
| // Iterates through the maze saving each character to a file | |
| for (int y = 0; y < kMazeRowsY; y++) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Defines a circle | |
| Circle::Circle(int gScreenWidth, int gScreenHeight, int speed) | |
| { | |
| moveCircleX = rand() % gScreenWidth / 2 + gScreenWidth / 4; | |
| moveCircleY = rand() % gScreenHeight / 2 + gScreenWidth / 4; | |
| radius = rand() % 20 + 5; | |
| xDir = rand() % speed - 5; | |
| yDir = rand() % speed - 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // precondition: list is pointed to by head; last node, if any, points to null | |
| // postcondition: nth node is deleted if it exists. A 1-based index is used | |
| public boolean delete(int n) | |
| { | |
| if (head == null) | |
| return false; | |
| if (n == 1) | |
| { | |
| ListNode temp = head; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // postcondition: Adds a node storing obj after position index in list. | |
| public boolean addAfterPos(int obj, int index) | |
| { | |
| if (head == null) | |
| return false; | |
| if (index < 1) | |
| return false; | |
| D_ListNode newNode = new D_ListNode(obj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // postcondition: Adds a node storing obj at front of this list. | |
| public void addFirst(int obj) | |
| { | |
| ListNode newNode = new ListNode(obj); | |
| if (head.next == head) | |
| { | |
| newNode.next = head; | |
| head.next = newNode; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "InputManager.h" | |
| void InputManager::AddListener(IReceivesInput* listener) | |
| { | |
| m_listeners.push_back(listener); | |
| } | |
| void InputManager::ClearListeners() | |
| { | |
| m_listeners.clear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void AISnake::Update(GameData& m_gameData) | |
| { | |
| FindClosestFood(m_gameData); | |
| // Adds all directions to vector to determine the best one | |
| std::vector<std::pair<float, Direction>> bestDirections; | |
| bestDirections.push_back({ CalculateRewardForDirection(Direction::Up, m_gameData), Direction::Up }); | |
| bestDirections.push_back({ CalculateRewardForDirection(Direction::Left, m_gameData), Direction::Left }); | |
| bestDirections.push_back({ CalculateRewardForDirection(Direction::Down, m_gameData), Direction::Down }); | |
| bestDirections.push_back({ CalculateRewardForDirection(Direction::Right, m_gameData), Direction::Right }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <SFML/Graphics.hpp> | |
| #include <iostream> | |
| template <typename T> | |
| class Node | |
| { | |
| public: | |
| Node(T newData) : data{ newData } {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ensures the input is within bounds, in a free column, or input is numerical | |
| bool validInput = false; | |
| while (!validInput) | |
| { | |
| std::cin >> chosenColumn; | |
| if (chosenColumn < 1 || chosenColumn > 7 || std::cin.fail()) | |
| { | |
| std::cin.clear(); | |
| std::cin.ignore(10000, '\n'); // Resets the cin, either by ignoring 10,000 characters or when a new line is hit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks for a winner by looping through the whole board | |
| bool checkForWinner(const std::vector<std::vector<char>>& board, char playerPiece) | |
| { | |
| // Horizontal Win | |
| for (int r = 0; r < rows; r++) | |
| { | |
| for (int c = 0; c <= cols - 4; c++) // Don't need to check last few columns, as they're impossible to win from. As we're checking from left to right - would exit bounds | |
| { | |
| if (board[r][c] == playerPiece && | |
| board[r][c + 1] == playerPiece && |
NewerOlder