Python

Object Oriented Programming

Take me to the Programs

Ceaser Cipher

12/24/2015

Just a little Python script I wrote so that I could pass any text through a Ceaser Cipher, which basically shifts all the letters up by a certain amount. I was reading 'Ghost In The Wires' by Kevin Mitnick, and at the start of every chapter is a piece of encrypted text so I made this program to decrypt the message. The user enters in the encrypted text or the text they want to encrypt, and the program outputs all the possible letter shifts that the text could have gone through, from letter shift 1 to 26. Using this you can encrypt the message, or use it how i did and decrypt a message by looking for the string that made sense from the output.

Flappy Bird

08/22/2014

This is a rudimentary implementation of the popular game, Flappy Bird. Unlike the past graphical games, this was programmed with Tkiner instead of Python, which means you can run it on any Python shell. Unfortunately, since it is on a different graphics library you are unable to run it on an online compiler. However, you can still view and download the code, and you can play the game with a Python Compiler. This game is made by having a square, which represents the user, jump up when the user clicks. The square only moves up and down. I then have two rectangles, which act as the tube. These tubes are programmed to always stay inline with one another, and move at the same rate. When these tubes reach the end of the screen, I call a function that resets the position of the tube and moves the gap seperating the tubes to a different position. This gap is made by generating a random number, and this acts as the bottom tubes height. This makes the gap between the tubes seperate at a different location each time.

Asteroids

03/22/2014

This is an clone of the famous game Asteroids, in which you must dodge and destroy as many asteroids as you can without being hit. It was made with Python and a graphics library called SimpleGUI. I used SimpleGUI, because it was the first Python graphics module I ever learnt, as it was taught in a Python course I did called 'An Introduction To Programming In Python'. This was one of the longer programs that I had to make, as I tried many different approaches to having multiple objects appear on the screen. My initial impulse was to have many different variables, each controlling one asteroid. However, I quickly realised that this was an extremely inefficent method. I then decided to use classes so that I could manage all the objects. I added classes for my asteroids and missles, and each time a missle/asteroid was generated I would append the object to a list by calling it to the class. I then drew each object one by iterating over the list using a for loop. This method worked much better, and it was a lot easier to control the flow of the program with this approach.

Pig Latin translator

02/18/2014

This is a Pig Latin translator I made, that will translate single english words into Pig Latin. This program is quite simple, as it is just a few functions that I call when certain letters and vowels appear in certain areas. At the start of my program, I have a few if statements that I use to check if:

1) There is the letter 'Y' in the word the user wants to translate
2) If the first letter of the word is a consonant, but the second letter is a vowel
3) The word begins with more than one vowel
4) The word begins with a vowel

These if statements let me call different functions depending on the word.

Tic-Tack-Toe

02/01/2014

This is a implementation of the game Tic-Tak-Toe. Its a very simple game to play, in which you either play as a cross or circle. To win you have to get three of your own shape in a row, in any direction. I made this game using SimpleGUI. I made this game by assigning each square a range. When one of these sectors was clicked on within the given range, I would run a short function that would determine whos turn it was, and extend this to a list that acted as the playing board for the program. This board would be checked on incrementally using if statements to check if any of the winning parameters were true. If so, it would output a message to the console on the board saying this player has won.

Atlas Game

01/29/2014

This is a game made using just Python. In this game the computer will guess a country, and you will have to guess another country starting with the same letter as the last country ended with. To make this game I had a while loop that repeated the process of taking in input from the user if the country they said was valid. To check this I had a list that had every single country on it. Once a country was guessed it would remove the country from that list. For the computers turn I would then iterate over the list to pick a country that started with the same letter as the user's country ended with. One big problem with this program was getting a list of every single country in the first place. After looking around on the internet, I managed to find a plain text version of all the countries. I installed this file, and made a Python program that read each word in the file and extended it to a string with the list formating I needed. At the end of this program, it outputed a long string of my formatted list that I could just copy and paste into my game.

Hangman

12/23/2013

Here is a version of the game 'Hangman' I programmed. In this game, the computer will guess a random word out of a list of words and you will have to guess the word correctly within a certain number of goes. I have also programmed a C++ version of the same game. The game works by splitting the word the computer has guessed into a list. Using this list, you can just iterate over all the elements to check if the users word has appeared in the list. If so, a different list that will be made up of empty slots will be filled up on the word that has been guessed. This list will then be outputted.

Palindrome Calculator

12/14/2013

This is a short program that I developed that will check if a word that the user enters is a palindrome or not. A palindrome is word that reads as the same word when it is flipped around (such as anna, or racecar). What this program does, is that it has a while loop that runs for as long as half the length of the word. This while loop runs in reverse though, so it checks the last letter, then the second last and so on. Each letter is checked with its reverse, so the last letter is check with the first letter. If they remain the same throughout the while loop, then the word is a palindrome. If even one of the letters is off, then the program breaks out of the loop and outputs that the word is not a palindrome.

Bounce

12/14/2013

This is a game called Bounce that I made with SimpleGUI. In this game, you play as a paddle and must keep bouncing the ball to stop it from hitting the ground. This was my first ever graphics game that I had programmed, and the first large project I had tried to undertake, which made it quite a challenge for me to program. The game works by constantly redrawing all the objects. The variables that control the postition of the ball are updated every few milliseconds, to give the illusion of movement. The same is done with the paddle. When the ball hits a wall or the paddle, I change the speed of the ball by multiplying it by -1. This makes it move in completely the opposite direction. This game was difficult for me to make as I had never made a 2D game before, and had no idea where to start. However, after trying out many different methods and doing some research online I managed to find a working solution.


UPDATE:

I have added a few bug fixes to the original game, and added some layout changes.