Esempio n. 1
0
int draw_field(SESS* s)
{	
	int x,y,c,i;
	
	for (x = 0; x < 3; x++)
	{
		if (x < 2) eiwic->output_print(s->out, "\037");

		for (y = 0; y < 3; y++)
		{
			c = s->field[x][y];

			if (c == 0)
				eiwic->output_printf(s->out, "%c", 'a' + x*3+y);
			else 
				eiwic->output_printf(s->out, "\002%c\002", (c == PLAYER1)?PLAYER1:PLAYER2);
				
			if (y < 2) eiwic->output_print(s->out, " | ");	
		}

		if (x < 2) eiwic->output_print(s->out, "\037\n");	
	}
	
	if (check_for_win(s, 1) || check_for_win(s, 2) || s->tics >= 9)
	{
		if (s->winner == NULL)
		  eiwic->output_printf(s->out, "\nAlright, no winner in this game.\n");
		else
		  eiwic->output_printf(s->out, "\nAnd the Winner is.... %s! Bravo!\n", s->winner->nick);
  
		for (i = 0; i < MAXSESSIONS; i++)
  		if (sessions[i] == s)
  		  sessions[i] = NULL;
		free(s);
  }
  else if (s->tics < 3)
   	eiwic->output_printf(s->out, "\n%s: Your turn, do !tic <letter>\n", s->current->nick);
	else
   	eiwic->output_printf(s->out, "\n");
   	
	return 1;
}
Esempio n. 2
0
/* 
 * unveil_around_player
 *   DESCRIPTION: Show the maze squares in an area around the player.
 *                Consume any fruit under the player.  Check whether
 *                player has won the maze level.
 *   INPUTS: (play_x,play_y) -- player coordinates in pixels
 *   OUTPUTS: none
 *   RETURN VALUE: 1 if player wins the level by entering the square
 *                 0 if not
 *   SIDE EFFECTS: draws maze squares for newly visible maze blocks,
 *                 consumed fruit, and maze exit; consumes fruit and
 *                 updates displayed fruit counts
 */
static int
unveil_around_player (int play_x, int play_y)
{
    int x = play_x / BLOCK_X_DIM; /* player's maze lattice position */
    int y = play_y / BLOCK_Y_DIM;
    int i, j;   /* loop indices for unveiling maze squares */

    /* Check for fruit at the player's position. */
    (void)check_for_fruit (x, y);

    /* Unveil spaces around the player. */
    for (i = -1; i < 2; i++)
	for (j = -1; j < 2; j++)
	    unveil_space (x + i, y + j);
    unveil_space (x, y - 2);
    unveil_space (x + 2, y);
    unveil_space (x, y + 2);
    unveil_space (x - 2, y);

    /* Check whether the player has won the maze level. */
    return check_for_win (x, y);
}
Esempio n. 3
0
void main()
{
	int  i=0, j=0, winner=2; 
	char isContinue = '0' ;

	while(1)
	{
		count = 0;
		for(i=0;i<9;i++){
			z[i]= 0 ;
			a[i]= 0 ; 
		}
	printf("\n\n\tWelcome to the game of Tic-Tac-Toe\n");
	printf("\tPlease enter numbers only from 1 to 9\n\n");
	printf("\n\tThe Blocks are numbered as below, for reference");
	printf("\n\t\t   |   |  \n\t\t 1 | 2 | 3 \n\t\t___|___|___  \n\t\t 4 | 5 | 6 \n\t\t___|___|___  \n\t\t 7 | 8 | 9 \n\t\t   |   |  \n\n");
	while(count<9)
	{
		if((count%2) == 0)
		{
		printf("   Player 1 make your move:\t");
		make_entry();

		winner = check_for_win();
		
		}

		if((count%2)==1)
		{
		 	printf("   Player 2 make your move:\t");
		 	make_entry();
		 winner = check_for_win();
		}
		count++;

		if(winner == 1) // if winner is Player1
		{
			printf("\n Player 1 wins!!! Congratulations\n");

		/*
			for(j=0;j<9;j++)
			printf("%d\t", z[j]);  */
			break;
		}

		if(winner == -1) // if winner is Player2
		{
			printf("\n Player 2 wins!!! Congratulations\n");

		/*
			for(j=0;j<9;j++)
			printf("%d\t", z[j]); */
			break;
		}

		if(winner == 3) // Draw :(
		{
			printf("\n Match Drawn\n");

		/*	for(j=0;j<9;j++)
			printf("%d\t", z[j]); */
			break;
		}
		DisplayBoard();
	}
	printf("Do you wish to continue[y/n]\n" );
	scanf("%c",&isContinue);
	if(isContinue == 'n'){
		printf("Exiting the game\nThanks for playing see you soon!!!!\n");
		break;
	}
}



}