Update SAE
This commit is contained in:
parent
cc9a68d4a1
commit
5a2f4c2f48
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "utils.h"
|
||||
#include "taquin.h"
|
||||
#include "graph_sup.h"
|
||||
@ -26,11 +27,6 @@ void UpdateTaquin() {
|
||||
}
|
||||
}
|
||||
|
||||
//Randomise le Taquin.
|
||||
void RandomizeTaquin() {
|
||||
|
||||
}
|
||||
|
||||
//Vérifie si le Taquin est en ordre et retourne 1 si oui, 0 si non.
|
||||
int CheckVictory() {
|
||||
int X, Y;
|
||||
@ -96,6 +92,32 @@ int MovePiece(int X, int Y, int Index, int ShouldUpdate) {
|
||||
return NewX + 2 * NewY;
|
||||
}
|
||||
|
||||
//Randomise le Taquin.
|
||||
void RandomizeTaquin() {
|
||||
int CX = 0, CY = 0;
|
||||
int LastMove = -1;
|
||||
|
||||
srand(Microsecondes());
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
LastMove = rand() % 4 == LastMove ? (LastMove + 1) % 4 : rand() % 4;
|
||||
srand(Microsecondes());
|
||||
|
||||
if (LastMove == 0 && CX + 1 < Columns) /*Droite*/ {
|
||||
CX++;
|
||||
MovePiece(CX, CY, Taquin[CX][CY], 0);
|
||||
} else if (LastMove == 1 && CY + 1 < Rows) /*Bas*/ {
|
||||
CY++;
|
||||
MovePiece(CX, CY, Taquin[CX][CY], 0);
|
||||
} else if (LastMove == 2 && CX - 1 > -1) /*Gauche*/ {
|
||||
CX--;
|
||||
MovePiece(CX, CY, Taquin[CX][CY], 0);
|
||||
} else if (LastMove == 3 && CY - 1 > -1) /*Haut*/ {
|
||||
CY--;
|
||||
MovePiece(CX, CY, Taquin[CX][CY], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaquinRenderLogicLoop() {
|
||||
int CurID = -1, LastID = -1, LastX = 0, LastY = 0, Victory = 0;
|
||||
|
||||
@ -249,6 +271,8 @@ void CreateTaquin(char * FileName, int ImX, int ImY, int RowNumber, int ColumnNu
|
||||
DessinerRectangle(49, OFFSET_Y + (500 - ImageY) / 2 - 1, ImageX + 1, ImageY + 1);
|
||||
ChargerImage(FileName, 50, OFFSET_Y + (500 - ImageY) / 2, 0, 0, ImageX, ImageY);
|
||||
|
||||
RandomizeTaquin(); //On randomise notre taquin.
|
||||
|
||||
UpdateTaquin();
|
||||
TaquinRenderLogicLoop(); //Cette fonction est responsable de tout le déroulement de la partie.
|
||||
ShowVictoryScreen(); //On est après une partie, on affiche l'écran de victoire.
|
||||
|
Loading…
Reference in New Issue
Block a user