Sie sind auf Seite 1von 3

Dayne Middleton

Task 2
Brief You must make sure you explain how splitting your program into functions, procedure, and libraries helps the game makers to maintain the code. This task fully covers M1. Why do we need functions in programming? A function is a piece of code in a program and can perform a specific task in python. There are several advantages of using functions These can be: To reuse codes Information hiding Improving the clarity of the code

For programmers in the game maker company can work on one small section of the code then combine all the sections to form a large programme. ( This is very essential for the company to do). Functions are very essential in python programming because they need to interact with other objects and codes. Functions can be assigned to variables, stored in collections or can be passed as arguments in the programme. This Functions can be used to make the physics of the game, for example character movement or object movement. An example of a keyword which can be helpful to make functions
Def

What is the def keyword? The def keyword is used to create a new user defined function. An example of def is
#! /user/bin/python # function.py Def root (X) : Return x * x A = root (2) B = root (15)

Dayne Middleton
Print A, B

So what are the advantages of functions? Listed before, there was a list of advantages of using functions. Reuse codes Is the practice of using the same segment of code in multiple applications. The benefit of re using a code is that a team of programmers can share the codes, so they do not have to solve the problem again. Abstraction Is a process of hiding away or removing characteristics from something in order to reduce it to a set of essential characteristics. Through the process of abstraction, a programmer hides all the relevant data about an object in order to reduce complexity and increase efficiency. To link this to game programming, a company may want their new games in development to be restricted so that other people cannot interpret their codes or corrupt the data. This can add efficiency to make sure that the data of the code is in secrecy, so only the programmers can access the information of the code. What are modules? Modular programming procedures is a common functionality which is usually grouped together into separate modules. By doing this the program can no longer consists of only one single part. Now it is divided into smaller parts which will interact through procedure calls and now form into a whole programming code. Creating a module Creating a module can be very easy to create. Every python program is a module, to make sure it is best to put p.y at the end of the extension so the program knows that the module belongs to the python program. An example of a python module
#!/usr/bin/python # Filename: mymodule.py def sayhi(): print 'Hi, this is mymodule speaking.' version = '0.1' # End of mymodule.py

Dayne Middleton

How to load a module From my module Import * which will load the module. The advantages of modular programming and how will this link with game making Game programs can be designed more easily because a small team deals with only a small part of the entire code. A single procedure can be developed for reuse (eliminating the need to retype the code many times). Modular programming allows many programmers to collaborate on the same game application.

The programmer can use modules to make UI (which is the interface elements); this can include option menus, huds. This means that the user can change the data in the module for the preferences of the game.

Das könnte Ihnen auch gefallen