combat_v3.py

Created by danio

Created on January 27, 2020

1.76 KB

Jeu de combat pour 2 personnes. La personne qui commence se fait aléatoirement. Chacun votre tour, vous aurez le choix entre ATTAQUER (les dégats sont aléatoires mais pas totalement…) ou SE RETIRER pour looter (le système de “lootbox” se fait au hasard entre un gain de vie, un gain de dégats pour le prochain tour, une perte de vie ou rien du tout). Le gagnant est le survivant, logique…

Commandes :

Joueur 1 –> 7: ATTAQUER / 4: RETRAIT

Joueur 2 –> 9: ATTAQUER / 6: RETRAIT


from random import*
from math import*

vie=[100, 100]
nom=["J1 : ","J2 : "]
n=randint(0,1)
d=2
degat_sup=[0,0]
atk=0


def stat():
    if vie[0]<0:
        vie[0]=0
    if vie[1]<0:
        vie[1]=0
    print("Vie J1 :",ceil(vie[0]),"Hp")
    print("Vie J2 :",ceil(vie[1]),"Hp")
    print()


def loot():
    global vie
    global degat
    global degat_sup
    lootbox=randint(1,4)
    if lootbox==1:
        vie[n]+=20
        print(">> Potion magique (+20Hp)")
    elif lootbox==2:
        degat_sup[n]=15
        print(">> Arme plus puissante (+15deg)")
    elif lootbox==3:
        vie[n]-=10
        print(">> Potion empoisonnée (-10Hp)")


def combat():
    global vie
    global touche
    global atk
    global degat
    global degat_sup
    degat=randint(15-d,15+d)+degat_sup[n]
    degat_sup[n]=0
    touche=int(input(nom[n]))
    if touche==7 and n==0:
            vie[not(n)]-=degat
            print("Attaque du joueur 1 : -"+str(degat)+"Hp")
            atk=1
    elif touche==9 and n==1:
            vie[not(n)]-=degat
            print("Attaque du joueur 2 : -"+str(degat)+"Hp")
            atk=1
    if atk==1:
            if touche==4 and n==0:
                    print("Retrait du joueur 1.")
                    atk=0
                    loot()
            elif touche==6 and n==1:
                    print("Retrait du joueur 2.")
                    atk=0
                    loot()
    elif atk==0:
             if (touche==4 and n==0) or (touche==6 and n==1):
                    print("Retrait qu'en cas d'attaque !")


while vie[0]>0 and vie[1]>0:
    combat()
    stat()
    n=not(n)
    if d<14:
        d+=1


if vie[0]>vie[1]:
    print("Victoire du joueur 1")
if vie[0]<vie[1]:
    print("Victoire du joueur 2")
if vie[0]==vie[1]:
    print("Égalité")

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.