Пример #1
0
template<typename DB> size_t test(int entries, int searches)
{
	{
		DB db;
	//time_watch_t ins, srch;
	
	//memdbg_start();
	//watch_start(&ins);
	for (int i=1;i < entries;i++)
	{
		db.Insert(getk(i), i+1);
	}
	//watch_finish(&ins, entries);

	//watch_start(&srch);
	//for (int j=0;j < 30;j++)
		for (int i=1;i < searches;i++)
		{
			db.Search(getk(i%entries));
		}
	//watch_finish(&srch, searches);

	//printf("Insert: "); watch_report(&ins, stdout);
	//printf(" Search: "); watch_report(&srch, stdout); putchar('\n');
	db.Stat();
}
	//memdbg_end();
	return 0;
}
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
	if(nums1.size()<1 && nums2.size() <1){
		return 0;
	}
	int len = nums1.size() + nums2.size();
	//len奇数mid1 mid2一样
	//偶数的话 mid1+1 == mid2
	int mid1 = (len+1)/2;
	int mid2 = len/2+1;

	return ((double)getk(nums1,0,nums2,0,mid1)+getk(nums1,0,nums2,0,mid2))/2;
}
Пример #3
0
gamekeys()
{
        char *charptr;

/* Set up a pointer to the variable we want to change (either for
 * box or for ball
 */
        if (ballorbox) charptr=&boxoffset;
        else charptr=&balloffset;

        switch( toupper(getk()) ) {      /* Use OZ to get the key */
                case K_DOWN:
                        down(charptr);
                        break;
                case K_UP:
                        up(charptr);
                        break;
                case K_RIGHT:
                        right(charptr);
                        break;
                case K_LEFT:
                        left(charptr);
                        break;
                case K_SWITCH:
                        ballorbox^=1;   /* Toggle ball/box */
                        break;
                case K_EXIT:
                        myexit();
                case K_CLEAR:
                        setuplevel();
        }
}
Пример #4
0
main()
{

float x,y,incr,yenlarge;
int z,buf;

	clg();
	incr=2.0/(float)getmaxx();
	yenlarge=(float)getmaxy() / 6.0;

	for (x=-3.0; x<0; x=x+incr)
	{
		buf=255;
		for (y=-3.0; y<3.0; y=y+0.2)
		{
			z = (int) (float)getmaxy() - (yenlarge * (y + 3.0) + ( yenlarge * sin (x*x + y*y) ));

			if (buf>z)
			{
				buf = z;
				plot ( (int) ((float)getmaxx() / 6.0 * (x + 3.0)), z);
				plot ( (int) ((float)getmaxx() / 6.0 * (3.0 - x)), z);
			}
		}
	}
	
	while (getk() != 13) {};
}
Пример #5
0
main()
{
        redrawscreen();         /* Define the windows */
/* Loop forever */
        while (1)
                getk();

}
Пример #6
0
void main() {
  unsigned char a;
  while (1) {
    a = getk();
    /* fputs("a",stdout); */
    printf("%u\n", a);
  }

}
Пример #7
0
int main(void){
	clock_t ini = clock();
	int ans = -1;
	for(int i = 1000001; ; i += 2)
		if((i % 5) && getk(i) > 1000000){ ans = i; break; }
	printf("Time spent: %.3lfs\n", ((double)(clock() - ini))/CLOCKS_PER_SEC);
	printf("Answer: %d\n", ans);
	return 0;
}
Пример #8
0
void XNextEvent(Display *display, int *event) {

	if (_x_must_expose == 1)
	{
		_x_must_expose = 0;
		*event = Expose;
		return;
	}

	if (getk() != 0)
		*event = KeyPress;

}
Пример #9
0
void main()
{

 	fputc_cons(12);

	xmax=SOS_WIDTH-1;
	ymax=SOS_MXLIN-1;
	
	a=-2.0; b=2.0;
	c=a; d=b;
	e=4.0;

	g=(b-a)/(float)xmax;
	h=(d-c)/(float)ymax;
	
	for(y=0; y<ymax; y++)
	{
	  j=(float)y*h+c;
	  for(x=xmax; x>=0; x--)
	  {
	     i=(float)x*g+a;
	     k=0;
	     l=0.0; m=0.0; n=0.0; o=0.0;
l110:	     k++;
	     if (k<100)  //Iterates
	     {
		p=n-o+i;
		m=2.0*l*m+j;
		l=p;
		n=l*l; o=m*m;

		if ((n+o)<e) goto l110;
		color=k&3;
		setcursorpos(y,x);
		switch (color) {
			case 1:
				fputc_cons('+');
				break;
			case 2:
				fputc_cons('*');
				break;
			case 3:
				fputc_cons('#');
				break;
		}

	     }
	  }
	}
	while (getk() != 13) {};
}
int getk(vector<int>& nums1,int start1, vector<int>& nums2, int start2,int k){
	int len1 = nums1.size();
	int len2 = nums2.size();
	if(start1 >= len1){
		return nums2[start2+k-1];
	}
	else if(start2 >= len2){
		return nums1[start1+k-1];
	}

	if(k==1){
		return min(nums1[start1],nums2[start2]);
	}
	else{
		int half = k/2;
		int mid1 = start1+half -1;
		int mid2 = start2 +half -1;

		int val1(INT_MAX);
		int val2(INT_MAX);

		/*如果某一个数超范围了,就是说他的size肯定小于k/2,第kth数肯定不在另一个数组k/2左边
		因为如果在另一个数组里k/2左边,那么该数组小于目标kth的最多有k/2个数,就算把第一个数组的数全部加上,总个数也小于k
		*/
		if(mid1 < len1){
			val1 = nums1[mid1];
		}
		if(mid2 < len2){
			val2 = nums2[mid2];
		}
		if(val1 > val2){
			return getk(nums1,start1, nums2,mid2+1,k-half);
		}
		return getk(nums1,mid1+1,nums2,start2,k-half);
	}
}
Пример #11
0
static uint8_t readkeys()
{
    switch ( toupper(getk()) ) {
    case K_UP:
        return MOVE_UP;
    case K_DOWN:
        return MOVE_DOWN;
    case K_LEFT:
        return MOVE_LEFT;
    case K_RIGHT:
        return MOVE_RIGHT;
    case K_POP:
        return MOVE_FIRE1;
    }
    return 0;
}
Пример #12
0
int main()
{
    long long a,b;
    int n;

    scanf("%d",&n);

    while (n--)
    {
        scanf("%lld%lld",&a,&b);

        printf("%d\n",getk(a,b));
    }

    return 0;
}
Пример #13
0
Файл: box.c Проект: z88dk/z88dk
void main() {
  int x, y, w, h;
  clg();

  while (1) {
    x = rand() % (getmaxx() );
    y = rand() % (getmaxy() );
    w = rand() % 16 + 4;
    h = rand() % 16 + 4;

    drawb(x, y, w, h);
    small_delay();
    if (getk() == 10) {
      break;
    }  // enter key is assigned to 10
  }
}
Пример #14
0
void kmeans::simplePrint(char* outfile) {
	
	pointNode* current = listHead.getNextNode();
	
	ofstream myoutfile(outfile); //open output file

	myoutfile << getk() << endl;
	myoutfile << to_string(getnumRow()) << " " << to_string(getnumCol()) << endl;
 
	while(current != NULL) {
		myoutfile << current->printPointnode();
		myoutfile << endl;
		current = current->getNext();
	}
	
	myoutfile.close();
	return;
}
Пример #15
0
main()
{
	char x, y, temp;

	for(y=0 ; y<8 ; y++)
	{
		temp = smile[y+2];
		for(x=0 ; x<8 ; x++)
		{
			if(temp & 1)
			{
				putsprite(spr_or, 8 * x, 8 * y, smile);
			}
			temp >>= 1;
		}
	}
	getk(); /*pause*/
}
Пример #16
0
void main()
{

 	clg();

	xmax=getmaxx();
	ymax=getmaxy()-1;
	
	a=-2.0; b=2.0;
	c=a; d=b;
	e=4.0;

	g=(b-a)/(float)xmax;
	h=(d-c)/(float)ymax;
	
	for(y=ymax/2; y>0; y--)
	{
	  j=(float)y*h+c;
	  for(x=xmax; x>0; x--)
	  {
	     i=(float)x*g+a;
	     k=0;
	     l=0.0; m=0.0; n=0.0; o=0.0;
l110:	     k++;
	     if (k<100)  //Iterates
	     {
		p=n-o+i;
		m=2.0*l*m+j;
		l=p;
		n=l*l; o=m*m;

		if ((n+o)<e) goto l110;
		if (k&1){
		  plot (x,y);
		  plot (x,ymax-y);
		}

	     }
	  }
	}
	while (getk() != 13) {};
}
Пример #17
0
int main()
{

	/* Open ZSock library */
	printf("\0017#1  \176(\200\0012C1\001S\001C");
	printf("Querying library\n");
	if (QueryPackage(LIB_TCP,0,0) == NULL ) {
		printf("Couldn't open library\n");
		sleep(3);
		exit(0);
	}
	user_pagein();
	process=0;
		
	printf("ZSock Waiting For Your Command\n");
	while(1) {
		BUSYINT();
		getk();
	}
}
Пример #18
0
static void checkover() 
{
    for ( int y = 0; y < ARENA_H; y++ ) {
        for ( int x = 0; x < ARENA_W - 1; x++ ) {
            if ( arena[y][x] && ( arena[y][x] == arena[y][x+1] ||
                 arena[y][x] == arena[y+1][x] ) ) {
                 return;
            }
        }
    }
    playing = 0;
    gotoxy(X_OFFSET + (ARENA_W / 2) - 4, Y_OFFSET + (ARENA_H / 2));
    cputs("GAME OVER!!");
#ifdef JOYSTICK_NUM
    while ( joystick(JOYSTICK_NUM) == 0 ) 
#else
    while ( getk() == 0 ) 
#endif
        ;
}
Пример #19
0
void GillespieProcess::fire()
{
    Real velocity( getk() * N_A );
    velocity *= getSuperSystem()->getSize();

    for( VariableReferenceVector::const_iterator
                 s( theVariableReferenceVector.begin() );
             s != theZeroVariableReferenceIterator; ++s )
    {
        VariableReference aVariableReference( *s );
        Integer aCoefficient( aVariableReference.getCoefficient() );
        do
        {
            ++aCoefficient;
            velocity *= aVariableReference.getVariable()->getMolarConc();
        }
        while( aCoefficient != 0 );
    }

    setActivity( velocity );
}
Пример #20
0
void Gamekeys(void)
{
	char *charptr;

    /* Set up a pointer to the variable we want to change
     * (either the box or the ball) */
	charptr = PieceIsBall ? &BoxOffset : &BallOffset;

	switch(getk())
	{
		case K_DOWN:
		  MovePiece(charptr,0,+1);
		  break;
		case K_UP:
		  MovePiece(charptr,0,-1);
		  break;
		case K_RIGHT:
		  MovePiece(charptr,+1,0);
		  break;
		case K_LEFT:
		  MovePiece(charptr,-1,0);
		  break;
		case K_SWITCH:
		  PieceIsBall^=1;   /* Toggle ball/box */
		  break;
		case K_EXIT:
		  exit(0);
		case K_NEXTLEV:    /* Okay this IS cheating... */
		  if(++Level==MAXLEVEL)
		  { --Level; break; }
		  SetupLevel();
		  break;
		case K_PREVLEV:
		  if(--Level==-1)
		  { ++Level; break; }
		  /* fall thrue */
		case K_CLEAR:
		  SetupLevel();
	}
}
Пример #21
0
Файл: sin.c Проект: z88dk/z88dk
void main() {
  int x, y;
  clg();

  for (x = 0; x < 144; x++) {
    y = (int)(24 * (1.0 - sin(x / 144.0 * 3.14 * 8)));
    plot(x, y);
  }

  sleep(1);  // sleep 1 second

  clg();
  plot(0,24);

  for (x = 0; x < 144; x++) {
    y = (int)(24 * (1.0 - sin(x / 144.0 * 3.14 * 8)));
     drawto(x,y);
  }


  while (getk() != 10) {
  };  // enter key is assigned to 10 in the g800 port of z88dk
}
Пример #22
0
int & getj() {
	static int j = getk();
	return j;
}
Пример #23
0
void main( void ) {

    int i, j, n;
    unsigned char v;
    
    // fixed 8.8:
    int x, y;
    
    int tecla;
    long pausa = 100;

    static unsigned char paleta [] = {
        
        // gggrrrbb
        
        0x04,
        0x08,
        0x0C,
        0x10,
        0x14,
        0x18,
        0x1C,
        0xBC,
        0xFC,
        0xF0,
        0xE0,
        0xE3,
        0xA3,
        0x23,
        0x0F,
        0x92,
    };
    
    unsigned char flagCambiarPantalla = 1;

    radasCls( 0 );

    radasPonerModoRadastan();

    radasPonerPaleta( paleta );




    sprites[ 0 ].x = 45;
    sprites[ 0 ].y = 3;
    sprites[ 0 ].tamx = 5;
    sprites[ 0 ].tamy = 5;
    sprites[ 0 ].velx = 1;
    sprites[ 0 ].vely = 0;
    sprites[ 0 ].color = 0x88;

    sprites[ 1 ].x = 35;
    sprites[ 1 ].y = 10;
    sprites[ 1 ].tamx = 10;
    sprites[ 1 ].tamy = 10;
    sprites[ 1 ].velx = 1;
    sprites[ 1 ].vely = 0;
    sprites[ 1 ].color = 0x44;

    sprites[ 2 ].x = 20;
    sprites[ 2 ].y = 20;
    sprites[ 2 ].tamx = 6;
    sprites[ 2 ].tamy = 6;
    sprites[ 2 ].velx = -1;
    sprites[ 2 ].vely = 0;
    sprites[ 2 ].color = 0x66;
    
    sprites[ 3 ].x = 16;
    sprites[ 3 ].y = 30;
    sprites[ 3 ].tamx = 8;
    sprites[ 3 ].tamy = 4;
    sprites[ 3 ].velx = 1;
    sprites[ 3 ].vely = 0;
    sprites[ 3 ].color = 0x99;
    
    sprites[ 4 ].x = 26;
    sprites[ 4 ].y = 40;
    sprites[ 4 ].tamx = 4;
    sprites[ 4 ].tamy = 5;
    sprites[ 4 ].velx = -1;
    sprites[ 4 ].vely = 0;
    sprites[ 4 ].color = 0xBB;

    
    for ( i = 0; i < NUM_SPRITES; i++ ) {
        Sprite *s = &sprites[ i ];
        s->xant = s->x;
        s->yant = s->y;
        s->xant2 = s->x;
        s->yant2 = s->y;
    }
    
    
    
    
    //pintarDegradado();

    srand( 1234 );
    n = 0;
/*
    for ( n = 0; n < 16; n++ ) {

        x = rand() & 0x7FFF;
        y = rand() & 0x3FFF;
        
        
        pintarPixel( x >> 8, y >> 8, n );
        
    }    
*/

    //    radasRectangulo( 3, 7, 10, 20, 0x48 );


    // Bucle principal
    
    x = 4;
//    y = 12;
    v = 0xFE;
    tecla = getk();
    tecla = 0;
    while ( tecla != ' ' ) {

        ula_sync();
        

        for ( i = 0; i < NUM_SPRITES; i++ ) {
            Sprite *s = &sprites[ i ];
            radasRectangulo( s->xant2, s->yant2, s->tamx, s->tamy, 0 );
        }

        for ( i = 0; i < NUM_SPRITES; i++ ) {
            Sprite *s = &sprites[ i ];

            int nx = s->x + s->velx;
            if ( ( nx + s->tamx >= PANTALLA_X2 ) || ( nx < 0 ) ) {
                s->velx = - s->velx;
            }
            else {
                s->x = nx;
            }
            
            s->xant2 = s->xant;
            s->yant2 = s->yant;
            s->xant = s->x;
            s->yant = s->y;

            radasRectangulo( s->x, s->y, s->tamx, s->tamy, s->color );
            
        }
        
        if ( flagCambiarPantalla ) {
            radasCambiarPantalla();
        }


/*
        x = rand() & 0x003B;
        y = rand() & 0x003B;
        v = rand() & 0x00FF;
//        v = v | ( v << 4 );
        radasRectangulo( x, y, 3, 4, v );
*/
/*        
        x = rand() & 0x007F;
        y = rand() & 0x003F;
        pintarPixel( x, y, n++ );

        rotarPaletaAdelante( paleta );
        radasPonerPaleta( paleta );
*/

        tecla = getk();
        
        if ( tecla ) {
            switch ( tecla ) {
                case 'x':
                    flagCambiarPantalla = 0;
                    break;
                case 'c':
                    flagCambiarPantalla = 1;
                    break;
                default:
                    break;
            }
        }
    }

    // Fin del programa
    radasCls( 0 );
    radasPonerModoNormal();
    radasCls( 0 );

}
Пример #24
0
int main(void)
{
	static Vector_t rot;
	static Vector_t t;
	static Point_t p[8];
	static unsigned c = 0;
	static int i;
	static int zf = 0;
#ifdef TIMING
    extern unsigned _oz64hz_word;
    static unsigned frames;
#endif
    //ozinitprofiler();
	//ozsetactivepage(1);
	//ozsetdisplaypage(0);
#ifdef TIMING
    frames=0;
    _oz64hz_word=0;
#endif
	while(c != 13) {
		//if(ozkeyhit()) c = ozngetch();
		//if(getk()) c = fgetc_cons();
		c=getk();
		switch(c) {
			case '1':
				zf -= 10;
				if(zf < -100) zf = -100;
				break;
			case '2':
				zf += 10;
				if(zf > 300) zf = 300;
				break;
			case '3':
				exit (0);
		}
		c = 0;
		for(i = 0; i < 8; i++) {
			ozcopyvector(&t,&cube[i]);
			ozrotatepointx(&t, rot.x);
			ozrotatepointy(&t, rot.y);
			t.z += zf; /* zoom factor */
			ozplotpoint(&t, &p[i]);
		}
		rot.y = (rot.y+1)%360;
		rot.x = (rot.x+2)%360;
		clg();
		/* top face */
		draw(p[0].x + MX, p[0].y + MY, p[1].x + MX, p[1].y + MY);
		draw(p[1].x + MX, p[1].y + MY, p[2].x + MX, p[2].y + MY);
		draw(p[2].x + MX, p[2].y + MY, p[3].x + MX, p[3].y + MY);
		draw(p[3].x + MX, p[3].y + MY, p[0].x + MX, p[0].y + MY);
		/* bottom face */
		draw(p[4].x + MX, p[4].y + MY, p[5].x + MX, p[5].y + MY);
		draw(p[5].x + MX, p[5].y + MY, p[6].x + MX, p[6].y + MY);
		draw(p[6].x + MX, p[6].y + MY, p[7].x + MX, p[7].y + MY);
		draw(p[7].x + MX, p[7].y + MY, p[4].x + MX, p[4].y + MY);
		/* side faces */
		draw(p[0].x + MX, p[0].y + MY, p[4].x + MX, p[4].y + MY);
		draw(p[1].x + MX, p[1].y + MY, p[5].x + MX, p[5].y + MY);
		draw(p[2].x + MX, p[2].y + MY, p[6].x + MX, p[6].y + MY);
		draw(p[3].x + MX, p[3].y + MY, p[7].x + MX, p[7].y + MY);
        //ozsetdisplaypage(!ozgetdisplaypage());
#ifdef TIMING
        frames++;
        if(_oz64hz_word>64*10)
        {
            static char buf[80];
            sprintf(buf,"%d frames in 10 seconds",frames);
            ozputs(0,0,buf);
            ozgetch();
            _oz64hz_word=0;
            frames=0;
        }
#endif
		//ozsetactivepage(!ozgetactivepage());
	}
}
Пример #25
0
void main()
{
restart:

#ifdef JOYSTICK
	hit_border();
#ifndef LOMEM
#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(EINSTEIN)
	msx_text();
#endif

#ifdef SPECTRUM
#ifdef ZX81
	hrg_off();
	zx_colour(112);
#endif
#endif

	printf("%c",12);
	  printf("\n  CHOOSE YOUR JOYSTICK INTERFACE\n\n");
	for (k=0 ; k!=GAME_DEVICES; k++)
	  printf("    %u - %s\n\n",k+1,joystick_type[k]);

	stick=0;
	while ((stick<1) || (stick>GAME_DEVICES)) {
	  stick=getk()-48;
	  }
#else
	stick=1;
#endif
#endif

#ifdef SPECTRUM
#ifdef ZX81
	hrg_on();
	zx_colour(112);
#endif
#endif


#ifdef CLOCK
    srand(clock());
#endif
	tt=-1;

#ifdef ZX81
#if (spritesize == 2)
	speed=500;
#else
	speed=300;
#endif
#else
#ifdef C128
#else
	speed=300;
#endif
#endif

start_level:
#ifdef ZX81
	speed-=100;
#else
	speed-=200;
#endif

	tt++; t=0; p=1;
	clg();
	hit_border();

#ifdef LAMBDA
	zx_border (INK_CYAN);
	zx_colour(112);
#endif


  for (m=1; m<=4; m+=2)
	for (n=0; n<=30; n+=2) {
		putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l);
		putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r);
		putsprite(spr_or,(n*spritesize),((m+4)*spritesizeh),brick_r);
		putsprite(spr_or,((n+1)*spritesize),((m+4)*spritesizeh),brick_l);
	#if (spritesize == 8)
	#ifdef SPECTRUM
	#ifdef ZX81
		*zx_cyx2aaddr(m+3,n) = m<<4;
		*zx_cyx2aaddr(m+3,n+1) = m<<4;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<4;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<4;
	#else
		*zx_cyx2aaddr(m+3,n) = m<<3;
		*zx_cyx2aaddr(m+3,n+1) = m<<3;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<3;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<3;
	#endif
	#endif
	#endif
	
	#ifdef LAMBDA
		*zx_cyx2aaddr(m+3,n) = m<<4;
		*zx_cyx2aaddr(m+3,n+1) = m<<4;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<4;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<4;
	#endif
	
	#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN)
	#if (spritesize == 8)
		set_attr(m+3,n,((m+1)<<1)|0x10);
		set_attr(m+3,n+1,((m+1)<<1)|0x10);
		set_attr(m+4,n,(m<<1)|0x10);
		set_attr(m+4,n+1,(m<<1)|0x10);
	#endif
	#endif
	}
  for (n=0; n<=30; n+=2) {
		putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l);
		putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r);
	#if (spritesize == 8)
	#ifdef SPECTRUM
	#ifdef ZX81
		*zx_cyx2aaddr(m+3,n) = 6<<4;
		*zx_cyx2aaddr(m+3,n+1) = 6<<4;
	#else
		*zx_cyx2aaddr(m+3,n) = 6<<3;
		*zx_cyx2aaddr(m+3,n+1) = 6<<3;
	#endif
	#endif
	#endif
	
	#ifdef LAMBDA
		*zx_cyx2aaddr(m+3,n) = 6<<4;
		*zx_cyx2aaddr(m+3,n+1) = 6<<4;
	#endif
	
	#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN)
	#if (spritesize == 8)
		set_attr(m+3,n,LIGHT_YELLOW|0x10);
		set_attr(m+3,n+1,LIGHT_YELLOW|0x10);
	#endif
	#endif
	}
	
	u=0; v=0; a=14; t=0; w=0;

  for (r=0; r<=6; r++) {
			m=10;  n=8+rand()%15;
			p=0; a=13;

#if (spritesize == 2)
	putsprite(spr_or,(a*spritesize),(21*spritesizeh)-1,paddle);
#else
	putsprite(spr_or,(a*spritesize),(21*spritesizeh),paddle);
#endif

#ifndef LOMEM
	for (i=0; i<=6; i++) {
	  putsprite (spr_and, (24+i)*spritesize, 23*spritesizeh, ball);
	  if (i>r)
		putsprite (spr_or, (24+i)*spritesize, 23*spritesizeh, ball);
	}
#endif

		g=200;

		/* Let's show where the ball stars before the dance begins */
		putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball);

		hit_border();
