SoFunction
Updated on 2024-12-19

Can python develop games?

python can write games, but it's not suitable. Let's analyze exactly why.

Can you build a car with a hammer? No one can say no, can they? It's true that there have been cars built with hammers throughout history. But generally speaking, it's better to use industrial robots, right?

Two of the larger, games that use Python are EVE and Civilization. But that's just an example, not of broad significance.
Generally speaking, there are two languages used to make games. One is C++. One is C#.

Python is, in theory, not only unsuitable for games, but for just about any large program. It's only suitable for writing smaller things, like a calculator, a crawler, etc.

There are 2 main areas, one is slow and the other is grammatical flaws.

Maybe you must be thinking that Python's syntax is so clean and elegant, how come it has flaws? But if you think about it, why aren't other languages as clean? Not so elegant? Why do you have to write int a=123 when you can just write a=123? Could it be that the designers of other languages have obsessive-compulsive disorder? The logic is simple: what goes around comes around.
If the data types, only strings and numbers, omit the process of declaring variables, of course, is not a problem. But as soon as the logic gets complex, the situation is completely different. The game, when you write it in C# or C++, will probably look like this.

technical ability a=xxxx;
weaponry b=xxxx;
character c=xxxx;
Yaksu in North Korea, near the border with Liaoning and Jiling province d=xxxx;
concert e=xxxx;

And Python? Something like this.

a=xxxx
b=xxxx
c=xxxx
d=xxxx

If you have very little code, obviously Python is more convenient. But if you create hundreds of objects and have over 10,000 lines of code. When you get to a few thousand lines of writing and you come across an object called x, do you still know what it really is? Is it a weapon? Or a bottle of potion? Or a picture? A piece of audio? A light? A house?
Don't think 10,000 lines of code is a lot.... . 10,000 lines wouldn't even finish writing a "Landlord".

The feeling of writing a big program in Python is when, on your first day, you write only 50 lines of code and create 3 classes and 5 objects. You feel so good, it's definitely the best language in the world. On the second day, when you've created 2 more classes and 5 more objects, you feel a little giddy. On the third day, after creating 2 more classes, you realize you have to read through the comments very carefully or you won't be able to write it. On day 4, you spend the whole day looking at the comments 。。。。

That's the bad thing about dynamic languages. At the beginning, the amount of code is small, you can not see any disadvantages, all kinds of savings, all kinds of cool. The more code, the more confused. Generally more than 500 lines, the efficiency of JAVA, C# and other languages will be reversed. 1000 lines, you have to add all kinds of comments to be able to read. 1000 lines, you have to add all kinds of comments to be able to read. 2000 lines, the comments will be more than the number of lines. In 2000 lines, the comments are more than the code. 5000 lines, the comments are completely out of place. 5000 lines, comments have been completely useless, they can not understand their own code, need to prepare to abandon the pit.

To summarize, it's not that python can't develop games, it's just not a good fit. Every language has its own strengths and weaknesses, and perhaps the game development piece is python's weakness.

python game example supplement:

licensing scheme

1. Introduction to the game

The computer randomly deals 52 cards (no king or queen) to the four players and displays each player's card on the screen.

2. Object-oriented programming

3. Procedural design steps

Designing Classes, the licensing program designs three classes: the Card class, the Hand class, and the Poke class.

Card class: Card class represents a card, in which the FaceNum field refers to the number 1 to 13 on the face of the card, and the Suit field refers to the suit, "Plums" is clubs, "Square" is diamonds, "Red The Suit field refers to the suit, with "Plums" being Clubs, "Square" being Diamonds, "Hearts" being Hearts, and "Black" being Spades.

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

Poke class: The Poke class represents a deck of cards. We can think of a deck of cards as a hand with 52 cards, so it inherits the Hand class. Since the cards list variable has to store 52 cards and has to be dealt and shuffled, the following methods are added.

Main program: The main program is relatively simple, because there are four players, so generate a list of players to store the initialization of the four players. Generate a deck of cards object instance poke1, call populate() method to generate a deck of 52 cards, call huffle() method to shuffle the cards to disrupt the order, 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","8","9","10","J","Q","K"] #Card face numbers 1-13
 SUITS=["Plum.","Square.","Red.","Black."]
#Plums are clubs, squares are diamonds, reds are hearts, and blacks are spades.

 def __init__(self,rank,suit,face_up=True):
  =rank    # refers to card numbers 1-13.
  =suit    #suit refers to the color of the flower
  self.is_face_up=face_up #Whether to display the front of the card, True for the front, False for the back of the card

 def __str__(self): #print()
  if self.is_face_up:
   rep=+ #+" "+str(self.pic_order())
  else:
   rep="XX"
  return rep

 def flip(self):    #Flopping method
  self.is_face_up=not self.is_face_up

 def pic_order(self):   # The sequential number of the license plate
  if =="A":
   FaceNum=1
  elif =="J":
   FaceNum=11
  elif =="Q":
   FaceNum=12
  elif =="K":
   FaceNum=13
  else:
   FaceNum=int()
  if =="Plum.":
   Suit=1
  elif =="Square.":
   Suit=2
  elif =="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 :
    rep+=str(card)+"\t"
  else:
   rep="Unlicensed."
  return rep
 def clear(self):
  =[]
 def add(self,card):
  (card)
 def give(self,card,other_hand):
  (card)
  other_hand.add(card)
class Poke(Hand):
 """ A deck of playing cards. """
 def populate(self):   #Generate a deck of cards
  for suit in :
   for rank in :
    (Card(rank,suit))
 def shuffle(self):   #Shuffle
  import random
  () # Disrupt the order of the cards
 def deal(self,hands,per_hand=13):
  for rounds in range(per_hand):
   for hand in hands:

    top_card=[0]
    (top_card)
    (top_card)
if __name__=="__main__":
 print("This is a module with classed for playing cards.")
 #Four players
 players=[Hand(),Hand(),Hand(),Hand()]
 poke1=Poke()
 ()   #Generate a deck of cards
 ()    #Shuffle
 (players,13)  # Sent to the players 13 copies each
 #Show the cards of the four players
 n=1
 for hand in players:
  print("Card Player.",n,end=":")
  print(hand)
  n=n+1
 input("\nPress the enter key to exit.")

To this point this article on python can develop games to this article, more related python can write games content please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!