Extra Credit 19/19


#1

Hey Guys I've just finished the battleship course and I wanted to know how to add a 'type in your name' feature, add multiple battleships or how to put a high score board. Still learning python. Please Help.


#2

Well, i am not going to code that for you, but if i am right you already had raw_input, which you can use to prompt users for things (for example names)

Multiply battleships is possible, you need to think for a moment how you want to do this. How many ships? The length of the ships, and you have to check the ships do not take the same position, this is quit tricky. Write your code in pseudo code first (just write the steps), and then start implanting.

If you want a scoreboard, you will have to work out a point system, do the math, and store the scores in a file or database (since otherwise the scores won't persist)

Break it down in to small steps, otherwise you might get a lot of bugs to work out. Good luck! This is a great challenge to improve your coding skill, at certain point you have to move away from following instructions, and think for yourself how you could solve this problem with the knowledge you gained, i know, this can be a big leap.


#3

Thanks alot @stetim94 I took your advice created two lists of 'player 1' and 'player 2' using the {} format, but the multiple battleships has proven quite tricky,do you have a sample code I can look at?


#4

No, i have actually never done this additional challenge. Well, i guess it pretty challenging. For starters i would first determine how many ships you want (1 x 4, 1 x 3 and 2 x 2 or something?)

Then i would make an array with the ships length (ships=[4,3,2,2]). This is more tricky then i thought. I would ask them which ship they wanted to place, join the array:

int(raw_input "available ships: %s. Which ship would you like to place?" % ", ".join(ships))

This should be done in a loop, to check if the are still ships available, after you validate the user input is valid (valid number, ship available), ask if the user wants to place it horizontal or vertical, and ask for the coordinate of the left (or top) position of the ship, depending on horizontal vertical.

This is far more tricky then i thought, if i look at it. I can write it, but that is going to take time


#5

Woah! will read more about storing items and variables in python tutorial. Thanks alot though, at least I know what I'm looking to achieve.:slightly_smiling: @stetim94


#6

Storing items in variables shouldn't be new?