def Execute(self,gui,dMaps,house,ID, Cselection):

        gui.ClearFrame()
        gui.CreateCanvas()

        self.DisplayMap(gui)

        house.FillHouse(gui,2,ID)

        if Cselection == 1:
            cat = Cat(gui,Info.name,Textures.TextureDict["cat"],self.ExitX,self.ExitY,house.List[ID].item)

        elif Cselection == 2:
            cat = Cat(gui,Info.name,Textures.TextureDict["snowball"],self.ExitX,self.ExitY,house.List[ID].item)

        elif Cselection == 3:
            cat = Cat(gui,Info.name,Textures.TextureDict["tom"],self.ExitX,self.ExitY,house.List[ID].item)

        elif Cselection == 4:
            cat = Cat(gui,Info.name,Textures.TextureDict["scratchy"],self.ExitX,self.ExitY,house.List[ID].item)

        elif Cselection == 5:
            cat = Cat(gui,Info.name,Textures.TextureDict["pink"],self.ExitX,self.ExitY,house.List[ID].item)


        dog = Dog(int(Info.difficulty),gui,Textures.TextureDict["dog"],cat)

        gui.root.bind("<z>",lambda event: self.preChange(cat.catID,gui,dMaps,house,dog, Cselection)) # changes to ouside map, <Return> is "enter" key

        dog.movement(gui)
示例#2
0
文件: Zoo.py 项目: Uyutaka/OOAD_Zoo
    def __initializeZoo():
        animals = []

        animals.append(Hippo("hippo1"))
        animals.append(Hippo("hippo2"))

        animals.append(Rhino("rhino1"))
        animals.append(Rhino("rhino2"))

        animals.append(Elephant("elephant1"))
        animals.append(Elephant("elephant2"))

        animals.append(Cat("cat1"))
        animals.append(Cat("cat2"))

        animals.append(Tiger("tiger1"))
        animals.append(Tiger("tiger2"))

        animals.append(Lion("lion1"))
        animals.append(Lion("lion2"))

        animals.append(Wolf("wolf1", WolfNoise()))
        animals.append(Wolf("wolf2", WolfNoise()))

        animals.append(Dog("dog1", DogNoise()))
        animals.append(Dog("dog2", DogNoise()))

        return animals
示例#3
0
    def add_new_data(self):
        """
        Scrap the battlecats website to get the most updated data.

        :return: The object itself
        """
        url = "https://battlecats-db.com/unit/status_r_all.html"
        css_path = "html body div div div div table tbody tr"

        response = requests.get(url)
        html_content = response.content
        soup = BeautifulSoup(html_content, "html.parser")

        for in_line in soup.select(css_path):
            new_cat = Cat.from_new_data(in_line)

            ID, form = new_cat.ID, new_cat.form

            key = (ID, form)

            old_cat = self.cat_dict.get(key)

            new_version = Cat.compare_versions(old_cat, new_cat)

            self.cat_dict[key] = new_version

        return self
示例#4
0
    def talk(self):
        """
		TomCat talks
		"""

        Cat.talk(self)
        print "Burp!"
