Exemplo n.º 1
0
/*
 *	subroutine to eat a cookie one is carrying
 */
void eatcookie (void)
{
    int i;
    char *p;

    while (1) {
	if ((i = whatitem("eat"))==ESC)  
		return;
	if (i != '.') {
	    if (i=='*') {
		showeat(); 
	    } else {
		if (iven[i-'a']==OCOOKIE) {
		    lprcat("\nThe cookie was delicious.");
		    iven[i-'a']=0;
		    if (!c[BLINDCOUNT]) {
			if ((p=fortune(fortfile))!=0) {
				lprcat("  Inside you find a scrap of paper that says:\n");
				lprcat(p);
			}
		    }
		    return;
		}
		if (iven[i-'a']==0) { ydhi(i); return; }
		lprcat("\nYou can't eat that!");  return;
	    }
	}
    }
}
Exemplo n.º 2
0
/* =============================================================================
 * FUNCTION: ocookie
 *
 * DESCRIPTION:
 * Function to process finding a cookie.
 *
 * PARAMETERS:
 *
 *   None
 *
 * RETURN VALUE:
 *
 *   None
 */
void ocookie(int ans)
{
  char *p;

  switch(ans)
  {
    case ESC:
    case 'i':
      return;

    case 'e':
      Print("The cookie tasted good.");
      forget(); /* no more cookie */
      if (c[BLINDCOUNT]) return;

      p = fortune(fortfile);
      if (p == (char *)NULL) return;

      Print("A message inside the cookie reads:");
      Print(p);
      return;

    case 't':
      if (take(OCOOKIE,0)==0) forget();
      return;

    default:
      break;
  }
}
Exemplo n.º 3
0
void ocookie()
{
	char *fortune(), *p;

	lprcat("\nDo you (e) eat it, (t) take it"); 
	iopts();
	while (1) 
		switch(getcharacter()) {
		case ESC:
		case 'i':	
			ignore();	
			return;

		case 'e':	
			lprcat("eat.\nThe cookie tasted good.");
			forget(); /* no more cookie	*/
			if (c[BLINDCOUNT]) return;
			if ((p=fortune(fortfile))==(char *)NULL) return;
			lprcat("  A message inside the cookie reads:\n"); 
			lprcat(p);
			return;

		case 't':	
			lprcat("take.");  
			if (take(OCOOKIE,0)==0) forget();
			return;
		};
}
Exemplo n.º 4
0
Arquivo: 3.c Projeto: gwg-bhb/exercise
int main(void)
{
	char quote[] = "I love you";
	printf("quote is where:%p\n", quote);
	fortune(quote);

	return 0;
}
Exemplo n.º 5
0
Arquivo: 2.c Projeto: gwg-bhb/exercise
int main(void)
{
	char quote[] = "I love you";

	printf("Message length:%ld\n", sizeof(quote));

	fortune(quote);

	return 0;
}
Exemplo n.º 6
0
int
main (int argc, char* argv[]) {
    
    // Read inputs
    Inputs* inputs = read_inputs();

    // Create image
    Image* image = new_image(
            inputs->box.xMax - inputs->box.xMin,
            inputs->box.yMax - inputs->box.xMin);

    // Generate random colors
    Color colors[inputs->numSites];
    for (int i = 0; i < inputs->numSites; i++) {
        colors[i] = random_color(); 
    }

    // Bruteforce voronoi
    for (int i = inputs->box.xMin; i < inputs->box.xMax; i++) {
        for (int j = inputs->box.yMin; j < inputs->box.yMax; j++) {
            Point curr = { .x = i, .y = j };
            int nearest = 0;
            for (int k = 0; k < inputs->numSites; k++) {
                double old_dist = distance_squared(&curr, &inputs->sites[nearest]);
                double new_dist = distance_squared(&curr, &inputs->sites[k]);
                if (new_dist < old_dist) {
                    nearest = k;
                }
            }
            set_pixel(i, j, colors[nearest], image); 
        }
    }

    // Do line sweep
    fortune(inputs, image);
    print_image(image);

    // Free memory
    free_image(image);
    free_inputs(inputs);

    return 0;
}