Beispiel #1
0
void
interrupt(void)
{
	char    line[81];	/* a place to store data already on screen */
	int     loop;		/* counter */
	int     x, y;		/* coordinates on screen */
	int     ch;		/* input */
	unsigned savealarm;	/* to save alarm value */

	savealarm = alarm(0);	/* turn off any alarms */

	getyx(stdscr, y, x);	/* save cursor location */

	for (loop = 0; loop < 80; ++loop) {	/* save line on screen */
		move(4, loop);
		line[loop] = inch();
	}
	line[80] = '\0';	/* nul terminate */

	if (Player.p_status == S_INBATTLE || Player.p_status == S_MONSTER)
		/* in midst of fighting */
	{
		mvaddstr(4, 0, "Quitting now will automatically kill your character.  Still want to ? ");
		ch = getanswer("NY", FALSE);
		if (ch == 'Y')
			death("Bailing out");
	} else {
		mvaddstr(4, 0, "Do you really want to quit ? ");
		ch = getanswer("NY", FALSE);
		if (ch == 'Y')
			leavegame();
	}

	mvaddstr(4, 0, line);	/* restore data on screen */
	move(y, x);		/* restore cursor */
	refresh();

	alarm(savealarm);	/* restore alarm */
}
Beispiel #2
0
void init()
{
	initscr();
	cbreak();
	noecho();
	curs_set(0);
	srand(time(0));

	dir_x = 1;
	dir_y = 0;
	
	head = (snake_tp)malloc(sizeof(snake_t));		//分配节点
	tail = (snake_tp)malloc(sizeof(snake_t));
	head->next = tail;
	tail->prev = head;
	head->x = rand() % WINDOW_RIGHT + 1;
	head->y = rand() % WINDOW_BOTTOM + 1;
	tail->x = head->x - dir_x;
	tail->y = head->y - dir_y;

	int temX, temY;
	do												//为食物分配坐标
	{
		temX = rand() % WINDOW_RIGHT;
		temY = rand() % WINDOW_BOTTOM;
		move(temX, temY);
	}while ( (char)inch() == CHAR_SNAKE);
	food.x = temX;
	food.y = temY;

	move(food.x, food.y);							//绘制食物
	addch(CHAR_FOOD);
	refresh();
	
	signal(SIGALRM, sig_alrm);						//将时钟信号和自定义函数进行关联
	set_ticker(100);								//设置定时器,0.5m后执行自定义函数

}
Beispiel #3
0
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i;
	usch *cp;

	goto run;
	for (;;) {
		ch = inch();
xloop:		if (ch == -1)
			return;
#ifdef PCC_DEBUG
		if (dflag>1)
			printf("fastscan ch %d (%c)\n", ch, ch > 31 ? ch : '@');
#endif
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case EBLOCK:
		case WARN:
		case CONC:
			error("bad char passed");
			break;

		case '/': /* Comments */
			if ((ch = inch()) == '/') {
cppcmt:				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				eatcmnt();
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '\n': /* newlines, for pp directives */
			i = ifiles->escln + 1;
			ifiles->lineno += i;
			ifiles->escln = 0;
			while (i-- > 0)
				putch('\n');
run:			for(;;) {
				ch = inch();
				if (ch == '/') {
					ch = inch();
					if (ch == '/')
						goto cppcmt;
					if (ch == '*') {
						eatcmnt();
						continue;
					}
					unch(ch);
					ch = '/';
				}
				if (ch != ' ' && ch != '\t')
					break;
				PUTCH(ch);
			}
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = inch();
				if (ch == ':') {
					ppdir();
					continue;
				}
				unch(ch);
				ch = '%';
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = inch()) != '\"') {
				if (ch == '\\') {
					PUTCH('\\');
					ch = inch();
				}
				if (ch == '\n') {
					warning("unterminated string literal");
					goto xloop;
				}
				if (ch == -1)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = inch();
			if (ch < '0' || ch > '9')
				goto xloop;

			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
nxp:				PUTCH(ch);
				ch = inch();
				if (ch == -1)
					return;
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = inch();
					if (ch == '-' || ch == '+')
						goto nxp;
					if (ch == -1)
						return;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character constant */
con:			PUTCH(ch);
			if (tflag)
				break; /* character constants ignored */
			while ((ch = inch()) != '\'') {
				if (ch == '\\') {
					PUTCH('\\');
					ch = inch();
				}
				if (ch == '\n') {
					warning("unterminated character constant");
					goto xloop;
				}
				if (ch == -1)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = inch();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';

			/* FALLTHROUGH */
		default:
#ifdef PCC_DEBUG
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
#endif
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = inch();
			} while (ch != -1 && (spechr[ch] & C_ID));

			if (flslvl)
				goto xloop;

			yytext[i] = 0;
			unch(ch);

			cp = stringbuf;
			if ((nl = lookup(yytext, FIND)) && kfind(nl)) {
				putstr(stringbuf);
			} else
				putstr(yytext);
			stringbuf = cp;

			break;
		}
	}
}
Beispiel #4
0
int
cinput(void)
{
	return inch();
}
Beispiel #5
0
int
sloscan(void)
{
	int ch;
	int yyp;

zagain:
	yyp = 0;
	ch = inch();
	yytext[yyp++] = (usch)ch;
	switch (ch) {
	case -1: /* EOF */
		return 0;

	case '\n': /* do not pass NL */
		unch(ch);
		yytext[yyp] = 0;
		return ch;

	case '\r': /* Ignore CR */
		goto zagain;

	case '0': case '1': case '2': case '3': case '4': case '5':
	case '6': case '7': case '8': case '9':
		/* reading a "pp-number" */
ppnum:		for (;;) {
			ch = inch();
			if (ch == -1)
				break;
			if ((spechr[ch] & C_EP)) {
				yytext[yyp++] = (usch)ch;
				ch = inch();
				if (ch == '-' || ch == '+') {
					yytext[yyp++] = (usch)ch;
				} else
					unch(ch);
				continue;
			}
			if ((spechr[ch] & C_ID) || ch == '.') {
				yytext[yyp++] = (usch)ch;
				continue;
			}
			break;
		}
		unch(ch);
		yytext[yyp] = 0;
		return NUMBER;

	case '\'':
chlit:
		for (;;) {
			if ((ch = inch()) == '\\') {
				if (chkucn())
					continue;
				yytext[yyp++] = (usch)ch;
				ch = inch();
			} else if (ch == '\'')
				break;
			if (ch == -1 || ch == '\n') {
				/* not a constant */
				while (yyp > 1)
					unch(yytext[--yyp]);
				goto any;
			}
			yytext[yyp++] = (usch)ch;
		}
		yytext[yyp++] = (usch)'\'';
		yytext[yyp] = 0;
		return NUMBER;

	case ' ':
	case '\t':
		while ((ch = inch()) == ' ' || ch == '\t')
			yytext[yyp++] = (usch)ch;
		unch(ch);
		yytext[yyp] = 0;
		return WSPACE;

	case '/':
		if ((ch = inch()) == '/') {	/* C++ comment */
			do {
				yytext[yyp++] = (usch)ch;
				ch = inch();
			} while (ch != -1 && ch != '\n');
			yytext[yyp] = 0;
			unch(ch);
			goto zagain;
		} else if (ch == '*') {		/* C comment */
			int c, wrn;
			extern int readmac;

			if (Cflag && !flslvl && readmac) {
				unch(ch);
				yytext[yyp] = 0;
				return CMNT;
			}

			wrn = 0;
		more:	while ((c = inch()) != '*') {
				if (c == -1)
					return 0;
				if (c == '\n')
					putch(c), ifiles->lineno++;
				else if (c == EBLOCK) {
					(void)inch();
					(void)inch();
				} else if (c == WARN)
					wrn = 1;
			}
			if ((c = inch()) == -1)
				return 0;
			if (c != '/') {
				unch(c);
				goto more;
			}
			if (!tflag && !Cflag && !flslvl)
				unch(' ');
			if (wrn)
				unch(WARN);
			goto zagain;
		}
		unch(ch);
		goto any;

	case '.':
		if ((ch = inch()) == -1)
			goto any;
		if ((spechr[ch] & C_DIGIT)) {
			yytext[yyp++] = (usch)ch;
			goto ppnum;
		}
		unch(ch);
		goto any;

	case '\"':
		if (tflag && defining)
			goto any;
	strng:
		for (;;) {
			if ((ch = inch()) == '\\') {
				if (chkucn())
					continue;
				yytext[yyp++] = (usch)ch;
				ch = inch();
			} else if (ch == '\"') {
				yytext[yyp++] = (usch)ch;
				break;
			}
			if (ch == -1 || ch == '\n') {
				warning("unterminated string");
				unch(ch);
				break;	// XXX the STRING does not have a closing quote
			}
			yytext[yyp++] = (usch)ch;
		}
		yytext[yyp] = 0;
		return STRING;

	case '\\':
		if (chkucn()) {
			--yyp;
			goto ident;
		}
		goto any;

	case 'L':
		if ((ch = inch()) == '\"' && !tflag) {
			yytext[yyp++] = (usch)ch;
			goto strng;
		} else if (ch == '\'' && !tflag) {
			yytext[yyp++] = (usch)ch;
			goto chlit;
		}
		unch(ch);
		/* FALLTHROUGH */

	/* Yetch, all identifiers */
	case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
	case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
	case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
	case 's': case 't': case 'u': case 'v': case 'w': case 'x':
	case 'y': case 'z':
	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
	case 'G': case 'H': case 'I': case 'J': case 'K':
	case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
	case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
	case 'Y': case 'Z':
	case '_': /* {L}({L}|{D})* */

	ident:
		for (;;) { /* get chars */
			if ((ch = inch()) == -1)
				break;
			if (ch == '\\') {
				if (chkucn())
					continue;
				unch('\\');
				break;
			}
			if ((spechr[ch] & C_ID) == 0) {
				unch(ch);
				break;
			}
			yytext[yyp++] = (usch)ch;
		}
		yytext[yyp] = 0; /* need already string */
		return IDENT;

	default:
		if ((ch & 0x80))
			goto ident;

	any:
		yytext[yyp] = 0;
		return yytext[0];
	} /* endcase */

	/* NOTREACHED */
}
Beispiel #6
0
int
main(int argc, char *argv[])
{
	int optc;
	int option_differences = 0,
	    option_differences_cumulative = 0,
			option_exec = 0,
			option_beep = 0,
        option_errexit = 0,
	    option_help = 0, option_version = 0;
	double interval = 2;
	char *command;
	char **command_argv;
	int command_length = 0;	/* not including final \0 */
    watch_usec_t next_loop; /* next loop time in us, used for precise time
                               keeping only */
	int pipefd[2];
	int status;
	pid_t child;

	setlocale(LC_ALL, "");
	progname = argv[0];

	while ((optc = getopt_long(argc, argv, "+bed::hn:pvtx", longopts, (int *) 0))
	       != EOF) {
		switch (optc) {
		case 'b':
			option_beep = 1;
			break;
		case 'd':
			option_differences = 1;
			if (optarg)
				option_differences_cumulative = 1;
			break;
        case 'e':
            option_errexit = 1;
            break;
		case 'h':
			option_help = 1;
			break;
		case 't':
			show_title = 0;
			break;
		case 'x':
		  option_exec = 1;
			break;
		case 'n':
			{
				char *str;
				interval = strtod(optarg, &str);
				if (!*optarg || *str)
					do_usage();
				if(interval < 0.1)
					interval = 0.1;
				if(interval > ~0u/1000000)
					interval = ~0u/1000000;
			}
			break;
		case 'p':
			precise_timekeeping = 1;
			break;
		case 'v':
			option_version = 1;
			break;
		default:
			do_usage();
			break;
		}
	}

	if (option_version) {
		fprintf(stderr, "%s\n", VERSION);
		if (!option_help)
			exit(0);
	}

	if (option_help) {
		fprintf(stderr, usage, progname);
		fputs("  -b, --beep\t\t\t\tbeep if the command has a non-zero exit\n", stderr);
		fputs("  -d, --differences[=cumulative]\thighlight changes between updates\n", stderr);
		fputs("\t\t(cumulative means highlighting is cumulative)\n", stderr);
		fputs("  -e, --errexit\t\t\t\texit watch if the command has a non-zero exit\n", stderr);
		fputs("  -h, --help\t\t\t\tprint a summary of the options\n", stderr);
		fputs("  -n, --interval=<seconds>\t\tseconds to wait between updates\n", stderr);
        fputs("  -p, --precise\t\t\t\tprecise timing, ignore command run time\n", stderr);
		fputs("  -v, --version\t\t\t\tprint the version number\n", stderr);
		fputs("  -t, --no-title\t\t\tturns off showing the header\n", stderr);
		fputs("  -x, --exec\t\t\t\tpass command to exec instead of sh\n", stderr);
		exit(0);
	}

	if (optind >= argc)
		do_usage();

	command_argv=&(argv[optind]); /* save for later */

	command = strdup(argv[optind++]);
	command_length = strlen(command);
	for (; optind < argc; optind++) {
		char *endp;
		int s = strlen(argv[optind]);
		command = realloc(command, command_length + s + 2);	/* space and \0 */
		endp = command + command_length;
		*endp = ' ';
		memcpy(endp + 1, argv[optind], s);
		command_length += 1 + s;	/* space then string length */
		command[command_length] = '\0';
	}

	get_terminal_size();

	/* Catch keyboard interrupts so we can put tty back in a sane state.  */
	signal(SIGINT, die);
	signal(SIGTERM, die);
	signal(SIGHUP, die);
	signal(SIGWINCH, winch_handler);

	/* Set up tty for curses use.  */
	curses_started = 1;
	initscr();
	nonl();
	noecho();
	cbreak();

	if (precise_timekeeping)
		next_loop = get_time_usec();

	for (;;) {
		time_t t = time(NULL);
		char *ts = ctime(&t);
		int tsl = strlen(ts);
		char *header;
		FILE *p;
		int x, y;
		int oldeolseen = 1;

		if (screen_size_changed) {
			get_terminal_size();
			resizeterm(height, width);
			clear();
			/* redrawwin(stdscr); */
			screen_size_changed = 0;
			first_screen = 1;
		}

		if (show_title) {
			// left justify interval and command,
			// right justify time, clipping all to fit window width
			asprintf(&header, "Every %.1fs: %.*s",
				interval, min(width - 1, command_length), command);
			mvaddstr(0, 0, header);
			if (strlen(header) > (size_t) (width - tsl - 1))
				mvaddstr(0, width - tsl - 4, "...  ");
			mvaddstr(0, width - tsl + 1, ts);
			free(header);
		}

		/* allocate pipes */
		if (pipe(pipefd)<0) {
		  perror("pipe");
			do_exit(7);
	  }

		/* flush stdout and stderr, since we're about to do fd stuff */
		fflush(stdout);
		fflush(stderr);

		/* fork to prepare to run command */
		child=fork();

		if (child<0) { /* fork error */
		  perror("fork");
			do_exit(2);
		} else if (child==0) { /* in child */
			close (pipefd[0]); /* child doesn't need read side of pipe */
			close (1); /* prepare to replace stdout with pipe */
			if (dup2 (pipefd[1], 1)<0) { /* replace stdout with write side of pipe */
			  perror("dup2");
				exit(3);
			}
			dup2(1, 2); /* stderr should default to stdout */

			if (option_exec) { /* pass command to exec instead of system */
			  if (execvp(command_argv[0], command_argv)==-1) {
				  perror("exec");
				  exit(4);
				}
			} else {
		    status=system(command); /* watch manpage promises sh quoting */

			  /* propagate command exit status as child exit status */
			  if (!WIFEXITED(status)) { /* child exits nonzero if command does */
			    exit(1);
			  } else {
			    exit(WEXITSTATUS(status));
		    }
			}

		}

		/* otherwise, we're in parent */
		close(pipefd[1]); /* close write side of pipe */
		if ((p=fdopen(pipefd[0], "r"))==NULL) {
		  perror("fdopen");
			do_exit(5);
		}


		for (y = show_title; y < height; y++) {
			int eolseen = 0, tabpending = 0;
			for (x = 0; x < width; x++) {
				int c = ' ';
				int attr = 0;

				if (!eolseen) {
					/* if there is a tab pending, just spit spaces until the
					   next stop instead of reading characters */
					if (!tabpending)
						do
							c = getc(p);
						while (c != EOF && !isprint(c)
						       && c != '\n'
						       && c != '\t');
					if (c == '\n')
						if (!oldeolseen && x == 0) {
							x = -1;
							continue;
						} else
							eolseen = 1;
					else if (c == '\t')
						tabpending = 1;
					if (c == EOF || c == '\n' || c == '\t')
						c = ' ';
					if (tabpending && (((x + 1) % 8) == 0))
						tabpending = 0;
				}
				move(y, x);
				if (option_differences) {
					chtype oldch = inch();
					unsigned char oldc = oldch & A_CHARTEXT;
					attr = !first_screen
					    && ((char)c != oldc
						||
						(option_differences_cumulative
						 && (oldch & A_ATTRIBUTES)));
				}
				if (attr)
					standout();
				addch(c);
				if (attr)
					standend();
			}
			oldeolseen = eolseen;
		}

		fclose(p);

		/* harvest child process and get status, propagated from command */
		if (waitpid(child, &status, 0)<0) {
		  perror("waitpid");
			do_exit(8);
		};

		/* if child process exited in error, beep if option_beep is set */
		if ((!WIFEXITED(status) || WEXITSTATUS(status))) {
          if (option_beep) beep();
          if (option_errexit) do_exit(8);
		}

		first_screen = 0;
		refresh();
		if (precise_timekeeping) {
			watch_usec_t cur_time = get_time_usec();
			next_loop += USECS_PER_SEC*interval;
			if (cur_time < next_loop)
				usleep(next_loop - cur_time);
		} else
		usleep(interval * 1000000);
	}

	endwin();

	return 0;
}
Beispiel #7
0
int main() {
    int ch, x, y;
    char fname[80];
    FILE *fp;
    bool entering_metadata = false;
    char to_delete;
    char existing;

    initscr();
    cbreak();
    noecho();

    nonl();
    intrflush(stdscr, false);
    keypad(stdscr, true);             /* Enable arrow keys.                  */

    getmaxyx(stdscr, ROW, COL);

    move(0,0);
    start_color();                    /* Yay colors!                         */
    init_pair(1, COLOR_RED, COLOR_WHITE);
    // attron(COLOR_PAIR(1));
    // printw("rows: %d, columns: %d\n", ROW, COL);

    char** contents = new_string_table(ROW, COL);

    char* blank_row = (char*)malloc(COL*sizeof(char));
    for (int i=0; i<COL; i++) {
        blank_row[i] = ' ';
    }


    getyx(stdscr, y, x);


    while (true) {
        ch = getch();
        switch (ch) {
            case KEY_LEFT:
                x -= 1;
                break;
            case KEY_RIGHT:
                x += 1;
                break;
            case KEY_UP:
                y -= 1;
                break;
            case KEY_DOWN:
                y += 1;
                break;
            case BACKSPACE:  /* KEY_BACKSPACE wasn't working. */
                --x;
                move(y, x);
                to_delete = inch();
                attron(COLOR_PAIR(1));
                addch(to_delete);
                attroff(COLOR_PAIR(1));
                break;
            case KEY_DC:
                //attron(COLOR_PAIR(1));
                addch('X');
                //attroff(COLOR_PAIR(1));
                break;
            case ESC:
                ch = getch();
                switch (ch) {
                    case ESC:          /* Press ESC twice to exit.           */
                        endwin();
                        free(blank_row);
                        delete_string_table(contents, ROW);
                        return 0;
                        break;
                    case 'w':
                        move(ROW-1, 0);
                        printw("Enter a file name (up to 80 characters): ");
                        echo();
                        if (getnstr(fname, 80) == ERR) {
                            perror("Something went wrong reading the file name you gave.");
                        }
                        noecho();
                        fp = fopen(fname, "w");
                        if (fp == NULL) {
                            perror("Cannot open file");
                        }
                        contents_to_file(contents, fp, ROW, COL);
                        fclose(fp);
                        move(ROW-1, 0);
                        printw(blank_row);
                        break;
                    default:
                        break;
                }
                break;
            default:
                existing = contents[y][x];
                //printw("%d", (int)existing);
                if (existing == '\0') {
                    addch(ch);
                    ensureposition(&y, &x);
                    contents[y][x] = ch;
                    ++x;
                }
                //getyx(stdscr, y, x);
                break;
        }
        ensureposition(&y, &x);
        move(y, x);
    }
}
Beispiel #8
0
/*
 * play_level:
 *	Let the player play the current level
 */
void
play_level(void)
{
	COORD	*cp;

	move(My_pos.y, My_pos.x);
	addch(PLAYER);
	refresh();
	for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) {
		if (cp->y < 0)
			continue;
		move(cp->y, cp->x);
		addch(ROBOT);
	}
	refresh();
#ifdef DEBUG
	standout();
	move(Min.y, Min.x);
	addch(inch());
	move(Max.y, Max.x);
	addch(inch());
	standend();
#endif /* DEBUG */
	flushinp();
	while (!Dead && Num_robots > 0) {
		move(My_pos.y, My_pos.x);
		if (!jumping())
			refresh();
		get_move();
		if (Field[My_pos.y][My_pos.x] != 0)
			Dead = TRUE;
		if (!Dead)
			move_robots();
		if (Was_bonus) {
			move(Y_PROMPT, X_PROMPT);
			clrtoeol();
			move(Y_PROMPT + 1, X_PROMPT);
			clrtoeol();
			Was_bonus = FALSE;
		}
	}

	/*
	 * if the player didn't die, add on the possible bonuses
	 */

	if (!Dead) {
		Was_bonus = FALSE;

		if (Level == Start_level && Start_level > 1) {
			move(Y_PROMPT, X_PROMPT);
			printw("Advance bonus: %d", S_BONUS);
			refresh();
			add_score(S_BONUS);
			Was_bonus = TRUE;
		}

		if (Wait_bonus != 0) {
			if (!Was_bonus)
				move(Y_PROMPT, X_PROMPT);
			else
				move(Y_PROMPT + 1, X_PROMPT);
			printw("Wait bonus: %d", Wait_bonus);
			refresh();
			add_score(Wait_bonus);
			Was_bonus = TRUE;
		}
	}
}
void objtransport()
{
	inch();
    int tx,ty;
	
	tx= objx ;
	ty= objy ;
	
	if(tx==0 && ty == 1)
    return ; 
	
	
	if (ori==1&&ty==0)
	{ c ='U';
	  turn(c);
	}
	else if (ori==1)
	{ c ='L';
	  turn(c);
	}
	else if (ori==3)
    {  c ='R';
	  turn(c);
	}
    else if (ori==2)
	{ char c ='U';
	  turn(c);
	}

while(1)	
 {	
   linefollower();
   if(f2==0)
   {  
		if(ori==3)
		tx--;
		else if(ori==4)
		ty--;
		else if(ori==2)
		ty++;
		else if(ori==1)
		tx++;
		f2=1;
	}
	inch();
   if(tx==0 && ty == 1)
   break; 
   
   
   else if (ty==0&&tx>0&&ori==4)
   turn('L');
   
   else if(ty==1&&ori==4)
   turn('L');
   
   else if(tx==0&&ori==3)
   turn('L');  
   
   else if (tx>=0||ty>=1||ty<1)
   turn('S');
   
  }
 // inch();	
  if(ori==2)
  {
	turn('R');
	inch();
  }
  if(ori==4)
  {
	turn('L');
	inch();
  }

}
int main(void)
{
   DDRD |=(1<<4)|(1<<5); //initialising PORTS of motors
   DDRD |=(1<<6)|(1<<7);
   DDRB |=(1<<0)|(1<<1); // lifting motor initialization
	 
   DDRC |=(1<<3);// initialising port of buzzer .
   DDRD |=(1<<1); 

   PORTB |= (1<<5); // activating pullups for switch
	 
	    lcd_init();
        PORTC|= (1<<1);  // initialising lcd
        lcd_gotoxy1(0);
	    

	//init();             //adc initialization    
	
   while(1)
  {
    
   c1=0;  
	lcd_gotoxy1(0);
	lcd_string("x:");
	lcd_showvalue1(currx);
	lcd_string("y:");
	lcd_showvalue1(curry);
	lcd_string("o:");
	lcd_showvalue1(ori);
	
   linefollower();
   
   
   update();
   
   takecareofobject();
     
   c1 = decide();
       
	   inch();
	   
	   
    turn(c1);
	
	
	lcd_gotoxy2(0);
	
	lcd_char(c1);
	lcd_string("ox : ");
	lcd_showvalue1(objx);
	lcd_string("oy : ");
	lcd_showvalue1(objy);
	
	//if((PINA & (1<<1))||(PINA & (1<<5)))
	//f2=0;
	if(c1=='N')
	break;
   
   }

}
Beispiel #11
0
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i;

	goto run;
	for (;;) {
		ch = NXTCH();
xloop:		if (ch == -1)
			return;
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case '/': /* Comments */
			if ((ch = inch()) == '/') {
				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				if (Cflag) { PUTCH('/'); PUTCH('*'); }
				for (;;) {
					ch = inch();
					if (ch == '\n') {
						ifiles->lineno++;
						PUTCH('\n');
					}
					if (ch == -1)
						return;
					if (ch == '*') {
						ch = inch();
						if (ch == '/') {
							if (Cflag) {
								PUTCH('*');
								PUTCH('/');
							} else
								PUTCH(' ');
							break;
						}
						unch(ch);
						ch = '*';
					}
					if (Cflag) PUTCH(ch);
				}
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '?':  /* trigraphs */
			if ((ch = chktg()))
				goto xloop;
			PUTCH('?');
			break;

		case '\\':
			if ((ch = NXTCH()) == '\n') {
				ifiles->lineno++;
				continue;
			} else {
				PUTCH('\\');
			}
			goto xloop;

		case '\n': /* newlines, for pp directives */
			ifiles->lineno++;
			do {
				PUTCH(ch);
run:				ch = NXTCH();
			} while (ch == ' ' || ch == '\t');
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = NXTCH();
				if (ch == ':') {
					ppdir();
					continue;
				} else {
					unch(ch);
					ch = '%';
				}
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = inch()) != '\"') {
				PUTCH(ch);
				if (ch == '\\') {
					ch = inch();
					PUTCH(ch);
				}
				if (ch < 0)
					return;
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = NXTCH();
			if (ch < '0' || ch > '9')
				goto xloop;
			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
				PUTCH(ch);
				ch = NXTCH();
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = NXTCH();
					if (ch == '-' || ch == '+')
						continue;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character literal */
con:			PUTCH(ch);
			if (tflag)
				continue; /* character constants ignored */
			while ((ch = NXTCH()) != '\'') {
				PUTCH(ch);
				if (ch == '\\') {
					ch = NXTCH();
					PUTCH(ch);
				} else if (ch < 0)
					return;
				else if (ch == '\n')
					goto xloop;
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = NXTCH();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';
			/* FALLTHROUGH */
		default:
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
			if (flslvl) {
				while (spechr[ch] & C_ID)
					ch = NXTCH();
				goto xloop;
			}
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch != '\n') {
						unch('\n');
						ch = '\\';
					} else {
						ifiles->lineno++;
						ch = NXTCH();
					}
				}
				if (ch < 0)
					return;
			} while (spechr[ch] & C_ID);
			yytext[i] = 0;
			unch(ch);
			if ((nl = lookup((usch *)yytext, FIND)) != 0) {
				usch *op = stringbuf;
				putstr(gotident(nl));
				stringbuf = op;
			} else
				putstr((usch *)yytext);
			break;
		}
	}
}
Beispiel #12
0
int
cinput()
{
	return inch();
}
Beispiel #13
0
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i = 0;
	int nnl = 0;
	usch *cp;

	goto run;
	for (;;) {
		ch = NXTCH();
xloop:		if (ch == -1)
			return;
#ifdef PCC_DEBUG
		if (dflag>1)
			printf("fastscan ch %d (%c)\n", ch, ch > 31 ? ch : '@');
#endif
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case EBLOCK:
		case WARN:
		case CONC:
			error("bad char passed");
			break;

		case '/': /* Comments */
			if ((ch = inch()) == '/') {
cppcmt:				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				if (eatcmnt())
					return;
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '?':  /* trigraphs */
			if ((ch = chktg()))
				goto xloop;
			PUTCH('?');
			break;

		case '\\':
			if ((ch = NXTCH()) == '\n') {
				ifiles->lineno++;
				continue;
			} else {
				PUTCH('\\');
			}
			goto xloop;

		case '\n': /* newlines, for pp directives */
			while (nnl > 0) { PUTCH('\n'); nnl--; }
run2:			ifiles->lineno++;
			do {
				PUTCH(ch);
run:				ch = NXTCH();
				if (ch == '/') {
					ch = NXTCH();
					if (ch == '/')
						goto cppcmt;
					if (ch == '*') {
						if (eatcmnt())
							return;
						goto run;
					} 
					unch(ch);
					ch = '/';
				}
			} while (ch == ' ' || ch == '\t');
			if (ch == '\\') {
				ch = NXTCH();
				if (ch == '\n')
					goto run2;
				unch(ch);
				ch = '\\';
			}
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = NXTCH();
				if (ch == ':') {
					ppdir();
					continue;
				} else {
					unch(ch);
					ch = '%';
				}
			} else if (ch == '?') {
				if ((ch = chktg()) == '#') {
					ppdir();
					continue;
				} else if (ch == 0) 
					ch = '?';
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = NXTCH()) != '\"') {
				if (ch == '\n')
					goto xloop;
				if (ch == '\\') {
					if ((ch = NXTCH()) != '\n') {
						PUTCH('\\');
						PUTCH(ch);
					} else
						nnl++;
					continue;
                                }
				if (ch < 0)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = NXTCH();
			if (ch < '0' || ch > '9')
				goto xloop;
			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
				PUTCH(ch);
nxt:				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch == '\n') {
						goto nxt;
					} else {
						unch(ch);
						ch = '\\';
					}
				}
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = NXTCH();
					if (ch == '-' || ch == '+')
						continue;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character literal */
