Pyqt mining mine Game Study Notes (6)

Source: Internet
Author: User

To learn other people's works, you have a great advantage and can look at your own shortcomings.

Your own shortcomings are often due to lack of basic knowledge and poor basic skills.

Today, I want to add another lesson: asterisk expression (* expression ).

In the mine mining program, two asterisks are used. One is in Main. py, and the other is in game_scene.py.

First, let's look at the first situation:

@pyqtSlot()def on_action_Setup_triggered(self):    result = setup.getSetup()    if not result: return    self.scene.setMap(*result)    self.scene.start()

The result here is returned from setup. py, which is like this:

def getSetup():    if SetupDlg().exec_() != QDialog.Accepted: return    return (conf.w, conf.h), conf.mines

That is, result = (Conf. W, Conf. h), Conf. Mines)

Then, parse the result with an asterisk. After calling the self. Scene. setmap (* result) function,

In game_scene.py:

def setMap(self, size, mines):        self.setup = size, mines        self.map_size = size        self.mines = mines

It can be seen that * The result is parsed into two objects, one being the size of the tuples and the other being the integer mine.

If * result Parsing is not required, the header parameter of the setmap function is an object of result, which must be parsed again.

The following function new_func uses the asterisk expression in the second part, which is also common:

def inGame(func):    """    check if this game is running    """    def new_func(self, *args, **kw):        if self.status != RUNNING: return        return func(self, *args, **kw)    return new_func

Note! First, the asterisk expression can only be used in the function header. Otherwise, it is a syntax error;

Second, the asterisk is important, not the parameter name;

Third, asterisks mean that the parameter belongs to the iterable type, and its length can be measured using the Len () function.

The following is a simple example:

>>> def func(*S,**K):print(S,'\n',K)...>>> func(1,[2,3],a=5,b='6',c='asd')(1, [2, 3]) {'a': 5, 'c': 'asd', 'b': '6'}>>>

 

Pyqt mining mine Game Study Notes (6)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.