From ddf2f00a43ab0aebbbc1dc161ddb395e67a390e6 Mon Sep 17 00:00:00 2001
From: Daniel Moix <dwm69@drexel.edu>
Date: Tue, 25 Jul 2023 17:46:55 -0400
Subject: [PATCH] Adding Lecture 5

---
 cs171/Lect05/addodds.py       | 12 ++++++++
 cs171/Lect05/for_range.py     | 11 +++++++
 cs171/Lect05/hangman.py       | 24 ++++++++++++++++
 cs171/Lect05/hello.py         | 13 +++++++++
 cs171/Lect05/set_iteration.py | 11 +++++++
 cs171/Lect05/stairs.py        |  6 ++++
 cs172/Lect05/bubble.py        | 20 +++++++++++++
 cs172/Lect05/bubble_bounce.py | 54 +++++++++++++++++++++++++++++++++++
 cs172/Lect05/bubbles.py       | 41 ++++++++++++++++++++++++++
 cs172/Lect05/dragon_drop.py   | 44 ++++++++++++++++++++++++++++
 cs172/Lect05/drawable.py      | 22 ++++++++++++++
 cs172/Lect05/hello.py         | 38 ++++++++++++++++++++++++
 cs172/Lect05/target.py        | 40 ++++++++++++++++++++++++++
 13 files changed, 336 insertions(+)
 create mode 100644 cs171/Lect05/addodds.py
 create mode 100644 cs171/Lect05/for_range.py
 create mode 100644 cs171/Lect05/hangman.py
 create mode 100644 cs171/Lect05/hello.py
 create mode 100644 cs171/Lect05/set_iteration.py
 create mode 100644 cs171/Lect05/stairs.py
 create mode 100644 cs172/Lect05/bubble.py
 create mode 100644 cs172/Lect05/bubble_bounce.py
 create mode 100644 cs172/Lect05/bubbles.py
 create mode 100644 cs172/Lect05/dragon_drop.py
 create mode 100644 cs172/Lect05/drawable.py
 create mode 100644 cs172/Lect05/hello.py
 create mode 100644 cs172/Lect05/target.py

