In this you taught you how to work with real-time keyboard input and control the rolling display on the console screen on the fly. This key feature sets the stage for designing a viable game in C. Before we move forward, though, we’d have to restructure our code into a more manageable form.
The attached sample solution for Assignment 2 is a monolithic implementation consisting of only one main() function. We’d need to refactor this flat-structured code into the standard “Game Loop”
structure as illustrated in the figure below:
Refactoring – Improving Code Maintainability without changing the functionalities of the program
Task 1 – Encapsulate all the initialization-related code into Initialize() function.
Task 2 – Encapsulate all the keyboard input related code into Input() function.
Task 3 – Encapsulate all the animation status related code into Update() function.
Task 4 - Encapsulate all the animation drawing related code into Draw() function.
Task 5 – Use enum to create a series of flags to track UP, DOWN, LEFT, RIGHT, STOP, and EXIT states of the animation. Example enumeration code is provided below:
enum myEnum {TYPEA, TYPEB, TYPEC}; //Declaring enumeration type
enum myEnum typeTracker; //Declaring enumeration variable
Through the refactoring process you may have to move certain variables to the global scope and define additional constants.
This is programming practice exercise. You can paste the solution of the above problem in the below comment section.
If you have any query or need solution of the above task then also comments or send your requirement details at:
realcode4you@gmail.com