1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
Bataille navale
*/
#include <stdio.h>
#define NELEM(a) (sizeof(a)/sizeof*(a))
typedef enum
{
WATER,
STS_NB
}
sts_e;
struct play
{
sts_e a[10][10];
};
void play_init (struct play *this)
{
size_t i;
for (i = 0; i < NELEM (this->a); i++)
{
size_t j;
for (j = 0; j < NELEM (*this->a); j++)
{
this->a[i][j] = WATER;
}
}
}
void play_display (struct play const *this)
{
size_t i;
for (i = 0; i < NELEM (this->a); i++)
{
size_t j;
for (j = 0; j < NELEM (*this->a); j++)
{
printf ("%2d", this->a[i][j]);
}
puts ("");
}
puts ("");
}
typedef enum
{
UNDEFINED,
N,
S,
E,
W,
DIR_NB
}
dir_e;
struct boat
{
/* position */
int x0;
int y0;
dir_e dir;
/* definition */
int len;
char const *name;
};
/*
Regles de placement
Les bateaux sont droits
les bateaux peuvent toucher le bord
les bateaux ne peuvent se toucher, même par le coin
NON :
XXX
XXX
OUI :
XXX
XXX
*/
void placement (struct play *p_play, struct boat *p_boat)
{
printf ("Placement de '%s'\n", p_boat->name);
{
/* tirage du x */
}
}
int main (void)
{
/* zone de jeux */
struct play play;
/* liste des bateaux a placer */
struct boat a_boats[] = {
{0, 0, UNDEFINED, 5, "Porte avion"},
{0, 0, UNDEFINED, 4, "Cuirassier"},
{0, 0, UNDEFINED, 3, "Destroyer 1"},
{0, 0, UNDEFINED, 3, "Destroyer 2"},
{0, 0, UNDEFINED, 2, "Fregate 1"},
{0, 0, UNDEFINED, 2, "Fregate 2"},
{0, 0, UNDEFINED, 2, "Fregate 3"},
{0, 0, UNDEFINED, 1, "Vedette 1"},
{0, 0, UNDEFINED, 1, "Vedette 2"},
{0, 0, UNDEFINED, 1, "Vedette 3"},
{0, 0, UNDEFINED, 1, "Vedette 4"},
};
size_t i;
randomize();
play_init (&play);
play_display (&play);
for (i = 0; i < NELEM (a_boats); i++)
{
struct boat *p = a_boats + i;
placement (&play, p);
}
play_display (&play);
return 0;
} |
Partager