diff --git a/cs171/Lect05/addodds.py b/cs171/Lect05/addodds.py
new file mode 100644
index 0000000..5a5d41b
--- /dev/null
+++ b/cs171/Lect05/addodds.py
@@ -0,0 +1,12 @@
+
+# Add up the odd integers entered by the user
+
+entry = 0
+total = 0
+
+while entry >= 0:
+    entry = int(input("Enter a positive integer. Negative quits\n"))
+    if entry > 0 and entry % 2 == 1:
+        total = total + entry
+        
+print("The total of the odd numbers entered is ", total)
\ No newline at end of file
diff --git a/cs171/Lect05/for_range.py b/cs171/Lect05/for_range.py
new file mode 100644
index 0000000..f8d7ced
--- /dev/null
+++ b/cs171/Lect05/for_range.py
@@ -0,0 +1,11 @@
+
+
+for n in range(10, 1, -1):
+    print(n, end=' ')
+
+print()
+
+message = "I love donuts"
+for letter in message:
+    if letter.lower() in ('a', 'e', 'i', 'o', 'u'):
+        print(letter)
diff --git a/cs171/Lect05/hangman.py b/cs171/Lect05/hangman.py
new file mode 100644
index 0000000..3712aec
--- /dev/null
+++ b/cs171/Lect05/hangman.py
@@ -0,0 +1,24 @@
+
+
+def check(secret, guess):
+    
+    if len(secret) != len(guess):
+        return "ERROR: Strings must be of equal length."
+    
+    emptyString = ''
+
+    for i in range(0, len(secret)):
+        if secret[i] == guess[i]:
+            emptyString += secret[i]
+        else:
+            emptyString += '-'
+# 
+#     while secret != output
+#     
+#     for elements in guess:
+#         secret == guess
+
+    return emptyString
+
+
+print(check("CAT", "HAT"))
\ No newline at end of file
diff --git a/cs171/Lect05/hello.py b/cs171/Lect05/hello.py
new file mode 100644
index 0000000..ed48d0b
--- /dev/null
+++ b/cs171/Lect05/hello.py
@@ -0,0 +1,13 @@
+
+lecture = 5
+
+while lecture <= 10:
+    # print(f"Hello Lecture {lecture}!")
+    lecture = lecture - 1
+    
+print("I am done. Finished at lecture", lecture)
+
+#     
+# if lecture <= 10:
+#     print(f"Hello Lecture {lecture}!")
+#     lecture = lecture + 1
\ No newline at end of file
diff --git a/cs171/Lect05/set_iteration.py b/cs171/Lect05/set_iteration.py
new file mode 100644
index 0000000..d231619
--- /dev/null
+++ b/cs171/Lect05/set_iteration.py
@@ -0,0 +1,11 @@
+
+stuff = set()
+
+stuff.add("Eggs")
+stuff.add("Milk")
+stuff.add("Cadillac")
+
+print(stuff)
+
+for item in stuff:
+    print(item)
\ No newline at end of file
diff --git a/cs171/Lect05/stairs.py b/cs171/Lect05/stairs.py
new file mode 100644
index 0000000..3bd8656
--- /dev/null
+++ b/cs171/Lect05/stairs.py
@@ -0,0 +1,6 @@
+
+
+for i in range(1, 6):
+    for j in range (0, i):
+        print('*', end=' ')
+    print()
\ No newline at end of file
diff --git a/cs172/Lect05/bubble.py b/cs172/Lect05/bubble.py
new file mode 100644
index 0000000..23c5435
--- /dev/null
+++ b/cs172/Lect05/bubble.py
@@ -0,0 +1,20 @@
+from drawable import Drawable
+import pygame
+
+class Bubble(Drawable):
+    
+    def __init__(self, x=0, y=0, color=(0, 0, 0), size=100):
+        super().__init__(x,y)
+        self.__color = color
+        self.__size = size
+        
+    def draw(self, surface):
+        pygame.draw.circle(surface, self.__color, self.getLocation(), self.__size)
+        
+    def move(self):
+        x, y = self.getLocation()
+        y = y + 1
+        self.setLocation((x, y))
+        
+    def get_rect(self):
+        pass
\ No newline at end of file
diff --git a/cs172/Lect05/bubble_bounce.py b/cs172/Lect05/bubble_bounce.py
new file mode 100644
index 0000000..3298fd3
--- /dev/null
+++ b/cs172/Lect05/bubble_bounce.py
@@ -0,0 +1,54 @@
+import pygame
+import random
+
+class Bubble:
+    
+    def __init__(self, pos, size=255, color=(0, 0, 0)):
+        self.__pos = pos
+        self.__size = size
+        self.__color = color
+        self.__dropSpeed = 5
+        
+    def bounce(self):
+        self.__dropSpeed = -12
+    
+    def draw(self, surface):
+        red, green, blue = self.__color
+        redStep = (255 - red) / self.__size
+        greenStep = (255 - green) / self.__size
+        blueStep = (255 - blue) / self.__size
+        currentSize = self.__size
+        while currentSize > 0:
+            pygame.draw.circle(surface, (red, green, blue), self.__pos, currentSize)
+            currentSize -= 1
+            red = redStep
+            green += greenStep
+            blue += blueStep
+        x, y = self.__pos
+        y += self.__dropSpeed
+        self.__pos = (x, y)
+        self.__dropSpeed += .8
+
+if __name__ == "__main__":
+    pygame.init()
+    surface = pygame.display.set_mode((800, 600))        
+    clock = pygame.time.Clock()
+    
+    bubble = Bubble((400, 300), 100, (0, 128, 0))
+    
+    while True:
+        surface.fill((255, 255, 255))
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT or \
+               event.type == pygame.KEYDOWN and \
+               event.__dict__['key'] == pygame.K_q:
+                pygame.quit()
+                exit()
+            elif event.type == pygame.KEYDOWN and \
+                  event.__dict__['key'] == pygame.K_SPACE:
+                bubble.bounce()
+        bubble.draw(surface)
+        pygame.display.update()
+        clock.tick(30)
+
+
diff --git a/cs172/Lect05/bubbles.py b/cs172/Lect05/bubbles.py
new file mode 100644
index 0000000..7d684eb
--- /dev/null
+++ b/cs172/Lect05/bubbles.py
@@ -0,0 +1,41 @@
+import pygame
+import random
+
+class Bubble:
+    
+    def __init__(self, pos, size=255, color=(0, 0, 0)):
+        self.__pos = pos
+        self.__size = size
+        self.__color = color
+    
+    def draw(self, surface):
+        red, green, blue = self.__color
+        redStep = (255 - red) / self.__size
+        greenStep = (255 - green) / self.__size
+        blueStep = (255 - blue) / self.__size
+        currentSize = self.__size
+        while currentSize > 0:
+            pygame.draw.circle(surface, (red, green, blue), self.__pos, currentSize)
+            currentSize -= 1
+            red = redStep
+            green += greenStep
+            blue += blueStep
+
+if __name__ == "__main__":
+    pygame.init()
+    surface = pygame.display.set_mode((800, 600))        
+    surface.fill((255, 255, 255))
+    clock = pygame.time.Clock()
+    
+    while True:
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT or \
+               event.type == pygame.KEYDOWN and \
+               event.__dict__['key'] == pygame.K_q:
+                pygame.quit()
+                exit()
+        nextBubble = Bubble((random.randint(0, 800), random.randint(0, 600)), random.randint(10, 100), (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))  
+        nextBubble.draw(surface)
+        pygame.display.update()
+        clock.tick(5)
+
diff --git a/cs172/Lect05/dragon_drop.py b/cs172/Lect05/dragon_drop.py
new file mode 100644
index 0000000..608fc0b
--- /dev/null
+++ b/cs172/Lect05/dragon_drop.py
@@ -0,0 +1,44 @@
+import pygame
+
+# Define some colors
+white = (255, 255, 255)
+black = (0, 0, 0)
+red = (255, 0, 0)
+
+# Define some game variables
+width = 800
+height = 600
+
+# Load some Dragons
+blueDragon = pygame.image.load("mario_blue.png")
+goldDragon = pygame.image.load("mario_gold.png")
+currentDragon = blueDragon
+
+pygame.init()
+surface = pygame.display.set_mode((width, height))
+surface.fill((255, 255, 255))
+
+while True:
+    for event in pygame.event.get():
+        if ((event.type == pygame.QUIT) or \
+            (event.type == pygame.KEYDOWN and \
+             event.__dict__['key'] == pygame.K_q)):
+            pygame.quit()
+            exit()
+        elif event.type == pygame.MOUSEBUTTONDOWN:
+            print("Click at", event.pos)
+            clickX, clickY = event.pos
+            dragonWidth = currentDragon.get_width()
+            dragonHeight = currentDragon.get_height()
+            x = clickX - dragonWidth / 2
+            y = clickY - dragonHeight / 2
+            surface.blit(currentDragon, (x, y))
+            if currentDragon == blueDragon:
+                currentDragon = goldDragon
+            else:
+                currentDragon = blueDragon
+        elif event.type == pygame.KEYDOWN and \
+             event.__dict__['key'] == pygame.K_SPACE:
+            surface.fill(white)
+            
+    pygame.display.update()
\ No newline at end of file
diff --git a/cs172/Lect05/drawable.py b/cs172/Lect05/drawable.py
new file mode 100644
index 0000000..a8cf432
--- /dev/null
+++ b/cs172/Lect05/drawable.py
@@ -0,0 +1,22 @@
+from abc import ABC, abstractmethod
+
+class Drawable(ABC):
+    
+    def __init__(self, x=0, y=0):
+        self.__x = x
+        self.__y = y
+        
+    def getLocation(self):
+        return (self.__x, self.__y)
+    
+    def setLocation(self, point):
+        self.__x = point[0]
+        self.__y = point[1]
+        
+    @abstractmethod
+    def draw(self, surface):
+        pass
+    
+    @abstractmethod
+    def get_rect(self):
+        pass
\ No newline at end of file
diff --git a/cs172/Lect05/hello.py b/cs172/Lect05/hello.py
new file mode 100644
index 0000000..4459ec3
--- /dev/null
+++ b/cs172/Lect05/hello.py
@@ -0,0 +1,38 @@
+import pygame
+from drawable import Drawable
+from bubble import Bubble
+import random
+
+width = 800
+height = 600
+
+pygame.init()
+surface = pygame.display.set_mode((width, height))
+surface.fill((255, 255, 255))
+pygame.display.set_caption("Hello CS 172")
+fpsClock = pygame.time.Clock()
+
+bubbles = []
+for _ in range(0, 100):
+    bubbles.append(Bubble(random.randint(0,width), random.randint(-1000,height), (random.randint(0,255), random.randint(0,255), random.randint(0,255)), random.randint(20,150)))
+
+while True:
+    surface.fill((255, 255, 255))
+    for event in pygame.event.get():
+        if event.type == pygame.QUIT or \
+            (event.type == pygame.KEYDOWN and event.__dict__['key'] == pygame.K_q):   
+            pygame.quit()
+            exit()
+            
+        if event.type == pygame.MOUSEBUTTONDOWN:
+            print(event.pos)
+            
+    #pygame.draw.line(surface, (0, 128, 0), (0, 0), (800, 600), 5)
+    #pygame.draw.circle(surface, (128, 0, 0), (width/2, height/2), 150)
+            
+    for bubble in bubbles:
+        bubble.draw(surface)
+        bubble.move()
+    
+    pygame.display.update()
+    fpsClock.tick(30)
\ No newline at end of file
diff --git a/cs172/Lect05/target.py b/cs172/Lect05/target.py
new file mode 100644
index 0000000..e084ed5
--- /dev/null
+++ b/cs172/Lect05/target.py
@@ -0,0 +1,40 @@
+import pygame
+
+pygame.init()
+width = 800
+height = 600
+radius = 200
+surface = pygame.display.set_mode((width, height))
+white = (255, 255, 255)
+red = (200, 0, 0)
+blue = (0, 0, 200)
+targetColor = white
+targetPos = (width/2, height/2)
+           
+surface.fill(white)
+
+def drawTarget(surface, pos, size, targetColor=(255,255,255)):
+    while size > 0:
+        pygame.draw.circle(surface, targetColor, targetPos, size)
+        size -= 25
+        if targetColor == blue:
+            targetColor = white
+        elif targetColor == white:
+            targetColor = red
+        else:
+            targetColor = blue
+
+while True:
+    for event in pygame.event.get():
+        if event.type == pygame.QUIT or \
+           event.type == pygame.KEYDOWN and \
+           event.__dict__['key'] == pygame.K_q:
+            exit()
+        if event.type == pygame.MOUSEMOTION:
+            surface.fill(white)
+            targetColor = white
+            targetPos = event.pos
+            drawTarget(surface, targetPos, radius, targetColor)
+
+        
+    pygame.display.update()
-- 
GitLab