Digital rain assignement

 Digital Rain Assignment

Introduction

This article is link to the assignment to create a code in c++. The code will create a digital rain. It became famous with the movie The Matrix:



Explanations

I used a multifile structure with 1 main.cpp, 1 header file and 1 cpp file. This structure is the standard structure to use if you include classes in your code.

I call a unique class in my main.cpp that will execute an infinite loop. The header file contains the declaration of the class, where I also declare the functions and the elements in my class. And then I code all the functions and the class in the cpp file.


This is the main.cpp calling the class Matrix to create a unique object.



In the header file I created 3 random functions that give a random behaviour to my code, and a display function. The array was added because I thought the project around an array of 100x1. Each column would have had an address in this array that would guaranty to not overwrite on the columns.




In the cpp file I coded the functions and the class elements:
3 random functions that will make the code more random, choose a random column, choose a second column and choose a random character to print.


The display function is given 2 random numbers that will be the columns to display the characters and a flag to display 1 or 2 columns of characters (it is adding some random display). This is made to make this function reusable instead of having 2 functions for 2 different cases.

This is the main piece of code and also de default constructor. It contains the main code with the while(1) loop to run it indefinitely. It is also using the other functions to display the columns of characters. In my strategy, it is printing a first character and then all the others of the column. This loops run indefinitely with random addresses for the column, and make the "rain" itself. But for more consistency, I added an extra function to randomly double the column with the previous functions.




Difficulties

I couldn't implement my first idea that was working from an array. The array would have been like an address log to manage the printing of the columns of characters. My problem was that I was not able to find a way to code a "static printing": printing the drops one by one next to each other.

I had an idea to solve that, but I already uploaded my code, so it's too late. I could have had created a big array and print it for each character that I add to this array.

Conclusion

My main mistake as been to stay focus on one technic and not try other ideas. I had to develop 3 different versions, and I didn't even solve my problem. I am not sure, but the "Big array" technic would have given me a better control on the printing and would have solved my problem. Another difficulty has been, at the beginning, to implement my idea in the different files. The file structure was a key and took time to get the good one. The final result is not exactly what I expected, I spent too much time trying to solve my problem in the same way rather than move backward to have a global point of view on the situation. This assignment gave me experience in problem-solving and time management.

Commentaires