diff --git a/README.md b/README.md index 5651ad2..b6062d9 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ +# Battleships + This is the classic battleships game, using the terminal and pygame in python. You use the terminal for inputting the positions, for either firing or creating the layout for your fleet. The project was made using the latest available python currently (Python 3.13.5). Have not tested on other versions. It uses the uv package manager. -To run the game: -1. Clone the repository, or download it as a zip file. Then unzip it. -2. Then run the command uv run main.py in the terminal. You should see a window pop up, and the terminal asking for you to input the position for your fleet, with instructions. +![preview battleships](/screenshot/preview.png) -This game was made for the boot.dev 2025 summer hackathon. This is my first major project that I have written without any kind of tutorial. I am happy with what I have achieved, +## To run the game: +1. Clone the repository with `git clone https://github.com/htamas1210/battleships.git`, or download it as a zip file, by clicking on the green Download button, then clicking Download Zip. Then unzip it. +2. In the folder that you dowloaded, open a terminal window. Then run the command `uv run main.py` in the terminal, this will run the game. You should see a window pop up, and the terminal asking for you to input the position for your fleet, with instructions. +3. If you are done with the game. In the terminal window press Ctrl+C to exit early. + +This game was made for the boot.dev 2025 summer hackathon. This is my first major project that I have written without any kind of tutorial (or ai). I am happy with what I have achieved, but not satisfied! I know the code is a mess and there are a lot of things I could have done better. I will fix them later, or just rewrite the whole thing to be better. Anyways, this was really fun to make, and to those who try out this really basic and simple game, I hope you enjoy it for what it is, and thank you for trying it out even if you do not vote for it. diff --git a/main.py b/main.py index d651ca4..d29eb70 100644 --- a/main.py +++ b/main.py @@ -38,7 +38,7 @@ def main(): player = Player(player_board, ship_pos.copy(), "Player") enemy = Player(enemy_board, ship_pos.copy(), "Enemy") - print_board(player_board) + #print_board(player_board) screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) @@ -93,7 +93,7 @@ def check_win(player, enemy): def check_valid_input(inp): ship_pos = [] s = inp.split(' ') - print("s", s) + #print("s", s) board = [] for i in range(BOARD_SIZE): board.append([]) @@ -107,10 +107,10 @@ def check_valid_input(inp): count = 0 for position in s: count += 1 - print("c", count) + #print("c", count) position = position.lower() t = position.split("-") - print("t", t) + #print("t", t) ship_pos.append((t[0], t[1])) if t[0][0] == t[1][0] and ord(t[0][0]) >= 97 and ord(t[0][0]) <= 106 and ord(t[1][0]) >= 97 and ord(t[1][0]) <= 106: #check if the fist chars match @@ -126,9 +126,9 @@ def check_valid_input(inp): return (False, board, ship_pos) board[ord(t[0][0])-97][column] = 0b01 #first means if it is hit, second means placement - print_board(board) + #print_board(board) else: - print("e1") + #print("e1") return (False, board, ship_pos) elif t[0][1] == t[1][1] and int(t[0][1]) <= 9 and int(t[1][1]) >= 0 and int(t[1][1]) <= 9 and abs(int(t[0][1]) - int(t[1][1]))+1 < 6: if ord(t[0][0]) >= 97 and ord(t[0][0]) <= 106 and ord(t[1][0]) >= 97 and ord(t[1][0]) <= 106 and t[0][0] != t[1][0]: @@ -143,12 +143,12 @@ def check_valid_input(inp): return (False, board, ship_pos) board[row][int(t[0][1])] = 0b01 #first means if it is hit, second means placement - print_board(board) + #print_board(board) else: - print("e2") + #print("e2") return (False, board, ship_pos) - print("e3") + #print("e3") return (True, board, ship_pos) if __name__ == "__main__": diff --git a/player.py b/player.py index 8c2c91d..8b792df 100644 --- a/player.py +++ b/player.py @@ -21,7 +21,7 @@ class Player(): self.board[ord(position[0])-97][int(position[1])] = 0b11 def shoot(self, position, enemy): - print("p", position) + #print("p", position) if enemy.board[ord(position[0])-97][int(position[1])] == 0b00: print("No ship at this position") @@ -107,6 +107,6 @@ class Player(): check = self.__check_valid_input(position) - print("rand pos: ", position) + print("enemy shoots at: ", position) self.shoot(position, enemy) diff --git a/screenshot/preview.png b/screenshot/preview.png new file mode 100644 index 0000000..927a75d Binary files /dev/null and b/screenshot/preview.png differ