Update SAE

This commit is contained in:
HORVILLE 2021-12-09 11:26:52 +01:00
parent 1e5af3a679
commit f3c626ac02
6 changed files with 108 additions and 15 deletions

View File

@ -4,14 +4,14 @@ taquin : main.o taquin.o menu.o graph_sup.o
main.o : main.c main.h
gcc -c main.c
graph_sup.o : graph_sup.c graph_sup.h
gcc -c graph_sup.c
taquin.o : taquin.c taquin.h
gcc -c taquin.c
menu.o : menu.c menu.h
gcc -c menu.c
graph_sup.o : graph_sup.c graph_sup.h
gcc -c graph_sup.c
clean :
rm -f *.o

View File

@ -3,15 +3,15 @@
#include <graph.h>
#include "graph_sup.h"
#include "taquin.h"
#include "menu.h"
int main(int argc, char* argv[]) {
InitialiserGraphique();
CreerFenetre((Maxx() - WIDTH) / 2, (Maxy() - HEIGHT) / 2, 1200, 700);
ChoisirTitreFenetre("Taquin"); /* Ben alors Denis, on nous cache des fonctions ? */
CreateTaquin("./images/luna.png", 500, 445, 4, 4);
Touche();
while (1) {
if (!DrawMenu()) break;
};
FermerGraphique();
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <string.h>
#include "taquin.h"
#include "graph_sup.h"
void UpdateSelection(char* selection, int param) {
if (selection == "lines") {
int i;
SetColor(0, 0, 0);
for (i = 0; i <= 5; i++) DessinerRectangle(WIDTH - 200, 75 + i * 70, 50, 50); //Lignes
SetColor(255, 0, 0);
for (i = 0; i <= 5; i++) DessinerRectangle(WIDTH - 200, 75 + (param-3) * 70, 50, 50);
} else if (selection == "columns") {
int i;
SetColor(0, 0, 0);
for (i = 0; i <= 5; i++) DessinerRectangle(WIDTH/2 + 150, 75 + i * 70, 50, 50); //Lignes
SetColor(255, 0, 0);
for (i = 0; i <= 5; i++) DessinerRectangle(WIDTH/2 + 150, 75 + (param-3) * 70, 50, 50);
}
};
int DrawMenu() {
ClearButtons();
int MenuHeight = HEIGHT - 120;
int Lines = 3, Columns = 3, i;
char filename[100];
strcpy(filename, "./images/luna.png");
SetColor(0, 0, 0);
char str[3];
for (i = 0; i <= 5; i++) {
AddButton(WIDTH/2 + 150, 75 + i * 70, 50, 50, 10 + i); //Colonnes
AddButton(WIDTH - 200, 75 + i * 70, 50, 50, 20 + i); //Lignes
sprintf(str, "%d", i+3);
EcrireTexte(WIDTH/2 + 175, 100 + i * 70, str, 2);
EcrireTexte(WIDTH - 175, 100 + i * 70, str, 2);
}
DessinerRectangle(WIDTH/2 - 100, HEIGHT - 100, 200, 80);
AddButton(WIDTH/2 - 100, HEIGHT - 100, 200, 80, 1);
UpdateSelection("lines", Lines);
UpdateSelection("columns", Columns);
SetColor(0, 0, 0);
DessinerRectangle(0, 0, WIDTH/2, MenuHeight/3);
DessinerRectangle(0, MenuHeight/3, WIDTH/2, MenuHeight/3);
DessinerRectangle(0, MenuHeight/3 * 2, WIDTH/2, MenuHeight/3);
DessinerSegment(WIDTH/2, 0, WIDTH/2, MenuHeight);
DessinerRectangle(0, MenuHeight, WIDTH, HEIGHT - MenuHeight);
while (1) {
if (DrawNextFrame()) {
if (SourisCliquee()) {
int BT_ID = GetButton(_X, _Y);
if (BT_ID >= 10 && BT_ID <= 15) {
Columns = BT_ID - 7;
UpdateSelection("columns", Columns);
} else if (BT_ID >= 20 && BT_ID <= 25) {
Lines = BT_ID - 17;
UpdateSelection("lines", Lines);
} else {
if (BT_ID == 1) {
ClearButtons();
EffacerEcran(GetColor(255, 255, 255));
CreateTaquin(filename, 500, 445, Lines, Columns);
}
}
}
}
}
return 0;
}

View File

@ -1,4 +1,6 @@
#ifndef _MENU_H
#define _MENU_H
int DrawMenu();
#endif

View File

@ -125,8 +125,8 @@ int TaquinRenderLoop() {
SourisPosition();
button_id = GetButton(_X, _Y);
if (button_id != last_id) {
if (button_id != -1) DrawPiece(button_id, selected);
if (last_id != -1) DrawPiece(last_id, black);
if (button_id > -1) DrawPiece(button_id, selected);
if (last_id > -1) DrawPiece(last_id, black);
last_id = button_id;
}
}
@ -158,8 +158,12 @@ void RandomizeTaquin() {
}
}
void ShowVictoryScreen() {
}
/* Crée le Taquin et lance les fonctions liées à la logique et au graphisme du Taquin */
void CreateTaquin(char * filename, int image_width, int image_height, int lines, int columns) {
void CreateTaquin(char * filename, int ImageWidth, int ImageHeight, int lines, int columns) {
/* On externalise les valeurs données afin de pouvoir facilement les utiliser plus tard. */
int i;
@ -167,8 +171,8 @@ void CreateTaquin(char * filename, int image_width, int image_height, int lines,
Columns = columns;
strcpy(Filename, filename);
ImageX = image_width;
ImageY = image_height;
ImageX = ImageWidth;
ImageY = ImageHeight;
PieceX = ImageX / Columns;
PieceY = ImageY / Lines;
@ -188,9 +192,17 @@ void CreateTaquin(char * filename, int image_width, int image_height, int lines,
RemplirRectangle(OffsetX - 1, OffsetY - 1, ImageX + 2, ImageY + 1);
ChargerImage(Filename, 50, OffsetY, 0, 0, ImageX, ImageY);
RandomizeTaquin();
AddButton(75, HEIGHT - 100, 250, 60, -2); //Bouton Quitter
AddButton(WIDTH - 325, HEIGHT - 100, 250, 60, -3); //Bouton Sauvegarder ?
SetColor(0, 0, 0);
DessinerRectangle(75, HEIGHT - 100, 250, 60);
DessinerRectangle(WIDTH - 325, HEIGHT - 100, 250, 60);
//RandomizeTaquin();
UpdateTaquin();
if (TaquinRenderLoop()) {
/*ShowVictoryScreen()*/
ShowVictoryScreen();
}
}

View File

@ -1,8 +1,6 @@
#ifndef _TAQUIN_H
#define _TAQUIN_H
extern int ImageX, ImageY;
void UpdateTaquin();
void UpdatePiece(int X, int Y, int Index, couleur Color);
void CreateTaquin(char * FileName, int ImageX, int ImageY, int RowNumber, int ColumnNumber);