diff --git a/game2048/grid_2048.py b/game2048/grid_2048.py index a173abd13607488c3d5bca24e955ed98de3b78b7..c3c7ff89bf34fad3caca487e2040ad68a62aa297 100644 --- a/game2048/grid_2048.py +++ b/game2048/grid_2048.py @@ -86,32 +86,6 @@ def grid_to_string_with_size_and_theme(grid, theme,n): def long_value_with_theme(grid,theme): return max(len(theme[v]) for v in get_all_tiles(grid)) - -# FONCTIONNALITE 3 - -def read_player_command(): - deplacements = {'g':"left",'d':"right",'h':"up",'b':"down"} - move = input("Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)): ") - while move not in ['g','d','h','b']: - move = input("Commande invalide. \n Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)): ") - return deplacements[move] - -def read_size_grid(): - size = input("Choisissez la taille de la grille : ") - while True: - try: - size = int(size) - except: - size = input("Taille invalide, choisissez un nombre entier. \n Choisissez la taille de la grille : ") - else: - break - return size - -def read_theme_grid(): - theme = input("Choisissez le numéro du thème : ") - while theme not in ['0','1','2']: - theme = input("Ce thème n'existe pas ! \n Choisissez le numéro du thème : ") - return THEMES[theme] # FONCTIONNALITE 4 diff --git a/game2048/test_grid_2048.py b/game2048/test_grid_2048.py index cf74e5a11df7fc1d11790350d27eb0f005a79e5e..2371025242bff69f3c882176236190ea1c776691 100644 --- a/game2048/test_grid_2048.py +++ b/game2048/test_grid_2048.py @@ -66,10 +66,6 @@ def test_long_value_with_theme(): assert long_value_with_theme(grid,THEMES["1"]) == 2 assert long_value_with_theme(grid,THEMES["2"]) == 1 -#FONCTIONNALITE 3 - -def test_read_player_command(monkeypatch): - monkeypatch.setattr('builtins.input', lambda x: "d") # FONCTIONNALITE 4 diff --git a/game2048/test_textual_2048.py b/game2048/test_textual_2048.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bffcea95b4da06a865aacd2a5e720924012dd821 100644 --- a/game2048/test_textual_2048.py +++ b/game2048/test_textual_2048.py @@ -0,0 +1,4 @@ +#FONCTIONNALITE 3 + +def test_read_player_command(monkeypatch): + monkeypatch.setattr('builtins.input', lambda x: "d") diff --git a/game2048/textual_2048.py b/game2048/textual_2048.py index abd46c05a7899d8514c72e962144b9235708054a..a24c190acc254bad5c52182b0c4d481cc3aadd07 100644 --- a/game2048/textual_2048.py +++ b/game2048/textual_2048.py @@ -1,3 +1,25 @@ +# FONCTIONNALITE 3 + def read_player_command(): - move = input("Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)):") - return move + deplacements = {'g':"left",'d':"right",'h':"up",'b':"down"} + move = input("Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)): ") + while move not in ['g','d','h','b']: + move = input("Commande invalide. \n Entrez votre commande (g (gauche), d (droite), h (haut), b(bas)): ") + return deplacements[move] + +def read_size_grid(): + size = input("Choisissez la taille de la grille : ") + while True: + try: + size = int(size) + except: + size = input("Taille invalide, choisissez un nombre entier. \n Choisissez la taille de la grille : ") + else: + break + return size + +def read_theme_grid(): + theme = input("Choisissez le numéro du thème : ") + while theme not in ['0','1','2']: + theme = input("Ce thème n'existe pas ! \n Choisissez le numéro du thème : ") + return THEMES[theme]