Game Development Reference
In-Depth Information
12.
Variable assignment
Consider the following two variable declarations and assignments:
int
x, y;
x = 40;
y = 12;
Indicate for each of the following groups of instructions what the values of
x
and
y
are when these instructions are executed after the above declarations and
instructions.
∗
y=x+1;
x=y+1;
x=y;
y=x;
x=y+1;
y=x
x = x+y;
y=x
y=x/3;
x=y
y=2/3
x;
y=x%6;
x=x/6;
−
−
∗
∗
1;
y;
3;
x=2
x/3;
−
x=x
y;
In one of the cases, the values of
x
and
y
are swapped. Does this work for all
possible values of
x
and
y
? If so, why is that? If not, in what cases does it
fail?
13.
Multiplying and dividing
Is there a difference between the following three instructions?
−
3
∗
time / 2;
position = 300
−
3/2
∗
time;
position = 300
−
time/2
∗
3;
position = 300
14.
Hours, minutes, seconds
Suppose that the integer variable
time
contains a (possibly large) number of
seconds. Write down a number of instructions that assign a value to the vari-
ables
hours
,
minutes
and
seconds
corresponding to their meaning, where the
values of
minutes
and
seconds
should be smaller than 60. Secondly, write the
instruction that performs the reverse operation. So, given the variables
hours
,
minutes
, and
seconds
, calculate the value that the variable
time
should con-
tain.
15.
The game loop
Which actions does the game loop consist of? Which actions are executed only
once, and which actions are executed multiple times? What is the use of these
different actions?
16.
Updating and drawing
We could put all the code from the
Update
method in the
Draw
method, and
leave out the
Update
method altogether. Why is it still useful to have different
methods?