Skip to content
Snippets Groups Projects
Commit ef193986 authored by Jakob Kirsch's avatar Jakob Kirsch
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
run: game.py
python3 game.py
edit:
jupp game.py
\ No newline at end of file
@
#
&
0
\ No newline at end of file
game.py 0 → 100644
import random, time, os
height = int(input("Height: "))
width = int(input("Width: "))
LIFE = ""
DEATH = " "
DELAY = float(input("Delay: "))
MAP = [[DEATH for x in range(0, width)] for y in range(0, height)]
def draw(map):
os.system("clear")
print("/" + "-" * len(map[0]) + "\\")
for row in map:
print("|", end = '')
for item in row:
print(item, end='')
print("|")
print("\\" + "-" * len(map[0]) + "/")
time.sleep(DELAY)
def check(map, x, y):
target = map[y][x]
target_near = []
try:
try: target_near.append(map[y + 1][x + 1])
except: pass
try: target_near.append(map[y + 1][x])
except: pass
try: target_near.append(map[y + 1][x - 1])
except: pass
try: target_near.append(map[y][x + 1])
except: pass
try: target_near.append(map[y][x - 1])
except: pass
try: target_near.append(map[y - 1][x + 1])
except: pass
try: target_near.append(map[y - 1][x])
except: pass
try: target_near.append(map[y - 1][x - 1])
except: pass
except: pass
life = 0
for target_item in target_near:
if target_item == LIFE:
life += 1
if life > 3 or life < 2:
map[y][x] = DEATH
elif life == 3:
map[y][x] = LIFE
else:
pass
def seed(map):
for y in range(0, len(map)):
for x in range(0, len(map[0])):
map[y][x] = random.choice([DEATH, LIFE])
#MAIN
seed(MAP)
while True:
draw(MAP)
for y in range(0, len(MAP)):
for x in range(0, len(MAP[0])):
check(MAP, x, y)
\ No newline at end of file
26
60
0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment