diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5c6473b..0cb4fdd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,7 @@ - - - - - + + + + @@ -80,6 +95,9 @@ @@ -88,9 +106,8 @@ @@ -115,7 +132,6 @@ - @@ -136,16 +152,36 @@ + - + + + - + + + - + + + + + + + @@ -303,16 +345,16 @@ - + - + - + @@ -364,6 +406,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -508,36 +578,46 @@ - - + + + + + + + + + + + + - - + + - + - - + + - + - - + + diff --git a/Constants.py b/Constants.py index e304249..718810f 100644 --- a/Constants.py +++ b/Constants.py @@ -11,4 +11,4 @@ blockSize = 20 # The maximum number of blocks on each side. xBound = 30 -yBound = 30 +yBound = 30 \ No newline at end of file diff --git a/Scope.py b/Scope.py new file mode 100644 index 0000000..ad7ab31 --- /dev/null +++ b/Scope.py @@ -0,0 +1,61 @@ +import pygame, sys +from random import randint + +# This file is where we're going to learn about scope, before we start digging around in the main game +# Here is a great place to make changes and experiment +# Look for questions marked "Q" -- these will be asked in discussion + +# Part 1: Global Variables +# Q: What happens if we get rid of the global keyword? Will that happen no matter where we use global? +global scores + +# Part 2: Variables in Loops +for i in range(0,20): + scores[i] = randint + +# Q: We're outside of our loop. What happens if we print i? + +# Part 3: Variables in functions +def check_high_score(oldScore, newScore): + #Q: We're inside our function. What value does newScore have? + if oldScore < newScore: + return newScore + else: + return oldScore +# Q: We're outside of our function. What value does newScore have? + +# Part 4: Variables in Classes +class Player(object): + # This is how we create an object in Python. Notice the parameters + def __init__(self, name): + # declare and initialize an instance variable + # Q: We use self in Python like we use this in Java. Something very different about the two. What? + self.name = name + self.score = 0 + + # Q: Can we use the same name "newScore" from Part 3 here? Why or why not? + def new_score(self, newScore): + self.score = check_high_score(self.score, newScore) + +# Q: Why do we only have one parameter here, our function had two? What's going on? +exampleUser = Player("Mr. Chuah") +exampleUser.score = new_score(999999999999) +print exampleUser.name, exampleUser.score + +# Part 5: Show what you've got +# Make two new players, name them after you and your partner. + +# Then, give the players new highscores from our list + +# Using a loop, add points to each player's score. + +# Find how much each player's score increased by. + +# Find which player has the lowest score. + +# Finally, describe the scopes of every variable you use. You must have at least four different scopes. + + + +# When you're done, brainstorm ideas with your partner about taking advantage of what we know about +# scope to add to our snake game. diff --git a/ScopeAssessment.py b/ScopeAssessment.py new file mode 100644 index 0000000..327cc16 --- /dev/null +++ b/ScopeAssessment.py @@ -0,0 +1,25 @@ +# Label the scope of each variable by drawing a box around the range in which it exists and is usable + +rainbowColors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"] +for i in range (7): + print rainbowColors[i] + +def foo(x): + x = x + global y + y = x * x + +for i in range (7): + print i + foo(i) + for j in range (i): + print '***' + print y + +class IceCream(object): + def __init__(self, flavor): + self.flavor = flavor + +favoriteFlavor = "chocolate" +scoop1 = IceCream("vanilla") +scoop2 = IceCream(favoriteFlavor) \ No newline at end of file diff --git a/checklist1.txt b/checklist1.txt deleted file mode 100644 index 02484dc..0000000 --- a/checklist1.txt +++ /dev/null @@ -1,28 +0,0 @@ --------------------------------------- -- Python Lesson 2: FUNctions & Color - --------------------------------------- - -Due to the changing seasons and shedding skin, the world of Snake looks greyer than it used to. -Your mission is to figure out how to change colors in our game and to change this boring, grey -world into something awesome. - -As you experiment with colors, make sure to answer the questions in this file. - -1) What does an RGB triple with low values like (20, 20, 20) look like? What about a triple with high values - like (240, 240, 240)? - -2) As you experiment with changing the color of the snake, keep track of the RGB values - that you discovered below. There are some colors that you should try to discover. - There are many ways to represent a color (for example, there are many shades of orange), - so record at least one RGB value. If you discover some cool colors, add them below! --- Example: GREY: (60, 60, 60) - -RED: -GREEN: -BLUE: -YELLOW: -PURPLE: -CYAN: - -3) How can we change the color of a block that already exists (like pieces of the snake)? - List how you modify the color of an existing block.