Task You will need to create a graphical interface to play the battleship game. (either your own or the suggested solution) and create a graphical user interface for it, which can look like the figure...

1 answer below »
python


Task You will need to create a graphical interface to play the battleship game. (either your own or the suggested solution) and create a graphical user interface for it, which can look like the figure below: The user shoots at a route by clicking on it. The GUI should display a dialog with an error message if the user tries to shoot at a route that has already been shot. When the user wins, it should appear as a dialog and the game will end. You can exit a GUI by closing all the windows, in this case by calling the destroy () method on the main window. Note: Your GUI does not have to look like the figure, what the figure shows is an easy way to do it on and use a Canvas with many squares. Using buttons instead is also a solution. Do you wish a challenge you can draw more advanced figures or try to import pictures or other graphics and use it. Sub-tasks In this task you do not have to follow the sub-tasks as long as you solve the problem defined in the previous chapter. The sub-tasks are included for those who need some guidance on how to solve the task. a) Create a method «content_in_route» in the battleship game class. This should take the coordinate of one of the squares in the game as a parameter and return a value based on the content. Define constants that represent the four states a route can have and return the constant for the route's state. The four modes are: not shot on yet, open water, floating ships, sunken ships. b) Create a class for a single route in the game. A square must have the coordinates of the square (this is square 5 in the x-direction and 3 in the y-direction), a reference to a Canvas object, a reference to the Canvas figure representing the square, and a reference to the game. All these must be transferred to the square in the constructor. Then create a method update that asks the game about the status of this pane and updates the Canvas shape of the pane based on this. C) Create a class for the GUI. The designer will set up the interface itself, create a 10x10 board with the squares from problem b where a rectangle is created in the Canvas object for each square. d) Create a method that handles mouse clicks. This should calculate which route the user clicked on based on the coordinate of the mouse event. Then it should call the shoot method of the game from on this square and then update the GUI. Finally, it should check if the user has won, and let us know. e) Bind
Answered 5 days AfterApr 08, 2021

Answer To: Task You will need to create a graphical interface to play the battleship game. (either your own or...

Shashi Kant answered on Apr 14 2021
148 Votes
Battle/snap4.png
Battle/instruct.py
instruction = "Captain!!!,Officer Harry Reporting.\n\
Intelligence report has informed there are three Enemy
Battleships approaching us.\n\
Our Radars are jammed and so are theirs.\n\
We have limited missiles so we need to act first and destroy them before they attack us..\n\
Captain, it is up to you to predict the enemy ships' locations and annihilate them.\n\
To destroy a ship, we need to hit it in three locations.\n\n\
All the best, Captain."
Battle/__pycache__/instruct.cpython-35.pyc
Battle/snap7.png
Battle/snap3.png
Battle/snap1.png
Battle/snap2.jpg
Battle/snap6.png
Battle/snap8.png
Battle/Battleship.py
from tkinter import Button,Label,Tk,font,messagebox,Message
from random import randrange
from instruct import instruction
count = 0
def Play():
global count
count = 0
wincount = 35
def Ship_verify(ship):
for i in ship[0]:
if i in ship[1] or i in ship[2]:
return False
for i in ship[1]:
if i in ship[2]:
return False
return True
def Ship_init():
ship = []
for i in range(3):
a = randrange(2,10)
b = randrange(2,10)
temp = tuple([a,b])
ship.append(temp)
for i in range(3):
temp = randrange(1,5)
if temp == 1:
temploc = list(ship[i])
ship[i] = [tuple(temploc),...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here