示例#5
0
文件: main.py 项目: freercurse/Boids
    def start(self):
        pg.init()
        cat = Cat()
        mouse = Mouse()
        screen = pg.display.set_mode((1024, 768))
        clock = pg.time.Clock()
        running = True
        sprite = pg.sprite.Group()
        sprite.add(cat)
        sprite.add(mouse)
        calcCoords = USEREVENT + 1

        pg.time.set_timer(calcCoords, 50)

        while running:

            if pg.event.get(calcCoords):
                mouse.calcCoords()
                cat.calcCoords()

            sprite.update([cat.pos, mouse.pos])
            self.AuraDetection([cat.pos, mouse.pos], cat, mouse)
            clock.tick(60)
            pg.display.set_caption("{:.2f}".format(clock.get_fps()))
            screen.fill((250, 250, 250))
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    running = False

            sprite.draw(screen)
            pg.display.flip()
    def Execute(self,gui,dMaps,house, Cselection):  

        gui.ClearFrame()
        gui.CreateCanvas()
        
        self.DisplayMap(gui)
        
        house.CreateObjects(gui.canvas,5,"house","grass")
        house.PlaceAllObjects(gui)

        if Cselection == 1:
            cat = Cat(gui,Info.name,Textures.TextureDict["cat"],self.ExitX,self.ExitY)

        elif Cselection == 2:
            cat = Cat(gui,Info.name,Textures.TextureDict["snowball"],self.ExitX,self.ExitY)
        
        elif Cselection == 3:
            cat = Cat(gui,Info.name,Textures.TextureDict["tom"],self.ExitX,self.ExitY)

        elif Cselection == 4:
            cat = Cat(gui,Info.name,Textures.TextureDict["scratchy"],self.ExitX,self.ExitY)

        elif Cselection == 5:
            cat = Cat(gui,Info.name,Textures.TextureDict["pink"],self.ExitX,self.ExitY)

        gui.root.bind("<z>",lambda event: self.preChange(gui.canvas.coords(cat.catID),gui,dMaps,house,cat, Cselection)) # changes to inside map, <Return> is "enter" key                 
示例#7
0
def do():
    pets = [Dog('狗狗', '小黑'), Cat('猫猫', '小花')]
    for p in pets:
        # 继承
        p.eat('骨头')
        # 多态
        p.call()
        print("******")
示例#8
0
    def __init__(self, master, queue, endCommand):
        self.queue = queue
        self.cat = Cat()

        # Windowless Mode.
        master.overrideredirect(1)

        # Set up the GUI
        console = tkinter.Button(master, text='Done', command=endCommand)
        img = self.cat.getImage()
        self.panel = tkinter.Label(master, image=img)
        self.label = tkinter.Label(master,
                                   text="Happiness: " +
                                   str(self.cat.getState()),
                                   fg=self.cat.getText())

        # Pack.
        self.panel.pack(side="top", fill="both", expand="yes")
        self.label.pack(side="top", fill="both", expand="yes")
        console.pack()
示例#9
0
class Main:
    if __name__ == '__main__':
        catie = Cat("catie")
        canny = Cat("cannie")
        lune = Lion("Lune")
        larry = Lion("Larry")
        john = ZooKeeper()

        store = [catie, canny, lune, larry]

        shelly = zooAnouncer()
        shelly.subscribe(john)

        john.wake(store)
        john.rollCall(store)
        john.feed(store)
        john.exercise(store)
        john.shut(store)

        shelly.unsubscribe(john)
示例#10
0
文件: Breeder.py 项目: mokosaur/kotki
 def breed(self):
     father = self.choose_parent()
     kitten_gender = randint(0, 1)
     kitten_params = {}
     for i in self.female.genes:
         male_random = randint(0, 1)
         female_random = randint(0, 1)
         kitten_params[i] = [
             self.female.genes[i][female_random],
             father.genes[i][male_random]
         ]
     return Cat(gender=[kitten_gender], name='Maciek', **kitten_params)
示例#11
0
    def populate(self):

        # Canine
        self.animals.append(Dog())
        self.animals.append(Dog('Dug'))
        self.animals.append(Wolf())
        self.animals.append(Wolf('Wifi'))

        # Feline
        self.animals.append(Cat())
        self.animals.append(Cat('Catherine'))
        self.animals.append(Tiger())
        self.animals.append(Tiger('Terry'))
        self.animals.append(Lion())
        self.animals.append(Lion('Lenny'))

        # Pachyderm
        self.animals.append(Elephant())
        self.animals.append(Elephant('Esther'))
        self.animals.append(Hippo())
        self.animals.append(Hippo('Harriet'))
        self.animals.append(Rhino())
        self.animals.append(Rhino('Rose'))
示例#12
0
    def from_old_data(cls):
        """
        Read the CSV and create the CatList object

        :return: the CatList object
        """
        cat_dict = dict()

        with open("neko.csv", encoding="utf8") as in_file:
            header = in_file.readline().strip()

            for in_line in in_file:
                in_cat = Cat.from_old_data(in_line)

                cat_dict[(in_cat.ID, in_cat.form)] = in_cat

        return cls(cat_dict, header)
示例#13
0
 def __init__(self):
     self.scores = {
         "cat": 0,
         "bird": 0
     }  #Dictionary of the score of each faction as an int
     self.items = {
         "sword": 2,
         "tea": 2,
         "boot": 2,
         "coin": 2,
         "crossbow": 1,
         "hammer": 1
     }  #Dictionary to keep track of item availibility
     self.deck = []  #List to keep track of available cards
     self.discard = []  #List for the discard
     self.clearingList = []
     #Initializing the players
     self.bird = Bird()
     self.cat = Cat()
    def generate_resources(self):
        unique_random_positions = self.generate_unique_random_positions()
        self.cheese_pos = []

        # self.cheese_pos = [[16, 21], [16, 5], [7, 18]]
        # self.cat = Cat([21, 8])
        # self.mouse = Mouse([21, 16])

        # self.cheese_pos = [[7, 11], [20, 14], [11, 27]]
        # self.cat = Cat([4, 20])
        # self.mouse = Mouse([4, 6])

        for i in range(self.num_of_cheese + 2):

            if i < self.num_of_cheese:
                self.cheese_pos.append(unique_random_positions[i])
            elif i < self.num_of_cheese + 1:
                self.cat = Cat(unique_random_positions[i])
            else:
                self.mouse = Mouse(unique_random_positions[i])
示例#15
0
class GuiPart:
    def __init__(self, master, queue, endCommand):
        self.queue = queue
        self.cat = Cat()

        # Windowless Mode.
        master.overrideredirect(1)

        # Set up the GUI
        console = tkinter.Button(master, text='Done', command=endCommand)
        img = self.cat.getImage()
        self.panel = tkinter.Label(master, image=img)
        self.label = tkinter.Label(master,
                                   text="Happiness: " +
                                   str(self.cat.getState()),
                                   fg=self.cat.getText())

        # Pack.
        self.panel.pack(side="top", fill="both", expand="yes")
        self.label.pack(side="top", fill="both", expand="yes")
        console.pack()

    def update(self):
        img = self.cat.getImage()
        text = "Happiness: " + str(self.cat.getState())

        self.panel.configure(image=img)
        self.panel.image = img

        self.label.configure(text=text, fg=self.cat.getText())
        self.label.text = text

    def processIncoming(self):
        """
        Handle all the messages currently in the queue (if any).
        """
        while self.queue.qsize():
            try:
                msg = self.queue.get(0)
                # Check contents of message and do what it says
                # As a test, we simply print it
                print(msg)
            except queue.Empty:
                pass

        self.update()
示例#16
0
def main():
    pets = [Dog('旺财'), Cat('凯迪'), Dog('大黄')]
    for pet in pets:
        pet.make_voice()
示例#17
0
from Cat import Cat

cats = [Cat(name='Барон', gender='мальчик', age='2 года'), \
        Cat(name='Сэм', gender='мальчик', age='2 года')]

for cats in cats:
    print(cats.print_cats())
示例#18
0
 def setUp(self):
     self.cat = Cat('pesho')
示例#19
0
class CatTests(unittest.TestCase):
    def setUp(self):
        self.cat = Cat('pesho')

    def test_cat_size__must_increase_after_eat(self):
        self.cat.eat()
        expected = 1
        actual = self.cat.size
        self.assertEqual(actual, expected)

    def test_fed_must_be_true_after_eat(self):
        self.cat.eat()
        expected = True
        actual = self.cat.fed
        self.assertEqual(actual, expected)

    def test_eat__must_raise_error_if_already_fed(self):
        self.cat.eat()
        with self.assertRaises(Exception) as cm:
            self.cat.eat()
        self.assertEqual(str(cm.exception), "Already fed.")

    def test_sleep__must_raise_error_if_not_fed(self):
        with self.assertRaises(Exception) as cm:
            self.cat.sleep()
        self.assertEqual(str(cm.exception), "Cannot sleep while hungry")

    def test_sleepy__must_be_false_if_slept(self):
        self.cat.eat()
        self.cat.sleep()
        expected = False
        actual = self.cat.sleepy
        self.assertEqual(actual, expected)
示例#20
0
def main():
    zk = Zookeeper()

    za = ZooAnnouncer(zk)

    zoo = []

    hippo1 = Hippo("Henry")
    hippo2 = Hippo("Hailey")

    zoo.append(hippo1)
    zoo.append(hippo2)

    elephant1 = Elephant("Earl")
    elephant2 = Elephant("Ezra")

    zoo.append(elephant1)
    zoo.append(elephant2)

    rhino1 = Rhino("Ron")
    rhino2 = Rhino("Roxie")

    zoo.append(rhino1)
    zoo.append(rhino2)

    tiger1 = Tiger("Tim")
    tiger2 = Tiger("Tina")

    zoo.append(tiger1)
    zoo.append(tiger2)

    lion1 = Lion("Larry")
    lion2 = Lion("Lindsey")

    zoo.append(lion1)
    zoo.append(lion2)

    cat1 = Cat("Charlie")
    cat2 = Cat("Courtney")

    zoo.append(cat1)
    zoo.append(cat2)

    wolf1 = Wolf("Warren")
    wolf2 = Wolf("Wanda")

    zoo.append(wolf1)
    zoo.append(wolf2)

    dog1 = Dog("Danny")
    dog2 = Dog("Daisy")

    zoo.append(dog1)
    zoo.append(dog2)

    zk.wakeUpAnimals(zoo)
    print("---------------------------------")
    zk.rollCall(zoo)
    print("---------------------------------")
    zk.feed(zoo)
    print("---------------------------------")
    zk.exercise(zoo)
    print("---------------------------------")
    zk.shutDownZoo(zoo)
    zk.remove_observer(za)
    del zk
from Cat import Cat

cat1 = Cat("Барон", "Male", 2)
cat2 = Cat("Сэм", "Male", 2)

print("Cat name {}, sex {}, age {}".format(cat1.name, cat1.sex, cat1.age))
print("Cat name {}, sex {}, age {}".format(cat2.name, cat2.sex, cat2.age))
示例#22
0
    if initialCatRadius < 1.:
        return inputdata()
    initialCatRadius *= 100.
    return initialCatRadius, initialMouseAngle, initialCatAngle


# we decide initial positions of cat and mouse relative to the random position of the statue
initialCatRadius, initialMouseAngle, initialCatAngle = inputdata()

# create mouse, statue and cat with initial conditions
statue = Statue(initialStatPosition, initialStatPosition, 0, 0)
mouse = Mouse2(initialStatPosition,
               initialStatPosition + 100 * unit(initialMouseAngle),
               initialMouseAngle - 90, 1, initialMouseAngle)
cat = Cat(initialStatPosition,
          initialStatPosition + initialCatRadius * unit(initialCatAngle),
          initialCatAngle - 90, 1, initialMouseAngle, initialCatRadius,
          initialCatAngle)

# add these fellas
arena.add(statue)  # Add a turtle at (200,200) heading 0=up
arena.add(mouse)
arena.add(cat)


def aboutWidget():
    top = Toplevel(menu=filemenu)
    top.title('About the UC Berkeley CS9H Turtle Arena')

    photo = PhotoImage(file='Joshua.gif')
    smallphoto = photo.subsample(15)
    photoLabel = Label(top, image=smallphoto)
示例#23
0
文件: testCat.py 项目: Ramil51/Repoz
from Cat import Cat
my_cat1 = Cat('Сэм', 2, 'муж')
print('my_cat1.name=', my_cat1.name)
print('my_cat1.age=', my_cat1.age)
print('my_cat1.sex', my_cat1.sex)