con:			PUTCH(ch);
			if (tflag)
				continue; /* character constants ignored */
			while ((ch = NXTCH()) != '\'') {
				if (ch == '\n')
					goto xloop;
				if (ch == '\\') {
					if ((ch = NXTCH()) != '\n') {
						PUTCH('\\');
						PUTCH(ch);
					} else
						nnl++;
					continue;
				}
				if (ch < 0)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = NXTCH();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';
			/* FALLTHROUGH */
		default:
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
			if (flslvl) {
				while (spechr[ch] & C_ID)
					ch = NXTCH();
				goto xloop;
			}
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch != '\n') {
						unch(ch);
						ch = '\\';
					} else {
						putch('\n');
						ifiles->lineno++;
						ch = NXTCH();
					}
				}
				if (ch < 0)
					return;
			} while (spechr[ch] & C_ID);

			yytext[i] = 0;
			unch(ch);

			cp = stringbuf;
			if ((nl = lookup((usch *)yytext, FIND)) && kfind(nl)) {
				putstr(stringbuf);
			} else
				putstr((usch *)yytext);
			stringbuf = cp;

			break;
		}
	}
}
struct Monster* drawLevel(char** roomDetails, struct Coordinates *roomCoordinates, struct HeroStatistics *heroStats, struct AllTheDoors * doorsInfo, int numberOfDetails, int currentRoom, struct Monster *monsterInfo, struct furthestRightWall *rightWall)
{
    char characterCheck;
    char holdingString[3];
    char * roomHeightString;
    char * roomWidthString;
    int roomHeightInt;
    int roomWidthInt;
    int tempItemX;
    int tempItemY;
    int i;
    int j;
    int k;
    int randomNumberOne;
    int twoDigitX;
    
    
    roomHeightInt = 0;
    roomWidthInt = 0;
    tempItemX = 0;
    tempItemY = 0;
    i = 0;
    j = 0;
    k = 0;
    randomNumberOne = 0;
    twoDigitX = 0;
    
