-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldProcessing.py
105 lines (94 loc) · 4.06 KB
/
FieldProcessing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import Human
import Obj
from Field import *
import Resources
from Human import *
import random
import time
from Obj import *
class FieldProcessing:
lstX_field = []
count = 0
@staticmethod
def gen_resources(count, class_obj):
while count != 0:
random.seed(time.time())
i = random.randint(0, len(FieldProcessing.lstX_field) - 1)
j = random.randint(0, len(FieldProcessing.lstX_field[0]) - 1)
if not FieldProcessing.lstX_field[i][j].is_obj():
FieldProcessing.lstX_field[i][j].add_obj(class_obj())
count -= 1
@staticmethod
def can_moving(human, direction):
pos = human.get_pos()
if direction == "R" and (pos[0] + 1 != len(FieldProcessing.lstX_field)):
return True
elif direction == "L" and (pos[0] - 1) >= 0:
return True
elif direction == "U" and (pos[1] - 1) >= 0:
return True
elif direction == "D" and (pos[1] + 1 != len(FieldProcessing.lstX_field[0])):
return True
elif direction == "RU" and (pos[0] + 1 != len(FieldProcessing.lstX_field)) and (pos[1] - 1) >= 0:
return True
elif direction == "RD" and (pos[0] + 1 != len(FieldProcessing.lstX_field)) and (
pos[1] + 1 != len(FieldProcessing.lstX_field[0])):
return True
elif direction == "LU" and (pos[0] - 1) >= 0 and (pos[1] - 1) >= 0:
return True
elif direction == "LD" and (pos[0] - 1) >= 0 and (pos[1] + 1 != len(FieldProcessing.lstX_field[0])):
return True
else:
return False
@staticmethod
def moving(human, direction):
if FieldProcessing.can_moving(human, direction) and FieldProcessing.count == 0:
pos = human.get_pos()
human.field.delete_human(human)
if direction == "R":
FieldProcessing.lstX_field[pos[0] + 1][pos[1]].add_human(human)
FieldProcessing.count = 10
elif direction == "L":
FieldProcessing.lstX_field[pos[0] - 1][pos[1]].add_human(human)
FieldProcessing.count = 10
elif direction == "U":
FieldProcessing.lstX_field[pos[0]][pos[1] - 1].add_human(human)
FieldProcessing.count = 10
elif direction == "D":
FieldProcessing.lstX_field[pos[0]][pos[1] + 1].add_human(human)
FieldProcessing.count = 10
elif direction == "RD":
FieldProcessing.lstX_field[pos[0] + 1][pos[1] + 1].add_human(human)
FieldProcessing.count = 10
elif direction == "RU":
FieldProcessing.lstX_field[pos[0] + 1][pos[1] - 1].add_human(human)
FieldProcessing.count = 10
elif direction == "LD":
FieldProcessing.lstX_field[pos[0] - 1][pos[1] + 1].add_human(human)
FieldProcessing.count = 10
elif direction == "LU":
FieldProcessing.lstX_field[pos[0] - 1][pos[1] - 1].add_human(human)
FieldProcessing.count = 10
else:
FieldProcessing.count -= 1
@staticmethod
def gen_filed():
for i in range(0, 73):
lstX_field = []
for j in range(0, 33):
lstX_field.append(Field(i, j))
FieldProcessing.lstX_field.append(lstX_field)
FieldProcessing.gen_resources(600, Resources.Tree)
FieldProcessing.gen_resources(400, Resources.Berries)
# FieldProcessing.gen_resources(100, Resources.Stone)
# FieldProcessing.gen_resources(50, Resources.Iron)
# FieldProcessing.gen_resources(45, Resources.Copper)
# FieldProcessing.gen_resources(20, Resources.Gold)
return FieldProcessing.lstX_field
@staticmethod
def get_filed():
return FieldProcessing.lstX_field
@staticmethod
def clean_class():
FieldProcessing.lstX_field = []
FieldProcessing.count = 0