diff --git a/.idea/begin_github.iml b/.idea/begin_github.iml
index d0876a7..d8b3f6c 100644
--- a/.idea/begin_github.iml
+++ b/.idea/begin_github.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/Game_shooter/Essaie.py b/Game_shooter/Essaie.py
new file mode 100644
index 0000000..b6183f6
--- /dev/null
+++ b/Game_shooter/Essaie.py
@@ -0,0 +1,43 @@
+import pygame
+from pygame.locals import *
+
+
+class App:
+ def __init__(self):
+ self._running = True
+ self._display_surf = None
+ self.size = self.weight, self.height = 1280, 800
+
+ def on_init(self):
+ pygame.init()
+ self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
+ self._running = True
+
+ def on_event(self, event):
+ if event.type == pygame.QUIT:
+ self._running = False
+
+ def on_loop(self):
+ pass
+
+ def on_render(self):
+ pass
+
+ def on_cleanup(self):
+ pygame.quit()
+
+ def on_execute(self):
+ if self.on_init() == False:
+ self._running = False
+
+ while (self._running):
+ for event in pygame.event.get():
+ self.on_event(event)
+ self.on_loop()
+ self.on_render()
+ self.on_cleanup()
+
+
+if __name__ == "__main__":
+ theApp = App()
+ theApp.on_execute()
\ No newline at end of file
diff --git a/Game_shooter/ball_move.py b/Game_shooter/ball_move.py
new file mode 100644
index 0000000..22d677f
--- /dev/null
+++ b/Game_shooter/ball_move.py
@@ -0,0 +1,25 @@
+import sys, pygame
+pygame.init()
+
+size = width, height = 400, 440
+speed = [1, 1]
+black = 0, 0, 0
+
+screen = pygame.display.set_mode(size)
+
+ball = pygame.image.load("intro_ball.gif")
+ballrect = ball.get_rect()
+
+while True:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT: sys.exit()
+
+ ballrect = ballrect.move(speed)
+ if ballrect.left < 0 or ballrect.right > width:
+ speed[0] = -speed[0]
+ if ballrect.top < 0 or ballrect.bottom > height:
+ speed[1] = -speed[1]
+
+ screen.fill(black)
+ screen.blit(ball, ballrect)
+ pygame.display.flip()
\ No newline at end of file
diff --git a/Game_shooter/intro_ball.gif b/Game_shooter/intro_ball.gif
new file mode 100644
index 0000000..bbc4a95
Binary files /dev/null and b/Game_shooter/intro_ball.gif differ
diff --git a/ICT-319/src/MathRequest.py b/ICT-319/src/MathRequest.py
index f68534e..f3f7ec1 100644
--- a/ICT-319/src/MathRequest.py
+++ b/ICT-319/src/MathRequest.py
@@ -1,5 +1,3 @@
-from ICT_319.src.MathLib import MathLib
-
class MathRequest:
def __init__ (self, ope1, oper, ope2,):
diff --git a/ICT-319/test/test_sample.py b/ICT-319/test/test_sample.py
index 6bf9c49..f8fb7e7 100644
--- a/ICT-319/test/test_sample.py
+++ b/ICT-319/test/test_sample.py
@@ -1,72 +1,26 @@
import unittest
-from src.Math_Lib import MathLib
-from src.Math_Request import MathRequest
+from src.MathRequest import MathRequest
-class TestMathLib(unittest.TestCase):
+class TestMathRequest(unittest.TestCase):
def setUp(self):
- mathLib = MathLib()
+ self.ope1 = 3
+ self.operator = '+'
+ self.ope2 = 5
+ self.mathRequest = MathRequest(self.ope1, self.operator, self.ope2)
- def test_execute_add_get_result(self):
- #given
- mathrequest = MathRequest(3, '+', 4)
+ def test_get_ope1(self):
+ self.assertEqual(self.ope1, self.mathRequest.get_ope1())
- #when
- MathLib.calculate(mathrequest)
+ def test_get_oper(self):
+ self.assertEqual( self.operator, self.mathRequest.get_operator())
- #then
- self.assertEqual(mathrequest.get_res(), 7)
+ def test_get_ope2(self):
+ self.assertEqual(self.ope2, self.mathRequest.get_ope2())
- def test_execute_sub_get_result(self):
- # given
- mathrequest = MathRequest(3, '-', 4)
-
- # when
- MathLib.calculate(mathrequest)
-
- # then
- self.assertEqual(mathrequest.get_res(), -1)
-
- def test_execute_mul_get_result(self):
- # given
- mathrequest = MathRequest(3, '*', 4)
-
- # when
- MathLib.calculate(mathrequest)
-
- # then
- self.assertEqual(mathrequest.get_res(), 12)
-
- def test_execute_div_get_result(self):
- # given
- mathrequest = MathRequest(3, '/', 4)
-
- # when
- MathLib.calculate(mathrequest)
-
- # then
- self.assertEqual(mathrequest.get_res(), 0.75)
-
- def test_execute_pow_get_result(self):
- # given
- mathrequest = MathRequest(3, '^', 81)
-
- # when
- MathLib.calculate(mathrequest)
-
- # then
- self.assertEqual(mathrequest.get_res(), )
-
- def test_execute_root_get_result(self):
- # given
- mathrequest = MathRequest(3, '**', 4)
-
- # when
- MathLib.calculate(mathrequest)
-
- # then
- self.assertEqual(mathrequest.get_res(), 1.32)
+ def test_to_string(self):
+ self.assertEqual("3 + 5 = None", self.mathRequest.to_string())
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
diff --git a/ICT-431/API_key.py b/ICT-431/API_key.py
new file mode 100644
index 0000000..251e750
--- /dev/null
+++ b/ICT-431/API_key.py
@@ -0,0 +1,14 @@
+import requests
+
+url = "http://10.229.33.64/rest/V1/integration/admin/token"
+data = {
+ "username": "API",
+ "password": "227227Ak!"
+}
+response = requests.post(url, json=data)
+
+if response.status_code == 200:
+ print("Jeton :", response.text)
+else:
+ print("Erreur :", response.status_code, response.text)
+
diff --git a/ICT114/ICT_114_Json/villes.json b/ICT114/ICT_114_Json/villes.json
new file mode 100644
index 0000000..5d556df
--- /dev/null
+++ b/ICT114/ICT_114_Json/villes.json
@@ -0,0 +1,23 @@
+{
+ "villes" : [
+ {
+ "nom" : "",
+ "population": "",
+ "superficie": "",
+ "altitude": ""
+ },
+ {
+ "nom" : "",
+ "population": "",
+ "superficie": "",
+ "altitude": ""
+ },
+ {
+ "nom" : "",
+ "population": "",
+ "superficie": "",
+ "altitude": ""
+ }
+ ]
+}
+
diff --git a/ICT114/ICT_114_PYTHON/Hashage_package/HashLib.py b/ICT114/ICT_114_PYTHON/Hashage_package/HashLib.py
new file mode 100644
index 0000000..5819829
--- /dev/null
+++ b/ICT114/ICT_114_PYTHON/Hashage_package/HashLib.py
@@ -0,0 +1,71 @@
+import random
+
+from ICT114.ICT_114_PYTHON.Hashage_package.HashRequest import HashRequest
+
+class CardHash:
+ # constante définissant la langueur du numéro de carte attendu
+ card_number = None
+ card_length = 15
+
+ def __init__(self):
+ pass
+ @classmethod
+ def validate_card_number(cls, card_number):
+ """
+ vérifie si le numéro de carte est valide avec l'algorithme de Luhn.'
+ """
+ return len(cls.card_number) == cls.card_length and \
+ card_number.isdigit()
+ @classmethod
+ def calculate_luhn_last_digit(cls, card_number):
+ """
+ Calcule le dernier chiffre d'un numéro de carte
+ de crédit pour rendre valide avec l'algorithme de Luhn.
+ """
+ """
+ Étape 1 : Vérification de l'entrée
+ """
+ if not cls.validate_card_number(card_number):
+ return "Erreur: Entrez exactement 15 chiffres."
+ """
+ Étape 2 : Convertir la chaîne de caractères en une liste de chiffres
+ """
+ digits = [int(d) for d in cls.card_number] # Chaque caractère devient un chiffre entier
+ """
+ Étape 3 : Appliquer l'algorithme de Luhn sur les 15 chiffres
+ """
+ checksum = cls.calculate_luhn_checksum(digits)
+ """
+ Étape 4 : Calculer le dernier chiffre (chiffre de contrôle)
+ """
+ # 1. Vérifie si le nombre est divisible par 10,2. Dit combien il manque pour faire 10 (donne le nombre manquant)3: vérifie que le nombre est compris entre 1-9.
+ last_digit = (10 - (checksum % 10)) % 10
+ return HashRequest.get_last_digit(last_digit, 2)
+
+ @staticmethod
+ def calculate_luhn_checksum(digits):
+ """
+ Applique l'algorithme de Luhn pour calculer le checksum.
+ """
+ checksum = 0 # Initialisation de la somme de contrôle
+ for i, digit in enumerate(reversed(digits)): # On parcourt les chiffres de droite à gauche
+ if i % 2 == 0: # Les positions paires (en partant de la droite)
+ digit *= 2 # Doubler le chiffre
+ if digit > 9: # Si le double est supérieur à 9
+ digit -= 9 # soustraire 9
+ checksum += digit # Ajouter le chiffre transformé ou brut à la somme de contrôle
+ return checksum
+
+class CardSelector:
+ card_length = CardHash.card_length
+
+ def __init__(self):
+ pass
+
+ @staticmethod
+ def generate_random_card_number(length=card_length):
+ """
+ Génère les 14 premiers chiffres d'un numéro de carte aléatoire.
+ """
+ return ''.join(str(random.randint(0, 9)) for _
+ in range(length))
\ No newline at end of file
diff --git a/ICT114/ICT_114_PYTHON/Hashage_package/HashRequest.py b/ICT114/ICT_114_PYTHON/Hashage_package/HashRequest.py
new file mode 100644
index 0000000..91403cd
--- /dev/null
+++ b/ICT114/ICT_114_PYTHON/Hashage_package/HashRequest.py
@@ -0,0 +1,21 @@
+class HashRequest:
+ def __init__(self, user_input, choice=None):
+ self.user_input = user_input
+ self.choice = choice
+ self.card_number = user_input
+ self.last_digit = None
+
+ def get_user_input(self):
+ return self.user_input
+
+ def get_choice(self):
+ return self.choice
+
+ def get_card_number(self):
+ return self.card_number
+
+ def get_last_digit(self,digit_count):
+ if not self.card_number or len(self.card_number) < digit_count:
+ raise ValueError(f"Invalid card number must be at least 1{digit_count} digits long")
+ self.last_digit = self.card_number[-digit_count:]
+ return self.last_digit
\ No newline at end of file
diff --git a/ICT114/ICT_114_PYTHON/Hashage_package/Hashage.py b/ICT114/ICT_114_PYTHON/Hashage_package/Hashage.py
new file mode 100644
index 0000000..4f041d7
--- /dev/null
+++ b/ICT114/ICT_114_PYTHON/Hashage_package/Hashage.py
@@ -0,0 +1,67 @@
+from random import choice
+
+from ICT114.ICT_114_PYTHON.Hashage_package.HashRequest import HashRequest
+from ICT114.ICT_114_PYTHON.Hashage_package.HashLib import CardHash, CardSelector
+
+choice_manually = 'manuel'
+choice_auto = 'auto'
+
+def get_and_validate_user_choice():
+ """
+ Demande et valide le choix de l'utilisateur
+ """
+ while True:
+ user_input = input(
+ "Voulez-vous entrer vos 14 chiffres ou générer un numéro aléatoire ? "
+ f"(entrez '{choice_manually}' ou '{choice_auto}') : "
+ ).strip().lower()
+ if user_input in [choice_manually, choice_auto]:
+ return user_input
+ else:
+ print("Choix invalide. Veuillez réessayer.")
+
+def display_result(user_input ,result):
+
+ if isinstance(result, tuple):
+ complete_card = f"{user_input}{result[0]}{result[1]}"
+ print(f"Les deux derniers chiffres pour rendre le numéro valide sont : {result[0]}{result[1]}")
+ print(f"Numéro complet : {complete_card}")
+ else:
+ print(result)
+
+def get_card_number_input(user_choice):
+
+ if user_choice == 'manuel':
+ user_input = input("Entrez les 14 premiers chiffres de"
+ "votre numéro de carte de crédit : ")
+ return user_input
+ elif user_choice == 'auto':
+ user_input = CardSelector.generate_random_card_number()
+ print(f"Numéro aléatoire généré : {user_input}")
+ return user_input
+
+ else:
+ print("Choix invalide. Veuillez réessayer.")
+ return None
+
+def run_program():
+ """
+ Programme de génération au Luhn
+ """
+ print("Bienvenue dans le générateur de numéros conformes à Luhn !")
+
+ user_choice = get_and_validate_user_choice()
+
+
+ user_input = get_card_number_input(user_choice)
+
+ hash_request = HashRequest(
+ user_input=user_input,
+ choice=user_choice)
+
+ result = hash_request.get_last_digit(2)
+
+ display_result(user_input, result)
+
+if __name__ == "__main__":
+ run_program()
diff --git a/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashLib.cpython-313.pyc b/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashLib.cpython-313.pyc
new file mode 100644
index 0000000..4bd2fc2
Binary files /dev/null and b/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashLib.cpython-313.pyc differ
diff --git a/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashRequest.cpython-313.pyc b/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashRequest.cpython-313.pyc
new file mode 100644
index 0000000..d4613a2
Binary files /dev/null and b/ICT114/ICT_114_PYTHON/Hashage_package/__pycache__/HashRequest.cpython-313.pyc differ
diff --git a/ICT114/ICT_114_PYTHON/Hashage_test/__pycache__/hashage_test.cpython-313.pyc b/ICT114/ICT_114_PYTHON/Hashage_test/__pycache__/hashage_test.cpython-313.pyc
new file mode 100644
index 0000000..1dab55c
Binary files /dev/null and b/ICT114/ICT_114_PYTHON/Hashage_test/__pycache__/hashage_test.cpython-313.pyc differ
diff --git a/ICT114/ICT_114_PYTHON/Hashage_test/hashage_test.py b/ICT114/ICT_114_PYTHON/Hashage_test/hashage_test.py
new file mode 100644
index 0000000..1059449
--- /dev/null
+++ b/ICT114/ICT_114_PYTHON/Hashage_test/hashage_test.py
@@ -0,0 +1,20 @@
+import unittest
+
+from ICT114.ICT_114_PYTHON.Hashage_package.HashRequest import HashRequest
+
+class MyTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.user_input = "auto"
+ self.choice = "auto"
+ self.HashRequest = HashRequest(self.user_input)
+
+ def test_get_user_input(self):
+ self.assertEqual(self.user_input, self.HashRequest.get_user_input())
+
+ def test_get_choice(self):
+ self.assertEqual(self.choice, self.HashRequest.get_choice())# add assertion here
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/ICT114/ICT_114_PYTHON/__pycache__/def_inventaire.cpython-313.pyc b/ICT114/ICT_114_PYTHON/__pycache__/def_inventaire.cpython-313.pyc
new file mode 100644
index 0000000..49d9e16
Binary files /dev/null and b/ICT114/ICT_114_PYTHON/__pycache__/def_inventaire.cpython-313.pyc differ
diff --git a/ICT114/ICT_114_TE/Kamano_recettes.xml b/ICT114/ICT_114_TE/Kamano_recettes.xml
new file mode 100644
index 0000000..917fa2e
--- /dev/null
+++ b/ICT114/ICT_114_TE/Kamano_recettes.xml
@@ -0,0 +1,42 @@
+
+
+
+ Fondant au chocolat
+ 20
+ 25
+ 6
+
+ Farine, 20g
+ sucre glace, 200g
+ Chocolat noir, 200g
+ Oeuf, 5 pièces
+ Beurre, 200g
+
+
+ Préchauffez le four à th 6 (180°), beurrez et farinez un moule à manqué.
+ Faites fondre le chocolat et le beurre coupés en morceaux au micro-ondes ou au bain-marie.
+ Ajoutez les œufs un à un en mélangeant au fouet à main, puis la farine et le sucre, remuez bien et versez la préparation dans le moule.
+ Enfournez pour 25 min, laissez tiédir puis démoulez. Mettez au frais avant de servir. L'idéal étant de le préparer la veille.
+
+
+
+ Cheeseburger maison
+ 30
+ 10
+ 4
+
+ pain hamburger, 4 pièces
+ gruyère, 4 tranches
+ laitue, 4 feuilles
+ tomate, 1 pièce
+ steak haché. 4 pièces
+ sauce hamburger, 2 cuillères à soupe
+
+
+ Lavez la tomate et coupez-la en rondelles. Lavez la laitue et réservez les 4 feuilles.
+ Saisir les steaks à feu vif dans une poêle légèrement huilée ou sur un gril 1 min de chaque côté. Baissez le feu et poursuivez la cuisson 2 min de chaque côté pour une cuisson saignante (4 pour une cuisson à point).
+ En fin de cuisson, salez, poivrez et placez une tranche de gruyère sur chaque steak pour le faire fondre.
+ Ouvrez les pains à burger et faites-les dorer au grille-pain. Tartinez les bases des pains de sauce, déposez dessus les steaks au fromage, les rondelles de tomate et les feuilles de laitue. Refermez les burgers. Servez aussitôt avec des frites maison et du ketchup.
+
+
+
\ No newline at end of file
diff --git a/ICT114/ICT_114_XML/villes.xml b/ICT114/ICT_114_XML/villes.xml
new file mode 100644
index 0000000..417c61e
--- /dev/null
+++ b/ICT114/ICT_114_XML/villes.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ICT_-216/scene_3.py b/ICT_-216/scene_3.py
new file mode 100644
index 0000000..3d1820c
--- /dev/null
+++ b/ICT_-216/scene_3.py
@@ -0,0 +1,16 @@
+import domoticz
+
+def onDeviceChanged(device):
+ # Vérifier si le nom de l'appareil et son état correspondent à la condition
+ if device['name'] == '13_bouton 1' and device['status'] == 'Off':
+ # Allumer l'appareil correspondant
+ domoticz.device('lampe chambre 13').switchOn()
+
+# Simuler un appareil qui change d'état (pour tester la fonction)
+test_device = {
+ 'name': '13_bouton 1',
+ 'status': 'Off'
+}
+
+# Appeler la fonction avec le test_device
+onDeviceChanged(test_device)
diff --git a/MA-24/ballonf.png b/MA-24/ballonf.png
new file mode 100644
index 0000000..77d183c
Binary files /dev/null and b/MA-24/ballonf.png differ
diff --git a/MA-24/bg_im.jpeg b/MA-24/bg_im.jpeg
new file mode 100644
index 0000000..c5210ff
Binary files /dev/null and b/MA-24/bg_im.jpeg differ
diff --git a/MA-24/identify.py b/MA-24/identify.py
new file mode 100644
index 0000000..7e34a62
--- /dev/null
+++ b/MA-24/identify.py
@@ -0,0 +1,15 @@
+from PIL import Image
+import os.path
+import sys
+
+if len(sys.argv) > 1:
+ print(sys.argv[1])
+else:
+ sys.exit('Syntax: identify.py [filename]')
+
+pic = sys.argv[1]
+img = Image.open(pic)
+X = img.size[0]
+Y = img.size[1]
+
+print(X, Y)
\ No newline at end of file
diff --git a/MA-24/perso.gif b/MA-24/perso.gif
new file mode 100644
index 0000000..f539144
Binary files /dev/null and b/MA-24/perso.gif differ
diff --git a/MA-24/perso2.webp b/MA-24/perso2.webp
new file mode 100644
index 0000000..3126ed6
Binary files /dev/null and b/MA-24/perso2.webp differ
diff --git a/MA-24/plateform.py b/MA-24/plateform.py
new file mode 100644
index 0000000..34fc438
--- /dev/null
+++ b/MA-24/plateform.py
@@ -0,0 +1,89 @@
+"""
+etape 1 : creating a platform
+
+etape 2 : moving platform
+
+etape 3 : adding player sprite and collision (+gravity)
+"""
+#Importing the pygame module
+import pygame
+
+#initiate pygame and give permission to use pygame's functionality
+pygame.init()
+
+#create a display surface object of specific dimension
+window = pygame.display.set_mode((600, 600))
+
+#creating a new clock object to track the amount of time
+clock = pygame.time.Clock()
+
+platform_vel = 5
+
+#startig coordinate of the platform
+x = 100
+y = 150
+
+#starting coordinates for player sprite
+player_x = 180
+player_y = 0
+
+#creating a new variable for gravity
+gravity = 8
+
+#creating a new rect for player
+player_rect = pygame.Rect(player_x, player_y, 50, 50)
+
+#creating a rect with width and height
+"""
+rect = [pygame.Rect(x, y, 200, 50), pygame.Rect(x, 300, 200, 50)]
+
+essaie de multiplateforme
+"""
+rect = pygame.Rect(x, y, 200, 50)
+
+#creating a boolean variable that we will use to run the while loop
+run = True
+
+#cretaing an infinite loop to run our game
+while run:
+
+ #setting the framerate to 30fps
+ clock.tick(30)
+
+ #multipying platform_vel with -1. if its x coordinate is less than 100 or greater than or equal to 300
+ #etape 2
+ if rect.left >= 300 or rect.left < 100 :
+ platform_vel *= -1
+
+ #Checking if player is colliding with platform or not using the colliderect() method.
+ #It will return a boolean value
+ collide = pygame.Rect.colliderect(rect, player_rect)
+
+ #If player is colliding with platform then setting coordinate of player bottom equal to
+ #top platform and adding the platform velocity
+ if collide:
+ player_rect.bottom = rect.top
+ player_rect.left += platform_vel
+
+ #adding platform_vel to x coordinate of our rect (etape 2)
+ rect.left += platform_vel
+
+ #adding gravity
+ player_rect.top += gravity
+
+ #drawing the rect on the screen using the draw.rect() method
+ pygame.draw.rect(window, (255, 0, 0), rect)
+
+ pygame.draw.rect(window, (0, 255, 0), player_rect)
+
+ #updating the display surface
+ pygame.display.update()
+
+ #filling the window with white color
+ window.fill((255, 255, 255))
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ run = False
+ pygame.quit()
+ quit()
\ No newline at end of file
diff --git a/MA-24/plateform.webp b/MA-24/plateform.webp
new file mode 100644
index 0000000..8614867
Binary files /dev/null and b/MA-24/plateform.webp differ
diff --git a/MA-24/pygame_bg.py b/MA-24/pygame_bg.py
new file mode 100644
index 0000000..b1c97ae
--- /dev/null
+++ b/MA-24/pygame_bg.py
@@ -0,0 +1,70 @@
+import pygame
+pygame.init()
+
+#setup pygame
+screen = pygame.display.set_mode((800,600))
+player = pygame.Rect((300,250,50,50))
+#clock = pygame.time.Clock()
+run =True
+
+#Loading the image
+bg_image = pygame.image.load('bg_im.jpeg')
+bg_image2 = pygame.image.load('ballonf.png')
+
+#scaling the image to fit the game window
+#bg_image = pygame.transform.scale(bg_image, (800,600)) --> image fixe
+
+#Image initial position
+x1=0
+#x2= bg_image.get_width() --> 2 images qui défile
+x2=0
+
+while run:
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ run = False
+
+ screen.fill((0,0,0.))
+ pygame.draw.rect(screen,(255,0,0),player)
+
+ #moving the bg
+ x1 -= 1
+ x2 -= 1
+
+ #resetting the image when it leaves screen
+ #if x1 == -1 *bg_image.get_width():
+ #x1 = bg_image.get_width() --> image qui bouge si on quitte la position 0 de l'écran
+ #if x2 == -1 *bg_image2.get_width():
+ #x2 = bg_image2.get_width() --> 2ème image qui défile avec la première
+ if x1 == -1 *bg_image.get_width(): #Même effet que précèdement avec les 2 images suaf que c'était un effet de profondeur qui était recherché ptr essayer avec des image plus "proche"
+ x1 = 0
+ if x2 == -1 *bg_image2.get_width():
+ x2 = 0
+
+ # Drawing image at position (0,0) --> essaie d'importation d'une image à la place du carré
+ #screen.blit(bg_image,(0,0))
+ #pygame.display.update()
+
+ #Drawing images at positions (x1, 0) and (x2,0)
+ screen.blit(bg_image,(x1,0))
+ screen.blit(bg_image2,(x2,0))
+ pygame.display.update()
+
+ #background = pygame.Surface(screen.get_size()) --> essaie d'implantation d'une image pour bg
+ #background = background.convert()
+ #background.fill((0,0,255))
+
+ key = pygame.key.get_pressed()
+ if key[pygame.K_a]:
+ player.move_ip(-1,0)
+ elif key[pygame.K_d]:
+ player.move_ip(1, 0)
+ elif key[pygame.K_w]:
+ player.move_ip(0, -1)
+ elif key[pygame.K_s]:
+ player.move_ip(0, 1)
+
+ pygame.display.update()
+
+pygame.quit()
\ No newline at end of file
diff --git a/MA-24/pygame_essaie_ennemis.py b/MA-24/pygame_essaie_ennemis.py
new file mode 100644
index 0000000..ca9b222
--- /dev/null
+++ b/MA-24/pygame_essaie_ennemis.py
@@ -0,0 +1,209 @@
+import pygame
+import math
+
+class Player():
+ def __init__(self, x, y, width, height):
+ self.x = x
+ self.y = y
+ self.width = width
+ self.height = height
+ self.velocity = 12
+ self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+ self.hitbox_w = self.width + 5
+ self.hitbox_h = self.height + 5
+ self.update_hitbox()
+
+ def update_hitbox(self):
+ self.hitbox_player = pygame.Rect(
+ self.x +(player_w-self.hitbox_w)//2,
+ self.y +(player_h - self.hitbox_h)//2,
+ self.hitbox_w,
+ self.hitbox_h
+ )
+
+ def draw(self, surface):
+
+ pygame.draw.rect(surface, 'red', self.rect)
+ #pygame.draw.rect(surface, 'black', self.hitbox_player,2)
+
+ def move(self, dx, dy):
+ #garde l'ancienne position avant le déplacement
+ old_x = self.x
+ old_y = self.y
+
+ #déplacement
+ self.x += dx
+ self.y += dy
+
+ #Màj du joeur
+ self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+ self.update_hitbox()
+
+ #vérif des limites
+ if self.rect.left < limite_x[0] or self.rect.right > limite_x[1]:
+ self.x = old_x
+ self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+
+ if self.rect.top < limite_y[0] or self.rect.bottom > limite_y[1]:
+ self.y = old_y
+ self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+
+class Enemy():
+ def __init__(self, x, y, width, height):
+ self.x = x
+ self.y = y
+ self.width = width
+ self.height = height
+ self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+ self.velocity = velocity
+
+ self.hitbox_w = width + 5
+ self.hitbox_h = height + 5
+ self.update_hitbox()
+
+ def update_hitbox(self):
+ #met à jour la hitbox
+ self.hitbox_enemy = pygame.Rect (
+ self.rect.x + (self.width - self.hitbox_w) // 2,
+ self.rect.y + (self.height - self.hitbox_h) // 2,
+ self.hitbox_w,
+ self.hitbox_h
+ )
+
+ def draw(self, window):
+
+ pygame.draw.rect(window, 'green', self.rect)
+ pygame.draw.rect(window, 'black', self.hitbox_enemy, 2)
+
+ def move (self, dx, dy):
+ #on garde l'ancienne position
+ old_ex, old_ey = self.x, self.y
+
+ self.rect.x += dx * velocity
+ self.rect.y += dy * velocity
+
+ #MàJ de l'ennemie
+ #self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+
+ if self.rect.left < limite_x[0] or self.rect.right > limite_x[1]:
+ self.rect.x = old_ex
+ #self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+
+ if self.rect.top < limite_y[0] or self.rect.bottom > limite_y[1]:
+ self.rect.y = old_ey
+ #self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
+
+ self.update_hitbox()
+
+ def move_towards_player(self, player, ):
+ #calculer la direction vers le joueur
+ dx = player.rect.x - self.rect.x
+ dy = player.rect.y - self.rect.y
+
+ #calculer la distance entre l'ennemi et le joueur
+ dist = math.hypot(dx, dy)
+
+ # Enemy AI: Move towards the player
+ if dist != 0:
+ dx /= dist
+ dy /= dist
+
+ #déplacer l'ennemi
+ self.rect.x += dx * (self.velocity -2)
+ self.rect.y += dy * (self.velocity -2)
+
+ self.update_hitbox()
+
+class HealthBar():
+
+ def __init__(self, x, y, width, height, max_hp):
+ self.x = x
+ self.y = y
+ self.width = width
+ self.height = height
+ self.hp = max_hp
+ self.max_hp = max_hp
+
+ def draw(self, surface):
+ #calculate health ratio
+ ratio = self.hp / self.max_hp
+ pygame.draw.rect(window, 'red', (700, 0, 300, 40))
+ pygame.draw.rect(window, 'green', (700, 0, int(300 * ratio), 40))
+
+class Collide_damage():
+ def __init__(self, x, y, max_damage):
+ self.x = x
+ self.y = y
+ self.damage = max_damage
+ self.max_damage = max_damage
+
+ def colide(self, player1, enemy):
+ collide = pygame.Rect.colliderect(enemy.rect, player1.rect)
+
+ #if collide:
+
+
+
+pygame.init()
+
+window_width, window_height = 1000, 1000
+window = pygame.display.set_mode((window_width, window_height))
+pygame.display.set_caption("Essaie de la Pygame")
+
+limite_x = (60, 940)
+limite_y = (60, 940)
+
+#store the initial coordinates of the player in two variables i.e x and y
+x, y = 100, 100
+velocity = 12
+player_w, player_h = 50, 50
+
+ex, ey = 720, 720
+enemy_w, enemy_h = 50, 50
+enemy_speed = 2
+
+player1 = Player(x, y, player_w, player_h)
+enemy = Enemy(x, y, enemy_w, enemy_h)
+
+health_bar = HealthBar(250,200,300,40,100)
+run = True
+clock = pygame.time.Clock()
+
+while run:
+ pygame.time.delay(30)
+ window.fill((255,255,255))
+
+ key = pygame.key.get_pressed()
+ if key[pygame.K_LEFT]:
+ player1.move(-player1.velocity, 0)
+ if key[pygame.K_RIGHT]:
+ player1.move(player1.velocity, 0)
+ if key[pygame.K_UP]:
+ player1.move(0, -player1.velocity)
+ if key[pygame.K_DOWN]:
+ player1.move(0, player1.velocity)
+
+ if player1.hitbox_player.colliderect(enemy.hitbox_enemy):
+ print("collision")
+
+ #draw health bar
+ health_bar.hp = 50
+ health_bar.draw(window)
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ run = False
+ pygame.quit()
+
+ # Enemy AI: Move towards the player
+ enemy.move_towards_player(player1)
+
+ #pygame.draw.rect(window, (255,0,0), player)
+ player1.draw(window)
+ enemy.draw(window)
+
+ pygame.display.flip()
+
+ pygame.display.update()
+
+pygame.quit()
\ No newline at end of file
diff --git a/MA-24/pygame_movements_player.py b/MA-24/pygame_movements_player.py
new file mode 100644
index 0000000..924b62d
--- /dev/null
+++ b/MA-24/pygame_movements_player.py
@@ -0,0 +1,190 @@
+#importing pygame module
+import pygame
+
+#initiate pygame and give permission to use pygame's functionality
+pygame.init()
+
+#create the display surface object of specific dimension
+window = pygame.display.set_mode((1000, 1000))
+
+#add caption in the window
+pygame.display.set_caption("Movement Player")
+
+#Initializing the clock. Clocks are used to track and control the frame-rate of a game
+clock = pygame.time.Clock() #étape 2
+
+#Creating a variable to check the direction of movement. We will change its value
+#whenever the player changes its direction
+direction = True
+
+#add player sprite
+image = [pygame.image.load('perso.gif'),
+ pygame.image.load('perso2.webp')]
+
+#store the initial coordinates of the player in two variables i.e x and y
+x=100
+y=100
+
+#create variable to store the velocity of player's movement
+velocity = 12
+
+#creating the Infinite loop
+run = True
+while run:
+
+ # filling the bg with white color
+ window.fill((255,255,255))
+
+ #display the player sprite at x and y coordinates
+ # window.blit(image, (x, y)) --> jusqu'a étape 3 car qu'une image
+
+ """
+ #iterate over the list of Event objects that was returned by pygame.event.get() method
+ for event in pygame.event.get():
+
+ #closing the window and program if the type of the text is QUIT
+ if event.type == pygame.QUIT:
+ run = False
+ pygame.quit()
+ quit()
+ """
+
+ """
+ Etape 1 : Mouvement des joueurs avec les flêches et velocity
+ """
+ """
+ #checking event key if the type of the event is KEYDOWN i.e. keyboard button is pressed
+ if event.type == pygame.KEYDOWN:
+
+ #Incresing the x coordinate if the button pressed is left arrow key
+ if event.key == pygame.K_LEFT:
+ x -= velocity
+
+ #Increasing the x coordinate if the button pressed is right arrow key
+ if event.key == pygame.K_RIGHT:
+ x += velocity
+
+ #Increasing the y coordinate if the button pressed is up arrow key
+ if event.key == pygame.K_UP:
+ y -= velocity
+
+ #Increasing the y coordinate if the button pressed is down arrow key
+ if event.key == pygame.K_DOWN:
+ y += velocity
+
+ #Draws the surface object to the screen
+ pygame.display.update()
+ """
+
+ """
+ Etape 2 : Moving players in continuous movement
+ """
+ """
+ #Set the frame rates to 60 fps
+ clock.tick(60)
+
+ #Storing the key pressed in a new variable using key.get_pressed() method
+ key_pressed_is = pygame.key.get_pressed()
+
+ #changing the coordinates of the player
+ if key_pressed_is[pygame.K_LEFT]:
+ x -= 8
+ if key_pressed_is[pygame.K_RIGHT]:
+ x += 8
+ if key_pressed_is[pygame.K_UP]:
+ y -= 8
+ if key_pressed_is[pygame.K_DOWN]:
+ y += 8
+
+ #draws the surface object to the screen
+ pygame.display.update()
+ """
+
+ """
+ Etape 3 : Flip players vertically
+ """
+ """
+ clock.tick(60)
+
+ if direction == True:
+ window.blit(image, (x, y))
+ if direction == False:
+ window.blit(pygame.transform.flip(image, True, False), (x, y))
+
+ # iterate over the list of Event objects that was returned by pygame.event.get() method
+ for event in pygame.event.get():
+
+ # closing the window and program if the type of the text is QUIT
+ if event.type == pygame.QUIT:
+ run = False
+ pygame.quit()
+ quit()
+
+ # Changing the value of the
+ # direction variable
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_RIGHT:
+ direction = True
+ elif event.key == pygame.K_LEFT:
+ direction = False
+
+ #Storing the key pressed in a new variable using key.get_pressed() method
+ key_pressed_is = pygame.key.get_pressed()
+
+ #Changing the coordinates of the player
+ if key_pressed_is[pygame.K_UP]:
+ y -= 5
+ if key_pressed_is[pygame.K_DOWN]:
+ y += 5
+ if key_pressed_is[pygame.K_LEFT]:
+ x -= 5
+ if key_pressed_is[pygame.K_RIGHT]:
+ x += 5
+
+ #Draws the surface object to the screen
+ pygame.display.update()
+ """
+
+ """
+ Etape 4 : Flip players with an other image
+ """
+
+ clock.tick(60)
+
+ if direction == True:
+ window.blit(image[0], (x, y))
+ if direction == False:
+ window.blit(image[1], (x, y))
+
+ # iterate over the list of Event objects that was returned by pygame.event.get() method
+ for event in pygame.event.get():
+
+ # closing the window and program if the type of the text is QUIT
+ if event.type == pygame.QUIT:
+ run = False
+ pygame.quit()
+ quit()
+
+ # Changing the value of the
+ # direction variable
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_RIGHT:
+ direction = True
+ elif event.key == pygame.K_LEFT:
+ direction = False
+
+ # Storing the key pressed in a new variable using key.get_pressed() method
+ key_pressed_is = pygame.key.get_pressed()
+
+ #Changing the coordinates of the player
+ if key_pressed_is[pygame.K_UP]:
+ y -= 5
+ if key_pressed_is[pygame.K_DOWN]:
+ y += 5
+ if key_pressed_is[pygame.K_LEFT]:
+ x -= 5
+ if key_pressed_is[pygame.K_RIGHT]:
+ x += 5
+
+ #Draws the surface object to the screen
+ pygame.display.update()
\ No newline at end of file