Python can write games, but not for them. Now let’s analyze the specific reasons.

Can you build a car with a hammer? Can’t anyone say no? It’s true that there were cars in history that were made with hammers. But in general, it’s better to use industrial robots, right?

There are two large Python games, EVE and Civilization. But this is an exception, not a general one. Generally speaking, there are two languages that are used to make games. One is C++.. One is C#..

Python, in theory, is not just unsuitable for games, but for any large program. Only good for small things, such as a calculator, a crawler, etc.

There are two main aspects, one is slow speed, the other is grammar defects.

You may think that Python’s syntax is so clean and elegant that it is flawed. But if you think about it, why aren’t other languages as clean? Not so elegant? Why do I have to write int a=123 when I could have just written a=123; ? Are the designers of other languages OCD? The simple truth is, you win some, you lose some. If the data type is just strings and numbers, omitting the declaration of variables is certainly not a problem. But when the logic is complicated, it’s a different story… In the game, if you write it in C# or C++, it looks something like this.

Skills a = XXXX. Weapons b = XXXX. Part c = XXXX; Potions d = XXXX. Music e = XXXX.

And the Python? It looks something like this





If you have very little code, Python is obviously convenient. But if you create hundreds of objects and over 10,000 lines of code… After writing thousands of lines, you encounter an object called X. Do you even know what it is? Is it a weapon? Or a potion? Or a picture? An audio clip? A light? A house? Don’t think 10,000 lines of code is a lot… 10, 000 lines would not even finish “Fighting the Landlord”.

Writing a large program in Python feels like, on your first day, you’ve only written 50 lines of code, created three classes, and five objects. You will feel so good, it is the best language in the world… The next day, you create two more classes and five more objects, and you get a little confused. On the third day, after creating two more classes, you find yourself having to read the comments very carefully or you won’t be able to write them. Day four, you read the notes all day…

This is the bad nature of dynamic languages. At the beginning of the code quantity is small, can not see any shortcomings, all kinds of trouble saving, all kinds of cool. The more code, the messier the brain. In general, after 500 lines, the efficiency of languages like Java, C# is surpassed. 1000 lines, you have to annotate everything to understand it. 2000 lines, that’s more comments than code. 5000 lines, comments are completely useless, you can’t read your own code, need to be ready to abandon the pit.

To sum up, Python isn’t bad for game development, it’s just not good for it. Each language has its own strengths and weaknesses, and Python’s game development side is probably where it falls short.

Python game examples add:

Licensing game

  1. The game is introduced

Four players play, and the computer randomly distributes 52 cards (not big or small) to the four players, and displays each player’s card on the screen.

  1. Object-Oriented Programming
  2. Programming steps

Design class, the licensing program designed three classes: Card class, Hand class and Poke class.

Card class: Card class represents a Card, in which FaceNum field refers to the numbers 1-13 on the Card face, Suit field refers to Suit, “plum” is the club, “square” is the square, “red” is the heart, and “black” is the spade.

Hand class: The Hand class represents the cards in a player’s Hand, which can be thought of as the cards in a player’s Hand, where the cards list variable stores the cards in a player’s Hand. You can add cards, empty your hand, give a card to another player, and so on.

Poke class: The Poke class represents a deck of cards, which we can think of as a player with 52 cards, so we inherit the Hand class. Since the cards list variable needs to store 52 cards, and it needs to deal and shuffle cards, the following method is added.

Main program: The main program is simple because there are four players, so it generates the players list to store the initialized four players. Create an object instance of a deck of cards, poke1, call populate() method to generate a deck of 52 cards, call huffle() method to shuffle the cards, call deal(players, 13) method to deal 13 cards to each player, and finally show all the cards of the four players.

class Card(): “” “” “A playing card.” RANKS = [” A “, “2”, “3”, “4”, “5”, “6”, “7”, “eight” and “9”, “10”, “J”, “Q”, “K”] # card Numbers 1-13 SUITS for = [” mei “, “party”, “red”, “black”]

Plums are clubs, squares are diamonds, reds are hearts, and blacks are spades

def __init__(self,rank,suit,face_up=True): Self. Rank =rank # is the number 1-13 self. Suit =suit #suit is the suit self. Is_FACE_UP = FACE_UP # is the front of the card, True is the front, False is the back of the card

def __str__(self): #print()

if self.is_face_up:

rep=self.suit+self.rank #+” “+str(self.pic_order())



return rep

Def flip(self): # flip method self.is_face_up=not self.is_face_up

Def pic_order(self): if self.rank==”A”: FaceNum=1 elif self.rank= “J”: FaceNum=11 elif self.rank==”Q”: Else: FaceNum=int(self.rank) if self.rank==” “; else: FaceNum=int(self.rank) if self.rank==” Elif self. Suit= =” red “: Suit=3 else: Suit=4 return (Suit-1)*13+FaceNum class Hand(): “”” A hand of playing cards. “”” def __init__(self):[] def __str__(self): if rep=”” for card in


Else: rep=” return rep def clear(self):[] def add(self,card): def give(self,card,other_hand): other_hand.add(card) class Poke(Hand): “” def populate(self): # Generate A deck of playing cards. “”” def populate(self): # Generate A deck of playing cards.


Shuffle ( def deal(self,hands,per_hand=13) for rounds in range(per_hand): for hand in hands:[0]

if __name__==”__main__”: Print (“This is a module with classed for playing cards.”) # Players =[Hand(),Hand(),Hand()] poke1=Poke() Poke1.populate () # shuffle() # deal(players,13) # distribute 13 cards to each player # display 4 cards n=1 for hand in players: Print (” hand “,n,end=”:”) print(hand) n=n+1 input(“\nPress the enter key to exit.”)

This is the end of my article on Can Python Write Games? More on this: Can Python Write Games? I hope you will support me in the future!