alexspy Alex's .py alexspy

Hi, I'm Alex. I created this Python blog to show people the latest games and code I'm working on, along with explanations and examples for anyone looking to learn more about Python, CGI / server-side programming, or just internet game development in general. Let me know what you think, and thanks for visiting!



Apr 10, 2013 : math_test.py

Here's a breakdown of how the math_test.py source code works, in 6 easy steps...

Interactive html games rely on recursion, which we accomplish in this example with two branches: a problem frame, and an evaluation frame.
  1. Check if the program is being asked to execute a problem frame or an evaluation frame, by looking for a hidden CGI variable called "eval_frame"...



  2. If the current frame is a problem frame, then generate a random algebra problem and start the timer...



  3. If the current frame is an evaluation frame, then check if the user's answer is correct and stop the timer...



  4. Print the algebra problem to the game GUI (user's html browser)...



  5. If this is a problem frame, then display a box for the user to enter his/her answer into, along with other necessary game info as hidden variables...



  6. If this is an evaluation frame, then display whether the user's answer was right or wrong along with how long it took them to give their answer...






Here's some other great python blogs I like to check out:

Nadia Alramli's Blog
The "Invent with Python" Blog
Carter Sande's Blog