93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
import string
|
|
import sys
|
|
import os
|
|
import time
|
|
import random
|
|
from Tomato import Tomato
|
|
from Cucumber import Cucumber
|
|
from Plant import Plant
|
|
from Point import Point
|
|
from Trac import Trac
|
|
|
|
string.ascii_letters = 'oOpPx'
|
|
string.ascii_numbers = '01'
|
|
OKGREEN = '\033[92m'
|
|
OKBLUE = '\033[94m'
|
|
OKRED = '\033[91m'
|
|
ENDC = '\033[0m'
|
|
|
|
|
|
def initialize_field():
|
|
field = []
|
|
for i in range(11):
|
|
row = []
|
|
for j in range(7):
|
|
if i == 0 or i == 10 or j == 0 \
|
|
or j == 3 or j == 6:
|
|
# row.append((Point((i, j)), None))
|
|
row.append(None)
|
|
elif i < 3:
|
|
# row.append((Point((i, j)), Cucumber()))
|
|
row.append(Cucumber())
|
|
else:
|
|
# row.append((Point((i, j)), Tomato()))
|
|
row.append(Tomato())
|
|
field.append(row)
|
|
return field
|
|
|
|
|
|
def print_field(field, tractor):
|
|
sys.stdout.write(OKBLUE)
|
|
sys.stdout.write("$")
|
|
sys.stdout.write(" ")
|
|
sys.stdout.write("\n")
|
|
|
|
for x, row in enumerate(field):
|
|
for y, i in enumerate(row):
|
|
if not i:
|
|
if tractor.get_position().get_x() == x \
|
|
and tractor.get_position().get_y() == y:
|
|
sys.stdout.write(OKBLUE)
|
|
sys.stdout.write(tractor.get_symbol())
|
|
sys.stdout.write(" ")
|
|
else:
|
|
sys.stdout.write(" ")
|
|
else:
|
|
symbol = i.get_symbol()
|
|
if symbol[1] == "green":
|
|
sys.stdout.write(OKGREEN)
|
|
sys.stdout.write(symbol[0])
|
|
sys.stdout.write(" ")
|
|
else:
|
|
sys.stdout.write(OKRED)
|
|
sys.stdout.write(symbol[0])
|
|
sys.stdout.write(" ")
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
def update_state(field):
|
|
for row in field:
|
|
for i in row:
|
|
if i:
|
|
i.tick(1)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
field = initialize_field()
|
|
tractor = Trac('S', Point((0,0)))
|
|
|
|
sys.stdout.write(ENDC)
|
|
i = 40
|
|
while i>=0:
|
|
if sys.platform == "win32":
|
|
os.system("cls")
|
|
else:
|
|
os.system("clear")
|
|
print_field(field, tractor)
|
|
update_state(field)
|
|
time.sleep(0.4)
|
|
i = i-1
|
|
print("The end of time")
|