reformatted the more confusing part of the code. added pause functionality

This commit is contained in:
Solomon W. 2020-03-16 11:37:06 -04:00
parent 3ca6fc88ad
commit 3b174eb92d
2 changed files with 67 additions and 39 deletions

Binary file not shown.

View File

@ -8,6 +8,14 @@
#define UP (1) #define UP (1)
#define DOWN (2) #define DOWN (2)
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
int main(int argc, char **argv) { int main(int argc, char **argv) {
WINDOW term = *initscr(); WINDOW term = *initscr();
start_color(); start_color();
@ -60,86 +68,106 @@ int main(int argc, char **argv) {
int get = getch(); int get = getch();
while(get!='q') { while(get!='q') {
if(get=='s') { if(get=='s') {
pause=1; pause=TRUE;
} }
int xPos = rand()%maxX;//get random x position for the stream int xPos = rand()%maxX;//get random x position for the stream
if(cascade[xPos]==ERR) {//make sure the stream is set to active if(cascade[xPos]==ERR) {//make sure the stream is set to active
cascade[xPos]=0; cascade[xPos]=0;
} }
for(int i=0; i<maxX; i++) {//move the streams down //---------swich to weird format-----------
if(cascade[i]!=ERR) { for(int i=0; i<maxX; i++)
{//move the streams up/down
if(!pause)
{
if(cascade[i]!=ERR)
{
tail[i] = cascade[i]-tailLen[i]; tail[i] = cascade[i]-tailLen[i];
if(cascade[i]==maxY) {//check if the position is at the bottom of the screen if(cascade[i]==maxY)
{//check if the position is at the bottom of the screen
cascade[i]=ERR;//set the position to ERR if it is at the bottom cascade[i]=ERR;//set the position to ERR if it is at the bottom
} else { }
if(rand()%10==1) {//check if the stream will jump else
if(!(jmpTail[i]<=maxY)) { {
if(dir==DOWN) { if(rand()%10==1)
{//check if the stream will jump
if(!(jmpTail[i]<=maxY))
{
if(dir==DOWN)
{
cascade[i]=cascade[i]+rand()%8; cascade[i]=cascade[i]+rand()%8;
jmpTail[i]=cascade[i]-tailLen[i]; jmpTail[i]=cascade[i]-tailLen[i];
} else { }
else
{
cascade[i]=cascade[i]-rand()%8; cascade[i]=cascade[i]-rand()%8;
jmpTail[i]=cascade[i]+tailLen[i]; jmpTail[i]=cascade[i]+tailLen[i];
} }
} }
} else { }
if(!pause) { else
if(dir==DOWN) { {
if(dir==DOWN)
{
cascade[i]++;//increase the position cascade[i]++;//increase the position
} else { }
else
{
cascade[i]--; cascade[i]--;
} }
} }
} }
} }
} }
//-------Back to normal format-------
if(tail[i]!=maxY) {//keep increasing the tail untill it is at the bottom if(tail[i]!=maxY) {//keep increasing the tail untill it is at the bottom
if(!pause) {
if(dir==DOWN) { if(dir==DOWN) {
tail[i]++; tail[i]++;
} else { } else {
tail[i]--; tail[i]--;
} }
} }
}
if(jmpTail[i]==maxY || jmpTail==0) { if(jmpTail[i]==maxY || jmpTail==0) {
jmpTail[i]=OK; jmpTail[i]=OK;
} else { } else {
if(!pause) {
if(dir==DOWN) { if(dir==DOWN) {
jmpTail[i]++; jmpTail[i]++;
} else { } else {
jmpTail[i]--; jmpTail[i]--;
} }
} }
}
mvaddch(jmpTail[i],i,' '); mvaddch(jmpTail[i],i,' ');
mvaddch(tail[i],i,' '); mvaddch(tail[i],i,' ');
mvaddch(cascade[i],i,(rand()%/*57*/57)+65); mvaddch(cascade[i],i,(rand()%60)+65);
} }
refresh(); refresh();
if(!pause) { if(!pause) {
get=getch(); timeout(time);
} else { } else {
timeout(-1); timeout(-1);
switch (getch()) { get=getch();
switch (get) {
case 's': case 's':
pause=!pause; pause=!pause;
break; break;
case 'r': case 'r':
pause=1; pause=FALSE;
if(dir=DOWN) { if(dir=DOWN) {
dir=UP; dir=UP;
} else { } else {
if(dir=UP) { if(dir=UP) {
dir=DOWN; dir=DOWN;
} }
} }
break; break;
case 'q':
get='q';
break;
} }
timeout(time); timeout(time);
} }
if(get!='q') {
get=getch();
}
} }
endwin(); endwin();
return 0; return 0;