How to code randomized battles for RPG
<p>I'm having trouble understanding how to add randomized combat to a text based rpg I am making. I've seen some videos on youtube about textbased games but they want the user to type. My user will only be typing to name their character. I will have a db broken into multiple tables. Locations, actions, equipment, npcs, events etc. Ideally combat would flow like this...</p>

<pre><code>Attacker roles random int + attack chance = attack
defender roles random int + dodge chance = dodge
attack - dodge = hit
if hit &gt; 0 roll damage
role random int + base damage = damage
role random int for crit
if crit &lt; crit chance then damage * 2 = damage2
damage2 - defenders armor rating int = applieddamage
defenders hp int - applieddamage
</code></pre>

<p>Any mock code or tutorials you know about would really help.</p>