my_cat2 = Cat('Барон', 2, 'муж')
print('my_cat2.name=', my_cat2.name)
print('my_cat2.age', my_cat2.age)
print('my_cat2.sex', my_cat2.sex)
示例#24
0
    def run(self, myMap):
        catPossibleMoveList = [[2, 1], [-2, -1], [-2, 1], [-1, -2], [-1, 2], [1, -2], [1, 2], [2, -1]]
        # catPossibleMoveList = [[-1, -2], [1, -2], [2, -1], [2, 1], [-1, 2], [1, 2], [-2, -1], [-2, 1]]

        mouseMoveTrackingList = []
        moveTrackingState = []
        stateStack = []
        catSearchedList = []
        remainingCheeseNum = 0
        stateStack.append(myMap)
        solution = None
        mouseMoveTrackingList.append(myMap.mouse.getPos())
        while(solution == None):
            if(len(stateStack) != 0):
                # FILO stack for DFS
                currentState = stateStack.pop(len(stateStack) - 1)
                # if with the same step moved, and mouse have no more cheese to eat, stop finding more successors, go backtracking
                if(len(currentState.cheeseList) != 0):
                    # Found the goal state
                    if(currentState.mouse.mousePos == currentState.cat.catPos):
                        solution = currentState
                        break

                    closestCheese = self.getClosestCheese(currentState.mouse.getPos(), currentState.cheeseList)
                    nextMouseMove = self.mouseMove(currentState.mouse.getPos(), closestCheese.getPos())
                    # add mouseMove to list
                    if(nextMouseMove not in mouseMoveTrackingList):
                        mouseMoveTrackingList.append(nextMouseMove)
                    # Generate current node's successors
                    for possibleMoves in catPossibleMoveList:
                        newCheeseList = []
                        for cheese in currentState.cheeseList:
                            cheese1 = Cheese(cheese.cheesePos)
                            newCheeseList.append(cheese1)
                        nextCatMove = [currentState.cat.catPos[0] + possibleMoves[1], currentState.cat.catPos[1] + possibleMoves[0]]
                        # generate a successor and set its parent to currentState
                        nextState = MapState(currentState, newCheeseList, Mouse(nextMouseMove), Cat(nextCatMove), currentState.mapWidth, currentState.mapHeight)
                        # set current state as its parent
                        nextState.parentState = currentState
                        # make sure nextCatMove is in boundary and the state is not in visited state list
                        if (nextCatMove[0] >= 0 and nextCatMove[0] < nextState.mapWidth and nextCatMove[1] < nextState.mapHeight and nextCatMove[1] >= 0 and (nextState not in catSearchedList)):
                            nextState.updateMousePos(nextMouseMove)
                            nextState.updateCatPos(nextCatMove)
                            catSearchedList.append(nextState)
                            # add the state to stack
                            stateStack.append(nextState)

                # count for iterations
                self.searchCount += 1
                print(self.searchCount)
                # print(self.searchCount)
                if(self.searchCount > 10000):
                    print("Having more than 10000 searchs, generating a new map...")
                    self.ifCatWin = False
                    break

            # cannot find a solution
            else:
                solution = currentState
                self.ifCatWin = False
                break
        if(solution != None and len(solution.cheeseList) != 0):
            self.ifCatWin = True
            remainingCheeseNum = len(solution.cheeseList)
            # add solution to tracking list one by one
            while(solution != None):
                moveTrackingState.append(solution)
                solution = solution.parentState
            moveTrackingState.reverse()

            for state in moveTrackingState:
                state.updateCatPos(state.cat.catPos)
                state.updateMousePos(state.mouse.mousePos)
                time.sleep(1)
                state.covertMapToUI()
            print("Cat Win!")
            print("Search Count:", self.searchCount)
            print("Total Move:", len(moveTrackingState) - 1)
            print("Number of cheeses remaining:", remainingCheeseNum)
示例#25
0
def crearGato(nombre: str, sonido: str):
    cat_miss: Cat = Cat(nombre, sonido)
    return cat_miss
示例#26
0
from Tkinter  import *                  # Import everything from Tkinter
from Arena    import Arena              # Import our Arena
from Cat      import Cat                # Import our Cat
from Mouse    import Mouse              # Import our Statue
from Statue   import Statue             # Import our Statue
from Vector   import *                  # Import everything from our Vector
from globalVars import *                # Import everything from globalVars
from random   import random             # Import random

tk = Tk()                               # Create a Tk top-level widget
arena = Arena(tk, 800, 600, padx=12, pady=6) # Create an Arena widget, arena
arena.pack()                            # Tell arena to pack itself on screen

