I’m trying to write a small program to make a sort of animation using ncurses. I have an external file, a header file, and a main file so far. Header file contains a class with a constructor that is initialized in my cpp file, a void function that is used in my cpp file, and two private member functions to hold a char and a time in microseconds from an input file. I’ve so far gotten my main file to pass the file to my cpp file AND have to constructor extract and assign the char and time to my private data members. The rest will all happen in my void function...this is where I’m hitting several walls and problems.
I want to fill the screen randomly with an X with a certain fore and background color using a bool 2D array. True (open) means that an X can be written to that spot. After the X is written there, the spots value changed to False (closed/filled) and it continues to look for True spots. After the ENTIRE screen in filled, it will just loop through all color pairs available in ncurses until I hit ctrl+c.
I’ve tried a lot of things and most had failed or partially worked or compiled and done nothing. I’m new to this all, especially ncurses.
How can I use ncurses “getyx” command and put those coordinates into a 2D array to check each element? Or should I use a different way to get screen coordinates and put them into my array?
I wanted to use “int rand()” function to generate a random number/array element to check and fill or not fill. I’ve been told its very archaic and maybe not the best. How would I make sure it checks every space? I’m confused about what number to % the coordinated of the screen with.
Should I use a while, do while, or for loop to type the X and then mark my spot as False? I’ve tried most of those to usually wrong results. And a bit confused on the logic.
In a test program...when I turned on my first color pair, wrote out “Hello”, tried to get the program to “sleep” for 5 seconds, and then change only the color….it did nothing for 5 seconds then showed me “Hello” with the first color pair on, not the second one. Why? Can you not change to color only, you must write a string or character again?
This is what I tried….didn’t work….
To change colors and run through the whole thing again….a few thing I could do? I thought I’d exit the first loop once the screen is full and the program can’t find any space, then go into the second loop and do it again. I’d have a nested loop so that once all my smaller loops have been done, it goes all the way back to the top and does it again. Would this work?
In general, I’m having some confusion with ncurses and some of the looping logic I guess. I’ve asked friends who are full blown experienced programmers, devs, software people….most haven’t even heard of the ncurses library. I’m trying to practice with C++ and make in interesting for myself. Perhaps I should try it without color?
Are there some good tutorials on ncurses? Any other examples or resources I should look at for similar programs? I’ve done tic tac toe before, but this is the entire screen…not just a limited 2D array “box”.
Any feedback, hints, advice, etc. would be greatly appreciated!