Initial commit
This commit is contained in:
commit
441143482a
13 changed files with 230 additions and 0 deletions
11
Makefile
Normal file
11
Makefile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -Wextra -std=c99
|
||||
OBJ=main.o horno.o empanada.o utils.o
|
||||
|
||||
all: horno_simulator
|
||||
|
||||
horno_simulator: $(OBJ)
|
||||
$(CC) $(CFLAGS) -o horno_simulator $(OBJ)
|
||||
|
||||
clean:
|
||||
rm -f *.o horno_simulator
|
||||
48
empanada.c
Normal file
48
empanada.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "empanada.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void inicializarEmpanada(Empanada* e, const char* relleno) {
|
||||
strncpy(e->relleno, relleno, 29);
|
||||
e->tiempo_coccion = 5 + rand() % 6;
|
||||
e->tiempo_actual = 0;
|
||||
e->activa = 1;
|
||||
e->estado = CRUDA;
|
||||
|
||||
int azar = rand() % 100;
|
||||
if (azar < 5) {
|
||||
e->estado = CUANTICA;
|
||||
} else if (azar < 15) {
|
||||
e->estado = SIN_RELLENO;
|
||||
e->tiene_relleno = 0;
|
||||
} else {
|
||||
e->tiene_relleno = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void cocinar(Empanada* e) {
|
||||
if (e->activa == 0) return;
|
||||
if (e->estado == CUANTICA || e->estado == SIN_RELLENO || e->estado == QUEMADA) return;
|
||||
|
||||
e->tiempo_actual++;
|
||||
|
||||
if (e->tiempo_actual < e->tiempo_coccion) {
|
||||
e->estado = EN_COCINA;
|
||||
} else if (e->tiempo_actual == e->tiempo_coccion) {
|
||||
e->estado = LISTA;
|
||||
} else {
|
||||
e->estado = QUEMADA;
|
||||
}
|
||||
}
|
||||
|
||||
const char* estadoToString(Estado estado) {
|
||||
switch (estado) {
|
||||
case CRUDA: return "Cruda";
|
||||
case EN_COCINA: return "En cocina";
|
||||
case LISTA: return "Lista";
|
||||
case QUEMADA: return "Quemada";
|
||||
case CUANTICA: return "Cuantica";
|
||||
case SIN_RELLENO: return "Sin relleno";
|
||||
default: return "Desconocido";
|
||||
}
|
||||
}
|
||||
26
empanada.h
Normal file
26
empanada.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef EMPANADA_H
|
||||
#define EMPANADA_H
|
||||
|
||||
typedef enum {
|
||||
CRUDA,
|
||||
EN_COCINA,
|
||||
LISTA,
|
||||
QUEMADA,
|
||||
CUANTICA,
|
||||
SIN_RELLENO
|
||||
} Estado;
|
||||
|
||||
typedef struct {
|
||||
char relleno[30];
|
||||
int tiempo_coccion;
|
||||
int tiempo_actual;
|
||||
Estado estado;
|
||||
int tiene_relleno;
|
||||
int activa;
|
||||
} Empanada;
|
||||
|
||||
const char* estadoToString(Estado estado);
|
||||
void cocinar(Empanada* e);
|
||||
void inicializarEmpanada(Empanada* e, const char* relleno);
|
||||
|
||||
#endif
|
||||
BIN
empanada.o
Normal file
BIN
empanada.o
Normal file
Binary file not shown.
26
horno.c
Normal file
26
horno.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include "horno.h"
|
||||
|
||||
void mostrarEmpanadas(Empanada horno[], int cantidad) {
|
||||
int mostradas = 0;
|
||||
for (int i = 0; i < cantidad; i++) {
|
||||
if (horno[i].activa == 0) continue;
|
||||
|
||||
printf("Empanada %d: %s - %s (%d/%d)",
|
||||
i + 1,
|
||||
horno[i].relleno,
|
||||
estadoToString(horno[i].estado),
|
||||
horno[i].tiempo_actual,
|
||||
horno[i].tiempo_coccion
|
||||
);
|
||||
if (horno[i].tiene_relleno == 0) printf(" [SIN RELLENO]");
|
||||
|
||||
printf("\n");
|
||||
mostradas++;
|
||||
}
|
||||
|
||||
if (mostradas == 0) {
|
||||
printf("El horno está vacio!\n");
|
||||
}
|
||||
}
|
||||
|
||||
10
horno.h
Normal file
10
horno.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef HORNO_H
|
||||
#define HORNO_H
|
||||
|
||||
#include "empanada.h"
|
||||
|
||||
#define MAX_EMPANADAS 10
|
||||
|
||||
void mostrarEmpanadas(Empanada horno[], int cantidad);
|
||||
|
||||
#endif
|
||||
BIN
horno.o
Normal file
BIN
horno.o
Normal file
Binary file not shown.
BIN
horno_simulator
Executable file
BIN
horno_simulator
Executable file
Binary file not shown.
79
main.c
Normal file
79
main.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "empanada.h"
|
||||
#include "horno.h"
|
||||
#include "utils.h"
|
||||
|
||||
int main() {
|
||||
Empanada horno[MAX_EMPANADAS];
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < MAX_EMPANADAS; i++) {
|
||||
horno[i].activa = 0;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
limpiarPantalla();
|
||||
imprimirHeader();
|
||||
printf("\n1. Agregar empanada\n2. Cocinar 1 segundo\n3. Mostrar horno\n4. Sacar empanada\n5. Salir\n> ");
|
||||
int opcion;
|
||||
scanf("%d", &opcion);
|
||||
getchar();
|
||||
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
char relleno[30];
|
||||
printf("Relleno: ");
|
||||
fgets(relleno, sizeof(relleno), stdin);
|
||||
relleno[strcspn(relleno, "\n")] = '\0';
|
||||
|
||||
int index = -1;
|
||||
for (int i = 0; i < MAX_EMPANADAS; i++) {
|
||||
if (horno[i].activa == 0) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != -1) {
|
||||
inicializarEmpanada(&horno[index], relleno);
|
||||
}
|
||||
else {
|
||||
printf("El horno está lleno.\n");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (int i = 0; i < MAX_EMPANADAS; i++) {
|
||||
cocinar(&horno[i]);
|
||||
}
|
||||
printf("Cocinando...\n");
|
||||
sleep(1);
|
||||
break;
|
||||
case 3:
|
||||
mostrarEmpanadas(horno, MAX_EMPANADAS);
|
||||
pausar();
|
||||
break;
|
||||
case 4:
|
||||
int cual;
|
||||
printf("¿Cual queré sacar? [1 a %d]?", MAX_EMPANADAS);
|
||||
scanf("%d", &cual);
|
||||
getchar();
|
||||
cual--;
|
||||
|
||||
if (cual >= 0 && cual < MAX_EMPANADAS && horno[cual].activa == 1) {
|
||||
printf("\nQue disfrutes tu empanada de '%s [%s]', campeón", horno[cual].relleno, estadoToString(horno[cual].estado));
|
||||
horno[cual].activa = 0;
|
||||
} else {
|
||||
printf("Ahi no hay nada!");
|
||||
}
|
||||
pausar();
|
||||
break;
|
||||
case 5:
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
main.o
Normal file
BIN
main.o
Normal file
Binary file not shown.
22
utils.c
Normal file
22
utils.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "utils.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void limpiarPantalla() {
|
||||
printf("\033[2J\033[H");
|
||||
}
|
||||
|
||||
void pausar() {
|
||||
printf("\nPresione ENTER para continuar...");
|
||||
getchar();
|
||||
}
|
||||
|
||||
void imprimirHeader() {
|
||||
printf("▗▄▄▄▖▗▖ ▗▖ ▗▄▄▖▗▄▄▄▖▗▄▄▖ ▗▄▖ ▗▄▄▖ ▗▄▄▖ ▗▄▄▖\n");
|
||||
printf("▐▌ ▐▛▚▖▐▌▐▌ ▐▌ ▐▌ ▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ \n");
|
||||
printf("▐▛▀▀▘▐▌ ▝▜▌▐▌▝▜▌▐▛▀▀▘▐▛▀▚▖ ▐▛▀▜▌▐▛▀▘ ▐▛▀▘ ▝▀▚▖\n");
|
||||
printf("▐▙▄▄▖▐▌ ▐▌▝▚▄▞▘▐▙▄▄▖▐▌ ▐▌ ▐▌ ▐▌▐▌ ▐▌ ▗▄▄▞▘\n");
|
||||
printf("\n");
|
||||
printf(" - Horno Simulator 2025 \n");
|
||||
printf("\n");
|
||||
}
|
||||
8
utils.h
Normal file
8
utils.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
void limpiarPantalla();
|
||||
void pausar();
|
||||
void imprimirHeader();
|
||||
|
||||
#endif
|
||||
BIN
utils.o
Normal file
BIN
utils.o
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue