-1

I am looking to create a "Top Trumps"-style game with my GCSE Computer Science class. I have managed to set up a superhero class, and then created a couple of superheroes from that (Hulk and Thor). I want to be able to pick an attribute from Thor and automatically compare it to Hulk and say which is higher.

Eventually I would like to have a list of, say, 20 superheroes, which are split evenly into 2 lists of lists. From this, the player's card should display for them to choose from then it will compare it to the corresponding attribute in the opponent's list (without it being seen until chosen). The winner will then remove the superhero from one list and place it in another, until one list is depleted.

I just do not know how to get the lists of lists set up and compare the values once selected.

import random
class Superhero (object):
    """A class that makes super hereos."""
    def __init__(self, name, beastrating, power, intelligence, specialpower, fightingskills, speed):
        self.name = name
        self.beastrating = beastrating
        self.power = power
        self.intelligence = intelligence
        self.specialpower = specialpower
        self.fightingskills = fightingskills
        self.speed = speed


    def displaySuperhero(self):
        print ("\nName: ", self.name, "\nBeastrating: ", self.beastrating, "\nPower: ", self.power, "\nIntelligence: ", self.intelligence, "\nSpecial Power: ", self.specialpower, "\nFighting Skills: ", self.fightingskills, "\nSpeed: ",self.speed)


Hulk = Superhero("Hulk", 10, 10, 1, 1, 7, 10)
Thor = Superhero("Thor", 1, 8, 8, 7, 8, 9)


Thor.displaySuperhero()
Hulk.displaySuperhero()
print("\n")
Deacon
  • 3,615
  • 2
  • 31
  • 52
Greo
  • 1
  • 2
  • You don't appear to be using lists *at all* so far. Have you tried reading a tutorial? Also, note that `beast_rating` is easier to parse than `beastrating`... – jonrsharpe Apr 22 '15 at 13:08
  • I have spent the last 4 hours trying to solve the problem, hence resorting to this :( – Greo Apr 22 '15 at 13:59
  • Note that as displayed, your code won't work. Your `__init__()` and `displaySuperhero()` methods are at the same level as your `class Superhero(object):`, rather than being indented so that they're **part** of it. Additionally, please show us what you have so far for your attempt at creating a list. Finally, what you're implementing here appears to be a deck of cards. There are multiple examples of this out there, [here](http://www.greenteapress.com/thinkpython/code/Card.py) is one from the book *[Think Python](http://www.greenteapress.com/thinkpython/)*. – Deacon Apr 22 '15 at 14:44
  • Sorry indentation was just a typo it is my first post. I have indented on my actual game and it works. I will look at the link and finish off what I am attempting to do, and post it tomorrow, thanks for your help. – Greo Apr 22 '15 at 15:09

1 Answers1

0
deck_of_cards = [Thor, Hulk, <etc>]

player_1_cards  = deck_of_cards [:len(deck_of_cards)/2]
player_2_cards  = deck_of_cards [len(deck_of_cards)/2:]

Something like that. You probably want to shuffle the deck first with something like this, Shuffling a list of objects in python

Community
  • 1
  • 1
cheesysam
  • 1,109
  • 5
  • 15
  • 32
  • Thanks cheesysam, that is actually really helpful and gives me something to build on – Greo Apr 22 '15 at 14:00