Beispiel #1
0
iline(cx0,cy0,cx1,cy1){
	int maxp,tt,j,np;
	char chx,chy,command;
	    float xd,yd;
	float dist2(),sqrt();
	movep(cx0,cy0);
	maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
	xd = cx1-cx0;
	yd = cy1-cy0;
	command = COM|((xd<0)<<1)|(yd<0);
	if(maxp == 0){
		xd=0;
		yd=0;
	}
	else {
		xd /= maxp;
		yd /= maxp;
	}
	inplot();
	spew(command);
	for (tt=0; tt<=maxp; tt++){
		chx= cx0+xd*tt-xnow;
		xnow += chx;
		chx = abval(chx);
		chy = cy0+yd*tt-ynow;
		ynow += chy;
		chy = abval(chy);
		spew(ADDR|chx<<3|chy);
	}
	outplot();
	return;
}
Beispiel #2
0
int main(){
	clock_t timelim;
	init();
	printw("Strawb catcher version 1\n");
	printw("\t\tPress F1 or ESC to quit");
	entity p;
	p.x = 10;
	p.y = 20;
	p.display = '@';
	p.score = 0;
	p.colour = 2;
	entity *playerptr = &p;
	entity fr[10];
	entity *fruitpointer = &fr;
	int i;
	definestats(fruitpointer);
	timelim = clock();
	int escape;
	
	while(1 == 1){
		int score = p.score;
		int o = 0;
		mvprintw(0,30,"Score : %d", score);
		movep(playerptr);
		draw(playerptr);
		collision(fruitpointer, playerptr);
		drawf(fruitpointer);
		timelim = clock() - timelim;
		escape = ((int)timelim)/CLOCKS_PER_SEC;
		mvprintw(0, 60,"Seconds : %d", ((int)timelim)/CLOCKS_PER_SEC);
		if(escape > 30){
		
			int d = 0;
			int displayscore = p.score;
			
			clear();
			mvprintw(10, 20, "Congratulations, you have scored %d points\n", displayscore);
			refresh();
			wait(10);
			deinit();
			}
	}
	



}
Beispiel #3
0
void
iline(int cx0, int cy0, int cx1, int cy1)
{
	int maxp,tt,j,np;
	char chx,chy;
	float xd,yd;
	float dist2(),sqrt();
		movep(cx0,cy0);
		maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
		xd = cx1-cx0;
		yd = cy1-cy0;
		if(xd >= 0)chx = RIGHT;
		else chx = LEFT;
		if(yd >= 0)chy = UP;
		else chy = DOWN;
		if(maxp==0){
			xd=0;
			yd=0;
		}
		else{
			xd /= maxp;
			yd /= maxp;
		}
		inplot();
		for (tt=0; tt<=maxp; tt++){
			j= cx0+xd*tt-xnow;
			xnow += j;
			j = abval(j);
			while(j-- > 0)spew(chx);
			j = cy0+yd*tt-ynow;
			ynow += j;
			j = abval(j);
			while(j-- > 0)spew(chy);
			spew ('.');
		}
		outplot();
		return;
}
Beispiel #4
0
move(xi,yi){
		movep(xconv(xsc(xi)),yconv(ysc(yi)));
		return;
}
Beispiel #5
0
/*
 * mainloop() -
 * основной цикл работы редактора
 */
mainloop()
{
    int i,m,first=1;
    register int j;
    int clsave,ccsave;
    int k;
    /* Хитрости с экономией памяти */
    register int *lre1= &lread1;
#define lread1 (*lre1)
    int thiscol, thisrow;
    char ich[8], *cp;
    /* Для команд с тремя вариантами аргументов */
    int (*lnfun)(),(*spfun)();
    int openlines(), openspaces(), closelines(),closespaces(),picklines(),
    pickspaces();
    /* === */
    extern int templ[4];
    struct viewport *oport;
    /*
     * Обработка одного символа или команды
     * ====================================
     */
    if (cursorline== 0) oldcline = 1;
    if (cursorcol == 0) oldccol  = 1;
#ifndef lint
    goto funcdone;
#endif
    FOREVER
        {
        csrsw = clrsw = 0;
        read1();
        if (errsw)
        {
            errsw = 0;
            clrsw = 1;
            goto errclear;
        }
        /*
         * Редактирование в строке
         */
        if ((! CTRLCHAR) || lread1 == CCCTRLQUOTE || lread1 == CCBACKSPACE || lread1 == CCDELCH)
        {
            /* Отмена в 1 колонке */
            if (lread1 == CCBACKSPACE  &&  cursorcol == 0)
            {
                lread1 = -1;
                goto contin;
            }
            if (openwrite[curfile] == 0) goto nowriterr;
            /* Строки у нас нет? Дай! */
            if (clineno != (i = curwksp->ulhclno+cursorline))
                getlin(i);
            /* исключение символа */
            if (lread1==CCDELCH || (imodesw && lread1==CCBACKSPACE) )
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (lread1 == CCBACKSPACE) thiscol--;
                if (ncline < thiscol + 2)
                {
                    if (lread1 == CCBACKSPACE) movecursor(LT);
                    lread1 = -1;
                    goto contin;
                }
                for (i=thiscol;i<ncline-2;i++) cline[i] = cline[i+1];
                ncline--;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
                fcline = 1;
                lread1 = -1;
                goto contin;
            }
            /* Проверка на границу окна */
            if (cursorcol > curport->rtext)
            {
                if (fcline) {
                    putline(0);
                    movep(defrport);
                    goto contin;
                }
                else  goto margerr;
            }
            fcline = 1;
            if (j = (lread1 == CCBACKSPACE))
            {
                movecursor(LT);
                lread1 = ' ';
            }
            if ((i = cursorcol + curwksp->ulhccno) >=
                (lcline - 2)) excline(i+2);
            if (i >= ncline-1)
            {
                for (k=ncline-1; k<=i; k++) cline[k] = ' ';
                cline[i+1] = NEWLINE;
                ncline = i+2;
            }
            else if (imodesw)
            {
                thiscol = cursorcol + curwksp->ulhccno;
                thisrow = cursorline;
                if (ncline >= lcline) excline(ncline+1);
                for (i=ncline;i>thiscol;i--) cline[i] = cline[i-1];
                ncline++;
                thiscol -= curwksp->ulhccno;
                putup(-(1+thiscol),cursorline);
                poscursor(thiscol,thisrow);
            }
            /* Выставим границу */
            if (cursorcol >= curport->rtext)
                curport->redit = curport->rtext + 1;
            /* Замена символа */
            if(lread1==CCCTRLQUOTE) lread1 = esc0;
            if (cursorcol == curport->rtext - 10) putcha(COBELL);
            cline[i] = lread1;
            putch(lread1,1);
            /* Если переехали границу */
            curport->redit = curport->rtext;
            if (j) movecursor(LT);
            lread1 = -1;
            goto contin;
        }
        /* Сдвиг вниз, если последняя строка  */
        if (lread1 == CCRETURN )
        {
            putline(0);
            if ( cursorline == curport->btext)
                movew(defplline);
            if((i=curwksp->ulhccno) !=0) movep(-i);
            movecursor(lread1);
            lread1= -1;
            goto errclear;
        }
        /*
         * Если команда перемещения
         */
        if (lread1<=BT) {
            movecursor(lread1);
            if (lread1 <= VMOTCODE ) {
                putline(0);
                if(curspos) goto newnumber;
            }
            lread1 = -1;
            goto contin;
        }
        /* Если граница поля */
        if (cursorcol > curport->rtext) poscursor(curport->rtext,cursorline);
        putline(0);
        if (lread1 == CCQUIT)
        {
            if (endit() == 0) goto funcdone;
            gosw = 0;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto gotarg;
        case CCLPORT:
            movep(- deflport);
            goto funcdone;
        case CCSETFILE:
            switchfile();
            goto funcdone;
        case CCCHPORT:
            chgport(-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            openlines(curwksp->ulhclno + cursorline,definsert);
            goto funcdone;
        case CCMISRCH:
            search(-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)
                goto nowriterr;
            closelines(curwksp->ulhclno + cursorline, defdelete);
            goto funcdone;
        case CCPUT:
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (pickbuf->nrows == 0) goto nopickerr;
            put(pickbuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCPICK:
            picklines(curwksp->ulhclno + cursorline, defpick);
            goto funcdone;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* change it */
            goto funcdone;
        case CCGOTO:
            gtfcn(0);
            goto funcdone;
        case CCMIPAGE:
            movew(- defmipage * (1+curport->btext));
            goto funcdone;
        case CCPLSRCH:
            search(1);
            goto funcdone;
        case CCRPORT:
            movep(defrport);
            goto funcdone;
        case CCPLLINE:
            movew(defplline);
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            savefile(NULL,curfile);
            goto funcdone;
        case CCMILINE:
            movew(-defmiline);
            goto funcdone;
        case CCDOCMD:
            goto notstrerr;
        case CCPLPAGE:
            movew(defplpage * (1+curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            makeport(deffile);
            goto funcdone;
        case CCTABS:
            settab(curwksp->ulhccno + cursorcol);
            goto funcdone;
            /*    case CCMOVELEFT:        */
            /*    case CCTAB:             */
            /*    case CCMOVEDOWN:        */
            /*    case CCHOME:            */
            /*    case CCRETURN:  */
            /*    case CCMOVEUP:  */
        default:
            goto badkeyerr;
        }
        /* Повтор ввода аргумента */
reparg:
        read1();
        if(CTRLCHAR) goto yesarg;
        else goto noargerr;
        /*
         * Дай аргумент!
         */
gotarg:
        param(0);
yesarg:
        if (lread1 == CCQUIT )
        {
            if (paraml>0 && (dechars(paramv,paraml),*paramv) == 'a')
            {
                gosw = 0;
                if (*(paramv+1) != 'd') return;
                cleanup();
                inputfile = -1; /* to force a dump */
                fatal("ABORTED");
            }
            if (endit() == 0) goto funcdone;
            gosw = 1;
            return;
        }
        switch (lread1)
        {
        case CCENTER:
            goto funcdone;
        case CCLPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(-i);
            goto funcdone;
        case CCSETFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if ( use0flg || !inputfile)
                dechars(paramv,paraml);
            use0flg=1;
            editfile(paramv,0,0,1,1);
            goto funcdone;
        case CCCHPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            chgport(i-1);
            goto funcdone;
        case CCOPEN:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) {
                splitline(curwksp->ulhclno + paramr0,
                paramc0 + curwksp->ulhccno);
                goto funcdone;
            }
            else {
                lnfun = openlines;
                spfun = openspaces;
                goto spdir;
            };
        case CCMISRCH:
        case CCPLSRCH:
            if (paramtype <= 0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            if (searchkey) free(searchkey);
            searchkey = paramv;
            paraml = 0;
            search(lread1==CCPLSRCH?1:-1);
            goto funcdone;
        case CCCLOSE:
            if (openwrite[curfile]==0)  goto nowriterr;
            if (paramtype == 0) combineline(curwksp->ulhclno + paramr0,
            paramc0 + curwksp->ulhccno);
            else {
                if(paramtype > 0 && paramv && paramv[0]=='>')
                {
                    msrbuf(deletebuf,paramv+1,0);
                    goto funcdone;
                }
                lnfun = closelines;
                spfun = closespaces;
                goto spdir;
            }
            goto funcdone;
        case CCPUT:
            if (paramtype >  0 && paramv && paramv[0]=='$' )
            {
                if (msrbuf(pickbuf,paramv+1,1))goto errclear;
                goto funcdone;
            }
            if (paramtype != 0)  goto notstrerr;
            if (openwrite[curfile]==0)
                goto nowriterr;
            if (deletebuf->nrows == 0) goto nodelerr;
            put(deletebuf,curwksp->ulhclno+cursorline,
            curwksp->ulhccno+cursorcol);
            goto funcdone;
        case CCMOVELEFT:
        case CCTAB:
        case CCMOVEDOWN:
        case CCHOME:
        case CCMOVEUP:
        case CCMOVERIGHT:
        case CCBACKTAB:
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            m = ((lread1<=BT) ? lread1:0);
            while (--i >= 0) movecursor(m);
            goto funcdone;
        case CCRETURN:
            if(paramtype <=0|| !paramv) goto notimperr;
            dechars(paramv,paraml);
            switch (paramv[0])
            {
            case '>':
                msvtag(paramv+1);
                goto funcdone;
            case '$':
                if(mdeftag(paramv+1)){
                    lread1= -1;
                    goto reparg;
                }
                else goto funcdone;
            case 'w':
                if(paramv[1]==' ' && paramv[2]=='+')
                    openwrite[curwksp->wfile]=1;
                else openwrite[curwksp->wfile]=0;
                goto funcdone;
            case 'k':
                defkey();
                goto funcdone;
            case 'r':
                rescreen(-1);
                goto funcdone; /* Восттановить экран */
            case 'd':
                if(paramv[1]==' ') defmac(&paramv[2]);
                goto funcdone;
            case 'q':
                lread1=CCQUIT;
                if(paramv[1]=='a') {
                    gosw=0;
                    return;
                }
                goto contin;
            default:
                goto noargerr;
            }
        case CCPICK:
            if (paramtype == 0) goto notimperr;
            if (paramtype > 0 && paramv && paramv[0]=='>')
            {
                msrbuf(pickbuf,paramv+1,0);
                goto funcdone;
            }
            lnfun = picklines;
            spfun = pickspaces;
            goto spdir;
        case CCINSMODE:
            imodesw = 1 - imodesw;  /* Щелкнем!! */
            goto funcdone;
        case CCGOTO:
            if (paramtype == 0) gtfcn(nlines[curfile]);
            else if (paramtype > 0)
            {
                if(paramv && paramv[0]=='$') {
                    mgotag(paramv+1);
                    goto funcdone;
                }
                if (s2i(paramv,&i)) goto notinterr;
                gtfcn(i-1);
            }
            else goto noargerr;
            goto funcdone;
        case CCMIPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(- i * (1 + curport->btext));
            goto funcdone;
        case CCRPORT:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movep(i);
            goto funcdone;
        case CCPLLINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(i);
            }
            goto funcdone;
        case CCDELCH:
            goto notimperr;
        case CCSAVEFILE:
            if (paramtype <=  0)  goto notstrerr;
            if (paramv == 0) goto noargerr;
            dechars(paramv,paraml);
            savefile(paramv,curfile);
            goto funcdone;
        case CCMILINE:
            if (paramtype < 0)  goto notstrerr;
            else if (paramtype == 0)  movew(cursorline - curport->btext);
            else if (paramtype > 0)
            {
                if (s2i(paramv,&i)) goto notinterr;
                movew(-i);
            }
            goto funcdone;
        case CCDOCMD:
            if(paramtype<=0) goto notstrerr;
            dechars(paramv,paraml);
            if (openwrite[curfile] == 0) goto nowriterr;
            callexec();
            goto funcdone;
        case CCPLPAGE:
            if (paramtype <= 0)  goto notstrerr;
            if (s2i(paramv,&i)) goto notinterr;
            movew(i * (1 + curport->btext));
            goto funcdone;
        case CCMAKEPORT:
            if (paramtype == 0)  removeport();
            else if (paramtype <  0)  goto notstrerr;
            else {
                dechars(paramv,paraml);
                makeport(paramv);
            }
            goto funcdone;
        case CCTABS:
            clrtab(curwksp->ulhccno + cursorcol);
            goto funcdone;
        default:
            goto badkeyerr;
        }
spdir:
        if (paramtype > 0)
        {
            if(paramv[0] == '$')
            {
                if(mdeftag(paramv+1)) goto spdir;
                else goto funcdone;
            }
            if (s2i(paramv,&i)) goto notinterr;
            if (i <= 0) goto notposerr;
            (*lnfun)(curwksp->ulhclno + cursorline, i);
        }
        else
        {
            if (paramc1 == paramc0)
            {
                (*lnfun)(curwksp->ulhclno+paramr0,
                (paramr1-paramr0)+1);
            }
            else (*spfun)(curwksp->ulhclno + paramr0,
            curwksp->ulhccno + paramc0,
            (paramc1-paramc0),
            (paramr1-paramr0) + 1);
        }
        goto funcdone;
badkeyerr:
        error(DIAG("Illegal key or unnown macro","Неизвестная клавиша или макро"));
        goto funcdone;
notstrerr:
        error(DIAG("Argument must be a string.","Аргумент должен быть строкой"));
        goto funcdone;
noargerr:
        error(DIAG("Invalid argument.","Плохой аргумент"));
        goto funcdone;
notinterr:
        error(DIAG("Argument must be numerik.","Аргумент должен быть числом"));
        goto funcdone;
notposerr:
        error(DIAG("Argument must be positive.","Аргумент должен быть положительным"));
        goto funcdone;
nopickerr:
        error(DIAG("Nothing in the pick buffer.","Буфер вставок пуст"));
        goto funcdone;
nodelerr:
        error (DIAG("Nothing in the close buffer.","Буфер убранных строк пуст"));
        goto funcdone;
notimperr:
        error(DIAG("Feature not implemented yet.","Еще не определено."));
        goto funcdone;
margerr:
        error("Margin stusk; move cursor to free.");
        goto funcdone;
nowriterr:
        error(DIAG("You cannot modify this file!","Вы не можете изменить этот файл."));
        goto funcdone;
funcdone:
        clrsw = 1;
newnumber:
        lread1 = -1;        /* signify char read was used */
errclear:
        oport = curport;
        k = cursorline;
        j = cursorcol;
        switchport(&paramport);
        paramport.redit = PARAMRINFO;
        if (clrsw)
        {
            if (!errsw && !first)
            {
                poscursor(0,0);
                info(blanks,PARAMRINFO);
            }
            poscursor(PARAMREDIT+2,0);
            if (oport->wksp->wfile)
            {
                info(DIAG("file ","файл "),PARAMRINFO);
                info(openfnames[oport->wksp->wfile],PARAMRINFO);
            }
            info(DIAG(" line "," строка: "),PARAMRINFO);
            clsave = cursorline;
            first=0;
            ccsave = cursorcol;
        }
        poscursor(ccsave,clsave);
        i = oport->wksp->ulhclno + k + 1; /* Рисуем номер строки */
        cp = ich + 8;
        *--cp = '\0';
        do
            (*--cp = '0' + (i % 10));
        while (i = i/10);
        info(cp,PARAMRINFO);
        *cp = '\0';
        while (cp != ich) *--cp = ' ';
        info(ich,PARAMRINFO);
        switchport(oport);
        paramport.redit = PARAMREDIT;
        poscursor(j,k);
        if (csrsw)
        {
            putch(COCURS,1);
            poscursor(j,k);
            dumpcbuf();
            sleep(1);
            putup(k,k);
            poscursor(j,k);
        }
        if (imodesw && clrsw && !errsw)
            telluser(DIAG("     ***** i n s e r t m o d e *****","  * * * * режим вставки * * * * "),0);
contin:
        ;
    }
#undef lread1
}