fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void input(int* n, char z)
  6. {
  7. while (1) {
  8. printf("%c座標を入力してください(0-3) >", z);
  9. scanf_s("%d", n);
  10. if (0 <= *n && *n < 4) {
  11. break;
  12. }
  13. printf("範囲外です\n");
  14. }
  15. }
  16.  
  17. int main()
  18. {
  19. int field[4 * 4] = {0};
  20. int bomb[2];
  21. int x, y;
  22. int round;
  23.  
  24. srand((unsigned)time(NULL));
  25. bomb[0] = rand() % 4;
  26. bomb[1] = rand() % 4;
  27.  
  28. for (round = 1; round <= 15; ) {
  29. for (y = 0; y < 4; y++) {
  30. for (x = 0; x < 4; x++) {
  31. printf("%d ", field[y * 4 + x]);
  32. }
  33. printf("\n");
  34. }
  35. printf("round %d\n", round, bomb[0], bomb[1]);
  36. input(&x, 'x');
  37. input(&y, 'y');
  38. if (field[y * 4 + x]) {
  39. printf("既に選んでいます\n");
  40. continue;
  41. }
  42. if (x == bomb[0] && y == bomb[1]) {
  43. printf("wham!\n");
  44. return 0;
  45. }
  46. field[y * 4 + x] = 1;
  47. round++;
  48. }
  49. printf("You Win!\n");
  50. return 0;
  51. }
  52.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty