Vous êtes sur la page 1sur 12

// � ChessMaster Version 1.

00 FR
// Copyright Lo�c Perrin - 2015
// all rights reserved

// D�claration des fonctions:

affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_selection(x,y, couleur);
affichage_deselection(x,y);
affichage_message(index);
affichage_last_move(last_move);
acquisition_tactile(plateau);
ajout_capture(piece, liste);
equipe(piece);
initialisation();
sauvegarde();
debugger();
partie_sauvegarde();
partie_chargement();
menu();
lancement();
takeback();
interaction();
ChessMaster();

// D�claration des variables globales:

plateau;
C_rouges;
C_bleus;
tour;
last_move;

sav_plateau;
sav_C_rouges;
sav_C_bleus;
sav_tour;
sav_last_move;

EXPORT slot1 := {0,0,0,0,0,0,0,0};


EXPORT slot2 := {0,0,0,0,0,0,0,0};
EXPORT slot3 := {0,0,0,0,0,0,0,0};
EXPORT slot4 := {0,0,0,0,0,0,0,0};
EXPORT slot5 := {0,0,0,0,0,0,0,0};

// D�finition des fonctions:

affichage_plateau()
BEGIN
LOCAL couleur := 0;

FOR Y FROM 0 TO 210 STEP 30 DO


couleur := 1 - couleur;
FOR X FROM 39 TO 249 STEP 30 DO
couleur := 1 - couleur;
IF couleur == 0 THEN
RECT_P(X,Y,X+30,Y+30,0,0);
ELSE
RECT_P(X,Y,X+30,Y+30,RGB(255,255,255),RGB(255,255,255));
END;
END;
END;

RECT_P(0,0,38,239,RGB(0,0,0),RGB(102,51,0));
RECT_P(279,0,319,239,RGB(0,0,0),RGB(102,51,0));

END;

//-----------------------------------------------------

affichage_tour(tour)
BEGIN
LOCAL couleur_contour;

IF tour == 1 THEN
couleur_contour := RGB(255,0,0);
ELSE
couleur_contour := RGB(0,0,255);
END;

RECT_P(0,0,38,239,couleur_contour,RGB(0,0,0,255));
RECT_P(279,0,319,239,couleur_contour,RGB(0,0,0,255));

END;

//-----------------------------------------------------

affichage_pieces(plateau)
BEGIN
LOCAL pieces, couleur := 0, num_piece;
pieces := "??????";

FOR Y FROM 1 TO 8 DO
FOR X FROM 1 TO 8 DO
num_piece := plateau(Y,X);
IF num_piece >= 7 THEN
couleur := 0;
num_piece := num_piece - 6;
ELSE
couleur := 1;
END;

IF num_piece ? 0 THEN
IF couleur == 1 THEN
TEXTOUT_P(CHAR(pieces(num_piece)),(X-1)*30+43,(Y-
1)*30,7,RGB(255,0,0)); //piece rouges
ELSE
TEXTOUT_P(CHAR(pieces(num_piece)),(X-1)*30+43,(Y-
1)*30,7,RGB(0,0,255)); //piece bleues
END;
END;
END;
END;
END;

//-----------------------------------------------------

affichage_piece_capture(C_rouges, C_bleus)
BEGIN
LOCAL pieces, num_piece_rouge, num_piece_bleue, position;
pieces := "??????";

FOR position FROM 1 TO 15 DO


num_piece_rouge := C_rouges(position);
num_piece_bleue := C_bleus(position);
IF num_piece_rouge ? 0 THEN
TEXTOUT_P(CHAR(pieces(num_piece_rouge)),13,position*16-16,3,RGB(255,128,128));
//piece rouges
END;
IF num_piece_bleue ? 0 THEN
TEXTOUT_P(CHAR(pieces(num_piece_bleue)),292,position*16-16,3,RGB(128,128,255));
//piece bleues
END;
END;

END;

//-----------------------------------------------------

affichage_selection(x,y,couleur)
BEGIN

x := (x-1)*30+39;
y := (y-1)*30;

