DEV Community

Cover image for Beginner's take on Class usage with basic logic
SamWegs
SamWegs

Posted on

Beginner's take on Class usage with basic logic

Hi All,

Welcome to my first project developed on my own. I have been working through various online programs to learn python and have hit a milestone with completing basic concepts.

The small terminal game I made here was primarily to understand how Classes operate and interact. With much of my free time spent playing video games I thought it would be a great opportunity to try to recreate one aspect of these games: fight sequencing.

When the script is run, the user will be informed of 2 set instanced classes they can pick and 2 instanced classes of enemies they can choose to fight. Each instance has a level variant which modifies baseline 'strength' and 'hitpoints'.

After selecting a user character and an enemy, you are then prompted to enter one of two actions. You can either 'attack' or 'shout'. The 'attack' input will roll a dice for baseline damage and then multiply by your strength level. With the roll being random, there is a chance you miss the target still. The 'shout' input will take your turn and increase your strength by a static '10'. This can stack through the course of the fight and directly ties into you 'attack' abilities multipliers.

User will always be given the first action. After each user action, the enemy will randomly use 'attack' or 'shout'. There is no smart AI to this (lots more I could expand into such as fight cases like execute range or enrage).

After each move, the terminal will report back both the user and enemies actions and their effects on the fight. The fight will continue until one of the combatants is at 0 healthpoints.

Creating this project opened my eyes to the back end that goes into games. I was only modeling the very surface of what goes on through a terminal. Imagine connecting this to graphics and the scope of what combat is in real life. While you won't be making split second decisions in this game, it was a great start into the realm of coding!

https://github.com/SamWegs/first-game.git

Image description

Top comments (0)