portmobi.blogg.se

Design thinking rock paper scissors
Design thinking rock paper scissors





design thinking rock paper scissors

design thinking rock paper scissors

In fact, I’d probably get rid of the Players entirely and store the game state inside the game, where it belongs. To be honest, I’m not entirely satisfied with this since I prefer having immutable objects as much as possible, and the player objects here are not immutable. Name = raw_input('What shall we call player !'.format(winner)) In summary, here’s how I’d do it: #!/usr/bin/env pythonĬHOICES =

Design thinking rock paper scissors code#

This way, the code can be executed directly or reused as a module.Īnd a check like while done = False is like fingernails across a blackboard for professional programmers: explicit checks against boolean literals never (!) make sense. The following is pretty much an established pattern in Python that all code should follow: def main(): The variable doesn’t contain a boolean value later on, why does it contain one now? Same goes for check – it should return None, not False. still a separation-of-concerns problem), neither all possible choices (i.e. go_player shouldn’t print text, its sole task should be to generate a random game choice. Notably, this includes naming conventions, and using meaningful names. Most importantly, read PEP8 (the Python style guide) and adhere to it. It should be a method.Ĭonsequently, Rock shouldn’t be a class. But here’s the gist:Ī class that has only one publicly called method (or less) isn’t a legitimate class. Ideally, watch the video first (it’s not that long) and come back later. The best OOP advice I can give for this code is: stop writing classes. Print(self.name + " chose " + self.go, end = ". Print("Player:", self.name, "created!\n") If p_a.go = "rock" and p_b.go = "scissors":Įlif p_a.go = "paper" and p_b.go = "rock":Įlif p_a.go = "scissors" and p_b.go = "paper": Temp = (input("What shall we call Player 2? ")) Temp = (input("What shall we call Player 1? ")) Print("**** Welcome to Rock, Paper, Scissors!****\n") Print(self.p2.name + ": " + str(self.p2.score)) Print(self.p1.name + ": " + str(self.p1.score)) I am just learning about using classes and I'd appreciate some advice on improving it. This is an OOP Rock, Paper, Scissors program I wrote in Python.







Design thinking rock paper scissors