Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #Written by plasticuproject
- from random import randint, choice
- import numpy as np
- import pandas as pd
- count = 50
- board = []
- carrier = []
- battleship = []
- cruiser = []
- submarine = []
- destroyer = []
- mark = 0
- df = pd.DataFrame({'A' : [1, 11, 21, 31, 41, 51, 61, 71, 81, 91],
- 'B' : [2, 12, 22, 32, 42, 52, 62, 72, 82, 92],
- 'C' : [3, 13, 23, 33, 43, 53, 63, 73, 83, 93],
- 'D' : [4, 14, 24, 34, 44, 54, 64, 74, 84, 94],
- 'E' : [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],
- 'F' : [6, 16, 26, 36, 46, 56, 66, 76, 86, 96],
- 'G' : [7, 17, 27, 37, 47, 57, 67, 77, 87, 97],
- 'H' : [8, 18, 28, 38, 48, 58, 68, 78, 88, 98],
- 'I' : [9, 19, 29, 39, 49, 59, 69, 79, 89, 99],
- 'J' : [10, 20, 30, 40, 50, 60, 70, 80 , 90, 100]})
- def make_game():
- carrier_start_space = [1, 2, 3, 4, 5, 6,
- 11, 12, 13, 14, 15, 16,
- 21, 22, 23, 24, 25, 26,
- 31, 32, 33, 34, 35, 36,
- 41, 42, 43, 44, 45, 46,
- 51, 52, 53, 54, 55, 56]
- battleship_start_space = [1, 2, 3, 4, 5, 6, 7,
- 21, 22, 23, 24, 25, 26, 27,
- 31, 32, 33, 34, 35, 36, 37,
- 41, 42, 43, 44, 45, 46, 47,
- 51, 52, 53, 54, 55, 56, 57,
- 61, 62, 63, 64, 65, 66, 67]
- cruiser_start_space = [1, 2, 3, 4, 5, 6, 7, 8,
- 11, 12, 13, 14, 15, 16, 17, 18,
- 21, 22, 23, 24, 25, 26, 27, 28,
- 31, 32, 33, 34, 35, 36, 37, 38,
- 41, 42, 43, 44, 45, 46, 47, 48,
- 51, 52, 53, 54, 55, 56, 57, 58,
- 61, 62, 63, 64, 65, 66, 67, 68,
- 71, 72, 73, 74, 75, 76, 77, 78]
- submarine_start_space = cruiser_start_space
- destroyer_start_space = [1, 2, 3, 4, 5, 6, 7, 8, 9,
- 11, 12, 13, 14, 15, 16, 17, 18, 19,
- 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 31, 32, 33, 34, 35, 36, 37, 38, 39,
- 41, 42, 43, 44, 45, 46, 47, 48, 49,
- 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 61, 62, 63, 64, 65, 66, 67, 68, 69,
- 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 81, 82, 83, 84, 85, 86, 87, 88, 89]
- for i in range(1, 101):
- board.append(i)
- v1 = choice(carrier_start_space)
- v2 = randint(1, 2)
- if v2 == 1:
- carrier.extend((v1, v1 + 1, v1 + 2, v1 + 3, v1 + 4))
- battleship_bad_4 = [v1 - 1, v1 - 2, v1 - 3, v1 - 4,
- v1 - 10, v1 - 10 + 1, v1 - 10 + 2,
- v1 - 10 + 3, v1 - 10 + 4, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3,
- v1 - 20 + 4, v1 - 30, v1 - 30 + 1,
- v1 - 30 + 2, v1 - 30 + 3, v1 - 30 + 4,
- v1 - 40, v1 - 40 + 1, v1 - 40 + 2,
- v1 - 40 + 3, v1 - 40 + 4]
- cruiser_bad_4 = [v1 - 1, v1 - 2, v1 - 3, v1 - 4,
- v1 - 10, v1 - 10 + 1, v1 - 10 + 2,
- v1 - 10 + 3, v1 - 10 + 4, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3,
- v1 - 20 + 4, v1 - 30, v1 - 30 + 1,
- v1 - 30 + 2, v1 - 30 + 3, v1 - 30 + 4]
- submarine_bad_4 = [v1 - 1, v1 - 2, v1 - 3, v1 - 4,
- v1 - 10, v1 - 10 + 1, v1 - 10 + 2,
- v1 - 10 + 3, v1 - 10 + 4, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3,
- v1 - 20 + 4, v1 - 30, v1 - 30 + 1,
- v1 - 30 + 2, v1 - 30 + 3, v1 - 30 + 4]
- destroyer_bad_4 = [v1 - 1, v1 - 2, v1 - 3, v1 - 4,
- v1 - 10, v1 - 10 + 1, v1 - 10 + 2,
- v1 - 10 + 3, v1 - 10 + 4, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3,
- v1 - 20 + 4]
- elif v2 == 2:
- carrier.extend((v1, v1 + 10, v1 + 20, v1 + 30, v1 + 40))
- battleship_bad_4 = [v1 - 10, v1 - 20, v1 - 30, v1 - 1,
- v1 - 2, v1 - 3, v1 + 10, v1 + 10 - 1,
- v1 + 10 - 2, v1 + 10 - 3, v1 + 20,
- v1 + 20 - 1, v1 + 20 - 2, v1 + 20 - 3,
- v1 + 30, v1 + 30 - 1, v1 + 30 - 2,
- v1 + 30 - 3, v1 + 40, v1 + 40 - 1,
- v1 + 40 - 2, v1 + 40 - 3]
- cruiser_bad_4 = [v1 - 10, v1 - 20, v1 - 1, v1 - 2, v1 + 10,
- v1 + 10 - 1, v1 + 10 - 2, v1 + 20, v1 + 20 - 1,
- v1 + 20 - 2, v1 + 30, v1 + 30 - 1, v1 + 30 - 2,
- v1 + 40, v1 + 40 - 1, v1 + 40 - 2]
- submarine_bad_4 = [v1 - 10, v1 - 20, v1 - 1, v1 - 2, v1 + 10,
- v1 + 10 - 1, v1 + 10 - 2, v1 + 20, v1 + 20 - 1,
- v1 + 20 - 2, v1 + 30, v1 + 30 - 1, v1 + 30 - 2,
- v1 + 40, v1 + 40 - 1, v1 + 40 - 2]
- destroyer_bad_4 = [v1 - 10, v1 - 1, v1 + 10, v1 + 10 - 1, v1 + 20,
- v1 + 20 - 1, v1 + 30, v1 + 30 - 1, v1 + 40,
- v1 + 40 - 1]
- for i in destroyer_bad_4:
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- for i in cruiser_bad_4:
- if i in battleship_start_space:
- battleship_start_space.remove(i)
- for i in submarine_bad_4:
- if i in cruiser_start_space:
- cruiser_start_space.remove(i)
- for i in destroyer_bad_4:
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- for i in carrier:
- if i in board:
- board.remove(i)
- if i in battleship_start_space:
- battleship_start_space.remove(i)
- if i in cruiser_start_space:
- cruiser_start_space.remove(i)
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- v1 = choice(battleship_start_space)
- v2 = randint(1, 2)
- if v2 == 1:
- battleship.extend((v1, v1 + 1, v1 + 2, v1 + 3))
- cruiser_bad_4 = [v1 - 1, v1 - 2, v1 - 10, v1 - 10 + 1,
- v1 - 10 + 2, v1 - 10 + 3, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3]
- submarine_bad_4 = [v1 - 1, v1 - 2, v1 - 10, v1 - 10 + 1,
- v1 - 10 + 2, v1 - 10 + 3, v1 - 20,
- v1 - 20 + 1, v1 - 20 + 2, v1 - 20 + 3]
- destroyer_bad_4 = [v1 - 1, v1 - 10, v1 - 10 + 1, v1 - 10 + 2,
- v1 - 10 + 3]
- elif v2 == 2:
- battleship.extend((v1, v1 + 10, v1 + 20, v1 + 30))
- cruiser_bad_4=[v1 - 10, v1 - 20, v1 - 30, v1 - 1, v1 - 2,
- v1 + 10 - 1, v1 + 10 - 2, v1 + 20 - 1,
- v1 + 20 - 2, v1 + 30 - 1, v1 + 30 - 2]
- submarine_bad_4=[v1 - 10, v1 - 20, v1 - 30, v1 - 1, v1 - 2,
- v1 + 10 - 1, v1 + 10 - 2, v1 + 20 - 1,
- v1 + 20 - 2, v1 + 30 - 1, v1 + 30 - 2]
- destroyer_bad_4 = [v1 - 10, v1 - 1, v1 + 10 - 1, v1 + 20 - 1,
- v1 + 30 - 1]
- for i in cruiser_bad_4:
- if i in cruiser_start_space:
- cruiser_start_space.remove(i)
- for i in destroyer_bad_4:
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- for i in submarine_bad_4:
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- for i in battleship:
- if i in board:
- board.remove(i)
- if i in cruiser_start_space:
- cruiser_start_space.remove(i)
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- v1 = choice(cruiser_start_space)
- v2 = randint(1, 2)
- if v2 == 1:
- cruiser.extend((v1, v1 + 1, v1 + 2))
- submarine_bad_4 = [v1 - 1, v1 - 2, v1 - 10, v1 - 10 + 1,
- v1 - 10 + 2, v1 - 20, v1 - 20 + 1,
- v1 - 20 + 2]
- destroyer_bad_4 = [v1 - 1, v1 - 10, v1 - 10 + 1, v1 - 10 + 2]
- elif v2 == 2:
- cruiser.extend((v1, v1 + 10, v1 + 20))
- submarine_bad_4=[v1 - 10, v1 - 20, v1 - 30, v1 - 1, v1 - 2,
- v1 + 10 - 1, v1 + 10 - 2, v1 + 20 - 1,
- v1 + 20 - 2]
- destroyer_bad_4 = [v1 - 10, v1 - 1, v1 + 10 - 1, v1 + 20 - 1,]
- for i in destroyer_bad_4:
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- for i in submarine_bad_4:
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- for i in cruiser:
- if i in board:
- board.remove(i)
- if i in submarine_start_space:
- submarine_start_space.remove(i)
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- v1 = choice(submarine_start_space)
- v2 = randint(1, 2)
- if v2 == 1:
- submarine.extend((v1, v1 + 1, v1 + 2))
- destroyer_bad_4 = [v1 - 1, v1 - 10, v1 - 10 + 1, v1 - 10 + 2]
- elif v2 == 2:
- submarine.extend((v1, v1 + 10, v1 + 20))
- destroyer_bad_4 = [v1 - 10, v1 - 1, v1 + 10 - 1, v1 + 20 -1]
- for i in destroyer_bad_4:
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- for i in submarine:
- if i in board:
- board.remove(i)
- if i in destroyer_start_space:
- destroyer_start_space.remove(i)
- v1 = choice(destroyer_start_space)
- v2 = randint(1, 2)
- if v2 == 1:
- destroyer.extend((v1, v1 + 1))
- elif v2 == 2:
- destroyer.extend((v1, v1 + 10))
- for i in destroyer:
- if i in board:
- board.remove(i)
- def play():
- global mark
- global x
- x = input('Choose your location to attack (1-100): ')
- print()
- print()
- print()
- print()
- if x == 'q':
- quit()
- try:
- x = int(x)
- except:
- print('You input was not understood, Mr. President.')
- if x in cruiser:
- mark = 'XX'
- elif x in carrier:
- mark = 'XX'
- elif x in battleship:
- mark = 'XX'
- elif x in destroyer:
- mark = 'XX'
- elif x in submarine:
- mark = 'XX'
- else:
- mark = '**'
- if x in board:
- print('MISS!!')
- board.remove(x)
- elif x in carrier:
- print('HIT!!')
- if len(carrier) == 1:
- print()
- print('You sunk the Russian Carrier.')
- carrier.remove(x)
- elif x in cruiser:
- print('HIT!!')
- if len(cruiser) == 1:
- print()
- print('You sunk the Russian Cruiser.')
- cruiser.remove(x)
- elif x in submarine:
- print('HIT!!')
- if len(submarine) == 1:
- print()
- print('You sunk the Russian Submarine.')
- submarine.remove(x)
- elif x in battleship:
- print('HIT!!')
- battleship.remove(x)
- elif x in destroyer:
- print('HIT!!')
- if len(destroyer) == 1:
- print()
- print('You sunk the Russian Destroyer.')
- destroyer.remove(x)
- else:
- print('Please choose a valid target to attack.')
- if len(battleship) == 0:
- print()
- print('You sunk my Battleship!!')
- graphic()
- quit()
- def graphic():
- global df
- global x
- global mark
- print()
- df = df.replace(x, mark)
- print(df.to_string(index=False))
- print()
- print()
- def main():
- global count
- running = True
- make_game()
- print()
- print()
- print('\t\t\tBATTLESHIP!!!')
- print("\t\tPress 'q' to quit at any time.")
- print()
- print()
- print('President Trump:')
- print()
- print('\tYou must sink the Russian Battleship before their NUKE detonates')
- print('\tand kills us all!! You have 50 hours. Godspeed, Mr. President.')
- print()
- print(df.to_string(index=False))
- while running:
- if count > 1:
- print()
- print(count, 'hours remaining until nuclear annilation.')
- print()
- if count== 1:
- print()
- print('You have 1 hour to stop the Russians or you are responsible')
- print('for the death of every American in the Country!!')
- print()
- count -= 1
- if count == -1:
- print()
- print('\t\t\tBOOOOOOOOOOMMMMMMM!!!!!!')
- print()
- print('(you daed)')
- quit()
- play()
- print()
- graphic()
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement