Skip to content

Commit

Permalink
Changed the way the cells are outputted
Browse files Browse the repository at this point in the history
Clears the terminal everytime it prints the cells in function Print_As_Grid.
  • Loading branch information
1Codealot authored Apr 30, 2023
1 parent b9c5018 commit eebaa8f
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Infection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random
import time
import random, time, os

Generation = 0

Expand All @@ -15,7 +14,8 @@
MinGensToUninfect=20\n\
ChanceOfHealing=5\n\
Immunity=1\n\
ImmuneCellCount=12")
ImmuneCellCount=12\n\
Delay=0.2")
#I guess these are default settings now ¯\_(ツ)_/¯
f.close()
finally:
Expand All @@ -28,6 +28,7 @@
ChanceOfHealing = f.readline()
Immunity = f.readline()
ImmuneCellCount = f.readline()
Delay = f.readline()

This comment has been minimized.

Copy link
@1Codealot

1Codealot Apr 30, 2023

Author Owner

Also added customisablity for time delay between each output.


f.close()

Expand All @@ -39,6 +40,7 @@
ChanceOfHealing=int(ChanceOfHealing[16:])
Immunity=int(Immunity[9:])
ImmuneCellCount=int(ImmuneCellCount[16:])
Delay=float(Delay[6:])

Cells=[] #Main List
InCells=[] #Place where cells were infected
Expand All @@ -64,12 +66,23 @@
Gen_Infected=(list(Gen_Infected))

def Print_As_Grid(X,Y):
os.system('cls' if os.name == 'nt' else 'clear')
GriddedString = ''
for n in range(len(Cells)):
if n % X == 0:
print()
print(Cells[n],end='')
#print()
#print(Cells[n],end='')
if n != 0:
GriddedString += "\n"
GriddedString += Cells[n] + ''
else:
print(Cells[n],end='')
#print(Cells[n],end='')
GriddedString += Cells[n] + ''

print(f"{GriddedString}\n{len(InCells)} Cells infected\nGeneration: {Generation}", end="\r") #Ew

# GriddedString += "\r"
# print(f"{GriddedString}",end = "\r")

Print_As_Grid(X,Y)

Expand All @@ -82,7 +95,7 @@ def Print_As_Grid(X,Y):
Gen_Infected[Infected]=Generation
InCells.append(Infected)

print("\n\n\n\n\n")
#print("\n\n\n\n\n")
Print_As_Grid(X,Y)

while len(InCells) != X*Y:
Expand Down Expand Up @@ -130,11 +143,8 @@ def Print_As_Grid(X,Y):
InCells.remove(h)

Generation += 1
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
Print_As_Grid(X,Y)

print("\n",len(InCells), "Cells infected.")
print("Generation:", Generation)
time.sleep(0.35)
Print_As_Grid(X,Y)
time.sleep(Delay)

input()

0 comments on commit eebaa8f

Please sign in to comment.