Zwischenstand Server- und Clientinitialisierung (Verbindung funktioniert noch nicht)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
def x_hoch_y(x, y):
|
||||
return x**y
|
||||
#alternativ: return pow(x,y)
|
||||
|
||||
print("13 hoch 7 ist: ", x_hoch_y(13,7))
|
||||
|
||||
print("2 hoch 9 ist: ", x_hoch_y(2,9))
|
||||
|
||||
print("4 hoch 2 ist: ", x_hoch_y(4,2))
|
||||
@@ -0,0 +1,11 @@
|
||||
listA = [2, 4.4, "HiHi", 15, 6.97]
|
||||
listB = [12, 82, "BlaBla"]
|
||||
|
||||
listC = listA + listB
|
||||
|
||||
print("listC: ", listC)
|
||||
|
||||
listC.reverse()
|
||||
print("listC reverse: ", listC)
|
||||
|
||||
#print("listC sort: ", listC.sort())
|
||||
@@ -0,0 +1,3 @@
|
||||
print("Das Eis kostet %.2f Euro" % ( 1.8 ) )
|
||||
print("Die Vorlesung startet um %2d:%2d Uhr" % ( 9, 45 ))
|
||||
print("Die Vorlesung startet um %02d:%02d Uhr" % ( 9, 45 ))
|
||||
@@ -0,0 +1,14 @@
|
||||
myData = {"first":"Jonka", "last":"Winkle", "day":10, "month":11, "year":1995}
|
||||
|
||||
print("Ganzer Name: ", myData["first"], myData["last"])
|
||||
|
||||
print("Geburtsdatum: ", myData["day"], myData["month"], myData["year"])
|
||||
|
||||
|
||||
def geburtstag(dictio):
|
||||
returnStr = str(dictio["day"]) + "." + str(dictio["month"])+ "." + str(dictio["year"])
|
||||
#alternativ: returnStr = "{:02d}.{:02d}.{:04d}".format(dictio["day"], dictio["month"], dictio["year"])
|
||||
return returnStr
|
||||
|
||||
|
||||
print("Hier das Ergebnis der geburtstag()-Fkt: ", geburtstag(myData))
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
print("Es hat geklappt!")
|
||||
@@ -0,0 +1,159 @@
|
||||
import pygame
|
||||
import random
|
||||
import time
|
||||
|
||||
running = False
|
||||
gameover = False
|
||||
|
||||
|
||||
def initScreen():
|
||||
global black, red, white, screen, width, height
|
||||
width = 640
|
||||
height = 400
|
||||
size = (width, height)
|
||||
|
||||
screen = pygame.display.set_mode(size)
|
||||
|
||||
white = (255, 255, 255)
|
||||
black = (0,0,0)
|
||||
red = (255,0,0)
|
||||
|
||||
pygame.display.set_caption("PONG!")
|
||||
|
||||
|
||||
|
||||
def initImage():
|
||||
global image, image_rect
|
||||
image = pygame.image.load("seehofer.png")
|
||||
image_rect = image.get_rect()
|
||||
image_rect.centerx = width/2
|
||||
image_rect.centery = height/2
|
||||
global size_image
|
||||
size_image = image.get_rect().size
|
||||
|
||||
|
||||
def initImageMovement():
|
||||
random.seed(a=None, version=2)
|
||||
rand_x = random.randint(1, 4)
|
||||
random.seed(a=None, version=2)
|
||||
rand_y = random.randint(1, 4)
|
||||
global move_vector
|
||||
move_vector = [ rand_x, rand_y ]
|
||||
|
||||
class Rectangle(pygame.Rect):
|
||||
def __init__(self, rect_width, rect_height):
|
||||
self.width = rect_width
|
||||
self.height = rect_height
|
||||
self.centerx = width/2
|
||||
self.centery = height - (rect_height/2)
|
||||
self.speed_x = 0
|
||||
|
||||
|
||||
def initRedRectangle():
|
||||
global red_rect
|
||||
red_rect = Rectangle(100, 12)
|
||||
|
||||
|
||||
def doMovement():
|
||||
time.sleep(0.01)
|
||||
image_rect.centerx += move_vector[0]
|
||||
image_rect.centery += move_vector[1]
|
||||
|
||||
if size_image[0]/2 <= image_rect.centerx <= width-(size_image[0]/2) and size_image[1]/2 <= image_rect.centery <= height-(size_image[1]/2):
|
||||
|
||||
pass
|
||||
else:
|
||||
if image_rect.centerx >= width-size_image[0]/2 or image_rect.centerx <= size_image[0]/2:
|
||||
# CASE 1: image bounces on the right/left wall
|
||||
move_vector[0] = -(move_vector[0])
|
||||
elif image_rect.centery <= size_image[1]/2:
|
||||
# CASE 2: image bounces on the upper wall
|
||||
move_vector[1] = -(move_vector[1])
|
||||
elif image_rect.centery >= height-size_image[1]/2:
|
||||
# CASE 3: image is about to pass the lower border of screen
|
||||
if image_rect.colliderect(red_rect):
|
||||
# CASE 3.1: image touches the red balk
|
||||
move_vector[1] = -(move_vector[1])
|
||||
if not image_rect.colliderect(red_rect):
|
||||
# CASE 3.2: image does not touch the red balk
|
||||
showGameOver()
|
||||
global gameover
|
||||
gameover = True
|
||||
|
||||
else:
|
||||
# CASE 4: image bounces in one of the upper corners (right or left)
|
||||
move_vector[0] = -(move_vector[0])
|
||||
move_vector[1] = -(move_vector[1])
|
||||
|
||||
def moveRedBalk():
|
||||
if (red_rect.width/2) <= red_rect.centerx <= width-(red_rect.width/2):
|
||||
red_rect.centerx += red_rect.speed_x * 3
|
||||
elif red_rect.centerx <= (red_rect.width/2) or red_rect.centerx >= width-(red_rect.width/2):
|
||||
red_rect.speed_x = -(red_rect.speed_x)
|
||||
red_rect.centerx += red_rect.speed_x * 3
|
||||
|
||||
def showGameOver():
|
||||
global text, gameover_rect
|
||||
font = pygame.font.Font(None, 38)
|
||||
text = font.render("Game Over!", 1, white)
|
||||
gameover_rect = text.get_rect()
|
||||
|
||||
gameover_rect.centerx = width/2
|
||||
gameover_rect.centery = height/2
|
||||
|
||||
|
||||
|
||||
def input():
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
return False
|
||||
if event.key == pygame.K_RIGHT:
|
||||
red_rect.speed_x = 1
|
||||
if event.key == pygame.K_LEFT:
|
||||
red_rect.speed_x = -1
|
||||
if event.type == pygame.KEYUP:
|
||||
red_rect.speed_x = 0
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def update():
|
||||
doMovement()
|
||||
moveRedBalk()
|
||||
|
||||
|
||||
|
||||
def draw():
|
||||
screen.fill(black)
|
||||
if gameover:
|
||||
screen.blit(text, gameover_rect)
|
||||
else:
|
||||
screen.blit(image, image_rect)
|
||||
pygame.draw.rect(screen, red, red_rect)
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
|
||||
#------------- MAIN PROGRAMM ----------------
|
||||
|
||||
pygame.init()
|
||||
initScreen()
|
||||
initImage()
|
||||
initImageMovement()
|
||||
initRedRectangle()
|
||||
running = True
|
||||
|
||||
|
||||
#---------------- GAME LOOP ------------------
|
||||
|
||||
while running:
|
||||
running = input()
|
||||
update()
|
||||
draw()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Repo_fuer_mEIM_Semester7
|
||||
|
||||
Dieses Repository enthält Python-Dateien die im Rahmen des Wahlpflichtmoduls "Informationssysteme in der Medizintechnik" (Dozent: Prof. Dr. Oliver Hofmann) erstellt wurden und verwaltet deren Versionskontrolle.
|
||||
@@ -0,0 +1,91 @@
|
||||
import pygame
|
||||
|
||||
def initScreen():
|
||||
global width, height, size
|
||||
width = 820
|
||||
height = 640
|
||||
size = (width, height)
|
||||
|
||||
global red, black
|
||||
red = (255, 0, 0, 0)
|
||||
black = (0, 0, 0, 0)
|
||||
|
||||
def initGame():
|
||||
global Rectangle
|
||||
Rectangle = initRectangle()
|
||||
global running
|
||||
running = False
|
||||
|
||||
def initSign():
|
||||
global image, image_rect
|
||||
image = pygame.image.load("seehofer.png")
|
||||
image_rect = image.get_rect()
|
||||
|
||||
class Rectangle(pygame.Rect):
|
||||
def __init__(self, x, y, width, height):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
self.speed_l = 0
|
||||
self.speed_r = 0
|
||||
|
||||
def initRectangle():
|
||||
x = 0
|
||||
y = 620
|
||||
width = 100
|
||||
height = 20
|
||||
|
||||
global My_Rect
|
||||
My_Rect = Rectangle(x, y, width, height)
|
||||
return My_Rect
|
||||
|
||||
def input():
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
return False
|
||||
if event.key == pygame.K_LEFT:
|
||||
My_Rect.speed_l = 1
|
||||
if event.key == pygame.K_RIGHT:
|
||||
My_Rect.speed_r = 1
|
||||
if event.type == pygame.KEYUP:
|
||||
Rectangle.speed_left = 0
|
||||
Rectangle.speed_right = 0
|
||||
|
||||
return True
|
||||
|
||||
def update():
|
||||
if(0 <= Rectangle.x < width):
|
||||
Rectangle.x += My_Rect.speed_r * 3
|
||||
Rectangle.x += My_Rect.speed_l * 3
|
||||
|
||||
image_rect.x = 100
|
||||
image_rect.y = 50
|
||||
|
||||
def draw():
|
||||
screen.fill(black)
|
||||
screen.blit(image, image_rect)
|
||||
pygame.draw.rect(screen, red, Rectangle)
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
# --------- Start of Main-Code ------------
|
||||
running = False
|
||||
|
||||
pygame.init()
|
||||
initScreen()
|
||||
initGame()
|
||||
initSign()
|
||||
screen = pygame.display.set_mode(size)
|
||||
|
||||
running = True
|
||||
|
||||
|
||||
while running == True:
|
||||
running = input()
|
||||
update()
|
||||
draw()
|
||||
@@ -0,0 +1,12 @@
|
||||
def mean(*params):
|
||||
x = 0
|
||||
sum = 0
|
||||
for curr in params:
|
||||
sum += curr
|
||||
x += 1
|
||||
return sum/x
|
||||
#alternativ: return sum/len(params)
|
||||
|
||||
print("Mittelwert aus 3, 6, 9, 10, 18, 22: ", mean(3, 6, 9, 10, 18, 22))
|
||||
|
||||
print("Mittelwert aus 1.2, 3.8, 9.0, 2, 25, 3.6: ", mean(1.2, 3.8, 9.0, 2, 25, 3.6))
|
||||
Reference in New Issue
Block a user