    if (currentRoom == 0)
    {
        monsterInfo[0].numberOfMonsters = 0;
    }
                    
    
    /*Loops once for each piece of information of the current line of the file*/
    while (i <= numberOfDetails)
    {
        tempItemX = 0;
        tempItemY = 0;
        /*Taking the Room height/width which I know will come first*/
        if (i == 0)
        {
            /*Parsing the height/width based on the X between them*/
            roomHeightString = strtok(roomDetails[0], "X");
            roomWidthString = strtok(NULL, "\0");
            
            /*Converting the height/width from strings to intergers.
             * Also if the height/width is less than 3, it will make it 
             * 3 so the room wont be just walls.*/
            
            roomHeightInt = atoi(roomHeightString);
            if (roomHeightInt < 3)
            roomHeightInt = 3;
            
            roomWidthInt = atoi(roomWidthString);
            if (roomWidthInt < 3)
            roomWidthInt = 3;
            
            
            /*This length of the if statement is because the special cases of room placement.
             * Because of how the values are based off of one another, there is a special case 
             * for the: first and 2nd rooms. After that it depends wether the room is in the 1st or 2nd row of rooms.*/
             
             /*The if statement will calculate the x/y values for each of the 4 rooms. 
              * These values will later be used to print the rooms in the appropriate places and with
              * appropriate sizes.*/
            if (currentRoom == 0)
            {
                /*Clears what the menu function has written off the screen.*/
                clear();
                
                /*This number will be used to add a bit of random placement to the rooms.*/
                randomNumberOne = rand() % 5;
                randomNumberOne = randomNumberOne + 2;
                
                /*Because this room #1 I want it right below where I print information.*/
                roomCoordinates[currentRoom].origin[0] = 1;
                
                /*Simple way of saying the y value of the origin is randomNumberOne from the left side of the screen*/
                roomCoordinates[currentRoom].origin[1] = randomNumberOne;
                
                /*Basing the location of the 4 walls on the origin and the given hieght/width.*/
                roomCoordinates[currentRoom].topWallY = roomCoordinates[currentRoom].origin[0];
                roomCoordinates[currentRoom].bottomWallY = (roomCoordinates[currentRoom].origin[0] + roomHeightInt - 1);
                roomCoordinates[currentRoom].leftWallX = roomCoordinates[currentRoom].origin[1];
                roomCoordinates[currentRoom].rightWallX = (roomCoordinates[currentRoom].origin[1] + roomWidthInt - 1);
            }
            else if (currentRoom == 1)
            {
                /*See comments for currentRoom == 0*/
                
                
                randomNumberOne = rand() % 5;
                randomNumberOne = randomNumberOne + 2;
                
                roomCoordinates[currentRoom].origin[0] = roomCoordinates[0].bottomWallY + randomNumberOne;
                
                randomNumberOne = rand() % 5;
                randomNumberOne = randomNumberOne + 1;
                
                roomCoordinates[currentRoom].origin[1] = randomNumberOne;
                roomCoordinates[currentRoom].topWallY = roomCoordinates[currentRoom].origin[0];
                roomCoordinates[currentRoom].bottomWallY = (roomCoordinates[currentRoom].origin[0] + roomHeightInt - 1);
                roomCoordinates[currentRoom].leftWallX = roomCoordinates[currentRoom].origin[1];
                roomCoordinates[currentRoom].rightWallX = (roomCoordinates[currentRoom].origin[1] + roomWidthInt - 1);
            }
            else if ((currentRoom % 2) == 0)
            {
                /*Most of this is similair to above*/
                
                
                randomNumberOne = rand() % 5;
                randomNumberOne = randomNumberOne + 2;
                
                roomCoordinates[currentRoom].origin[0] = randomNumberOne + 1;
                
                /*The left wall of this room will be based off of the two rooms directly to its left.
                 * It will take the highest x value of the right walss of the rooms to its left.
                 * It then uses that value + a random number to determine the x value of this room's left wall.*/
                if (roomCoordinates[(currentRoom - 2)].rightWallX > roomCoordinates[(currentRoom - 1)].rightWallX)
                {
                    roomCoordinates[currentRoom].origin[1] = roomCoordinates[(currentRoom - 2)].rightWallX + randomNumberOne;
                }
                else
                {
                    roomCoordinates[currentRoom].origin[1] = roomCoordinates[(currentRoom - 1)].rightWallX + randomNumberOne;
                }
                
                
                roomCoordinates[currentRoom].topWallY = roomCoordinates[currentRoom].origin[0];
                roomCoordinates[currentRoom].bottomWallY = (roomCoordinates[currentRoom].origin[0] + roomHeightInt - 1);
                roomCoordinates[currentRoom].leftWallX = roomCoordinates[currentRoom].origin[1];
                roomCoordinates[currentRoom].rightWallX = (roomCoordinates[currentRoom].origin[1] + roomWidthInt - 1);
            }
            else if ((currentRoom % 2) == 1)
            {
                /*For the most part, see above comments*/
                
                
                randomNumberOne = rand() % 3;
                randomNumberOne = randomNumberOne + 2;
                
                roomCoordinates[currentRoom].origin[0] = roomCoordinates[(currentRoom - 1)].bottomWallY + randomNumberOne;
                
                /*Just changing the random number so the height/width arent based off the same number.*/
                randomNumberOne = rand() % 3;
                randomNumberOne = randomNumberOne + 1;
                
                /*This rooms left wall starting value is based off of the left wall value of the room above it*/
                roomCoordinates[currentRoom].origin[1] = roomCoordinates[(currentRoom - 1)].origin[1] + randomNumberOne;
                
                roomCoordinates[currentRoom].topWallY = roomCoordinates[currentRoom].origin[0];
                roomCoordinates[currentRoom].bottomWallY = (roomCoordinates[currentRoom].origin[0] + roomHeightInt - 1);
                roomCoordinates[currentRoom].leftWallX = roomCoordinates[currentRoom].origin[1];
                roomCoordinates[currentRoom].rightWallX = (roomCoordinates[currentRoom].origin[1] + roomWidthInt - 1);
            }
            
            /*First makes j = the y value of the top wall of the room*/
            j = roomCoordinates[currentRoom].origin[0];
            
            /*After having gotten the values of the four walls of the room from the above if statement, 
             * the program uses this information to properly place and print the rooms.*/
            
            /*The loop will run for the height of the room going from top to bottom.*/
            while (j <= roomCoordinates[currentRoom].bottomWallY)
            {
                /*Making the k value equal to the x value of the left wall of the room*/
                k = roomCoordinates[currentRoom].origin[1];
                
                /*This loop will go along the current height of the room (j) from the left to ride sides.
                 * Runs for the width of the room*/
                while (k <= roomCoordinates[currentRoom].rightWallX)
                {
                    /*If thecurrent y value of the line being printed is the top or bottom wall, it prints to top/bottom wall character.*/
                    if ((j == roomCoordinates[currentRoom].topWallY) || (j == roomCoordinates[currentRoom].bottomWallY))
                    {
                        mvprintw(j, k, "-");
                    }
                    /*Else if the current k value is the left or right wall, it prints the appropriate character.*/
                    else if ((k == roomCoordinates[currentRoom].rightWallX) || (k == roomCoordinates[currentRoom].leftWallX))
                    {
                        mvprintw(j, k, "|");
                    }
                    /*If not then it must be floor area and the appropriate symbol is printed*/
                    else
                    {
                        mvprintw(j, k, ".");
                    }
                    k++;
                }
                j++;
            }
            refresh();
        }
        /*Now that the "floor plan" of the room has been printed, I add on the 
         * doors/hero/things that are present in that room.*/
        else
        {
            /*roomDetails is an array of pointers. Each pointer is a piece of information
             * from the current line of the file.*/
             
             /*If the segment of information begins with a d, it must be a door needing to be placed.*/
            if (roomDetails[i][0] == 'd')
            {
                /*Because the value of where the door is could be a number that is 1/2 digits, had to account for both cases.*/
                
                /*If the null terminator is the 4th character, then the door posistion is a one digit number.*/
                if (roomDetails[i][3] == '\0')
                {
                    /*Taking the number from the pointer of the information and turning it into an int.*/
                    holdingString[0] = roomDetails[i][2];
                    holdingString[1] = '\0';
                    tempItemX = atoi(holdingString);
                }
                /*If the null terminator is the 5th character, then the door posistion is a two digit number.*/
                else if (roomDetails[i][4] == '\0')
                {
                    /*Taking the number from the pointer of the information and turning it into an int.*/
                    holdingString[0] = roomDetails[i][2];
                    holdingString[1] = roomDetails[i][2];
                    holdingString[2] = '\0';
                    tempItemX = atoi(holdingString);
                }
                
                /*This if statement makes use of the temporary number that is found above.
                 * Depending on which wall the door is in, it places the door tempItemX units
                 * away from the north/west wall*/
                if (roomDetails[i][1] == 'n')
                {
                    mvprintw(roomCoordinates[currentRoom].topWallY, (roomCoordinates[currentRoom].leftWallX + tempItemX), "+");
                }
                else if (roomDetails[i][1] == 'e')
                {
                    mvprintw((roomCoordinates[currentRoom].topWallY + tempItemX), roomCoordinates[currentRoom].rightWallX, "+");
                }
                else if (roomDetails[i][1] == 's')
                {
                    mvprintw(roomCoordinates[currentRoom].bottomWallY, (roomCoordinates[currentRoom].leftWallX + tempItemX), "+");
                }
                else if (roomDetails[i][1] == 'w')
                {
                    mvprintw((roomCoordinates[currentRoom].topWallY + tempItemX), roomCoordinates[currentRoom].leftWallX, "+");
                }
                
                /*Once we have moved to the the door character (+) into place, 
                 * I take the coordinates of the door and save it in a struct*/
                getyx(stdscr, (doorsInfo[currentRoom].doorY[doorsInfo[currentRoom].doorsInRoom]), (doorsInfo[currentRoom].doorX[doorsInfo[currentRoom].doorsInRoom]));
                
                /*Changing the coordinates of the doors because the cursor moves once you print something.*/
                doorsInfo[currentRoom].doorX[doorsInfo[currentRoom].doorsInRoom]--;
                doorsInfo[currentRoom].doorsInRoom++;
            }
            
            /*If the first character of the segment of the information is one of the "things"*/
            else if ((roomDetails[i][0] == 'g')||(roomDetails[i][0] == 'm')||(roomDetails[i][0] == 'p')||(roomDetails[i][0] == 's')||(roomDetails[i][0] == 'w') || (roomDetails[i][0] == 'h'))
            {
                twoDigitX = 0;
                
                /*As done in the above door part of the if statement,
                 * need to be able to take 1 or 2 digit numbers.*/
                 
                 
                 
                 /*Finds where the comma is and twoDigitX is equal to 
                  * number of digits the x value - 1*/
                if (roomDetails[i][2] == ',')
                {
                    holdingString[0] = roomDetails[i][1];
                    holdingString[1] = '\0';
                    tempItemY = atoi(holdingString);
                }
                else if (roomDetails[i][3] == ',')
                {
                    holdingString[0] = roomDetails[i][1];
                    holdingString[1] = roomDetails[i][2];
                    holdingString[2] = '\0';
                    tempItemY = atoi(holdingString);
                    twoDigitX = 1;
                }
                    
                /*Looks for the end of the string and uses that information to 
                 * expect either a one or two digit y value. Knows where to look
                 * for the null terminator based off of twoDigitX*/
                if (roomDetails[i][(4 + twoDigitX)] == '\0')
                {
                    holdingString[0] = roomDetails[i][(3 + twoDigitX)];
                    holdingString[1] = '\0';
                    tempItemX = atoi(holdingString);
                }
                /*Noticed a problem with things at the end of the line in the input file 
                 * so added in searching for the \n*/
                else if ((roomDetails[i][(5 + twoDigitX)] == '\0') || (roomDetails[i][(5 + twoDigitX)] == '\n'))
                {
                    holdingString[0] = roomDetails[i][(3 + twoDigitX)];
                    holdingString[1] = roomDetails[i][(4 + twoDigitX)];
                    holdingString[2] = '\0';
                    tempItemX = atoi(holdingString);
                }
                
                /*Now has the x/y values of the thing to be placed. 
                 * Changes it based on where the currentRoom is.*/
                tempItemX = tempItemX + roomCoordinates[currentRoom].origin[1];
                tempItemY = tempItemY + roomCoordinates[currentRoom].origin[0];
                
                /*If one of the values would place the item in the wall, 
                 * it moves the item away from the wall.*/
                if (tempItemX == roomCoordinates[currentRoom].leftWallX) 
                {
                    tempItemX++;
                }
                else if (tempItemX == roomCoordinates[currentRoom].rightWallX)
                {
                    tempItemX--;
                }
                
                if (tempItemY == roomCoordinates[currentRoom].topWallY) 
                {
                    tempItemY++;
                }
                else if (tempItemY == roomCoordinates[currentRoom].bottomWallY)
                {
                    tempItemY--;
                }
               
                
                /*Because the rogue character set is not just the input characters, 
                 * it changes what will be printed based on the character.*/
                if (roomDetails[i][0] == 's')
                {
                    roomDetails[i][0] = '%';
                }
                else if (roomDetails[i][0] == 'g')
                {
                    roomDetails[i][0] = '*';
                }
                else if (roomDetails[i][0] == 'p')
                {
                    roomDetails[i][0] = '!';
                }
                else if (roomDetails[i][0] == 'w')
                {
                    roomDetails[i][0] = ')';
                }
                
                /*Now printing the Item to the screen*/
                if (roomDetails[i][0] == 'h')
                {
                    mvprintw(tempItemY, tempItemX, "@");
                    
                    /*Saves the x/y of where the hero is being printed to. 
                     * Also saves which room it's printed to.*/
                    heroStats->currentX = tempItemX;
                    heroStats->currentY = tempItemY;
                    heroStats->currentRoom = currentRoom;
                }
                else if (roomDetails[i][0] == 'm')
                {
                        /*thing = monsterInfo[0].numberOfMonsters; 
                        thing++;
                    
                    mvprintw(0,0,"%d", thing);
                    getch();
                        monsterInfo = realloc(monsterInfo, sizeof(struct Monster )*(thing+2));
                        monsterInfo[0].numberOfMonsters = thing;
                    
                    if (doorsInfo == NULL)
                    {
                        mvprintw(0, 0, "out of memory: exiting upon keypress");
                        getch();
                        exit(1);
                    }*/
                    
                    monsterInfo[0].numberOfMonsters++;
                    monsterInfo = realloc(monsterInfo, sizeof(struct Monster )*(monsterInfo[0].numberOfMonsters+1));
                    
                    if (doorsInfo == NULL)
                    {
                        mvprintw(0, 0, "out of memory: exiting upon keypress");
                        getch();
                        exit(1);
                    }
                
    
                    randomNumberOne = rand() % 5;
                    randomNumberOne = randomNumberOne;
                    
                    monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].type = randomNumberOne;
                    
                    /*First checking to see if there is another item/thing in the spot about to be printed to.*/
                    move (tempItemY, tempItemX);
                    characterCheck = inch();
                    
                    /*Will only print if there is nothing in the spot*/
                    if (characterCheck == '.')
                    {
                        switch (randomNumberOne)
                        {
                            case BAT:
                                roomDetails[i][0] = 'B';
                                break;
                            case HOBGOBLIN:
                                roomDetails[i][0] = 'H';
                                break;
                            case SNAKE:
                                roomDetails[i][0] = 'S';
                                break;
                            case JACKAL:
                                roomDetails[i][0] = 'J';
                                break;
                            case KOBOLD:
                                roomDetails[i][0] = 'K';
                                break;
                            default:
                                break;
                            
                        }
                        mvprintw(tempItemY, tempItemX, "%c", roomDetails[i][0]);
                        
                        monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].posX = tempItemX;
                        monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].posY = tempItemY;
                        monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].lastTile = '.';
                        monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].oldX = tempItemX;
                        monsterInfo[(monsterInfo[0].numberOfMonsters - 1)].oldY = tempItemY;
                    }
                    
                }
                else
                {
                    /*First checking to see if there is another item/thing in the spot about to be printed to.*/
                    move (tempItemY, tempItemX);
                    characterCheck = inch();
                    
                    /*Will only print if there is nothing in the spot*/
                    if (characterCheck == '.')
                        mvprintw(tempItemY, tempItemX, "%c", roomDetails[i][0]);
                }
            }
        }
        i++;
    }
    if (currentRoom == 5)
    {
        if (roomCoordinates[currentRoom].rightWallX > roomCoordinates[(currentRoom-1)].rightWallX)
        {
            rightWall->xValue = roomCoordinates[currentRoom].rightWallX;
        }
        else
        {
            rightWall->xValue = roomCoordinates[(currentRoom-1)].rightWallX;
        }
    }
    return (&monsterInfo[0]);
}
Beispiel #15
0
/*
 * move_robots:
 *	Move the robots around
 */
