Today I started the exercise lesson 'Battleships.' I actually had to make a very small Battleships game (but just full on coding text version). For people who don't know, the objective of battleships is to guess a certain number in order to sink the battleship. Look at the picture below for an example of it if you don't know what it is.
BATTLESHIPS GAME EXAMPLE |
Today I did half of the lessons as intended, and got as far as to making the base of the game, where the person can guess the number, the computer choosing a random battleship number, and if they guess it right, it leaves a congratulations message.
WHERE I LEFT OFF |
Since I didn't learn anything I'll do a more detailed explanation of what each section of code does.
- So first I had to make the base of the game board. This is seen on line 3-12. I created 5x5 rows/columns of the letter O's, using variables, def, and for and in.
- After that I had to make the game board have an actual battleship to sink. This is seen on line 14-21. I had to make the code choose random rows and columns to place the battleship.
- Third step, I had to add int(raw_input) to let the user actually type a number in to guess. The codes for this was only on lines 22 and 23.
THE RESULT/OTHER SIDE OF CODE |
- The fourth step was to print out ''Congratulations" message once the user has sunk the battleship. This code is located on line 29-30.
I did not learn anything new today, and just used the codes/functions I already learned. For example, to make this so far, all I had to do was use variables, print, and def, etc; So that's why I decided to combine the two sections of what I learned and what I did today together.
No comments:
Post a Comment