Last active
December 10, 2015 15:19
-
-
Save itsjef/4453955 to your computer and use it in GitHub Desktop.
bắn tàu đê \:D/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
# -*- coding: utf-8 -*- | |
from random import randint | |
board = [] | |
turn = 0 | |
#tạo sân chơi | |
for x in range(0,5): | |
board.append(['O']*5) | |
def print_board(board): | |
for row in board: | |
print " ".join(row) | |
print "Let's play Battleship!\n" | |
print_board(board) | |
#random tọa độ thuyền | |
def random_row(board): | |
return randint(0,len(board)-1) | |
def random_col(board): | |
return randint(0, len(board[0])-1) | |
ship_row = random_row(board) | |
ship_col = random_col(board) | |
#print ship_row+1 #cheat =) | |
#print ship_col+1 #cheat =) | |
#vào game | |
for turn in range(4): | |
guess_row = input('Guess Row: ') | |
guess_col = input('Guess Col: ') | |
if (guess_row-1) == ship_row and (guess_col-1) == ship_col: | |
print "Congratulations! You sunk le battleship!" | |
break | |
else: | |
if (guess_row < 1 or guess_row > 5) or (guess_col < 1 or guess_col > 5): | |
print "Bleh, not even in the ocean, brah." | |
elif (board[guess_row-1][guess_col-1]) == 'X': | |
print "You guessed that one already." | |
else: | |
print "You missed dat SOAB!" | |
board[guess_row-1][guess_col-1] = 'X' | |
print "Guess left: "+str(3-turn)+'\n' | |
turn += 1 | |
print_board(board) | |
if turn == 4: | |
print 'Game Over!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment