Skip to content

Commit 35f19a8

Browse files
author
Belvedere Tiburon Library CoderDojo
committed
Update files
1 parent f426db2 commit 35f19a8

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

__pycache__/screens.cpython-35.pyc

3.41 KB
Binary file not shown.

__pycache__/window.cpython-35.pyc

0 Bytes
Binary file not shown.

mainloop.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
master.geometry("500x250")
88
app = Screens(master=master)
99
master.mainloop()
10+
11+
input("Press enter to quit")

screens.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def new_lesson(self, unit, screenNum):
3838
#partNum: 0 is what your building, then 1, 2, 3, 4, 5
3939
def new_proj(self, unit, partNum):
4040
self.master.geometry(self.screenBounds)
41-
projStr = "self.p"+unit
41+
projStr = "self.p"+str(unit)
4242
p = eval(projStr)
4343
self.new(unit)
4444
self.cenLbl(p[partNum].title)
4545
if partNum > 0:
46-
self.btnPrev(p[screenNum-1].func)
46+
self.btnPrev(p[partNum-1].func)
4747
if partNum < len(p)-1:
48-
self.btnPrev(p[screenNum+1].func)
48+
self.btnNext(p[partNum+1].func)
4949

5050
def __init__(self, master=None):
5151
self.homeBounds = "800x1000"
@@ -208,19 +208,19 @@ def loops(self):
208208
self.multiLbl("So as you can see, a for loop loops for every item in a list and a while loop repeats while a condition is true. For for loops, a function that is commonly used is range(n). Range makes a list of numbers between 0 (inclusive) and n (exclusive). So range(3) returns [0, 1, 2] and range(1) returns [0]. If you're using for with a dictionary, for thing in dict will make thing the key but for key, value in dict will have key as the key and value as the value. Mind blown. A while loop will run while the condition is True.")
209209

210210

211-
def bs_intro(self):
212-
self.new_proj(1, 0)
213-
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the row and column correctly.")
214-
215-
def bs_empty_list(self):
216-
self.new_proj(1, 1)
217-
self.multiLbl("This lesson is pretty self explanatory. Make an empty list called the board. board=[].")
218-
219-
def bs_board_list(self):
220-
self.new_proj(1, 2)
221-
self.multiLbl("""Now we need to make the list store where the ship is and where you fired and stuff so let's get right to the Chase. Or Wells Fargo. Or whatever bank you use. So, there's this thing I haven't told you. Actually two things. Number 1: If there's a list inside a list, it's called a 2-dimensional list or a 2D list. A list in a list in a list is a 3D list. Etc, etc, etc. The other thing is that you can create lists with multiple copies of the same value by wrapping it in square brackets (as in to create a list of one item) and multiplying it by a certain amount. Let me give you an example. Let's say you wanted a list with 3 "O"s stored in cheerios. You could initialize it like this: cheerios = ["O", "O", "O"] or you could initialize it like this: cheerios = ["O"]*3 and still get the same result. We'll use this when making our board. Instead of doing a manual 2D array and stuff, we're going to do it like this:\nrows = 5\ncols = 5\n board=[["O"]*5]*5 and you will get [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O']]""")
222-
223-
def bs_print_board(self):
224-
self.new_proj(1, 3)
225-
self.multilbl("""We need a method to print out the board good because we don't want it looking like [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O']]. We want to join it. So the function called print_board which will take one argument, board and will have a for loop in which we are doing a command *for row in board*. The command is a method I haven't told you about yet. It's called join. The syntax is like this: str.join(list). For example, we want to print O O O O O where it's currently printing ['O', 'O', 'O', 'O', 'O'] so we do " ".join(board) to join the board with spaces. That is our command in the for loop.""")
226-
211+
def bs_intro(self):
212+
self.new_proj(1, 0)
213+
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the row and column correctly.")
214+
215+
def bs_empty_list(self):
216+
self.new_proj(1, 1)
217+
self.multiLbl("This lesson is pretty self explanatory. Make an empty list called the board. board=[].")
218+
219+
def bs_board_list(self):
220+
self.new_proj(1, 2)
221+
self.multiLbl("""Now we need to make the list store where the ship is and where you fired and stuff so let's get right to the Chase. Or Wells Fargo. Or whatever bank you use. So, there's this thing I haven't told you. Actually two things. Number 1: If there's a list inside a list, it's called a 2-dimensional list or a 2D list. A list in a list in a list is a 3D list. Etc, etc, etc. The other thing is that you can create lists with multiple copies of the same value by wrapping it in square brackets (as in to create a list of one item) and multiplying it by a certain amount. Let me give you an example. Let's say you wanted a list with 3 "O"s stored in cheerios. You could initialize it like this: cheerios = ["O", "O", "O"] or you could initialize it like this: cheerios = ["O"]*3 and still get the same result. We'll use this when making our board. Instead of doing a manual 2D array and stuff, we're going to do it like this:\nrows = 5\ncols = 5\n board=[["O"]*5]*5 and you will get [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O']]""")
222+
223+
def bs_print_board(self):
224+
self.new_proj(1, 3)
225+
self.multiLbl("""We need a method to print out the board good because we don't want it looking like [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O']]. We want to join it. So the function called print_board which will take one argument, board and will have a for loop in which we are doing a command *for row in board*. The command is a method I haven't told you about yet. It's called join. The syntax is like this: str.join(list). For example, we want to print O O O O O where it's currently printing ['O', 'O', 'O', 'O', 'O'] so we do " ".join(board) to join the board with spaces. That is our command in the for loop.""")
226+

0 commit comments

Comments
 (0)