Okay, so this week I did some more screwing around with the Battleship game. Now, when someone inputs anything other than a number from 1 to 5, the while loop causes the entire thing to restart. It uses this code:
While the Python course hasn't taught me how to do while loops (gettit?) or how to anticipate and fix value errors, I found part of this code on stackoverflow and adapted it to the battleship program.
Then I tried to make it so that when the game prints, it print the board with the rows and columns labeled 1 through 5, so that the player wouldn't be confused. Then I made it so that it printed the board before the guess row input, with the labels for the rows put in brackets. I did the same thing for the columns, you can see it here:
Then I started learning about while loops. It was informational.
Showing posts with label Battleship. Show all posts
Showing posts with label Battleship. Show all posts
October 2, 2014
Week of 09/28/14 - Python Part 04
September 30, 2014
Week of 09/21/14 - Python Part 03
This week, what I did was work on the "Battleship!" lesson on codeacademy, where I make a game of battleship using a list of lists, random integers, and for loops. What I was doing on friday was screwing around with the code, like trying to make it so the player doesn't have to type 0-4, and instead 1-5. I was also trying to use a snippet of code that I found on stackoverflow, which would let me check if someone typed in letters instead of numbers. However, I couldn't figure out how to use that snippet to ask the user to give input again, using only a number. It would probably require another for loop or something. I also tried making it so that the board would have the rows and columns labeled. And then somehow I broke the definition of print_board(board), and I'm pretty sure it was something further down, but, I don't know what went wrong or how to fix it. So now I'll probably revert to a previous part of the lesson, copy all the code I wrote, replace it, and try my modifications again.
Subscribe to:
Posts (Atom)


