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 140 141 142 143 144 145 146 147 148
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define dice 16
#define face 6
#define size_board 4
int di, r, i, j = 0;
char c;
const char *grid[size_board][size_board];
const char *de[dice][face] = {
{"E", "H", "I", "S", "N", "R"},
{"M", "S", "R", "I", "A", "O"},
{"D", "C", "M", "P", "A", "E"},
{"R", "C", "L", "S", "A", "E"},
{"N", "U", "L", "E", "G", "Y"},
{"E", "N", "O", "D", "T", "S"},
{"S", "H", "E", "F", "E", "I"},
{"F", "X", "R", "A", "O", "I"},
{"I", "B", "A", "L", "T", "R"},
{"E", "G", "I", "N", "T", "V"},
{"Z", "E", "V", "A", "D", "N"},
{"M", "A", "Q", "O", "B", "J"},
{"U", "E", "O", "N", "T", "K"},
{"P", "E", "L", "U", "T", "S"},
{"W", "R", "L", "E", "V", "I"},
{"O", "T", "A", "E", "I", "A"}
};
//fonction de generation grille de jeu
int
genergrid (int i, int j, int di, int r)
{
//si la grille est egale a zero
if (grid[i - 1][j - 1] == NULL)
{
// on y met un dé de[di-1] avec une face [r-1]
grid[i - 1][j - 1] = de[di - 1][r - 1];
/*printf("%d", i);
printf("%d\n", j);*/
return 0;
}
else
{
i = rand () % 4 + 1;
j = rand () % 4 + 1;
genergrid (i, j, di, r);
}
}
int
getch (char c)
{
c = getchar ();
if (c = getchar () != EOF)
{
}
return 0;
}
int
main (int argc, char *argv[])
{
printf (" \033[2J");
srand (time (NULL));
for (di = 1; di < dice + 1; di = di + 1)
{
int r = rand () % 6 + 1;
/*printf("%s", de[di-1][r-1]);*/
i = rand () % 4 + 1;
j = rand () % 4 + 1;
genergrid (i, j, di, r);
}
for (i = 1; i < 5; i = i + 1)
{
for (j = 1; j < 5; j = j + 1)
{
printf ("\033[%d;%dH", i, j);
printf ("%s", grid[i - 1][j - 1]);
printf ("\n");
}
}
int chrono = 0;
int tempsPrecedent = 0, tempsActuel = 0;
do
{
printf ("\033[6;3H");
printf ("%d s\n", chrono);
tempsActuel = clock ();
printf("actuel %ld\n\n",tempsActuel/CLOCKS_PER_SEC);
printf("temps precedent %ld\n",tempsPrecedent/CLOCKS_PER_SEC);
printf("temps restant %d\n",(tempsActuel - tempsPrecedent));
printf("%ld secondes\n", tempsActuel/CLOCKS_PER_SEC);
if ((tempsActuel - tempsPrecedent) > 30) /* Si 30 ms s'est écoulée */
{
tempsPrecedent = tempsActuel;
}
/* Le temps "actuel" devient le temps "precedent" pour nos futurs calculs */
else /* Si ça fait moins de 1 s depuis le dernier tour de boucle, on endort le programme le temps qu'il faut */
{
usleep (30 - (tempsActuel - tempsPrecedent));
}
}
while (tempsActuel/CLOCKS_PER_SEC<180);
// printf ("fini");
printf ("\e[?25l");
getch (c);
printf ("\e[?25h");
return 0;
} |
Partager