From b56ccb610a077ceeecba083a7d9da36bbad97f9f Mon Sep 17 00:00:00 2001 From: htom Date: Sat, 26 Jul 2025 14:13:55 +0200 Subject: [PATCH] player class --- board.py | 5 +++++ draw.py | 1 + main.py | 6 +++++- player.py | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 board.py create mode 100644 draw.py create mode 100644 player.py diff --git a/board.py b/board.py new file mode 100644 index 0000000..5b4abef --- /dev/null +++ b/board.py @@ -0,0 +1,5 @@ +class Board(): + def __init__(self, board): + self.board = board + + diff --git a/draw.py b/draw.py new file mode 100644 index 0000000..de436a8 --- /dev/null +++ b/draw.py @@ -0,0 +1 @@ +class diff --git a/main.py b/main.py index c0ba0a4..4c71688 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import pygame import sys from constants import * +from player import * def main(): print("Starting BattleShip!") @@ -24,10 +25,13 @@ def main(): good_inp, player_board = check_valid_input(inp) enemy_board = player_board.copy() + player = Player(player_board) + enemy = Player(enemy_board) + for i in range(10): for j in range(10): - print(f"{board[i][j]} ", end="") + print(f"{player.board[i][j]} ", end="") print() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) diff --git a/player.py b/player.py new file mode 100644 index 0000000..948e8e1 --- /dev/null +++ b/player.py @@ -0,0 +1,12 @@ +class Player(): + def __init__(self, board, ships = 5): + self.board = board + self.ships = ships #alive ships + self.shot_positions = [] #just add the shot positions here individually + + def get_hit(self, position): + pass + + def shoot(self, position): + pass +