Closed

Battleship Python Code Edited

This project received 9 bids from talented freelancers with an average bid price of $339 USD.

Get free quotes for a project like this
Employer working
Skills Required
Project Budget
N/A
Total Bids
9
Project Description

Need to complete the following python shell code:

import pygame

import random

# RESOURCES

def drawBoards(screen, board1, board2):

[url removed, login to view](screen, 40, 80, 25)

[url removed, login to view](screen, 350, 80, 25)

[url removed, login to view]()

def convertToBoard(pos):

x = int((pos[0] - 350) / 25)

y = int((pos[1] - 80) / 25)

return (x, y)

class Board:

def __init__(self):

[url removed, login to view] = [[0 * 10] * 10 for x in range(10)];

def drawSelf(self, screen, x, y, tileSize):

for r in range(len([url removed, login to view])):

for c in range(len([url removed, login to view][r])):

if [url removed, login to view][r][c] == 0: # blank water = blue

drawColor = (0, 0, 255)

elif [url removed, login to view][r][c] == 1: # unhit ship = light blue

drawColor = (150, 150, 255)

elif [url removed, login to view][r][c] == 2: # miss = yellow

drawColor = (255, 255, 0)

elif [url removed, login to view][r][c] == 3: # hit ship = red

drawColor = (255, 0, 0)

[url removed, login to view](screen, drawColor, [url removed, login to view](x + c * tileSize, y + r * tileSize, tileSize, tileSize))

for r in range(len([url removed, login to view])):

[url removed, login to view](screen, (0, 0, 0), (x + r * tileSize, y), (x + r * tileSize, y + len([url removed, login to view]) * tileSize))

[url removed, login to view](screen, (0, 0, 0), (x, y + r * tileSize), (x + len([url removed, login to view]) * tileSize, y + r * tileSize))

def setValue(self, x, y, value):

[url removed, login to view][y][x] = value

def getValue(self, x, y):

return [url removed, login to view][y][x]

def enemyAttack(player):

# DO STUFF HERE

# /DO STUFF HERE

return False

def playerAttack(enemy, seenEnemy, x, y):

# DO STUFF HERE

# /DO STUFF HERE

return False

def placeShip(board, shipSize):

# DO STUFF HERE

# /DO STUFF HERE

pass

# /RESOURCES

screen = pygame.display.set_mode((640, 480))

playersTurn = True

# TODO: set up player, enemy, and seenEnemy boards

# DO STUFF HERE

# place ships

# /DO STUFF HERE

while True:

evt = [url removed, login to view]()

if [url removed, login to view] == [url removed, login to view]:

break

if playersTurn and [url removed, login to view] == [url removed, login to view]:

# process mouse actions

coord = convertToBoard([url removed, login to view])

x = coord[0]

y = coord[1]

# TODO: process human input, fire at point (x, y)

# DO STUFF HERE

# /DO STUFF HERE

# process enemy attack

if not playersTurn:

if enemyAttack(player):

enemyHits += 1

playersTurn = True

# TODO: call drawBoards with appropriate input

# DO STUFF HERE

# /DO STUFF HERE

# after victory, wait for X button

while True and (playerHits == 17 or enemyHits == 17):

evt = [url removed, login to view]()

if [url removed, login to view] == [url removed, login to view]:

break

[url removed, login to view]()

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online