CSC 15 Lab 8 ------------------------------------------------------------------------------ For today's lab you are to do the following: 1. Finish Lab 7. 2. Conduct an experiment and draw your own conclusions. 3. Finish my awesome-retro "monstertron" game (optional) -------------- CONDUCT THE FOLLOWING EXPERIMENT: ###First, write down what you PREDICT to be the output: #Execute the following program: x = 2 y = x x += 1 print x, y # what do you expect to be printed here? (duh) A = [2,4,6] B = A A[0] += 1 print A # what do you expect to be printed here? print B # and here? print "--------------------------" # just to separate the output def f(x): x = 10 # end f def g(A,B): A[1] = 10 B = [0,0,0,0] # end g f(x) # will this change x to 10? g(A,B) # will this change A or B? print x, y print A print B ############### Now, THEORIZE as to what happened. That is, develop your own theory or explanation for the behavior of this program. WRITE IT DOWN AS CLEARLY AS POSSIBLE IN A FEW PARAGRAPHS. Be sure to answer the following points: a. Why the variable y did not change when x was changed ( by x += 1)? b. Why B[1] was changed along with A[1]. Is this behavior consistent with what happened in the case of x? How are arrays different from simple variables? c. Why did function f not change the global variable x? d. Why did function g cause the global array A to change? Is this behavior consistent with that of the function f? e. (this one is especially important): What did function g do to the variable B. Why did the global variable B not change as well, just like A did. That is, what's the difference between the lines (A[1] = 10) and (B = [0,0,0,0])? f. Why do you think Python behaves in this apparently inconsistent why? You may discuss these problems among yourselfs. But please remember to be SCIENTIFICALLY OBJECTIVE in your answers. You were asked to conduct an experiment and develop a scientific explanation for it. Here are some examples of NON-scientific ways to think about your explanations: "because python sucks" "because X said so and he's really smart" "because this is what the professor would probably want me to say" ############## ---------------------------------------------------------------- MONSTERTRON For part 3 of this lab, you are to modify the Monstertron program to add diamonds. The object of the game is for the professor to collect all the diamonds before the monsters can get him. I will demonstrate what I mean in class. The professor can fire at the monsters to temporarily freeze them. You may modify the game any way you see fit. The following are a brief explanation of some of the most important variables of the game. You'll need to add others. Remember to not use globals unless necessary: that is, unless you need to access them in mulitple functions. ########### # The object of the this game is to capture all the diamonds while avoiding # the monsters. You also have can fire up to three energy bombs at a time, # which will momentarily freeze the monsters. # The variables that control the game are: # px, py, pdx, pdy, prad: these variables control the position, movement, # and radius of the "professor" representing the human player. # b, BX, BY, BDX, BDY, BSTATE, Brad: vectors that control the bombs/bolts. # The BSTATE vector controls whether a bomb is active. ## The above variables are global: they are accessed and modified by both the # the keyhandler and the mydraw function, which contains the main animation # loop. ## The follwing variables, however, are all local within mydraw: # m, MX, MY, MDX, MDY, MF : these vectors control the monsters. m is the # number of monsters. MF is the freeze state. When zero, monster can move # speed: controls speed that the human moves. Monsters move at approximately # the same speed, but there is a randomness to the Monsters' movements. ########### ---------- The game is currently organized in one large while loop in the mydraw function. Can you think of a way to break it up into smaller, more manageable chunks?