#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void input(int* n, char z)
{
	while (1) {
		printf("%c座標を入力してください(0-3) >", z);
		scanf_s("%d", n);
		if (0 <= *n && *n < 4) {
			break;
		}
		printf("範囲外です\n");
	}
}

int main()
{
	int	field[4 * 4] = {0};
	int	bomb[2];
	int	x, y;
	int	round;

	srand((unsigned)time(NULL));
	bomb[0] = rand() % 4;
	bomb[1] = rand() % 4;

	for (round = 1; round <= 15; ) {
		for (y = 0; y < 4; y++) {
			for (x = 0; x < 4; x++) {
				printf("%d ", field[y * 4 + x]);
			}
			printf("\n");
		}
		printf("round %d\n", round, bomb[0], bomb[1]);
		input(&x, 'x');
		input(&y, 'y');
		if (field[y * 4 + x]) {
			printf("既に選んでいます\n");
			continue;
		}
		if (x == bomb[0] && y == bomb[1]) {
			printf("wham!\n");
			return 0;
		}
		field[y * 4 + x] = 1;
		round++;
	}
	printf("You Win!\n");
	return 0;
}
