예제 #1
0
파일: house.py 프로젝트: Pluttodk/pyweek30
 def build_raft(self, ressources):
     if ressources >= variables.RAFT_COST:
         if self.raft == None:
             self.raft = Raft()
         self.raft.work()
         return True
     else:
         print("You need to chop more trees")
         return False
예제 #2
0
파일: house.py 프로젝트: Pluttodk/pyweek30
class House:
    """
    The only place where Timmy can rest and where he can build the dock
    """
    def __init__(self):
        self.color_base = (100, 100, 100)
        self.color_roof = (0, 200, 0)
        self.x, self.y = variables.HOUSE_CENTER
        self.width = 50
        self.height = 50
        self.raft = None
        self.life = 0
        self.house_sprite = pg.image.load("sprites/house.png")

    def draw(self, screen, is_sailing=False):

        #Draw roof
        screen.blit(self.house_sprite, (self.x, self.y))

        if self.raft != None and not is_sailing:
            self.raft.draw(screen)

    def work(self):
        self.color_base = (self.color_base[0] + 1, self.color_base[1] + 1,
                           self.color_base[2] + 1)

    def is_dead(self):
        return False

    def build_raft(self, ressources):
        if ressources >= variables.RAFT_COST:
            if self.raft == None:
                self.raft = Raft()
            self.raft.work()
            return True
        else:
            print("You need to chop more trees")
            return False

    def get_pos(self):
        return (self.x + self.house_sprite.get_rect().width // 2,
                self.y + self.house_sprite.get_rect().height // 2)

    def calc_nearest_object(self, x):
        if self.x - variables.RANGE <= x <= (
                self.x + self.house_sprite.get_rect().width) + variables.RANGE:
            return self
        elif self.raft != None:
            return self.raft.calc_nearest_object(x)
        else:
            return None
예제 #3
0
    def __init__(self, port, initialMembers=None):
        # persistent state
        # TODO: make persistent
        self.currentTerm = 0
        self.votedFor = None
        self.log = []

        # volatile state
        self.commitIndex = 0
        self.lastApplied = 0

        # other state
        self.role = Role.FOLLOWER
        self.port = port
        # a global lock for thread synhronization between the poll method
        # and the rpc methods
        self.lock = threading.Lock()

        # init server
        processor = Raft.Processor(self)
        transport = TSocket.TServerSocket(port=port)

        self.server = ThreadPoolThriftServer(processor, transport)

        self.initialMembers = initialMembers
예제 #4
0
def main():
    if len(sys.argv) != 2:
        print('Usage: python main.py <node_name>')
        sys.exit(1)

    node_name = sys.argv[1]

    configuration = Configuration()
    configuration.load()
    if node_name not in configuration.nodes.keys():
        print('Node {} is not in cluster.conf'.format(node_name))
        sys.exit(1)

    state = State()
    state.load(node_name)

    raft = Raft(node_name, configuration, state)

    raft.reset_election_timer()
    server = HttpServer(raft.parse_json_request)
    server.run(configuration.nodes[node_name]['port'])
예제 #5
0
def connectClient(addr, port):
    # Make socket
    transport = TSocket.TSocket(addr, port)

    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = Raft.Client(protocol)

    # Connect
    transport.open()
    return client
예제 #6
0
frog = []
turtle = []
crocodile = []
land = []
arena = Arena(600, 480)
logo = g2d.load_image("Frogger-logo.png")
background = g2d.load_image("frogger_bg.png")
sprite = g2d.load_image("frogger_sprites.png")
gameover = g2d.load_image("gameover.png")
win = g2d.load_image("win.png")
pygame.mixer.init()
pygame.mixer.music.load("froggeraudio.mp3")
pygame.mixer.music.play()
for i in range(0, 4):
    x = randint(100, 200)
    raft.append(Raft(arena, x, int((i * 40) + 80), 0))
    raft.append(Raft(arena, x + 270, int((i * 40) + 80), 1))
    raft.append(Raft(arena, x + 520, int((i * 40) + 80), 2))
for i in range(0, 4):
    if (i % 2 == 0):
        x = randint(100, 250)
        turtle.append(Turtle(arena, x, int((i * 40) + 100)))
        turtle.append(Turtle(arena, x + 30, int((i * 40) + 100)))
        turtle.append(Turtle(arena, x + 60, int((i * 40) + 100)))
        x = randint(350, 480)
        turtle.append(Turtle(arena, x, int((i * 40) + 100)))
        turtle.append(Turtle(arena, x + 30, int((i * 40) + 100)))
        turtle.append(Turtle(arena, x + 60, int((i * 40) + 100)))
    else:
        x = randint(100, 250)
        crocodile.append(Crocodile(arena, x, int((i * 40) + 100)))
예제 #7
0
from raft import Raft
import tkinter as tk

if __name__ == '__main__':
    raft = Raft()

    window = tk.Tk()
    window.resizable(False, False)
    window.title("Raft Demo")

    keyLabel = tk.Label(master=window, text='Key')
    keyLabel.grid(row=0, column=0, padx=5, pady=5, sticky='nse')

    keyEntry = tk.Entry(master=window, width=10)
    keyEntry.grid(row=0, column=1, pady=5, sticky='nsew')

    toggleBtn = tk.Button(master=window, text='Start Server')
    toggleBtn.grid(row=0, column=2, columnspan=2, pady=5, sticky='nsew')

    valLabel = tk.Label(master=window, text='Value')
    valLabel.grid(row=1, column=0, padx=5, pady=5, sticky='nse')

    valEntry = tk.Entry(master=window, width=10)
    valEntry.grid(row=1, column=1, pady=5, sticky='nsew')

    sendBtn = tk.Button(master=window, text='Send', command=raft.commit)
    sendBtn.grid(row=1, column=2, padx=5, pady=5, sticky='nsew')

    retrieveBtn = tk.Button(master=window,
                            text='Retrieve',
                            command=raft.retrieveFroKey)
예제 #8
0
import g2d
from actor import Actor, Arena
from raft import Raft
from fiume import Fiume
from turtle import Turtle
from vehicle import Vehicle
from crocodile import Crocodile
from land import Land
from random import randint

arena = Arena(600, 480)
raft = Raft(arena, 0, 0, 0)
turtle = Turtle(arena, 0, 0)
crocodile = Crocodile(arena, 0, 0)


class Frog(Actor):
    def __init__(self, arena, x, y):
        self._x, self._y = x, y
        self._w, self._h = 18, 15
        self._speed = 7
        self._dx, self._dy = 0, 0
        self._arena = arena
        self._death = 0
        self._collideraft = False
        self._collidefiume = False
        self._collideturtle = False
        self._collidecrocodile = False
        arena.add(self)

    def move(self):