I am a beginner level programmer and recently I started learning OOP, so I made a simple war game
import random
cardsstart = 4 * range(2, 15)
cardsstart.extend([15, 15]);random.shuffle(cardsstart)
cardslen = len(cardsstart)/2
class cards:
def __init__(self):
"""intializes a set of cards(deck) to the object
"""
global cards
self.deck = [cardsstart.pop() for i in range(cardslen)]
def take(self, crd):
"""appends the card given to the object's list deck"""
crd = [crd] if type(crd) is not list else crd
self.deck.extend(crd)
random.shuffle(self.deck)
def give(self, crd):
"""removes the card given from the object's list deck"""
crd = [crd] if type(crd) is not list else crd
for i in crd:
self.deck.remove(i)
player = cards()
enemy = cards()
while True:
raw_input()
if len(player.deck) == 0:
print 'rival won'
break
elif len(enemy.deck) == 0:
print 'you won'
break
print 'player shown his', player.deck[0]
print 'rival shown his', enemy.deck[0]
if player.deck[0] > enemy.deck[0]:
print 'player took rival\'s card'
player.take(enemy.deck[0])
enemy.give(enemy.deck[0])
elif player.deck[0] == enemy.deck[0]:
print 'WAR'
n = 3
while True:
print 'the war is on. player ruling card is {} and rival ruling card is {}'.format(player.deck[n], enemy.deck[n])
if player.deck[n] > enemy.deck[n]:
print 'player won the war'
player.take(enemy.deck[0:n])
enemy.give(enemy.deck[0:n])
break
elif player.deck[n] == enemy.deck[n]:
print 'cards are equal!another war round starting'
n += 3
else:
print 'rival won the war'
enemy.take(player.deck[0:n])
player.give(player.deck[0:n])
break
else:
print 'rival took player\'s card'
enemy.take(player.deck[0])
player.give(player.deck[0])
Looking for advice on how to make it better? Any other tips?