Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #470

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

OleksiukStepan
Copy link

Added and implemented:

  1. Added the Cell class for filling empty cells and as a parent for Deck.
  2. Added a special attribute to the Deck class to customize its symbol on the field ("□")
  3. class Ship methods:
  • get_deck (Return the deck located at the coordinates)
  • fire (Match Deck as damaged ("*") or drowned ("x") if all ship Decks are damaged)
  • if_all_deck_is_damaged (Verifies if all decks are damaged)
  • create_decs (Create Decks based on ship length)
  • create_ship (Instantiate Ship)
  1. class Battleship methods:
  • getter, setter ship (Also for deploying ships to the field)
  • fire (Return information about the shot. Also can display field changes)
  • add_ships_to_the_field (Placing ships on the field based on their coordinates)
  • print_field (Printing field to the console)
  • get_symbol_from_cell (Retrieving symbol ("□", "~", "*", "x") from the cell)
  • create_empty_field (Create a field with the required coordinates and fill it with Cells ("~"))

app/main.py Outdated

@classmethod
def create_ship(cls, ship_cords: tuple) -> Ship:
return Ship(*ship_cords)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cls instead of Ship, it's the purpose of classmethod

app/main.py Outdated
Comment on lines 116 to 119
if isinstance(cell, Ship):
return cell.get_deck(cords[0], cords[1]).symbol
else:
return cell.symbol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for else statement because if statement has return

app/main.py Outdated
Comment on lines 40 to 43
deck = self.get_deck(row, column)
deck.is_alive = False
deck.symbol = "*"
return "Sunk!" if self.if_all_deck_is_damaged() else "Hit!"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit don't get it. In case deck is not found, get_deck returns None, but you set deck.is_alive = False anyway. Shouldn't it be missed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct. The method get_deck cannot return None, as each ship consists solely of decks; thus, it will always return a deck. I've made some adjustments to ensure it functions more accurately.

@OleksiukStepan
Copy link
Author

Small changes:

  • Ship -> cls
  • removed else

Updated get_deck logic:

  • Now get_deck returns only the deck.
  • Added a check for duplicate coordinates: if the deck is already hit, print a message.

@OleksiukStepan OleksiukStepan requested a review from MNDonut August 27, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants