Skip to content

Vortigaunt2004/Half-Life-0.5-V4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Half-Life-0.5-V4

Download or paste this code into a text editor that uses python and run :) This is a Python code that simulates a simple game where the player encounters enemies and fights against them. The Player class represents the player, with attributes for health, armor, and ammo, and methods for attacking and defending. The attack method reduces the ammo count by 1 and returns a random damage value between 10 and 20. The defend method calculates the damage received by subtracting the enemy's damage from the player's armor. If the armor is greater than or equal to the damage, it reduces the armor count, and if not, it reduces the health count by the difference between the damage and armor. The is_alive method returns a boolean indicating whether the player's health is greater than 0. The game has a list of enemies, each represented as a dictionary with a name, health, and damage value. The random_encounter function randomly selects an enemy from the list and prints a message about the encounter. The game loop starts by creating a Player instance with health=100, armor=50, and ammo=30. It then enters an infinite loop where it repeatedly selects an enemy using random_encounter, and enters a battle loop where the player and the enemy take turns attacking and defending until one of them is defeated. The player can choose to attack or defend on their turn. If the player wins, they receive a random amount of ammo and health as loot. The code could be improved by adding more variety to the enemy encounters, adding more actions for the player to choose from, and implementing a game over condition. This is a basic game loop that defines a Player class, an enemies list, a random_encounter() function, and several dialogue lists for different characters.

The Player class has attributes for health, armor, and ammo, and methods for attacking, healing, defending, and checking if the player is alive.

The enemies list contains several enemy dictionaries with attributes such as name, health, and damage.

The random_encounter() function randomly selects an enemy from the enemies list and returns the dictionary.

The dialogue lists for Eli, Alyx, Gman, Kleiner, and Barney are not used in the current implementation of the game loop.

The game loop creates an instance of the Player class with 100 health, 50 armor, and 30 ammo. The loop then runs continuously until the player dies or types "exit".

In each iteration of the loop, the player encounters a random enemy using the random_encounter() function. The loop then gives the player a choice of actions: attack, heal, defend, or flee.

If the player chooses to attack, the enemy takes a random amount of damage between 10 and 20. If the player chooses to heal, the player gains 20 health if they have at least 5 ammo. If the player chooses to defend, the player's armor absorbs damage up to its value, and any excess damage is subtracted from the player's health. If the player chooses to flee, there is a 50% chance that they succeed.

If the player defeats the enemy, the loop continues to the next iteration. If the player dies, the loop ends and the game is over. If the player types "exit", the loop ends and the game is over.

Releases

No releases published

Packages

No packages published

Languages