Browse Source

Version final

master Vf
BARRAUX Arthur 2 years ago
parent
commit
b6a29b45e9
  1. 7
      cli.py
  2. BIN
      getkey/__pycache__/__init__.cpython-38.pyc
  3. BIN
      getkey/__pycache__/keynames.cpython-38.pyc
  4. BIN
      getkey/__pycache__/platforms.cpython-38.pyc
  5. BIN
      getkey/__pycache__/unikeys.cpython-38.pyc
  6. 260
      main.py

7
cli.py

@ -94,17 +94,16 @@ class Cli():
except: except:
pass pass
def draw_bar(self, percent, x, y, **kwargs): def draw_bar(self, percent, x, y, length=40, **kwargs):
"""dessine la barre de vie""" """dessine la barre de vie"""
length = 40
part_to_draw = length * percent // 100 part_to_draw = length * percent // 100
for key, value in kwargs.items(): for key, value in kwargs.items():
if key == 'color': if key == 'color':
self.draw('|{}{}|'.format(''.join(['' for i in range(part_to_draw)]), ''.join( self.draw('|{}{}|'.format(''.join(['' for i in range(part_to_draw)]), ''.join(
[' ' for i in range(length - part_to_draw)])), x, y, color=value) [' ' for i in range(length - part_to_draw)])), x, y, color=value)
else: return
self.draw('|{}{}|'.format(''.join(['' for i in range(part_to_draw)]), ''.join( self.draw('|{}{}|'.format(''.join(['' for i in range(part_to_draw)]), ''.join(
[' ' for i in range(length - part_to_draw)])), x, y, color='WHITE') [' ' for i in range(length - part_to_draw)])), x, y, color='GREEN')
def wipe(self): def wipe(self):
"""vide le contenu de self.screen""" """vide le contenu de self.screen"""

BIN
getkey/__pycache__/__init__.cpython-38.pyc

Binary file not shown.

BIN
getkey/__pycache__/keynames.cpython-38.pyc

Binary file not shown.

BIN
getkey/__pycache__/platforms.cpython-38.pyc

Binary file not shown.

BIN
getkey/__pycache__/unikeys.cpython-38.pyc

Binary file not shown.

260
main.py