void
move_robots(void)
{
	COORD	*rp;

#ifdef DEBUG
	move(Min.y, Min.x);
	addch(inch());
	move(Max.y, Max.x);
	addch(inch());
#endif /* DEBUG */
	for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) {
		if (rp->y < 0)
			continue;
		mvaddch(rp->y, rp->x, ' ');
		Field[rp->y][rp->x]--;
		rp->y += sign(My_pos.y - rp->y);
		rp->x += sign(My_pos.x - rp->x);
		if (rp->y <= 0)
			rp->y = 0;
		else if (rp->y >= Y_FIELDSIZE)
			rp->y = Y_FIELDSIZE - 1;
		if (rp->x <= 0)
			rp->x = 0;
		else if (rp->x >= X_FIELDSIZE)
			rp->x = X_FIELDSIZE - 1;
		Field[rp->y][rp->x]++;
	}

	Min.y = Y_FIELDSIZE;
	Min.x = X_FIELDSIZE;
	Max.y = 0;
	Max.x = 0;
	for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++)
		if (rp->y < 0)
			continue;
		else if (rp->y == My_pos.y && rp->x == My_pos.x)
			Dead = TRUE;
		else if (Field[rp->y][rp->x] > 1) {
			mvaddch(rp->y, rp->x, HEAP);
			rp->y = -1;
			Num_robots--;
			if (Waiting)
				Wait_bonus++;
			add_score(ROB_SCORE);
		}
		else {
			mvaddch(rp->y, rp->x, ROBOT);
			if (rp->y < Min.y)
				Min.y = rp->y;
			if (rp->x < Min.x)
				Min.x = rp->x;
			if (rp->y > Max.y)
				Max.y = rp->y;
			if (rp->x > Max.x)
				Max.x = rp->x;
		}

