Alex's .py alexspy

Hey. I created this Python blog to share the latest games and code I'm working on, along with explanations and examples so you can follow along. This should be a helpful resource for anyone looking to learn more about CGI / server-side programming and internet game development in general. Post your comments at the bottom.



Feb 12, 2022 : wordleJR.py  (source code)

I made a wordle clone to try to impress my kids. I added an accumulating points system because points are awesome. Obviously. The word list is borrowed from the original author Josh Wardle. The game play and HTML generation is done with python, but the button-based text entry is done with a few lines of javascript. I know, I know, don't judge me. Maybe I'll try to learn brython for next time.



Sept 15, 2013 : rpg_hero.py  (source code)

This is the first game I've created that's fully touch-screen compatible. I eliminated all keyboard inputs so everything is click-based. The game play itself is original since I designed it from scratch, but the turn-based framework is based on the rpg-style games from back in the 8-bit console days. The image to the right of the game changes depending on what actions are chosen. Also, this game was my first experience using dictionaries to send large amounts of game data into and out of the program. The game gets much more difficult the further you go, so it's important to be strategic about how fast you advance. Also, there's a few secrets built into the game that can be discovered if you read the dialogue closely. Enjoy.



Oct 21, 2013 : pilot_school.py  (source code)

Just something fun to keep practicing my python. No new or challenging programming tricks were required for this game, but it was interesting to see how fast I could write all the code now that I've been learning python for 2 years now. In total, it took about 20 hours of writing code spread out over 4 weeks to finish the game. The game tests how fast you can scan a block of data and pick out which number doesn't occur as often as the rest. This is kind of similar to how programmers scan their code looking for bugs before running it, so any super-hackers out there should be able to put up the best scores. Let's see what you've got!



Feb 10, 2013 : math_test.py  (source code)

Here's a test to see how fast you can solve an algebra problem in your head. Middle schoolers and younger should use Test #1. High schoolers and older should use Test #2. Plus, I added a High Scores list on the right using persistant data storage with the help of Python's sqlite3 module. If you solve Test #2 correctly, a special code will display in blue below your answer. Copy and paste this into the Key Code box on the right and you'll be able to post your name onto the High Scores list for everyone to see.




Dec 2, 2012 : roman_dice.py

Here's a fun game of risk & reward using dice. Lowest total wins the pot. Players bid for the advantage of rolling second (and the tie-breaker). The hardest part about writing this code was the number of different stages in each round. Bidding, rolling and settling up all have to be handled a little differently depending on how far into the game you are. There's probably a cleaner way to have orgainized it, but what I ended up with was 10 different branches to make it fully recursive.




Oct 20, 2012 : one_card_poker.py(source code)

Here's a simple game of 1 card poker I wrote (high card wins). The dealer's decisions to bet or fold are made using an algorithm modeled after the way a human would decide during in a real game of poker. In computer programming, this is called artificial intelligence.




Sept 1, 2012 : hangman_game.py(source code)

Here's a game of hangman I wrote. The original algorithm for this game contained a while loop which continuously processed the player's guesses until either the correct word was guessed, or the player ran out of guesses. To get the game to display in static HTML though, a continuously running loop just wasn't practical, so I had to rewrite it as a recursive function instead. To add a little something extra, the mystery word is scraped from an external page using the urllib2.urlopen function. Click here for a detailed explanation of the source code.




Jan 14, 2012 : rand_pool.py(source code)

The output below is a random display of two balls on a pool table. The python code that generates the image also figures out which pocket you should shoot into. Since the layout is random, if you refresh the page you should see a different shot every time.





Mar 1, 2012 : code-locker.py

This app can turn a message of any length into an encoded message. As long as two people know the same combination to lock or unlock the code, the original message can be recovered automatically using this website.





May 5, 2012 : bball-movie.py

This graphic is a created from a series of pictures of a bouncy ball at different points in it's bounce. The color and bounciness of the ball are chosen randomly, so if you close and reopen the page it should look a little different each time. The sequence of images are generated in a loop using PIL, then sewn together and compressed into a .swf file so they can be replayed in a web page at high speed.





Oct 28, 2012 : post_tweets.py

This is a length limited comment section (140 characters, like twitter) I created with Python, and it actually turned out to be super simple to write! It uses persistant data storage to retain the 5 most recent posts. Feel free to test it out by leaving comments on how you like the site!




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

Python 4 Kids
Planet Python
Best Python Blogs
Nadia Alramli's Blog
The "Invent with Python" Blog
Carter Sande's Blog