Pokémon Battle Simulator
The Pokémon series has always been a favorite of mine. Thus to commemorate the series, I decided to create a fan game around it. To challenge myself, I decided to create this in an unconventional engine: Visual Studio. I decided to focus specifically on battles in order to ease my workload. To start, I created a basic UI using some pre-existing artwork, the UI features 2 phases, one featuring the fight or switch button, the other showcasing the 4 moves.
The first phase of the UI
The second phase
Additionally, the UI features a text box, battle sprites for each character, and a simple menu at the top. Once that was done, I set to writing out some code. My main goal was to keep the code as modular and versatile as I could, so that adding new pokémon, moves, types, etc. would take as minimal effort as possible. to accomplish this, without writing any code in the main file, I created 3 additional classes: Move.cs to store the list of moves, movesets, and the parameters for a move structure, specifically the name, damage/healing value, move type (wheter it be a damaging or healing move as those were the 2 pressing types to deal with), the move’s element, and which stat it utilizes; Pokemon.cs to store 2 different lists of pokémon, the player’s and the enemies —I did this to make it easier to allow both the player and enemy to have the same pokémon and still have the system work, as well as the parameters for the pokemon structure, such as name, type, current/max health, as well as their stats, and type —however, to further ease the challenge, as well as making it simpler overall, I decided each pokémon would have only one type, rather than some having 2; and finally the arguably most complicated one, not due to the complexity of the code, but the monotony of adding more to it: the TypeChart.cs, this class stores all the types in the game, as well as the type chart, which in this case was a 2d array. However, as there are 18 types in the base game, the method used to add types became more intricate as I added types, and due to the nature of such a table, if I were to add a new type in the future, I would have to add in a new column for every preexisting type in addition to the additional function call to add a row. Each class additionally contains any functions related to it, IE the TypeChart class contains, as previously mentioned, functions to add types, as well as to find the effectiveness of moves, while the Moves and Pokemon classes would contain functions to add moves and pokemon respectively, while the moves class additonally contains a function to add move sets.
With the side classes essentially finished, I started on the main class. To begin, I tried adding actual pokémon as well as displaying their info, after the game displayed the correct pokémon’s information, as well as their move set. After wards, I created a switching method to switch the player’s pokémon. Then, I went to research how exactly how pokémon battles work. Through this, I found the following formula:
where Level is the player’s level (In my case, I’m keeping all the pokémon at level 100), Power is the move’s base power, A is the corresponding Pokémon’s attack stat, and D is the defender’s corresponding defence stat, and where modifier is a separate value calculated by this formula: This information was found on bulbapedia.bulbagarden.net. To simplify the equation, I reduced it to Modifier = Random X STAB X Effectiveness, as the other values were irrelevant (such as Badge and other).
To start, I created an Attack function, and calculated the move’s effectiveness, based on the TypeChart class’ FindEffectiveness function, as well as figuuring out the move’s STAB, 2 if the move and user have the same type, and 1 else wise. with this, I simply followed the formula. Then I added text to the info text box, such as the move’s name and the damage dealt. However to keep my code clean and segregated, this function only calculates damage, not actually dealing it, that is in a seperate function so aptly named DealDamage which additionally updates the info text box with the correct information. I then called this function when each move button is clicked and if the move selected is a damaging move. When this worked, I flushed out the roster by adding more pokémon, as well as implementing the UI to heal all the player’s pokemon and to generate new ones. Then, I added in healing moves which were far more simple. Then, I built a simple AI which would use a move that would be more effective more often than not, or would use a healing move if it has one when wounded. Then, I flushed out the switch function so that when a player switches their pokémon, the AI takes a turn. The pokémon with the highest speed attacks first, with the AI being favored in the case of a tie. Admittedly, this function was a tad difficult to fully implement, as it was tedious to keep track of all the states and ensure dialogue was coherent and correct. After this was finished, I had all the neccessary planned features, and finished by adding more pokémon and moves, as well as randomising the player’s team and the starting enemy.
As always, here’s a link to where you can download this project: Pokémon Battle Simulator