Web Analytics Made Easy - Statcounter

Battleship

A GUI front-end for a Battleship or Minesweeper game

This is not a complete game but rather a GUI that's ready for you to add your game logic to it.

There are 3 versions of this code, each with different levels of use of list comprehensions.

This window is a grid of buttons with each key being the row and column of the button.

It takes in clicks and will randomly change the button color and text that was clicked to either an "M" for Missing or "H" for hit.

The idea here is to drop in the code for the hit/miss logic and call this code when a button is clicked.

The layout definition is unusual in this example compared to other PySimpleGUI programs. Normally the layout is done all at one time, in a single statement layout = [[.....]]. This code uses a "contactenated layout" because the buttons are created using a list comprehension.

Note that these programs are using the new expanded Look and Feel Themes released in version 4.6 of PySimpleGUI.

Screenshot from Windows:

battleshipdarkblue3.jpg

Implementation 1 - List Comprehension for Board

Implementation 2 - List Comprehension for Board Rows

Implementation 3 - No List Comprehension