Advertisement
BeamNG_IRC

Attaaaack! python game

Mar 12th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. from random import *
  2. import time, os, sys
  3. def start(): # start script
  4.     os.system('cls') # clears the screen for a fresh start
  5.     art()
  6.     def_health = 100 # can't be too high, or else errors will occur
  7.     global health # globalise it for use outside of start()
  8.     global player_name # globalise it for use outside of start()
  9.     global p2_health # globalise it for use outside of start()
  10.     global player2_name # globalise it for use outside of start()
  11.     global turn # globalise it for use outside of start()
  12.     global fast # globalise it for use outside of start()
  13.     health = def_health # health is an integer
  14.     p2_health = def_health # health is an integer
  15.     player_name = 'Bot 1' # default players name
  16.     player2_name = 'Bot 2' # default players name
  17.     turn = randint(1,2) # determines randomly who begins
  18.     fast = 0 # set to 1 for quick battles
  19.     names = 1 # allows custom names, set to 0 for no
  20.     if names == 1:
  21.         player_name = raw_input('Player 1 name:>') # player 1 name
  22.         player2_name = raw_input('Player 2 name:>') # player 2 name
  23.     global first
  24.     if turn == 1:
  25.         first = player_name # player 1 goes first
  26.     else:
  27.         first = player2_name # player 2 goes first
  28.     game() # call game()
  29. def game(): #actual 'game' is here
  30.     os.system('cls') # clears the screen for a fresh start
  31.     art()
  32.     print 'Players:'
  33.     print '********'
  34.     print "[1]", player_name, 'Health', health # player1 stats
  35.     print "[2]", player2_name, 'Health', p2_health # player2 stats
  36.     print '********'
  37.     if turn == 1:
  38.         nameshot = player_name
  39.     else:                              # sets name of the next person to attack
  40.         nameshot = player2_name
  41.     print nameshot, 'will now attack.'
  42.     if fast == 0:
  43.         time.sleep(3) # waits 3 seconds before action
  44.     attack() # now ataaack!
  45. def attack():
  46.     if turn == 1:
  47.         minus = randint(5,30) # random amount of health loss
  48.         global p2_health
  49.         p2_health = p2_health - minus # set new health
  50.         if p2_health < 1:
  51.             p2_health = 0
  52.             global winner
  53.             winner = player_name
  54.             end()
  55.         global turn
  56.         turn = 2 # selects next player as the next turn
  57.         game() # return to game()
  58.     else:
  59.         minus = randint(5,30) # random amount of health loss
  60.         global health
  61.         health = health - minus # set new health
  62.         if health < 1:
  63.             health = 0
  64.             global winner
  65.             winner = player2_name
  66.             end()
  67.         global turn
  68.         turn = 1 # selects next player as the next turn
  69.         game() # return to game()
  70. def end():
  71.     os.system('cls') # clears the screen for a fresh start
  72.     #print first, 'went first' # debugger
  73.     art()
  74.     print 'The winner is:', winner
  75.     print 'Players:'
  76.     print '********'
  77.     print player_name, 'Health', health # player1 stats
  78.     print player2_name, 'Health', p2_health # player2 stats
  79.     print '********'
  80.     sys.exit('Game Over')
  81. def art(): # ATAAAAACK
  82.     print '        _   _             _    _ '
  83.     print '       | | | |           | |  | |'
  84.     print '   __ _| |_| |_ __ _  ___| | _| |'
  85.     print '  / _` | __| __/ _` |/ __| |/ / |'
  86.     print ' | (_| | |_| || (_| | (__|   <|_|'
  87.     print '  \__,_|\__|\__\__,_|\___|_|\_(_)'
  88.     print ''
  89. start() #starts the preperation function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement