コード例 #1
0
targeter()
{

    while (TRUE) {
	recvclr();
	targetx = (rand() % (XMAXFIELD-6)) + 2;
	targety = (rand() % (YMAXFIELD-6)) + 2;
	targetvalue=(rand() % 9)+1;
	newsend(pidplotter,3,targetx,targety,targetvalue+48 );
	resume(pidtimer = create(removetarget,200,13,"remover",0));
	if (receive() != REMOVE)
	    kill(pidtimer);
	else	
	    newsend(pidplotter,3,targetx,targety ,' ');
    }
}
コード例 #2
0
ファイル: robot.c プロジェクト: m3y54m/32bitmicro
robot()
{
    int oldx, oldy;
    int direc;
    int diffx;
    int diffy;
    
    robotx = rand()%(XMAXFIELD-3)+2;
    roboty = rand()%(YMAXFIELD-3)+2;
    
    direc = EAST;

    oldx=robotx;
    oldy=roboty;

    while (TRUE) {
	sleep10(1);
	diffx = targetx-robotx;
	diffy = targety-roboty;
	if (diffy<0) {			/* NORTH */
	    if (diffx>0)
		direc = NE;
	    else if (diffx<0)
		direc = NW;
	    else
		direc = NORTH;
	}
	
	else if (diffy>0) {		/* SOUTH */
	    if (diffx>0)
		direc = SE;
	    else if (diffx<0)
		direc = SW;
	    else
		direc = SOUTH;
	}
	else {				/* HORIZONTAL */
	    if (diffx>0)
		direc = EAST;
	    else if (diffx<0)
		direc = WEST;
	    else
		direc = SIT;
	}

	switch (direc) {
	  case SIT:	continue;
	  case NORTH:	if (roboty > 1)     --roboty; break;
	  case SOUTH:	if (roboty < YMAXFIELD)  ++roboty; break;
	  case WEST:	if (robotx > 1)     --robotx; break;
	  case EAST:	if (robotx < XMAXFIELD)  ++robotx; break;
	  case NE:	if (roboty>1 && robotx<XMAXFIELD) {
	                    --roboty; ++robotx;  }    break;
	  case NW:	if (roboty>1 && robotx>1) {
	                    --roboty; --robotx;  }    break;
	  case SE:	if (roboty<YMAXFIELD && robotx<XMAXFIELD) {
	                    ++roboty; ++robotx;  }    break;
	  case SW:	if (roboty<YMAXFIELD && robotx>1) {
	                    ++roboty; --robotx;  }    break;
	}
	newsend(pidplotter,3,oldx,oldy,' ');
	newsend(pidplotter,3,robotx,roboty,'R');
	oldx=robotx;
	oldy=roboty;
    }
}