Hackerszone
Welcome Guest,
learn to hack easily with tutorials, python, notepad hacks and more!
Join today, fast and free!

Are you new to hacking? Learn the basics in computer configuration, hacking tools, and hacker terminology all found here on this forum!

Join today!!

Join the forum, it's quick and easy

Hackerszone
Welcome Guest,
learn to hack easily with tutorials, python, notepad hacks and more!
Join today, fast and free!

Are you new to hacking? Learn the basics in computer configuration, hacking tools, and hacker terminology all found here on this forum!

Join today!!
Hackerszone
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 

 


Rechercher Advanced Search

HZ Tracker
Hacking Widget Visitor Details
Latest topics
»  How to study to understand and apply RPA?
Battle ship in python EmptyTue Feb 02, 2021 7:12 am by manas41

» SQL injection and Quote escaping
Battle ship in python EmptySun Jun 28, 2015 11:42 am by ADS1

» [TUT] Chmod: Files & Permissions [TUT]
Battle ship in python EmptyThu Jun 04, 2015 12:45 pm by Guest

» Reaver pixiewps
Battle ship in python EmptyThu Jun 04, 2015 12:23 pm by voidfletcher

» How To Crash Someone's Skype in 10 SECONDS
Battle ship in python EmptyThu Jun 04, 2015 12:20 pm by voidfletcher

» Internet Security & IP Security (IPSec)
Battle ship in python EmptyMon May 18, 2015 9:00 pm by voidfletcher

» [Python] Infinite / Definite File Generator
Battle ship in python EmptyMon May 18, 2015 8:58 pm by ADS1

» [C#] String Case-Inversion
Battle ship in python EmptyMon May 18, 2015 8:57 pm by ADS1

» Rekall Memory Forensic Framework
Battle ship in python EmptySat May 16, 2015 8:55 pm by ADS1

Who is online?
In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests :: 1 Bot

None

[ View the whole list ]


Most users ever online was 38 on Sun Mar 19, 2023 10:07 pm

Battle ship in python

2 posters

Go down

Battle ship in python Empty Battle ship in python

Post by Admin Fri Jun 27, 2014 6:23 pm

So I made this battle ship game in python a while back, decided to post it here.

Code:

#made by HZ admin
board = [] #declares the game board
for x in range(5):
board.append(["O"] * 5)#fills the board with o's
def print_board(board):#makes a function to print board.
for row in board:
print " ".join(row)
def play_game():
print "Let's play Battleship!"
player1=raw_input('What is your name:')
print 'Let your opponent enter his name'
player2=raw_input('What is your name:')
print player1 + ' ' + 'is going first. He will hide his battleship and'+ ' ' + player2 +' '+ 'will guess the location.'
point1=0
point2=0
turns=int(raw_input("How many times do you want to play the game?"))
while turns!=0:#this is where the entire game is played.
print_board(board)
ship_row=int(raw_input("What row is your battleship on?"))
ship_col=int(raw_input("What column is your battleship on?"))
if (ship_row < 0 or ship_row > 4) or (ship_col < 0 or ship_col > 4):
print "Oops, that's not even in the ocean."
print 'Enter a number greater than zero and less than five'
ship_row=int(raw_input("What row is your battleship on?"))
ship_col=int(raw_input("What column is your battleship on?"))
elif(board[ship_row][ship_col] == "X"):
print "You entered that one already."
ship_row=int(raw_input("What row is your battleship on:"))
ship_col=int(raw_input("What column is your battleship on:"))
for i in range(0,27):
print ' '
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))
if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sunk my battleship!"
point2+=1
else:
if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
print "Oops, that's not even in the ocean."
elif(board[guess_row][guess_col] == "X"):
print "You guessed that one already."
else:
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
point1+=1
if turns==1:
print_board(board)
turns-=1
print player1+':'+str(point1)
print player2+':'+str(point2)
if point1>point2:
print 'Congragulations' +' ' + player1 +' ' + 'you beat' + ' ' + player2 + ' ' + 'in battleship.'
elif point2>point1:
print 'Congragulations' + ' '+player2 +' ' + 'you beat' + ' ' + player1 + ' ' + 'in battleship.'
else:
print 'Wow you both tied each other'

play_game()

Admin
Coder
Coder

Posts : 101
Join date : 2014-04-07

https://thehackerszone.forumotion.com

Back to top Go down

Battle ship in python Empty Re: Battle ship in python

Post by kyle5647 Fri Jun 27, 2014 6:36 pm

This is pretty freakin aweome!!!! Great work!!!
kyle5647
kyle5647
Member
Member

Posts : 40
Join date : 2014-04-08

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum