From 5d3189d7345dd3b26a5753a16020ed4f7df0c4b1 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 23 Nov 2014 12:18:04 +0100 Subject: Verschieben aller Dateien in Unterordner --- src/pong.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/pong.py (limited to 'src/pong.py') diff --git a/src/pong.py b/src/pong.py new file mode 100644 index 0000000..574253a --- /dev/null +++ b/src/pong.py @@ -0,0 +1,79 @@ +# zustand.Ball +# Ball.xKoordinate() +# Ball.yKoordinate() +# +# zustand.listeBall() +# zustand.Schlaeger +# Schlaeger.identifikation() +# Schlaeger.yKoordinate() +# Schlaeger.punktzahl() +# zustand.listeSchlaeger() +# +# zug.ausgabe(text) +# zug.nachOben() +# zug.nachUnten() + +import math + +def zug(id, zustand, zug): + if not "round" in globals(): + # in der ersten Runde nur initialisieren + globals()["t_ballX"] = globals()["letztes_ballX"] = getBall(zustand).xKoordinate() + globals()["t_ballY"] = globals()["letztes_ballY"] = getBall(zustand).yKoordinate() + globals()["deltaX"] = globals()["deltaY"] = globals()["round"] = globals()["count"] = 0 + return + + globals()["round"] += 1 + +# zug.ausgabe("Runde " + str(globals()["round"])) + + globals()["t_ballX"] = getBall(zustand).xKoordinate() + globals()["t_ballY"] = getBall(zustand).yKoordinate() + + if (globals()["t_ballX"] < 15 and globals()["deltaX"] <= 0) or (globals()["t_ballX"] > 50 and globals()["deltaX"] >= 0) \ + or (globals()["t_ballY"] < 5) or (globals()["t_ballY"] > 55): + globals()["letztes_ballX"], globals()["letztes_ballY"] = globals()["t_ballX"], globals()["t_ballY"] + globals()["count"] = 0 + + if globals()["count"] != 0: + globals()["deltaX"] = float((globals()["t_ballX"] - globals()["letztes_ballX"]) / globals()["count"]) + globals()["deltaY"] = float((globals()["t_ballY"] - globals()["letztes_ballY"]) / globals()["count"]) + globals()["count"] += 1 + + bounces = 0 + if globals()["deltaX"] != 0: + schritte = abs(0 + globals()["t_ballX"] / globals()["deltaX"]) + #nach `schritte` Runden ist der Ball beim anderen Spieler + bounces = math.floor((globals()["t_ballY"] + abs(globals()["deltaY"] * schritte)) / 60) +# zug.ausgabe("Achtung: ") +# zug.ausgabe(bounces) +# zug.ausgabe(schritte) + + if globals()["deltaX"] < 0: + schritte = abs(0 - globals()["t_ballX"]) / globals()["deltaX"] + target_ballY = ((globals()["t_ballY"] + abs(globals()["deltaY"] * schritte)) % 60) + else: + target_ballY = 30 + + if globals()["t_ballX"] > 55 or globals()["t_ballX"] < 10: + target_ballY = globals()["t_ballY"] + + if getMe(zustand, id).yKoordinate() > target_ballY - 3: + zug.nachOben() + else: + if getMe(zustand, id).yKoordinate() < target_ballY - 3: + zug.nachUnten() + +### +def getMe(zustand, id): + if zustand.listeSchlaeger()[0].identifikation() == id: + return zustand.listeSchlaeger()[0] + return zustand.listeSchlaeger()[1] + +def getEnemy(zustand, id): + if zustand.listeSchlaeger()[0].identifikation() == id: + return zustand.listeSchlaeger()[1] + return zustand.listeSchlaeger()[0] + +def getBall(zustand): + return zustand.listeBall()[0] -- cgit v1.3.1