If you would rather not read about battle mechanics, you can simulate all your battles on a website called Pokemon Showdown!.
First, you need to know how the order of moves in each turn is determined. Switching happens first, and mega evolution comes immediately after. If a Pokemon is targeted by pursuit and attempts to switch, then the pursuit will go first. Then, all the +5 priority moves execute, then +4, and so on until the -7 moves finish executing. If multiple Pokemon use moves within the same priority bracket, then the fastest one will move first (or, if trick room is active, the slowest one). If multiple Pokemon have the same speed and priority, then the order is random.
The following sections involve formulas. Remember that Pokemon rounds down to the nearest integer after each multiplication and division.
When an attack is used, it usually deals damage according to this formula. If the attack is physical, then the damage depends the user's physical attack and the target's physical defense. If it's special, then it depends on the user's special attack and the target's special defense.
(((2*level/5+2)*base power*attack stat)/(defense stat*50)+2)*modifiers
The most important modifiers are the random factor (a random multiplier between 17/20 and 1), same type attack bonus (damage is multiplied by 3/2 if attack type matches one of attacker's types), the type chart, critical hits (damage is multiplied by 3/2, among other complications), and burns (physical damage is multiplied by 1/2 if attacker is burned). There are lots of other things that can change a move's damage.
Unless the Pokemon is Shedinja, max HP determined by this formula.
The attack stats, defense stats, and speed are determined by this formula.
((2*base stat+IVs+EVs/4)*level/100+5)*nature modifier
Stats can change in many ways. The most common way is stage multipliers, which range from -6 to +6. If an attack stat, a defense stat, or speed has a positive number of stages, then the stat is multiplied by 1+stage/2. If one of those stats has a negative number of stages, then the stat is multiplied by 2/(2+stage).
When a Pokemon is defeated, the opponents that were active when the defeated Pokemon was active gain experience. This is the formula for experience gain.
(base experience yield*level of defeated Pokemon*modifiers)/7
There are several other things that affect experience gain.