#ifdef SOUND
		for (i=1; i<14; i++) {
			bit_synth(4, 199+i, 200+i, 239+i, 240+i);
			putsprite(spr_xor,(n*spritesize),(m*spritesizeh),ball);
		}
		bit_synth(9, 255, 254, 253, 252);
#endif

		putsprite(spr_and,(n*spritesize),(m*spritesizeh),ball);

		while (m <= 20) {

			/* delay */
			do_delay();

			move_ball();

			/* total score count is 574 */
			if (t>=573) goto start_level;

			if (u==20)
				putsprite(spr_and,(v*spritesize),(u*spritesizeh),bounce);
			else
				putsprite(spr_and,(v*spritesize),(u*spritesizeh),ball);

			/* Intermediate step to move the ball smoothly */
			putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball);
			do_delay();
			putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball);

			u=m; v=n;
			if (m==20)
				putsprite(spr_or,(n*spritesize),(m*spritesizeh),bounce);
			else
				putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball);

/*
	#ifdef SOUND
		bit_click();
	#endif
*/

#ifdef JOYSTICK
			if (joystick(stick) & MOVE_LEFT) {
				move_left();
				if (joystick(stick) & MOVE_FIRE)
					move_left();
			}
			if (joystick(stick) & MOVE_RIGHT) {
				move_right();
				if (joystick(stick) & MOVE_FIRE)
					move_right();
			}
#else
			k=getk();
			switch (k) {
				case '2':
					move_left();
					break
				case '1':
					move_left();
					move_left();
					break;
				case '9':
					move_right();
					break;
				case '0':
					move_right();
					move_right();
					break;
			}
#endif
		}
		/* ball is lost */

#if (spritesize == 2)
	  putsprite(spr_and,(a*spritesize),(21*spritesizeh)-1,paddle);
#else
	  putsprite(spr_and,(a*spritesize),(21*spritesizeh),paddle);
#endif
  }


#ifdef ZX81
#if (spritesize == 2)
  #asm
			ld	a,$1e
			ld	i,a
  #endasm
#endif
#endif

#ifndef LOMEM
#ifdef BANNERS
  putsprite(spr_or,40,(12*spritesizeh),scorebanner);
  sprintf (scoretxt,"%05u",tt*1000+t);

  k=0;
  for (i=0; i<5; i++) {
    putsprite (spr_or, 140+i+k, 12*spritesizeh+7, &bigdigit[(scoretxt[i]-48)*38]);
	if (scoretxt[i]=='1')
		k+=5;
	else
		k+=14;
  }

#else
  printf("%c\n\n Score: %u ",12,tt*1000+t);
#endif
#endif

/*  return (tt*1000+t); */
#ifdef SOUND
bit_fx2(5);
#endif
while (getk()) {}
while (!getk()) {}

goto restart;

}
Пример #26
0
main()
{
	int x,y,z;
	int flag  = 1;
	int speed = 1;
	char *ptr;
	for (x=10; x<39; x+=3)
	{
		putsprite(spr_or,2*x   ,x,bullet);
		putsprite(spr_or,2*x-10,x,bullet);
		putsprite(spr_or,2*x+10,x,bullet);
	}

	x=40;
	y=20;

	bksave(x,y,arrow_bk);

	while(flag!=2)
	{
		switch(getk())
		{
			case 11: /* arrow up */
			  y-=speed;
			  flag=1;
			  break;
			case 10: /* arrow down */
			  y+=speed;
			  flag=1;
			  break;
			case 9:  /* arrow right */
			  x+=speed;
			  flag=1;
			  break;
			case 8:  /* arrow left */
			  x-=speed;
			  flag=1;
			  break;
			case 13: /* [Enter] */
			  flag=2;
			  break;
			default: /* reset speed */
			  speed=1;
			  break;
		}
		if(x<0) x=0;
		if(y<0) y=0;
		if(x>(SCREENX-8)) x=(SCREENX-8);
		if(y>(SCREENY-8)) y=(SCREENY-8);
		if(flag==1)
		{
			if(speed<3)
			speed++;

			bkrestore(arrow_bk);
			bksave(x,y,arrow_bk);
			putsprite(spr_or,x,y,arrow);
			putsprite(spr_mask,x,y,arrow_mask);
			flag = 0;
		}
	}
}
Пример #27
0
main()
{
#ifdef DETAILED
	sz=getmaxy()/2-5;
	long_sz=sz-18;
	short_sz=sz/2;
#else
	sz=getmaxy()/2-1;
	long_sz=sz-2;
	short_sz=sz/2;
#endif	
	cx=getmaxx()/2;
	cy=getmaxy()/2;
	
	printf("%cTime set..\n\n  Hours: ",12);
	gets(hr);
	k=atoi(hr);
	printf("\n  Minutes: ");
	scanf("%s",hr);
	j=atoi(hr);

	k=k*5+(j/12);
	if (k<15)
		k=k+45;
	else
		k-=15;

	if (j<15)
		j=j+45;
	else
		j-=15;
	
	clg();

	circle(cx,cy,cy,1);
#ifdef DETAILED
	circle(cx,cy,cy-3,1);
	circle(cx,cy,3,1);
#endif
	for (i=0;i<60;i++) {
		x=icos(i*6)*sz/256;
		y=isin(i*6)*sz/256;
		
		plot (cx+x,cy+y);
	
	}

#ifdef DETAILED
	for (i=0;i<12;i++) {
		x=isin(i*30)*(sz-8)/256;
		y=icos(i*30)*(sz-8)/256;
		putsprite(spr_or, cx+x-5, cy-y-3, roman_nums + i*16 + 7*(i>8));
	}
#endif

	x=-1;

	i=0;
	
	tm=clock();
	
	while (getk()!=' ') {
		tm=clock();
		if (i++ == 59) i=0;
		if (i == 45) {
			if (x != -1) {
				// min
				undraw(cx-1,cy+1,cx+x_min,cy+y_min);
				undraw(cx+1,cy-1,cx+x_min,cy+y_min);
				undraw(cx+1,cy+1,cx+x_min,cy+y_min);
				undraw(cx-1,cy-1,cx+x_min,cy+y_min);
			}
			if (j++ == 59) {
				j=0;
			}
			if (j == 45) {
				if (x != -1) {
					undraw(cx,cy,cx+x_hr,cy+y_hr);
					undraw(cx-1,cy+1,cx+x_hr-1,cy+y_hr+1);
					undraw(cx+1,cy-1,cx+x_hr+1,cy+y_hr-1);
					undraw(cx+1,cy+1,cx+x_hr+1,cy+y_hr+1);
					undraw(cx-1,cy-1,cx+x_hr-1,cy+y_hr-1);
				}
				if (k++ == 59) k=0;
			}
		}

		if (x != -1) {
			//sec
			undraw(cx,cy,cx+x,cy+y);
		}
		x=icos(i*6)*long_sz/256;
		y=isin(i*6)*long_sz/256;

		x_min=icos(j*6)*long_sz/256;
		y_min=isin(j*6)*long_sz/256;

		x_hr=icos(k*6)*short_sz/256;
		y_hr=isin(k*6)*short_sz/256;

		// sec
		draw(cx,cy,cx+x,cy+y);

		// min
		draw(cx-1,cy+1,cx+x_min,cy+y_min);
		draw(cx+1,cy-1,cx+x_min,cy+y_min);
		draw(cx+1,cy+1,cx+x_min,cy+y_min);
		draw(cx-1,cy-1,cx+x_min,cy+y_min);

		// hr
		draw(cx,cy,cx+x_hr,cy+y_hr);
		draw(cx-1,cy+1,cx+x_hr-1,cy+y_hr+1);
		draw(cx+1,cy-1,cx+x_hr+1,cy+y_hr-1);
		draw(cx+1,cy+1,cx+x_hr+1,cy+y_hr+1);
		draw(cx-1,cy-1,cx+x_hr-1,cy+y_hr-1);

		circle(cx,cy,3,1);
#ifdef DETAILED
		circle(cx,cy,5,1);
#endif

		while ((clock() < (tm+CLOCKS_PER_SEC))&&(clock() > CLOCKS_PER_SEC)) {}
		tm=clock();
	
	}

}
Пример #28
0
void Ping()
{
    char	buffer[80];
    char	buffer2[20];
    u16_t	i;
    u16_t	sequence;
    u32_t	ident;
    u32_t	timeout;
    ipaddr_t  addr;
    
    printf("Enter hostname/IP to ping\n");

    fgets_cons(buffer,79);
    if ( (addr=resolve_i(buffer) ) == 0L ) {
	printf("\nUnknown host\n");
	return;
    }

    

    memset(pingstat,0,sizeof(pingstat));
    
    ident = sequence = 0;
    received = pingav = pingmin = pingmax = 0;
    
    if ( icmp_register(ping_handler) == NULL ) {
	printf("\nCan't register handler..\n");
	return;
    }
    
    printf("\nPING %s (%s): 56 data bytes\n",buffer,inet_ntoa_i(addr,buffer2));


    timeout = set_timeout(50);
    for (;;) {
	if (  chk_timeout(timeout) ) {
	    timeout = set_timeout(100);
	    if ( ping_send(addr,&ident) ) 
		ident++;
	    else
		break;
	} 
#ifdef __Z88__
	if (getk() == 27 ) break;
#else
	if ( ident == 4 )
	    break;
#endif
	BUSYINT();
   }


    icmp_deregister();
    /* Just to test the resolver.... */
    if (reverse_addr_lookup_i(addr,buffer) == 0 )
	inet_ntoa_i(addr,buffer);
    printf("\n--- %s ping statistics ---\n",buffer);
    printf("%lu packets transmitted, %d packets received, %d%% packet loss\n",ident,received, 100-((received*100)/ident)  );
    printf("round-trip time min/avg/max= %d/%d/%d ms\n",pingmin,(pingav*10)/received,pingmax);
    return;
}
Пример #29
0
int & getb() {
	static int b = getk();
	return b;
}