CLASES en PYTHON, TODOS los pilares de POO aplicados a un EJEMPLO COMPLETO desde CERO

BitBoss
10 Jan 202227:32

Summary

TLDRIn this video, a combat simulation between two characters, jugador_1 and jugador_2, is created using a while loop where both attack each other until one dies. The script tracks turns and prints each character's actions. The combat resolution determines the winner based on which character is still alive. The story evolves as one character, Guts, is downgraded from a Warrior to a simple Character, changing the combat mechanics. The video also invites viewers to explore and modify the code to better understand the mechanics and challenges of damage calculation in combat simulations.

Takeaways

  • 😀 The combat system between two characters involves a turn-based structure where each player attacks the other until one dies.
  • 😀 A while loop is used to continue the fight as long as both characters are alive.
  • 😀 A `turno` (turn) variable is introduced to track the number of turns and print relevant messages for each attack.
  • 😀 After the loop finishes, the game checks which character is alive to determine the winner, or if it's a tie.
  • 😀 The character classes were initially specialized (e.g., Guerrero for warrior), but were later simplified to a generic `Personaje` (character) class.
  • 😀 The change to a more generic class removed unnecessary attributes, such as a sword (`espada`), affecting how combat is calculated.
  • 😀 The damage calculation in the combat system may face issues if a character's strength (`fuerza`) is lower than their defense (`defensa`).
  • 😀 The script encourages users to explore and modify the code via a provided Colab link, promoting experimentation.
  • 😀 The video includes an interactive element where viewers can try the code themselves and suggest improvements in the comments.
  • 😀 The speaker prompts the audience to think about how to handle cases where the character's strength is less than their defense, asking for potential solutions.
  • 😀 The speaker explains that changes to the class and combat logic impact the game's behavior, providing a clear explanation for the observed outcomes.

Q & A

  • What is the purpose of the `while` loop in the battle simulation?

    -The `while` loop ensures that the battle continues as long as both characters are alive. It allows them to attack each other in turns until one of the characters is defeated.

  • How does the battle simulation determine when to stop the fight?

    -The battle stops when either `jugador_1` or `jugador_2` is no longer alive. The condition used is typically `while jugador_1.vivo() and jugador_2.vivo()`, which checks if both players are still alive.

  • Why is the `turno` variable used in the script?

    -The `turno` variable is used to track the current turn in the battle. It is initialized to 0 and is incremented after each turn to keep the battle organized and provide insight into how many rounds have passed.

  • What happens when the `turno` variable is incremented?

    -When the `turno` variable is incremented, it marks the progression of the battle and indicates that a new round of attacks is taking place between the two characters.

  • What does the program print after the battle ends?

    -After the battle ends, the program prints a message announcing the winner. If `jugador_1` is still alive, they are declared the winner. If not, the program checks if `jugador_2` is alive and declares them the winner. If neither is alive, it’s a draw.

  • How does the script handle changes in character classes, particularly between `Guerrero` and `Personaje`?

    -The script changes the character class from `Guerrero` (Warrior) to `Personaje` (Character) by removing the extra attribute for the sword. This change affects the damage calculation, making the battle results different.

  • What problem arises after changing the class from `Guerrero` to `Personaje`?

    -After the class change, the damage calculation method is altered, which leads to different results in the battle. Specifically, Vanessa deals more damage to Guts after the change, indicating that the new character class has different attack calculations.

  • What formula is being referred to in the question about character strength and defense?

    -The formula being referred to is the damage calculation formula, which typically takes into account a character's strength and the opponent's defense. The question asks what happens if the strength is lower than the defense, implying a potential issue with the formula.

  • What might happen if a character's strength is less than the opponent's defense in the damage calculation?

    -If a character's strength is less than the opponent's defense, the calculated damage might be zero or negative, which could result in no damage being dealt. This would require a solution to ensure that the damage is at least a minimum value, such as preventing it from going below zero.

  • What solution could be proposed for the problem where strength is lower than defense?

    -One solution could be to implement a minimum damage value, ensuring that even if strength is less than defense, the damage does not drop below zero. This could be achieved by adjusting the damage calculation formula to include a lower bound.

Outlines

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Mindmap

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Keywords

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Highlights

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now

Transcripts

plate

This section is available to paid users only. Please upgrade to access this part.

Upgrade Now
Rate This

5.0 / 5 (0 votes)

Related Tags
Coding TutorialGame DevelopmentCombat MechanicsPython TutorialCharacter BattleGame LogicDamage FormulaStrategyVideo GameInteractive CodeProgramming