#ifdef DEBUG
	standout();
	move(Min.y, Min.x);
	addch(inch());
	move(Max.y, Max.x);
	addch(inch());
	standend();
#endif /* DEBUG */
}
Beispiel #16
0
int
sloscan(void)
{
	int ch;
	int yyp;

zagain:
	yyp = 0;
 	ch = inch();
	yytext[yyp++] = (usch)ch;
	switch (ch) {
	case -1:
		return 0;
	case '\n':
		/* sloscan() never passes \n, that's up to fastscan() */
		unch(ch);
		yytext[yyp] = 0;
		return ch;

	case '\r': /* Ignore CR's */
		yyp = 0;
		break;

	case '0': case '1': case '2': case '3': case '4': case '5': 
	case '6': case '7': case '8': case '9':
		/* readin a "pp-number" */
ppnum:		for (;;) {
			ch = inch();
			if (ch == -1)
				break;
			if (spechr[ch] & C_EP) {
				yytext[yyp++] = (usch)ch;
				ch = inch();
				if (ch == '-' || ch == '+') {
					yytext[yyp++] = (usch)ch;
				} else
					unch(ch);
				continue;
			}
			if ((spechr[ch] & C_ID) || ch == '.') {
				yytext[yyp++] = (usch)ch;
				continue;
			} 
			break;
		}
		unch(ch);
		yytext[yyp] = 0;

		return NUMBER;

	case '\'':
chlit:		
		for (;;) {
			if ((ch = inch()) == '\\') {
				yytext[yyp++] = (usch)ch;
				yytext[yyp++] = (usch)inch();
				continue;
			} else if (ch == -1 || ch == '\n') {
				/* not a constant */
				while (yyp > 1)
					unch(yytext[--yyp]);
				ch = '\'';
				goto any;
			} else
				yytext[yyp++] = (usch)ch;
			if (ch == '\'')
				break;
		}
		yytext[yyp] = 0;

		return NUMBER;

	case ' ':
	case '\t':
		while ((ch = inch()) == ' ' || ch == '\t')
			yytext[yyp++] = (usch)ch;
		unch(ch);
		yytext[yyp] = 0;
		return WSPACE;

	case '/':
		if ((ch = inch()) == '/') {
			do {
				yytext[yyp++] = (usch)ch;
				ch = inch();
			} while (ch != -1 && ch != '\n');
			yytext[yyp] = 0;
			unch(ch);
			goto zagain;
		} else if (ch == '*') {
			int c, wrn;
			extern int readmac;

			if (Cflag && !flslvl && readmac) {
				unch(ch);
				yytext[yyp] = 0;
				return CMNT;
			}

			wrn = 0;
		more:	while ((c = inch()) != '*') {
				if (c == -1)
					return 0;	
				if (c == '\n')
					putch(c), ifiles->lineno++;
				else if (c == EBLOCK) {
					(void)inch();
					(void)inch();
				} else if (c == WARN)
					wrn = 1;
			}
			if ((c = inch()) == -1)
				return 0;
			if (c != '/') {
				unch(c);
				goto more;
			}
			if (!tflag && !Cflag && !flslvl)
				unch(' ');
			if (wrn)
				unch(WARN);
			goto zagain;
		}
		unch(ch);
		ch = '/';
		goto any;

	case '.':
		if ((ch = inch()) == -1)
			return 0;
		if ((spechr[ch] & C_DIGIT)) {
			yytext[yyp++] = (usch)ch;
			goto ppnum;
		} else {
			unch(ch);
			ch = '.';
		}
		goto any;

	case '\"':
		if (tflag && defining)
			goto any;
	strng:
		for (;;) {
			if ((ch = inch()) == '\\') {
				yytext[yyp++] = (usch)ch;
				yytext[yyp++] = (usch)inch();
				continue;
			} else if (ch == -1) {
				break;
			} else 
				yytext[yyp++] = (usch)ch;
			if (ch == '\"')
				break;
		}
		yytext[yyp] = 0;
		return STRING;

	case 'L':
		if ((ch = inch()) == '\"' && !tflag) {
			yytext[yyp++] = (usch)ch;
			goto strng;
		} else if (ch == '\'' && !tflag) {
			yytext[yyp++] = (usch)ch;
			goto chlit;
		}
		unch(ch);
		/* FALLTHROUGH */

	/* Yetch, all identifiers */
	case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
	case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 
	case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 
	case 's': case 't': case 'u': case 'v': case 'w': case 'x': 
	case 'y': case 'z':
	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
	case 'G': case 'H': case 'I': case 'J': case 'K':
	case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 
	case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 
	case 'Y': case 'Z':
	case '_': /* {L}({L}|{D})* */

		/* Special hacks */
		for (;;) { /* get chars */
			if ((ch = inch()) == -1)
				break;
			if ((spechr[ch] & C_ID)) {
				yytext[yyp++] = (usch)ch;
			} else {
				unch(ch);
				break;
			}
		}
		yytext[yyp] = 0; /* need already string */
		/* end special hacks */

		return IDENT;
	default:
	any:
		yytext[yyp] = 0;
		return yytext[0];

	} /* endcase */
	goto zagain;
}
Beispiel #17
0
int
yylex(void)
{
	static int ifdef, noex;
	struct symtab *nl;
	int ch, c2;

	while ((ch = sloscan()) == WSPACE)
		;
	if (ch < 128 && (spechr[ch] & C_2))
		c2 = inch();
	else
		c2 = 0;

	switch (ch) {
	case '=':
		if (c2 == '=') return EQ;
		break;
	case '!':
		if (c2 == '=') return NE;
		break;
	case '|':
		if (c2 == '|') return OROR;
		break;
	case '&':
		if (c2 == '&') return ANDAND;
		break;
	case '<':
		if (c2 == '<') return LS;
		if (c2 == '=') return LE;
		break;
	case '>':
		if (c2 == '>') return RS;
		if (c2 == '=') return GE;
		break;
	case '+':
	case '-':
		if (ch == c2)
			error("invalid preprocessor operator %c%c", ch, c2);
		break;

	case '/':
		if (Cflag == 0 || c2 != '*')
			break;
		/* Found comment that need to be skipped */
		for (;;) {
			ch = inch();
		c1:	if (ch != '*')
				continue;
			if ((ch = inch()) == '/')
				break;
			goto c1;
		}
		return yylex();

	case NUMBER:
		if (yytext[0] == '\'') {
			yylval.node.op = NUMBER;
			yylval.node.nd_val = charcon(yytext);
		} else
			cvtdig(yytext[0] != '0' ? 10 :
			    yytext[1] == 'x' || yytext[1] == 'X' ? 16 : 8);
		return NUMBER;

	case IDENT:
		if (strcmp((char *)yytext, "defined") == 0) {
			ifdef = 1;
			return DEFINED;
		}
		nl = lookup(yytext, FIND);
		if (ifdef) {
			yylval.node.nd_val = nl != NULL;
			ifdef = 0;
		} else if (nl && noex == 0) {
			usch *och = stringbuf;
			int i;

			i = kfind(nl);
			unch(WARN);
			if (i)
				unpstr(stringbuf);
			else
				unpstr(nl->namep);
			stringbuf = och;
			noex = 1;
			return yylex();
		} else {
			yylval.node.nd_val = 0;
		}
		yylval.node.op = NUMBER;
		return NUMBER;
	case WARN:
		noex = 0;
		/* FALLTHROUGH */
	case PHOLD:
		return yylex();
	default:
		return ch;
	}
	unch(c2);
	return ch;
}
void retreat()
{
   unsigned int tx=0,ty=1;
   ori=1;
   
  
   if(objx==0&&objy==1)
   {
     turn('R');
	 return;
   }
   else if(objy==0||objy==1)
   turn('L');   
   else if(objx>0&&objy>1)
   turn('S');
   else if (objx==0&&objy>1)
   turn('R');
   
   while(1)
   {
      linefollower();
	  
	  if(f2==0)
	 { 
		if(ori==2)
		ty++;
		else if(ori==1)
		tx++; 
		else if(ori==3)
		tx--;
		else if(ori==4)
		ty--;
	    f2=1;
	  }
		inch();
	     if(tx==objx && ty == objy)
         break; 
   
         else if (ty==0&&tx==0)
         turn('R');
   
         else if((ty==0||ty==1)&&tx==objx)
         turn('R');
    
         else if (tx<objx||ty>objy||ty<objy)
         turn('S');

   }
     
	 switch (c) 
	   {
	     case 'L' : turn('L');
		          break; 
	     case 'R' : turn('R');
	              break;
	     case 'U' : turn('S');
	              break; 
		}         
	 
   
}
Beispiel #19
0
int
main(int argc, char *argv[])
{
	int optc;
	int option_differences = 0,
	    option_differences_cumulative = 0,
	    option_help = 0, option_version = 0;
	double interval = 2;
	char *command;
	int command_length = 0;	/* not including final \0 */

	setlocale(LC_ALL, "");
	progname = argv[0];

	while ((optc = getopt_long(argc, argv, "+d::hn:vt", longopts, (int *) 0))
	       != EOF) {
		switch (optc) {
		case 'd':
			option_differences = 1;
			if (optarg)
				option_differences_cumulative = 1;
			break;
		case 'h':
			option_help = 1;
			break;
		case 't':
			show_title = 0;
			break;
		case 'n':
			{
				char *str;
				interval = strtod(optarg, &str);
				if (!*optarg || *str)
					do_usage();
				if(interval < 0.1)
					interval = 0.1;
				if(interval > ~0u/1000000)
					interval = ~0u/1000000;
			}
			break;
		case 'v':
			option_version = 1;
			break;
		default:
			do_usage();
			break;
		}
	}

	if (option_version) {
		fprintf(stderr, "%s\n", VERSION);
		if (!option_help)
			exit(0);
	}

	if (option_help) {
		fprintf(stderr, usage, progname);
		fputs("  -d, --differences[=cumulative]\thighlight changes between updates\n", stderr);
		fputs("\t\t(cumulative means highlighting is cumulative)\n", stderr);
		fputs("  -h, --help\t\t\t\tprint a summary of the options\n", stderr);
		fputs("  -n, --interval=<seconds>\t\tseconds to wait between updates\n", stderr);
		fputs("  -v, --version\t\t\t\tprint the version number\n", stderr);
		fputs("  -t, --no-title\t\t\tturns off showing the header\n", stderr);
		exit(0);
	}

	if (optind >= argc)
		do_usage();

	command = strdup(argv[optind++]);
	command_length = strlen(command);
	for (; optind < argc; optind++) {
		char *endp;
		int s = strlen(argv[optind]);
		command = realloc(command, command_length + s + 2);	/* space and \0 */
		endp = command + command_length;
		*endp = ' ';
		memcpy(endp + 1, argv[optind], s);
		command_length += 1 + s;	/* space then string length */
		command[command_length] = '\0';
	}

	get_terminal_size();

	/* Catch keyboard interrupts so we can put tty back in a sane state.  */
	signal(SIGINT, die);
	signal(SIGTERM, die);
	signal(SIGHUP, die);
	signal(SIGWINCH, winch_handler);

	/* Set up tty for curses use.  */
	curses_started = 1;
	initscr();
	nonl();
	noecho();
	cbreak();

	for (;;) {
		time_t t = time(NULL);
		char *ts = ctime(&t);
		int tsl = strlen(ts);
		char *header;
		FILE *p;
		int x, y;
		int oldeolseen = 1;

		if (screen_size_changed) {
			get_terminal_size();
			resizeterm(height, width);
			clear();
			/* redrawwin(stdscr); */
			screen_size_changed = 0;
			first_screen = 1;
		}

		if (show_title) {
			// left justify interval and command,
			// right justify time, clipping all to fit window width
			asprintf(&header, "Every %.1fs: %.*s",
				interval, min(width - 1, command_length), command);
			mvaddstr(0, 0, header);
			if (strlen(header) > (size_t) (width - tsl - 1))
				mvaddstr(0, width - tsl - 4, "...  ");
			mvaddstr(0, width - tsl + 1, ts);
			free(header);
		}

		if (!(p = popen(command, "r"))) {
			perror("popen");
			do_exit(2);
		}

		for (y = show_title; y < height; y++) {
			int eolseen = 0, tabpending = 0;
			for (x = 0; x < width; x++) {
				int c = ' ';
				int attr = 0;

				if (!eolseen) {
					/* if there is a tab pending, just spit spaces until the
					   next stop instead of reading characters */
					if (!tabpending)
						do
							c = getc(p);
						while (c != EOF && !isprint(c)
						       && c != '\n'
						       && c != '\t');
					if (c == '\n')
						if (!oldeolseen && x == 0) {
							x = -1;
							continue;
						} else
							eolseen = 1;
					else if (c == '\t')
						tabpending = 1;
					if (c == EOF || c == '\n' || c == '\t')
						c = ' ';
					if (tabpending && (((x + 1) % 8) == 0))
						tabpending = 0;
				}
				move(y, x);
				if (option_differences) {
					chtype oldch = inch();
					char oldc = oldch & A_CHARTEXT;
					attr = !first_screen
					    && ((char)c != oldc
						||
						(option_differences_cumulative
						 && (oldch & A_ATTRIBUTES)));
				}
				if (attr)
					standout();
				addch(c);
				if (attr)
					standend();
			}
			oldeolseen = eolseen;
		}

		pclose(p);

		first_screen = 0;
		refresh();
		usleep(interval * 1000000);
	}

	endwin();

	return 0;
}
Beispiel #20
0
int process_key_up(int y, int x, int level, int have_key)
{
	int wall, c;
	move(--y, x); // Move the cursor up by one
	switch(wall = inch())
	{
		case '#' : move(++y, x); break;
		case '+' :
		{
			if(have_key == 1)
			{
				unlock();
				have_key--;
				move(++y, x);
			}
			else
			{
				move(22, 0);
				deleteln();
				mvprintw(22, 0, "This door appears to be locked.... You need a key.");
				move(++y, x);
			}
			break;
		}
		case ' ' :
		{
			move(++y, x);
			addch(' ');
			move(--y, x);
			addch('@');
			move(++y, x);
			break;
		}
		case 'o' :
		{
			level_completed(level++);
			switch(c = getch())
			{
				case 'c' : draw_maze(++level); break; // Continue and render next level.
				case 'q' : endwin(); return 0; break; // Close ncurses window
			}
			break;
		}
		case 'E' :
		{
			have_key++;
			move(22, 0);
			deleteln();
			mvprintw(22, 0, "You picked up a rusty key....");
			move(++y, x);
			addch(' ');
			move(--y, x);
			addch('@');
			move(y, x);
			break;
		}
	}
	refresh();
	return(y);
	return(x);
}
Beispiel #21
0
cell pp_curs_inch(cell x) {
	if (!Running) return UNSPECIFIC;
	return make_char(inch());
}
Beispiel #22
0
int movement(char input, int mazeBottom)
{
    int currentY;
    int currentX;
    int oldY;
    int oldX;
    int quit;
    char currentCharacter;

	quit = 0;
    currentY = 0;
    currentX = 0;
    oldY = 0;
    oldX = 0;

    getyx(stdscr, currentY, currentX);
    getyx(stdscr, oldY, oldX);

    if (input == 'j')
    {
        move(currentY, (currentX-1));
        printw("");
        getyx(stdscr, currentY, currentX);
        currentCharacter = inch();
    }
    else if (input == 'i')
    {
        move((currentY-1), currentX);
        printw("");
        getyx(stdscr, currentY, currentX);
        currentCharacter = inch();
    }
    else if (input == 'l')
    {
        move(currentY, (currentX+1));
        printw("");
        getyx(stdscr, currentY, currentX);
        currentCharacter = inch();
    }
    else if (input == 'k')
    {
        move((currentY+1), currentX);
        printw("");
        getyx(stdscr, currentY, currentX);
        currentCharacter = inch();
    }
    else if (input == 'q')
    {
		quit = 1;
	}
    if (currentCharacter == '#')
    {
		mvprintw(mazeBottom, 0, "You tried to move into a wall which you cannot do.");
		move(oldY, oldX);
	}
	else if (currentCharacter == 'E')
	{
		quit = 2;
	}
	else
	{
		mvprintw(mazeBottom, 0, "                                                  ");
		move(currentY, currentX);
	}
    return (quit);
}