RECT_P(x,y,x+29,y+29,couleur,RGB(0,0,0,255));
RECT_P(x+1,y+1,x+28,y+28,couleur,RGB(0,0,0,255));

END;

//-----------------------------------------------------

affichage_deselection(x,y)
BEGIN
LOCAL couleur;

x := (x-1)*30+39;
y := (y-1)*30;

IF GETPIX_P(x+2,y+2) == RGB(0,0,0) THEN


couleur := RGB(0,0,0);
ELSE
couleur := RGB(255,255,255);
END;

RECT_P(x,y,x+29,y+29,couleur,RGB(0,0,0,255));
RECT_P(x+1,y+1,x+28,y+28,couleur,RGB(0,0,0,255));

END;

//-----------------------------------------------------
affichage_message(index)
BEGIN

RECT_P(95,95,225,145,RGB(136,66,29));
RECT_P(100,100,220,140,RGB(131,166,151));

IF index == 1 THEN
TEXTOUT_P("Echec",132,106,7,RGB(0,0,0));
END;

IF index == 2 THEN
TEXTOUT_P("Mat",140,106,7,RGB(0,0,0));
END;

IF index == 3 THEN
TEXTOUT_P("Pat",142,106,7,RGB(0,0,0));
END;

IF index == 4 THEN
TEXTOUT_P("Partie nulle",103,106,7,RGB(0,0,0));
END;

END;

//-----------------------------------------------------

affichage_last_move(last_move)
BEGIN

affichage_selection(last_move(1),last_move(2),RGB(128,128,128));
affichage_selection(last_move(3),last_move(4),RGB(128,128,128));

END;

//-----------------------------------------------------

acquisition_tactile(plateau)
BEGIN
LOCAL x, y, coord, piece;

x := IP(MOUSE(0));
y := IP(MOUSE(1));
//conversion coordonn�es:
x := CEILING((x - 40)/30);
y := CEILING(y/30);

IF x>8 OR x<1 OR y>8 OR y<1 THEN


x := -1;
y := -1;
piece := -1;
ELSE
piece := plateau(y,x);
END;

RETURN {x, y, piece};


END;

//-----------------------------------------------------
ajout_capture(piece, liste)
BEGIN

FOR I FROM 1 TO SIZE(liste) DO


IF liste(I)==0 THEN
liste(I) := piece;
RETURN liste;
END;
END;

RETURN -1;
END;

//-----------------------------------------------------

equipe(piece)
BEGIN

IF piece >= 7 THEN


A := 0;
ELSE
A := 1;
END;

IF piece == 0 THEN
A := -1
END;

RETURN A;
END;

//-----------------------------------------------------

initialisation()
BEGIN

plateau := [[2,3,4,5,6,4,3,2],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[7,7,7,7,7,7,7,7],
[8,9,10,11,12,10,9,8]];
C_rouges := MAKELIST(0,X,1,15);
C_bleus := MAKELIST(0,X,1,15);
tour := 0;
last_move := {-1,-1,-1,-1};

sav_plateau := plateau;
sav_C_rouges := C_rouges;
sav_C_bleus := C_bleus;
sav_tour := tour;
sav_last_move := last_move;

END;

//-----------------------------------------------------

sauvegarde()
BEGIN

sav_plateau := plateau;
sav_C_rouges := C_rouges;
sav_C_bleus := C_bleus;
sav_tour := tour;
sav_last_move := last_move;

END;

//-----------------------------------------------------

partie_sauvegarde()
BEGIN
LOCAL nom_slot1, nom_slot2, nom_slot3, nom_slot4, nom_slot5, nom := "";

nom_slot1 := slot1(1) + " / " + slot1(2) + " / " + slot1(3);


nom_slot2 := slot2(1) + " / " + slot2(2) + " / " + slot2(3);
nom_slot3 := slot3(1) + " / " + slot3(2) + " / " + slot3(3);
nom_slot4 := slot4(1) + " / " + slot4(2) + " / " + slot4(3);
nom_slot5 := slot5(1) + " / " + slot5(2) + " / " + slot5(3);

