Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Continuous Mode (-r) to Run Train Continuously #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions sl.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int ACCIDENT = 0;
int LOGO = 0;
int FLY = 0;
int C51 = 0;
int CONTINUOUS = 0; // New variable to indicate continuous mode

int my_mvaddstr(int y, int x, char *str)
{
Expand All @@ -75,6 +76,7 @@ void option(char *str)
case 'F': FLY = 1; break;
case 'l': LOGO = 1; break;
case 'c': C51 = 1; break;
case 'r': CONTINUOUS = 1; break; // Handle -r option
default: break;
}
}
Expand All @@ -83,6 +85,7 @@ void option(char *str)
int main(int argc, char *argv[])
{
int x, i;
int ch = 0; // Variable to store user input, initialized to 0

for (i = 1; i < argc; ++i) {
if (*argv[i] == '-') {
Expand All @@ -97,27 +100,33 @@ int main(int argc, char *argv[])
leaveok(stdscr, TRUE);
scrollok(stdscr, FALSE);

for (x = COLS - 1; ; --x) {
if (LOGO == 1) {
if (add_sl(x) == ERR) break;
do {
for (x = COLS - 1; x >= -80; --x) { // Loop the train from right to left
if (LOGO == 1) {
if (add_sl(x) == ERR) break;
}
else if (C51 == 1) {
if (add_C51(x) == ERR) break;
}
else {
if (add_D51(x) == ERR) break;
}
ch = getch(); // Get user input
if (ch == 'q') { // Check if 'q' is pressed
CONTINUOUS = 0; // Set CONTINUOUS to 0 to stop the loop
break;
}
refresh();
usleep(40000);
}
else if (C51 == 1) {
if (add_C51(x) == ERR) break;
}
else {
if (add_D51(x) == ERR) break;
}
getch();
refresh();
usleep(40000);
}
} while (CONTINUOUS); // Repeat the loop if in continuous mode

mvcur(0, COLS - 1, LINES - 1, 0);
endwin();

return 0;
}


int add_sl(int x)
{
static char *sl[LOGOPATTERNS][LOGOHEIGHT + 1]
Expand Down