The program itself began with some simple output into the python shell (the board is simply printed onto the screen as shown):
The output for a game of Mastermind. |
But first, some logistics. Both versions of the game (text and graphic) allow for the selection of the number of holes, the number of rows, and the number of colors. This prompting can be seen at the top of the image above. Of course, the program tests to make sure that this input is valid (meaning it is greater than zero) before allowing the user to continue. The program itself generates a random code which the user must then guess in the number of rounds (rows) specified. When the guess is completed (and checked for validity), the program calculates and prints the score before the user's next turn. It is a simple game of mastermind, and extremely easy to implement.
The fun part comes in the graphic, which evenly spaces the rows and holes so that it fits within the frame of the screen. I was also able to include colors (which is much more bright and exciting) instead of simply just numbers. However, each number is still tied to a color in the graphic game in order to allow for easy of user input.
The games can range from fairly simple (only three possible colors):
I could have won sooner if I was paying attention. |
But the games can get much more complex with the addition of more holes and more colors:
I had some pretty good luck on this one. |
I just could not guess that last color. |
All of these graphic displays were controlled by text input similar to the first picture, the only difference being that the board is displayed graphically instead of as text in the python shell.
There was another extra credit option: to implement a code by which the computer would guess a code chosen by the user. But I ran out of time this week, and was unable to actually get to this part of the problem. As usual, it was all a lot of fun, with a generally pleasing result (though it had a number of annoying bugs along the way).
Too much procrastination happened this weekend, so I still have quiet a bit to do. No more fun and games: back to work.
Sweet! I had to program a airline seating system. Based on customer input, I had to reserve the right seats. Smoking? No smoking? Aisle? Window? Exit Row?
ReplyDeleteIt was really annoying to program that on a dot matrix terminal. Let me tell you.