midX = arena.width/2                    # Horizontal center of window
midY = arena.height/2                   # Vertical center of window
mouseAngle = random()*360*scaleRad      # Random mouse angle to initialize
catAngle = random()*360*scaleRad        # Random cat angle to initialize
catRadius = 5                           # Random cat radius to initialize

statue = Statue(Vector(midX,midY), 0)   # Create a statue in center of arena, arbitrary heading
arena.add(statue)                       # Add statue

mouse = Mouse(Vector(midX + statue.radius*scalePixel*cos(mouseAngle), midY - statue.radius*scalePixel*sin(mouseAngle)), 0, arena, statue) # Create a mouse at right edge of statue, arbitrary heading since it will be overwritten in initialization
arena.add(mouse)                        # Add mouse
 
cat = Cat(Vector(midX + catRadius*scalePixel*cos(catAngle), midY - catRadius*scalePixel*sin(catAngle)), 0, arena, statue, mouse) # Create a cat at given angle and radius, arbitrary heading since it will be overwritten in initialization
arena.add(cat, "cat")                   # Add cat and specify that it's a cat as extra argument

tk.mainloop()                           # Enter the Tkinter event loop
from Canidae import Dog
from Cat import Cat

bob = Dog('Bob', 'Caramelo')
bob.bark()

felix = Cat('Felix', 'Preto e branco')
felix.purr()
示例#28
0
文件: main1.py 项目: duydo131/farmer
from Dog import Dog
from Cat import Cat
import random
import time
import pickle

random.seed(32)
n = 100
t = 6
filename = "animal.dat"

farm = []

for i in range(n):
    r = random.randrange(0, 2)
    farm.append(Dog() if r == 0 else Cat())

day = 1
while day <= t:
    print("day {day}:".format(day=day))
    for animal in farm:
        animal.hurry()
    eat = random.sample(range(n), n * 3 // 10)
    for i in eat:
        farm[i].eat()
    day += 1
    file_animal = open(filename, 'wb')
    pickle.dump(farm, file_animal)
    time.sleep(1)

file_animal.close()
示例#29
0
文件: catmouse.py 项目: mwehlast/cs9h
Created on Sun Nov 18 15:44:25 2018

@author: Morten
"""

from tkinter import *  # Import everything from Tkinter
from Arena import Arena  # Import our Arena
from Turtle import Turtle  # Import our Turtle
from Vector import *  # Import everything from our Vector
from Statue import Statue
from Mouse import Mouse
from Cat import Cat
from globalVariables import *

statueRadius = 1
statuePosition = Vector(200, 200)
mouseAngle = -57.0
catAngle = 0.0
catRadius = 4.0

tk = Tk()  # Create a Tk top-level widget
arena = Arena(tk)  # Create an Arena widget, arena
arena.pack()  # Tell arena to pack itself on screen
s = Statue(statuePosition,
           statueRadius)  # Add a turtle at (200,200) heading 0=up
m = Mouse(statue=s, angle=mouseAngle, arena=arena)
c = Cat(arena=arena, mouse=m, angle=catAngle, radius=catRadius)
arena.add(s)
arena.add(m)
arena.add(c)
tk.mainloop()
示例#30
0
from Mouse import Mouse
from Cat import Cat
from Cheese import Cheese
from BFS import BFS
from DFS import DFS
from AStar import AStarSearch
import copy

# Initialize items' position, not used for random map
cheese1 = Cheese([1,10])
cheese2 = Cheese([11, 1])
cheese3 = Cheese([4,8])

cheeseList = [cheese1, cheese2, cheese3]
mouse = Mouse([6, 4])
cat = Cat([10, 7])

MAP_HEIGHT = 12
MAP_WIDTH = 12
searchMethod = BFS()


myMap = MapState(None, cheeseList, mouse, cat, MAP_WIDTH, MAP_HEIGHT)
# set random positions
myMap.setInitState()

# ------------------For random map---------------
while(searchMethod.ifCatWin == False):
    print("Generating a random map...")
    searchMethod = BFS()
    # searchMethod = DFS()