@ -3,15 +3,14 @@ import cli
import time import time
import getkey import getkey
class Animation: class Animation:
""" class de gestion des animations""" """ class de gestion des animations du personnage"""
def __init__(self, x, y, shape): def __init__(self, x, y, shape):
self.x = x self.x = x
self.y = y self.y = y
self.shape = shape self.shape = shape
self.state = '' self.state = 'right'
def blink(self, start_color, end_color): def blink(self, start_color, end_color):
""" Fait clignoter le calque""" """ Fait clignoter le calque"""
@ -19,14 +18,15 @@ class Animation:
for i in range(8): for i in range(8):
self.layer.refresh() self.layer.refresh()
if i % 2 == 0: if i % 2 == 0:
self.display('right', color=start_color) self.display(self.state, color=start_color)
else: else:
self.display('right', color=end_color) self.display(self.state, color=end_color)
gui.display() gui.display()
time.sleep(0.4) time.sleep(0.2)
del self.layer del self.layer
def display(self, side, **kwargs): def display(self, side, **kwargs):
"""affiche le personnage"""
self.state = side self.state = side
if side == 'right': if side == 'right':
cuted_shape = self.shape[0].split('\n') cuted_shape = self.shape[0].split('\n')
@ -37,28 +37,48 @@ class Animation:
if key == 'color': if key == 'color':
gui.draw(cuted_shape[i], self.x, self.y + i, color=value) gui.draw(cuted_shape[i], self.x, self.y + i, color=value)
def move(self, x, y, speed): def move(self, x, y, speed, **kwargs):
"""le fait bouger selon x et y"""
self.layer = cli.Layer(gui, self.x, self.y, self.shape[0].split('\n')) self.layer = cli.Layer(gui, self.x, self.y, self.shape[0].split('\n'))
colori = 'WHITE'
for key, value in kwargs.items():
if key == 'color':
colori = value
try:
direction = x // abs(x) * speed direction = x // abs(x) * speed
except:
direction = 1
for i in range(0, x, direction): for i in range(0, x, direction):
self.x += direction self.x += direction
self.layer.refresh() self.layer.refresh()
self.layer.x += direction self.layer.x += direction
self.display(self.state, color='BLUE') self.display(self.state, color=colori)
gui.display()
time.sleep(0.3)
try:
direction = y // abs(y) * speed
except:
direction = 1
for i in range(0, y, direction):
self.y += direction
self.layer.refresh()
self.layer.y += direction
self.display(self.state, color=colori)
gui.display() gui.display()
time.sleep(0.3) time.sleep(0.3)
del self.layer del self.layer
class Personnage(Animation): class Personnage(Animation):
def __init__(self, nom, x, y): """Class de base du personnage"""
def __init__(self, nom, x, y, xp):
self.nom = nom self.nom = nom
self.coef_attack = 1 self.coef_attack = 1
self.coef_defense = 1 self.coef_defense = 1
self.pdv = 2 self.pdv = 20
self.max_pdv = 20 self.max_pdv = 20
self.xp = 1 self.xp = xp
self.inv = ['potion'] self.inv = ['potion'for i in range(7)]
self.shape = ['', ''] self.shape = ['', '']
self.x = x self.x = x
@ -77,18 +97,11 @@ class Personnage(Animation):
def change_pdv(self, nb_pdv): def change_pdv(self, nb_pdv):
self.pdv += nb_pdv self.pdv += nb_pdv
def affiche_caracteristiques(self):
"""affiche les caracteristiques"""
pass
def affiche_inv(self):
pass
class Guerrier(Personnage): class Guerrier(Personnage):
def __init__(self, nom, x, y): def __init__(self, nom, x, y, xp=1):
super().__init__(nom, x, y) super().__init__(nom, x, y, xp)
self.weapon = "épée" self.weapon = "épée"
self.class_name = """ ██████ ██ ██ ███████ ██████ ██████ ██ ███████ ██████ self.class_name = """ ██████ ██ ██ ███████ ██████ ██████ ██ ███████ ██████
@ -105,8 +118,8 @@ class Guerrier(Personnage):
class Voleur(Personnage): class Voleur(Personnage):
def __init__(self, nom, x, y): def __init__(self, nom, x, y, xp=1):
super().__init__(nom, x, y) super().__init__(nom, x, y, xp)
self.coef_attack = 3 self.coef_attack = 3
self.class_name = """██ ██ ██████ ██ ███████ ██ ██ ██████ self.class_name = """██ ██ ██████ ██ ███████ ██ ██ ██████
@ -123,8 +136,8 @@ class Voleur(Personnage):
class Magicien(Personnage): class Magicien(Personnage):
def __init__(self, nom, x, y): def __init__(self, nom, x, y, xp=1):
super().__init__(nom, x, y) super().__init__(nom, x, y, xp)
self.coef_attack = 10 self.coef_attack = 10
self.class_name = """███ ███ █████ ██████ ██ ██████ ██ ███████ ███ ██ self.class_name = """███ ███ █████ ██████ ██ ██████ ██ ███████ ███ ██
@ -141,8 +154,8 @@ class Magicien(Personnage):
class Elfe(Personnage): class Elfe(Personnage):
def __init__(self, nom, x, y): def __init__(self, nom, x, y, xp=1):
super().__init__(nom, x, y) super().__init__(nom, x, y, xp)
self.coef_attack = 8 self.coef_attack = 8
self.class_name = """███████ ██ ███████ ███████ self.class_name = """███████ ██ ███████ ███████
@ -160,18 +173,205 @@ class Elfe(Personnage):
class App: class App:
def __init__(self): def __init__(self):
self.width = 120 self.width = 120
self.height = 36 self.height = 37
self.character = 0 self.character = 0
self.potion_shape = """ _____
`.___,'
(___)
< >
) (
/`-.\\
/ \\
/ _ _\\
:,' `-.' `:
| |
: ;
\ /
`.___.' """.split('\n')
self.opponent = [Guerrier("Guerrier", 80, 45), Voleur("Voleur", 80, 45), Magicien("Magicien", 80, 45), Elfe("Elfe", 80, 45)]
self.title = """ ██ ███████ ██ ██ ██████ ███████ ██████ ██████ ██ ███████ self.title = """ ██ ███████ ██ ██ ██████ ███████ ██████ ██████ ██ ███████
""".split('\n') """.split('\n')
def play(self): def draw_arena(self, ennemi, choice):
"""Dessine toute l'arène et les joueur durant la phase jeu"""
gui.wipe()
self.character.display('right', color='BLUE')
self.opponent[ennemi].display('left', color='GREEN')
gui.draw_bar(self.character.pdv * 100 // self.character.max_pdv, 5, 25, 30, color='RED')
gui.draw_bar(self.character.xp * 100 // 20, 5, 27, 30, color='GREEN')
gui.draw(self.character.nom, 15, 2, weight='BOLD')
gui.draw(str(self.character.pdv), 38, 25, color='RED')
gui.draw(str(self.character.xp), 38, 27, color='GREEN')
gui.draw_bar(self.opponent[ennemi].pdv * 100 // self.opponent[ennemi].max_pdv, 75, 25, 30, color='RED')
gui.draw_bar(self.opponent[ennemi].xp * 100 // 20, 75, 27, 30, color='GREEN')
gui.draw(self.opponent[ennemi].nom, 90, 2)
gui.draw(str(self.opponent[ennemi].pdv), 108, 25, color='RED')
gui.draw(str(self.opponent[ennemi].xp), 108, 27, color='GREEN')
gui.draw(''.join(['_' for i in range(self.width)]), 0, 28)
gui.draw('Attaquer', 5, 30)
gui.draw('Inventaire', 5, 31)
gui.draw('Quiter', 5, 32)
gui.draw('->', 2, 30 + choice)
gui.display()
def show_inventory(self, position):
"""Dessine l'inventaire"""
gui.wipe() gui.wipe()
self.character.move(-40, 0, 2) gui.draw("Pressez échape pour sortir de l'inventaire", 45, 0)
gui.draw('+' + ''.join(['-' for i in range(self.width-2)]) + '+', 0, 1)
gui.draw('+' + ''.join(['-' for i in range(self.width-2)]) + '+', 0, self.height-2)
for i in range(1, self.height-3):
if i == 16:
gui.draw(''.join(['+'+''.join(['-' for j in range(29)]) for k in range(4)]), 0, 1+i)
else:
gui.draw(''.join(['|'+''.join([' ' for j in range(29)]) for k in range(4)]), 0, 1+i)
for j in range(self.character.inv.count('potion')):
x = j % 4
y = j // 4
if [x, y] == position:
color_fill = 'YELLOW'
else:
color_fill = 'WHITE'
gui.draw('Eau de vie', 30*x+10, 17*y+2, color=color_fill)
for i in range(len(self.potion_shape)):
gui.draw(self.potion_shape[i], 30*x+6, 17*y+3+i, color=color_fill)
gui.display()
def combat(self, ennemi):
"""Simule l'attaque des joeurs"""
# attaque du joueur
if self.character.jet_attaque() > self.opponent[ennemi].jet_defense():
self.opponent[ennemi].change_pdv(-1*random.randint(1, 8))
self.opponent[ennemi].blink('RED', 'GREEN')
# test si l'ennemi est mort
if self.opponent[ennemi].pdv <= 0:
self.opponent[ennemi].move(40, 0, 4)
self.character.change_xp(1)
self.character.max_pdv += 5
self.character.change_pdv(round(self.character.max_pdv * 0.2))
if random.randint(0,5) == 0:
self.character.inv.append('potion')
ennemi = random.randint(0, 3)
self.opponent[ennemi].__init__(self.opponent[ennemi].nom, 120, 5, random.randint(1, self.character.xp+1))
self.opponent[ennemi].max_pdv = 20 + 5 * (self.opponent[ennemi].xp-1)
self.opponent[ennemi].pdv = self.opponent[ennemi].max_pdv
self.opponent[ennemi].move(-40, 0, 4)
return ennemi
else:
self.character.change_pdv(-1*random.randint(1, 4))
self.character.blink('RED', 'BLUE')
# test si le joueur est toujours en vie
if self.character.pdv <= 0:
return None
# attaque de l'ennemi
if self.opponent[ennemi].jet_attaque() < self.character.jet_defense():
self.opponent[ennemi].change_pdv(-1*random.randint(1, 4))
self.opponent[ennemi].blink('RED', 'GREEN')
# test si l'ennemi est mort
if self.opponent[ennemi].pdv <= 0:
self.opponent[ennemi].move(40, 0, 4)
self.character.change_xp(1)
self.character.max_pdv += 5
self.character.change_pdv(round(self.character.max_pdv * 0.2))
if random.randint(0,5) == 0:
self.character.inv.append('potion')
ennemi = random.randint(0, 3)
self.opponent[ennemi].__init__(self.opponent[ennemi].nom, 120, 5, random.randint(1, self.character.xp+1))
self.opponent[ennemi].max_pdv = 20 + 5 * (self.opponent[ennemi].xp-1)
self.opponent[ennemi].pdv = self.opponent[ennemi].max_pdv
self.opponent[ennemi].move(-40, 0, 4)
return ennemi
else:
self.character.change_pdv(-1*random.randint(1, 8))
self.character.blink('RED', 'BLUE') self.character.blink('RED', 'BLUE')
# test si le joueur est toujours en vie
if self.character.pdv <= 0:
return None
def play(self):
"""Gère la phase de jeu"""
gui.wipe()
self.character.move(-40, 0, 4, color='BLUE')
ennemi = random.randint(0, 3)
self.opponent[ennemi].move(0, -40, 4, color='GREEN')
choice = 0
while self.character.pdv > 0:
self.draw_arena(ennemi, choice)
while True:
key = getkey.getkey()
if key == getkey.keys.UP:
choice = abs((choice-1) %3)
break
elif key == getkey.keys.DOWN:
choice = abs((choice+1) %3)
break
elif key == getkey.keys.ENTER:
if choice == 0:
# combat
result = self.combat(ennemi)
if result != None:
ennemi = result
if choice == 1:
# affichage de l'inventaire
position = [0, 0]
while True:
self.show_inventory(position)
key = getkey.getkey()
if key == getkey.keys.UP:
if position[1] > 0:
position[1] -= 1
elif key == getkey.keys.DOWN:
if position[1] < 1:
position[1] += 1
elif key == getkey.keys.RIGHT:
if position[0] < 3:
position[0] += 1
elif key == getkey.keys.LEFT:
if position[0] > 0:
position[0] -= 1
elif key == getkey.keys.ENTER:
self.character.pdv += round((self.character.max_pdv - self.character.pdv) * 0.5)
if self.character.pdv > self.character.max_pdv:
self.character.pdv = self.character.max_pdv
self.character.inv.remove('potion')
elif key == getkey.keys.ESCAPE:
break
if choice == 2:
exit()
break
# le joueur à perdu
gui.wipe()
game_over = """
""".split('\n')
for i in range(len(game_over)):
gui.draw(game_over[i], 60 - len(game_over[i])//2, 12+i, color='RED')
gui.display()
def setting(self, name, number_char): def setting(self, name, number_char):
"""permet de choisir son type de personnage""" """permet de choisir son type de personnage"""

Loading…
Cancel
Save