progrmming concepts

Category: Entertainment

Presentation Description

No description available.


Presentation Transcript

General Programming Concepts:

General P rogramming Concepts Computer Games Design


Algorithm An algorithm is a sequence of steps designed to perform a particular task . The idea of an algorithm is to describe exactly how to do something. Algorithm for making a Cup of Tea 1 . Get tea-making equipment: a. Open cupboard b. Get cup c. Get teabag d. Close cupboard e. Open fridge f. Get milk g. Close fridge 2. Put teabag in cup 3. Fill kettle from tap: a. Place kettle under tap b. Turn on tap c. Turn off tap 4. Boil kettle: a. Plug kettle in b. Turn kettle on 5. Pour water into cup


Constant A value that doesn’t change throughout the game or program. Can be used for maximum values, speed, position etc const string WIZARD_ASSETNAME = "Hero"; const int START_POSITION_X = 225; const int START_POSITION_Y = 245; const int WIZARD_SPEED = 160; const int MOVE_UP = -1; const int MOVE_DOWN = 1; const int MOVE_LEFT = -1; const int MOVE_RIGHT = 1;


Variables A variable is the word for data that is stored in memory. Variables have a type and must be declared as a particular type e.g variableType variableName Vector2 Position = new Vector2(0, 0); Texture2D mSpriteTexture ; string AssetName ; Rectangle Size;

Data type:

Data type What different types of data can we store? int – a whole number 1,2,3 etc Float :- can represent fractional numbers to about 7 digits of accuracy Double:- double the accuracy of float String:- datatype for text bool:- datatype for a boolean i.e true /false

Operators Mathematical :

Operators Mathematical Operator Operation + Addition: expression1 + expression2 - Subtraction: expression1 - expression2 * Multiplication: expression1 * expression2 / Division expression1 / expression2


Concatenation The + operator also will add strings together. This operation is called concatenation, or “cat” for short. When we concatenate we are joining the strings together, like train cars, to make a longer string. E.g. “Player 1” + yourname

More Operators :

More Operators Arithmetic + - * / % Logical (boolean and bitwise) & | ^ ! ~ && || true false String concatenation + Increment, decrement ++ -- Relational == != < > <= >= Assignment = += -= *= /= %= &= |= ^= <<= >>=

Control Logic & Loops:

Control Logic & Loops If Statements While For foreach Switch Statements


Methods A Method is just a segment of code that does a particular job: In XNA common methods we will be using are: Initialize() LoadContent () Draw() Update()


Classes What is a Class? A Class is simply a set of code that does a particular job. For example in a bat and ball game You might have a class that handles all the coding for the ball in your game, and one that handle the bat. The idea is that you can reuse this code (Class) whenever you need it, or when you need it in other projects. It saves you from having to write the same thing over and over again. Think of a Class as a recipe. If you had a recipe for a delicious Cake, the recipe will tell you what you need to do to make the cake. But it's not the cake itself. It's the instructions for the cake. If you have the recipe, you can make Cakes whenever you need them.


Objects What is an Object? An Object is the thing that the recipe makes - The Cake itself. You do all the coding in a Class (recipe), and then instruct C# to make an object (the Cake). The two processes are different. But all you are really doing with Classes and Objects is trying to separate code into chunks, so that it can be reused. When the code is being used, it's an object. But the object is created from your code (Class).

authorStream Live Help