83 lines
2.0 KiB
C
83 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include "structs.h"
|
|
#include "gamedefs.h"
|
|
#include "game.h"
|
|
|
|
void
|
|
nuevojuego (struct game *g)
|
|
{
|
|
int x, y, z, cantidad;
|
|
|
|
g->status=PLAYING;
|
|
g->display->up = 0.0f;
|
|
g->display->zoom = 0.0f;
|
|
g->display->tilt_y = 0.0f;
|
|
g->display->side = 0.0f;
|
|
g->descubiertas = 0;
|
|
g->start_time = time (NULL);
|
|
|
|
cantidad = g->config->n;
|
|
for (x = 1; x < g->config->side[0] - 1; x++)
|
|
for (y = 1; y < g->config->side[1] - 1; y++)
|
|
for (z = 1; z < g->config->side[2] - 1; z++)
|
|
g->campoV[x][y][z] = NUEVO;
|
|
for (x = 1; x < g->config->side[0] - 1; x++)
|
|
for (y = 1; y < g->config->side[1] - 1; y++)
|
|
for (z = 1; z < g->config->side[2] - 1; z++)
|
|
g->campo[x][y][z] = 0;
|
|
|
|
srand (time (NULL));
|
|
while (cantidad > 0)
|
|
{
|
|
x = 1 + (int) (rand () / ((float) RAND_MAX) * (g->config->side[0] - 2));
|
|
y = 1 + (int) (rand () / ((float) RAND_MAX) * (g->config->side[1] - 2));
|
|
z = 1 + (int) (rand () / ((float) RAND_MAX) * (g->config->side[2] - 2));
|
|
if (g->campo[x][y][z] == 0)
|
|
{
|
|
g->campo[x][y][z] = BOMBA;
|
|
cantidad--;
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
descubrir (struct game *g, int x, int y, int z)
|
|
{
|
|
int i, j, k, num = 0;
|
|
int lado1 = g->config->side[0], lado2 = g->config->side[1], lado3 =
|
|
g->config->side[2];
|
|
|
|
if (g->campoV[x][y][z] == NUEVO)
|
|
{
|
|
if (g->campo[x][y][z] != BOMBA)
|
|
{
|
|
for (i = -1; i <= 1; i++)
|
|
for (j = -1; j <= 1; j++)
|
|
for (k = -1; k <= 1; k++)
|
|
if (g->campo[x + i][y + j][z + k] == BOMBA)
|
|
num++;
|
|
g->campoV[x][y][z] = num;
|
|
g->descubiertas++;
|
|
if (g->descubiertas ==
|
|
(lado1 - 2) * (lado2 - 2) * (lado3 - 2) - g->config->n)
|
|
g->status = WON;
|
|
if (num == 0)
|
|
{
|
|
g->campoV[x][y][z] = 0;
|
|
for (i = -1; i <= 1; i++)
|
|
for (j = -1; j <= 1; j++)
|
|
for (k = -1; k <= 1; k++)
|
|
if (!(i == 0 && j == 0 && k == 0)
|
|
&& g->campoV[x + i][y + j][z + k] != BOMBA)
|
|
descubrir (g, x + i, y + j, z + k);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g->status = LOST;
|
|
}
|
|
}
|
|
}
|