Battleship Python Code Edited

Budget N/A
Bids 9
Average Bid $339

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]()

Post a Project Like This

Looking to make some money?

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

Bids on this Project

  • MostafaSM Profile Picture

    MostafaSM

    Vancouver,  Canada

    I am developing for 7 years. and I have so many experience in computer programming fields and I Have so many experiences in Management/ MArketing

    PHP, C Programming, Java, and Javascript

  • Qiantangren Profile Picture

    Qiantangren

    Hangzhou,  China

    be familiar with image processed and bar code recognized, using c/c++ to develop in Windows platform. In website I may use PHP or Python to design and develop.

    PHP, Python, Windows Desktop, and Linux

  • tkordic Profile Picture

    tkordic

    Belgrade,  Serbia

    Streaming engineer. Education Faculty of Mathematics, University of Belgrade, Serbia, Department Informatics and Computer Science. Technical Skills Programing languages Java / Android JavaScript / HTML Python Perl Lua MySql Sqlite OS administration Debian / Ubuntu Source code control SVN Git

    PHP, C Programming, Java, and Audio Services

  • pedjaa Profile Picture

    pedjaa

    Belgrade,  Serbia

    3 years of experience in: PLC&SCADA - Siemens WinCC, WinCCFlexible, Step 7 and Schneider Electric Unity Pro XL.

    C Programming, Python, Delphi, and Android

  • pmwheatley Profile Picture

    pmwheatley

    Budapest,  Hungary

    I'm currently working as a QA Engineer (with a strong emphasis on test automation and continuous integration) and a Mobile Developer (for both Android and iOS). I have experience of Agile development techniques, and tools such as JIRA, Jenkins, Basecamp and Testflight. I also have a keen interest in open source software and it's application towards language and education. A strong and varied academic background combined with many years experience working in various countries around the world helps ensure a professional and reliable service.

    PHP, Perl, Java, and Javascript

  • ddhnyh1 Profile Picture

    ddhnyh1

    Dandong,  China

    -Web & Programming > Node.JS > PHP > jQuery > Bootstrap > Frontend development > ASP.NET, ASP.NET MVC > WordPress > Magento > Umbraco Why choose me: 1. More than 10 years of professional experience in multinational software companies. 6 years of which was devoted as a Project Manager. 2. Relevant freelancer experience handling multiple responsibilities: as a web programmer, virtual assistant, project manager and frontend developer. 3. Perfect 5-star feedback on all 51 completed jobs. 4. Responsible, highly resourceful, detail-oriented, reliable, goal-oriented, relentless, self-motivated, open-minded, and willing to learn. Which are unlike other developers: -Quick response time -Attention to detail -Quality Assurance testing with submission of error free work -On time delivery -Delivery of work precisely according to specifications -Clear and excellent communication through chat n call (as client prefers) -Delivering the best quality of work

    PHP, ASP, C Programming, and Java

  • solomonhume Profile Picture

    solomonhume

    Beijing,  China

    Python master. Educated in all sciences.

    Python

  • tlyx Profile Picture

    tlyx

    Simferopol,  Ukraine

    6 years in Windows Development, 4 years in Linux Development - Linux, Windows, OS X - C/C++, C# - Python, Shell scripting - Databases - WinAPI - Web scraping, parsing, voting scripts, bots - Network programming

    C Programming, Python, .NET, and Windows Desktop