-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy2048.cpp
More file actions
110 lines (101 loc) · 3.28 KB
/
my2048.cpp
File metadata and controls
110 lines (101 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <string>
#include <iostream>
#include <vector>
#include <ncurses.h>
#include <assert.h>
using namespace std;
typedef vector<vector<int> > Plateau;
#include "Jeu2048.h"
int main(){
// test de toutes les fonction du projet
test_all_func();
initscr();
keypad(stdscr, TRUE);
//TEST SI LE TERMINAL SUPPORT LES COULEURS
if (has_colors() == FALSE){
endwin();
printf("Le terminal ne supporte pas les Couleurs\n ");
exit(1);
}
//set up des couleurs
start_color();
init_pair(1, COLOR_YELLOW, COLOR_BLACK);
init_pair(2, COLOR_WHITE, COLOR_RED);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
init_pair(4, COLOR_BLACK, COLOR_WHITE);
//DEBUT DU JEU AVEC PLATEAU INITIAL
PS plateau;
plateau.plateau = plateauInitial(plateauVide());
plateau.score = 0;
string affichage = dessine(plateau.plateau);
printw("Pour commencer une partie, appuyez sur Entré");
refresh();
getch();
attron(COLOR_PAIR(1));
printw(affichage.c_str());
attron(COLOR_PAIR(1));
refresh();
int direction;
bool winCondition = estGagnant(plateau.plateau);
bool loseCondition = estTermine(plateau.plateau);
//LES TOURS DU JEU
while (winCondition == false and loseCondition == false){
printw((" SCORE: " + to_string(plateau.score)).c_str());
direction = getch();
clear();
if (direction == KEY_UP){
plateau = deplacement(plateau, 1);
affichage = dessine(plateau.plateau);
attron(COLOR_PAIR(1));
printw(affichage.c_str());
attron(COLOR_PAIR(1));
refresh();
} if (direction == KEY_DOWN){
plateau = deplacement(plateau, 2);
affichage = dessine(plateau.plateau);
attron(COLOR_PAIR(1));
printw(affichage.c_str());
attron(COLOR_PAIR(1));
refresh();
} if (direction == KEY_LEFT){
plateau = deplacement(plateau, 3);
affichage = dessine(plateau.plateau);
attron(COLOR_PAIR(1));
printw(affichage.c_str());
attron(COLOR_PAIR(1));
refresh();
} if (direction == KEY_RIGHT){
plateau = deplacement(plateau, 4);
affichage = dessine(plateau.plateau);
attron(COLOR_PAIR(1));
printw(affichage.c_str());
attron(COLOR_PAIR(1));
refresh();
}
winCondition = estGagnant(plateau.plateau);
loseCondition = estTermine(plateau.plateau);
}
if(estGagnant(plateau.plateau) == true){
attron(COLOR_PAIR(2));
printw("You defeated 2048 \nAppuyez sur F1 pour quitté\nCMD + fn + f1 sur mac");
attron(COLOR_PAIR(2));
} else {
attron(COLOR_PAIR(2));
printw("\nVous avez perdu. \n");
printw("Votre score final est de: ");
attron(COLOR_PAIR(2));
attron(COLOR_PAIR(4));
printw((to_string(plateau.score) + "\n").c_str());
attron(COLOR_PAIR(4));
attron(COLOR_PAIR(3));
printw("\nAppuyez sur F1 pour quitté \nCMD + fn + f1 sur mac");
attron(COLOR_PAIR(3));
} refresh();
int quitButton;
quitButton = getch();
while(quitButton != KEY_F(1)){
quitButton = getch();
}
endwin();
return 0;
}