S := 1;
CHOOSE(S,"Sauvegarder:",nom_slot1, nom_slot2, nom_slot3, nom_slot4, nom_slot5);

IF S == 1 THEN
INPUT(nom,"Nommer la partie:");
slot1(1) := nom;
slot1(2) := Date;
slot1(3) := Time;
slot1(4) := tour;
slot1(5) := C_rouges;
slot1(6) := C_bleus;
slot1(7) := plateau;
slot1(8) := last_move;

END;

IF S == 2 THEN
INPUT(nom,"Nommer la partie:");
slot2(1) := nom;
slot2(2) := Date;
slot2(3) := Time;
slot2(4) := tour;
slot2(5) := C_rouges;
slot2(6) := C_bleus;
slot2(7) := plateau;
slot2(8) := last_move;
END;

IF S == 3 THEN
INPUT(nom,"Nommer la partie:");
slot3(1) := nom;
slot3(2) := Date;
slot3(3) := Time;
slot3(4) := tour;
slot3(5) := C_rouges;
slot3(6) := C_bleus;
slot3(7) := plateau;
slot3(8) := last_move;
END;
IF S == 4 THEN
INPUT(nom,"Nommer la partie:");
slot4(1) := nom;
slot4(2) := Date;
slot4(3) := Time;
slot4(4) := tour;
slot4(5) := C_rouges;
slot4(6) := C_bleus;
slot4(7) := plateau;
slot4(8) := last_move;
END;

IF S == 5 THEN
INPUT(nom,"Nommer la partie:");
slot5(1) := nom;
slot5(2) := Date;
slot5(3) := Time;
slot5(4) := tour;
slot5(5) := C_rouges;
slot5(6) := C_bleus;
slot5(7) := plateau;
slot5(8) := last_move;
END;

RETURN 1;

END;

//-----------------------------------------------------

partie_chargement()
BEGIN
LOCAL nom_slot1, nom_slot2, nom_slot3, nom_slot4, nom_slot5, nom := "";

nom_slot1 := slot1(1) + " / " + slot1(2) + " / " + slot1(3);


nom_slot2 := slot2(1) + " / " + slot2(2) + " / " + slot2(3);
nom_slot3 := slot3(1) + " / " + slot3(2) + " / " + slot3(3);
nom_slot4 := slot4(1) + " / " + slot4(2) + " / " + slot4(3);
nom_slot5 := slot5(1) + " / " + slot5(2) + " / " + slot5(3);

S := 1;
CHOOSE(S,"Charger:",nom_slot1, nom_slot2, nom_slot3, nom_slot4, nom_slot5);

IF S == 1 AND slot1(2) ? 0 THEN


tour := slot1(4);
C_rouges := slot1(5);
C_bleus := slot1(6);
plateau := slot1(7);
last_move := slot1(8);
END;

IF S == 2 AND slot2(2) ? 0 THEN


tour := slot2(4);
C_rouges := slot2(5);
C_bleus := slot2(6);
plateau := slot2(7);
last_move := slot2(8);
END;
IF S == 3 AND slot3(2) ? 0 THEN
tour := slot3(4);
C_rouges := slot3(5);
C_bleus := slot3(6);
plateau := slot3(7);
last_move := slot3(8);
END;

IF S == 4 AND slot4(2) ? 0 THEN


tour := slot4(4);
C_rouges := slot4(5);
C_bleus := slot4(6);
plateau := slot4(7);
last_move := slot4(8);
END;

IF S == 5 AND slot5(2) ? 0 THEN


tour := slot5(4);
C_rouges := slot5(5);
C_bleus := slot5(6);
plateau := slot5(7);
last_move := slot5(8);
END;

RETURN 1;

END;

//-----------------------------------------------------

menu()
BEGIN

S := 1;
CHOOSE(S,"Menu:","Continuer","Sauvegarder","Nouvelle partie","Charger
partie","Quitter");

RETURN S;

END;

//-----------------------------------------------------

lancement()
BEGIN

RECT_P(0,0,319,239,RGB(128,128,128));
RECT_P(30,30,289,139,RGB(110,70,0));
RECT_P(40,40,279,129,RGB(168,168,255));

TEXTOUT_P("CHESS",130,50,7,RGB(168,0,0));
TEXTOUT_P("MASTER",123,70,7,RGB(168,0,0));
TEXTOUT_P("For HP Prime",121,100,3,RGB(255,255,255));
TEXTOUT_P("Copyright Lo�c Perrin - 2015 - FR",5,225,1,RGB(0,0,0));
TEXTOUT_P("V1.0",295,225,1,RGB(0,0,0));

TEXTOUT_P("??????",10,170,7,RGB(255,255,255));
TEXTOUT_P("??????",177,170,7,RGB(0,0,0));
WAIT(2);

END;

//-----------------------------------------------------

takeback()
BEGIN

plateau := sav_plateau;
C_rouges := sav_C_rouges;
C_bleus := sav_C_bleus;
tour := sav_tour;
last_move := sav_last_move;

END;

//-----------------------------------------------------

interaction()
BEGIN
LOCAL x1, x2, y1, y2;
LOCAL piece1, piece2, coord1, coord2;
LOCAL key;

WAIT(-1);

WHILE MOUSE(0) == -1 DO

key := GETKEY();

IF key == 19 THEN
takeback();
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);
END;

IF key >= 0 AND key <= 13 THEN

S := menu();

IF S == 1 THEN
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);

END;

IF S == 2 THEN
partie_sauvegarde();
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);
END;

IF S == 3 THEN
initialisation();
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);
END;

IF S == 4 THEN
partie_chargement();
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);
END;

IF S == 5 THEN
KILL;
END;
END;

END;

coord1 := acquisition_tactile(plateau);
x1 := coord1(1);
y1 := coord1(2);
piece1 := coord1(3);
affichage_selection(x1,y1,RGB(0,200,0));

WHILE MOUSE(0) ? -1 DO
END;

WHILE MOUSE(0) == -1 DO
END;

coord2 := acquisition_tactile(plateau);
x2 := coord2(1);
y2 := coord2(2);
piece2 := coord2(3);
affichage_selection(x2,y2,RGB(0,255,0));

WHILE MOUSE(0) ? -1 DO
END;

RETURN {x1,y1,piece1,x2,y2,piece2};

END;

//------------------------Programme principale------------------------

EXPORT ChessMaster()
BEGIN
LOCAL x1, x2, y1, y2;
LOCAL piece1, piece2, coord;

lancement();

IFERR
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
THEN
MSGBOX("Un probl�me est survenu, la partie � �t� r�initialis�e...");
initialisation();
sauvegarde();
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
END;

WHILE 1 DO

coord := interaction();
x1 := coord(1); y1 := coord(2); piece1 := coord(3);
x2 := coord(4); y2 := coord(5); piece2 := coord(6);

WHILE MIN(coord) == -1 OR x1 == x2 AND y1 == y2 OR equipe(piece1) ? tour OR


piece1 == 0 OR equipe(piece1) == equipe(piece2) DO
affichage_deselection(x1,y1);
affichage_deselection(x2,y2);
coord := interaction();
x1 := coord(1); y1 := coord(2); piece1 := coord(3);
x2 := coord(4); y2 := coord(5); piece2 := coord(6);
END;

sauvegarde();

IF equipe(piece2) == 0 THEN
ajout_capture(piece2-6,C_bleus)?C_bleus;
ELSE
ajout_capture(piece2,C_rouges)?C_rouges;
END;

plateau(y2,x2):=piece1;
0?plateau(y1,x1);

last_move(1) := x1;
last_move(2) := y1;
last_move(3) := x2;
last_move(4) := y2;

tour := 1 - tour;
affichage_plateau();
affichage_tour(tour);
affichage_pieces(plateau);
affichage_piece_capture(C_rouges, C_bleus);
affichage_last_move(last_move);
END;
END;

Vous aimerez peut-être aussi