class Worker(MovingEntity):

    # identifier.
    id = None
    FSM = None
    pos = None
    circle = None
    speed = None
    Path = []

    # internal stats.

    def __init__(self):
        self.id = BaseGameEntityClass.SetID(self)
        self.FSM = StateMachine(self)
        self.FSM.SetCurrentState(Begin_Life_Worker())
        self.FSM.SetGlobalState(WorkerGlobalState())
        for node in self.map.grid:
            if node.isSpawn:
                self.pos = node.id
                self.circle = node.center
        self.speed = JsonLoader.Data["worker"]["speed"]
        self.circle = Circle(self.circle, 3)
        self.circle.setFill(JsonLoader.Data["worker"]["color"])

    def Update(self):
        self.FSM.Update()

    def GetFSM(self):
        return self.FSM
class Explorer(MovingEntity):

    id = None
    FSM = None
    circle = None
    pos = None
    searchRectangel = None
    speed = None
    path = []

    def __init__(self, worker):
        self.id = worker.id
        self.pos = worker.pos
        self.circle = worker.circle
        self.circle.setFill(JsonLoader.Data["explorer"]["color"])
        center = self.circle.getCenter()
        self.searchRectangel = Rectangle(
            Point(center.getX() - 100,
                  center.getY() + 100),
            Point(center.getX() + 100,
                  center.getY() - 100))
        #self.searchRectangel.draw(self.window.window)
        self.FSM = StateMachine(self)
        self.FSM.SetCurrentState(Begin_Life_Explorer())
        self.FSM.SetGlobalState(ExplorerGlobalState())
        self.speed = JsonLoader.Data["explorer"]["speed"]

    def Update(self):
        self.FSM.Update()

    def ExploreNeighbours(self):
        neighbours = self.map.ExploreNeighbours(self.pos)
        for node in neighbours:
            self.window.window.items[node].setFill(self.map.grid[node].color)
示例#3
0
class FineWorker(MovingEntity):
    # identifier.
    id = 0  # number of worker
    FSM = None
    pos = None  # number of the tile worker is on.
    circle = None
    speed = None  # speedmodifier

    # used to time durations of things.
    startTime = 0
    freezeTime = 0

    path = []

    def __init__(self, worker):
        self.id = worker.id
        self.pos = worker.pos
        EntityManager.RemoveEntity(self)
        EntityManager.RegisterEntity(self)
        self.circle = worker.circle
        self.circle.setFill(self.data["fineworker"]["color"])
        self.FSM = StateMachine(self)
        self.FSM.SetCurrentState(Begin_Life_Fine_Worker())
        self.FSM.SetGlobalState(FineWorkerGlobalState())
        self.speed = self.data["fineworker"]["speed"]

    def Update(self):
        self.FSM.Update()
示例#4
0
class Explorer(MovingEntity):

    id = None
    FSM = None
    circle = None
    pos = None
    searchRectangel = None
    speed = None
    path = None
    pathBack = []
    failedPathFindingAttempts = 0
    maxDist = None

    def __init__(self, worker):
        self.id = worker.id
        self.pos = worker.pos
        EntityManager.RemoveEntity(self)
        EntityManager.RegisterEntity(self)
        self.circle = worker.circle
        self.circle.setFill(self.data["explorer"]["color"])
        self.pathBack = []
        self.FSM = StateMachine(self)
        self.FSM.SetCurrentState(Begin_Life_Explorer())
        self.FSM.SetGlobalState(ExplorerGlobalState())
        self.speed = self.data["explorer"]["speed"]
        self.maxDist = self.data["explorer"]["maxdist"]

    def Update(self):
        self.FSM.Update()

    def ExploreNeighbours(self):
        neighbours = self.map.ExploreNeighbours(self.pos)
        for nodeindex in neighbours:
            self.window.window.items[nodeindex].setFill(
                self.map.grid[nodeindex].color)
            for tree in range(0, self.map.grid[nodeindex].numTrees):
                self.map.grid[nodeindex].trees.append(Tree(tree, nodeindex))
                self.map.grid[nodeindex].trees[-1].circle.draw(
                    self.window.window)
            if self.map.grid[nodeindex].trees:
                Manager.ResourceManager.treenodes.append(
                    self.map.grid[nodeindex])
                self.map.grid[nodeindex].dist = (
                    (abs(self.map.grid[nodeindex].x -
                         self.map.grid[self.townHall.pos].x))) + (
                             (abs(self.map.grid[nodeindex].y -
                                  self.map.grid[self.townHall.pos].y)))

    def Del(self):
        self.circle.undraw()
        EntityManager.Del(self.id)
示例#5
0
class Worker(MovingEntity):

    # identifier.
    id = 0  # number of worker
    FSM = None
    pos = None  # number of the tile worker is on.
    circle = None
    speed = None  # speedmodifier

    startTime = 0
    freezeTime = 0
    carrying = {}

    path = []
    pathBack = []

    # internal stats.

    def __init__(self):
        self.SetID()
        self.path = None
        self.pathBack = []
        self.carrying = {}
        self.FSM = StateMachine(self)
        self.FSM.SetCurrentState(Begin_Life_Worker())
        self.FSM.SetGlobalState(WorkerGlobalState())
        EntityManager.RegisterEntity(self)
        for node in self.map.grid:
            if node.isSpawn:
                self.pos = node.id
                self.circle = node.center
        self.speed = self.data["worker"]["speed"]
        self.circle = Circle(self.circle, 3)
        self.circle.setFill(self.data["worker"]["color"])

    def Update(self):
        self.FSM.Update()

    def GetFSM(self):
        return self.FSM
示例#6
0
文件: SpelAI.py 项目: clahul-9/AiLabb
from State import *
from StateMachine import *
from GameEntity import *

Person = GaneEntity1(0)
Person.currentState = State2()
stateMachine = StateMachine(Person)

stateMachine._CurrentState = State2()
stateMachine.Update()
stateMachine._CurrentState = State1()
stateMachine.Update()