예제 #1
0
def player_fire(data):
    game_id = int(data['game_id'])
    user_id = int(data['user_id'])
    enemy_id = (user_id + 1) % 2
    coord_x = int(data['coord']['x'])
    coord_y = int(data['coord']['y'])
    try:
        game = ROOMS[game_id]

        if game.running and not game.finished:
            hitted, killed, error = game.fire(coord_x, coord_y, user_id)

            if error:
                emit('error', Signals(521, game=game).__str__(), room=game_id)
                game.error = False
            else:
                emit("fired", {
                    'game_id': game_id,
                    'enemy_id': enemy_id,
                    'next_player_id': game.current_player,
                    'is_hit': hitted,
                    'coord': {
                        'x': coord_x,
                        'y': coord_y
                    },
                    'is_ship': killed
                },
                     room=game_id)

                if game.finished:
                    emit("game-finished", game.statistics(), room=game_id)
        else:
            emit("error", Signals(522, game=game).__str__())
    except KeyError:
        emit('error', Signals(519, id=game_id).__str__())
    def get_signals(self):
        signals = Signals(self.sample_rate, self.order_appliances,
                          breakpoint_classification_my_data, self.improved,
                          "temperature_mydata.csv")
        signals.set_signals_mydata(self.appliances)

        return signals
예제 #3
0
 def __init__(self):
     super().__init__()
     self.signals = Signals()
     self.initUI()
     self.setSignals()
     self.decensor = Decensor(self)
     self.current_is_mosaic = None
예제 #4
0
 def __init__(self):
     super().__init__()
     self.signals = Signals()
     self.initUI()
     self.setSignals()
     self.decensor = Decensor(self)
     self.load_model()
예제 #5
0
def setting_ships_up(data):
    game_id = int(data['game_id'])
    player_id = int(data['user_id'])
    # print("Ships has been planted", data)

    try:
        game = ROOMS[game_id]
        print(data)
        game.ustanovka(user_id=data['user_id'], ships=data['ships'])
        if player_id == 0:
            game.setted_1 = True
        elif player_id == 1:
            game.setted_2 = True
        if game.setted_1 and game.setted_2:
            print("The game id=", game_id, " starts")
            game.running = True
            socketio.emit("game-started", {
                "game_id": game_id,
                "next_player_id": 0
            },
                          room=game_id)

    except KeyError:
        print("No game with such id")
        emit('error', Signals(519, id=game_id).__str__())
예제 #6
0
def create_game(data):
    game_id = len(ROOMS)
    game = Game(game_id, data['name'])
    ROOMS[game_id] = game
    join_room(game_id)

    emit('created', Signals(219, game=game, name=data['name']).__str__())
예제 #7
0
def player_fire(data):
    game_id = int(data['game_id'])
    user_id = int(data['user_id'])
    # if user_id == 1, then enemy_id == (1+1)%2 == 0
    enemy_id = (user_id + 1) % 2
    print(data)
    coord_x = int(data['coord']['x'])
    coord_y = int(data['coord']['y'])
    print(coord_x, coord_y)
    try:
        game = ROOMS[game_id]

        if game.running and not game.finished:
            hitted, killed, error = game.fire(coord_x, coord_y, user_id)

            game.printfield()
            if error:
                print("Game ", game_id, "error")
                emit('error', Signals(521, game=game).__str__(), room=game_id)
                game.error = False
            else:

                emit("fired", {
                    'game_id': game_id,
                    'enemy_id': enemy_id,
                    'next_player_id': game.current_player,
                    'is_hit': hitted,
                    'coord': {
                        'x': coord_x,
                        'y': coord_y
                    },
                    'is_ship': killed
                },
                     room=game_id)

                if game.finished:
                    print("the game is finished, winner is ", game.winner)

                    print(game.statistics())
                    emit("game-finished", game.statistics(), room=game_id)
        else:
            print("WTF MAN, game id=", game_id, " is not active")
            print(Signals(522, game=game).__str__())
            emit("error", Signals(522, game=game).__str__())
    except KeyError:
        emit('error', Signals(519, id=game_id).__str__())
예제 #8
0
def join_game(data):
    game_id = int(data['game_id'])
    try:
        game = ROOMS[game_id]
        answer = game.join_user2(data['name'])

        if answer:
            join_room(game_id)

            emit('joined', Signals(221, game=game).__str__(), room=game_id)
        else:
            some_users_list = []
            for x in game.players:
                some_users_list.append(x.get_name())
            emit('error', Signals(520, game=game).__str__())
    except KeyError:
        emit("error", Signals(519, id=game_id).__str__())
예제 #9
0
 def __init__(self):
     self.I_Mem = Memory()
     self.D_Mem = Memory()
     self.RF = RegisterFile()
     self.RegPC = Register()
     self.signals = Signals()
     self.cycle_num = 0
     self.mode = 0
예제 #10
0
    def __init__(self, game_events_window):
        self.bullet_flag = True
        self.game_events = game_events_window

        self.signal = Signals()
        self.draw_player()
        self.init_bullet()
        self.init_bullets_thread()
        self.init_thread_on_shoot()
예제 #11
0
 def __init__(self):
     super(MainWindow, self).__init__()
     self.setAttribute(Qt.WA_AlwaysStackOnTop)
     self.signals = Signals()
     self.context = Context(self.signals)
     self.setupUi(self)
     self.create_views_and_dialogs()
     self.setup_window_tabs()
     self.createMenuBarActions()
     self.connect_buttons()
     self.connect_signals()
예제 #12
0
 def initialize_threads(self):
     """ Initializes io threads"""
     super().initialize_threads()
     self.dashboard_interval = int(self.ping_interval * 2)
     self.topic_fastclock_pub = self.publish_topics[Global.FASTCLOCK]
     self.topic_dashboard_pub = self.publish_topics[Global.DASHBOARD]
     self.topic_node_pub = self.publish_topics[Global.NODE]
     self.topic_ping_sub = self.subscribed_topics[Global.PING]
     # print("!!! ping sub: "+self.topic_ping_sub)
     self.topic_sensor_sub = self.subscribed_topics[Global.SENSOR]
     self.topic_backup_sub = self.subscribed_topics[Global.BACKUP]
     # print("!!! backup sub: "+self.topic_backup_sub)
     if Global.CONFIG in self.config:
         if Global.OPTIONS in self.config[Global.CONFIG]:
             if Global.TIME in self.config[Global.CONFIG][Global.OPTIONS]:
                 if Global.FAST in self.config[Global.CONFIG][
                         Global.OPTIONS][Global.TIME]:
                     if Global.RATIO in self.config[Global.CONFIG][
                             Global.OPTIONS][Global.TIME][Global.FAST]:
                         self.fast_ratio = int(
                             self.config[Global.CONFIG][Global.OPTIONS][
                                 Global.TIME][Global.FAST][Global.RATIO])
                     if Global.INTERVAL in self.config[Global.CONFIG][
                             Global.OPTIONS][Global.TIME][Global.FAST]:
                         self.fast_interval = int(
                             self.config[Global.CONFIG][Global.OPTIONS][
                                 Global.TIME][Global.FAST][Global.INTERVAL])
             if Global.PING in self.config[Global.CONFIG][Global.OPTIONS]:
                 self.ping_interval = self.config[Global.CONFIG][
                     Global.OPTIONS][Global.PING]
             if Global.BACKUP in self.config[Global.CONFIG][Global.OPTIONS]:
                 self.backup_path = self.config[Global.CONFIG][
                     Global.OPTIONS][Global.BACKUP]
     self.roster = Roster(self.log_queue,
                          file_path=Global.DATA + "/" + Global.ROSTER +
                          ".json")
     self.switches = Switches(self.log_queue,
                              file_path=Global.DATA + "/" +
                              Global.SWITCHES + ".json")
     self.warrants = Warrants(self.log_queue,
                              file_path=Global.DATA + "/" +
                              Global.WARRANTS + ".json")
     self.signals = Signals(self.log_queue,
                            file_path=Global.DATA + "/" + Global.SIGNALS +
                            ".json")
     self.layout = Layout(self.log_queue,
                          file_path=Global.DATA + "/" + Global.LAYOUT +
                          ".json")
     self.dashboard = Dashboard(self.log_queue,
                                file_path=Global.DATA + "/" +
                                Global.DASHBOARD + ".json")
     self.sensors = Sensors(self.log_queue,
                            file_path=Global.DATA + "/" + Global.SENSORS +
                            ".json")
예제 #13
0
def stop_game(data):
    alive_user_id = data['user_id']
    game_id = data['game_id']
    game = ROOMS[game_id]
    if not game.finished:
        game.finished = True
        game.winner = alive_user_id
        emit("game-extra-finished",
             Signals(249, game=game, id=alive_user_id).__str__(),
             room=game_id)
        leave_room(game_id)
        close_room(game_id)
예제 #14
0
def disconnected():
    if len(rooms()) > 1:
        game_id = -1
        for x in rooms():
            try:
                x += 1
                game_id = x - 1
            except TypeError:
                pass
        game = ROOMS[game_id]
        if not game.finished:
            socketio.emit("pinger", Signals(245).__str__(), room=game_id)
예제 #15
0
 def setSignals(self):
     self.signals = Signals()
     # set signal variable name same as method name preventing confusion
     self.signals.total_ProgressBar_update_MAX_VALUE.connect(
         self.total_ProgressBar_update_MAX_VALUE)
     self.signals.total_ProgressBar_update_VALUE.connect(
         self.total_ProgressBar_update_VALUE)
     self.signals.signal_ProgressBar_update_MAX_VALUE.connect(
         self.signal_ProgressBar_update_MAX_VALUE)
     self.signals.signal_ProgressBar_update_VALUE.connect(
         self.signal_ProgressBar_update_VALUE)
     self.signals.update_progress_LABEL.connect(self.update_progress_LABEL)
예제 #16
0
def join_game(data):
    game_id = int(data['game_id'])
    try:
        game = ROOMS[game_id]
        answer = game.join_user2(data['name'])

        if answer:
            print("Yes, gamer ", data['name'], " has joined")
            join_room(game_id)
            print(rooms())

            emit('joined', Signals(221, game=game).__str__(), room=game_id)
        else:
            print("Nope, gamer ", data['name'], " cannot join this game")
            some_users_list = []
            for x in game.players:
                some_users_list.append(x.get_name())
            print("The answer to my dear friend is: forbidden, ",
                  Signals(520, game=game).__str__())
            emit('error', Signals(520, game=game).__str__())
    except KeyError:
        print("The game with id=", game_id, " doesn't exist")
        emit("error", Signals(519, id=game_id).__str__())
예제 #17
0
def stop_game(data):
    alive_user_id = data['user_id']
    disconnected_man = data['enemy_id']
    game_id = data['game_id']
    game = ROOMS[game_id]
    if not game.finished:
        print("Game id=", game_id, " has been stopped due to player ",
              disconnected_man, " disconnected")
        game.finished = True
        game.winner = alive_user_id
        emit("game-extra-finished",
             Signals(249, game=game, id=alive_user_id).__str__(),
             room=game_id)
        leave_room(game_id)
        close_room(game_id)
예제 #18
0
    def __init__(self, editor):
        self.editor = editor

        self.signals = Signals()
        self.triggers = TriggerManager(editor)
        connect_all(self, self.signals, self.triggers, textbuffer=self.editor.textbuffer)

        self.block_word_reset = False
        self.words = None
        self.start_word = None
        self.start_offset = None
        
        self.indexer = IndexerProcessManager(self.signals.sender, editor)
        self.dictionary_manager = DictionaryManager(self.signals.sender, editor)
        self.communicator = ProcessCommunicator(self.signals.sender, editor)
        self.extractor = TextExtractor(self.signals.sender, editor)
        self.buffer_monitor = BufferMonitor(self.signals.sender, editor)
예제 #19
0
    def load_house(self, house: int):
        print("loading house: " + str(house))
        selection = self.appliance_selection[house]
        window_start, window_end = self.window_selection[house]
        self.dataset.set_window(start=window_start, end=window_end)
        elec = self.dataset.buildings[house].elec

        train_appliances = dr.load_appliances_selection(
            elec, self.order_appliances, selection, self.sample_rate)
        train_total = dr.load_total_power_consumption(elec, selection,
                                                      self.sample_rate)
        signals = Signals(self.sample_rate, self.order_appliances,
                          breakpoint_classification, self.improved,
                          "temperature_redd.csv")
        signals.set_signals(train_appliances, train_total)

        return signals
예제 #20
0
    def __init__(self, parent=None, args=None, macros=None):
        super(JetTracking, self).__init__(parent=parent,
                                          args=args,
                                          macros=macros)

        # reference to PyDMApplication - this line is what makes it so that you
        # #can avoid having to define main() and instead pydm handles that
        # for you - it is a subclass of QWidget
        self.app = QApplication.instance()
        # load data from file
        self.load_data()

        self.signals = Signals()
        self.vreader = ValueReader(self.signals)
        self.worker = StatusThread(self.signals)
        self.buffer_size = 300
        self.correction_thread = None
        # assemble widgets
        self.setup_ui()
예제 #21
0
def setting_ships_up(data):
    game_id = int(data['game_id'])
    player_id = int(data['user_id'])

    try:
        game = ROOMS[game_id]
        game.ustanovka(user_id=data['user_id'], ships=data['ships'])
        if player_id == 0:
            game.setted_1 = True
        elif player_id == 1:
            game.setted_2 = True
        if game.setted_1 and game.setted_2:
            game.running = True
            socketio.emit("game-started", {
                "game_id": game_id,
                "next_player_id": 0
            },
                          room=game_id)

    except KeyError:
        emit('error', Signals(519, id=game_id).__str__())
예제 #22
0
def signal_handler(signum, frame):
    print_now("Sub: signal handler for {}".format(Signals(signum).name))
예제 #23
0
 def init_signal(self):
     self.signal = Signals()
     self.signal.defender_player_signal.connect(self.player.reverse_bullet)
     self.signal.redraw_defender_signal.connect(self.redrawing_defender)
     self.signal.defender_enemy_signal.connect(self.enemies.hide_bullets)
예제 #24
0
 def init_signals(self):
     self.signal = Signals()
     self.signal.closed_signal.connect(self.close_game)
     self.signal.stop_game_singal.connect(self.menu)
     self.signal.restart_signal.connect(self.restart_game)
     self.signal.reverse_bullet_player.connect(self.player.reverse_bullet)
예제 #25
0
import serial
from serial import SerialException
import serial.tools.list_ports

# Project Modules
from signals import Signals
from server import Server

from queue import Queue

socket_queue = Queue()

server = Server(port=25565)
server.start(socket_queue)

ecg_signals = Signals()

root = Tk.Tk()

hr = IntVar(root, value=80)
threshold = IntVar(root, value=20)

position = StringVar(root, value='RIP')
serial_position = IntVar(root, value='0')
hr1=StringVar(root, value='0')

override_position = BooleanVar(root, value=False)

pathway_1 = IntVar(root, value=0)
pathway_2 = IntVar(root, value=0)
예제 #26
0
                MEM.set_data(value)
                # may use int_to_signed_32(value)
                MEM.run()
                # print ("Mem[%s]=%s"% ( hex(address),hex(value)))
                #need to set the value in memory module
    MEM.set_memwrite(0)
    return


if __name__ == '__main__':
    test = 'sig'
    "Test " + test
    if (test == 'print'):
        print_signal("B", 1, 1)
        print_signal("R", 31, 5)
        print_signal("Immd", 0xFABC, 16)
        print_signal("PC", 0x040000C4, 32)
        print_signal("RV", -1, 32)
        print_int("NoNL", -1)
        println_int("WithNL", -2)
    elif (test == 'load'):
        from hardware import Memory
        I_Mem = Memory()
        load_file(I_Mem, "input.txt")
        I_Mem.dump()
    elif (test == 'sig'):
        from signals import Signals
        sig = Signals()
        print_signals_1(sig)
        print_signals_2(sig)
예제 #27
0
from database import Database
from signals import Signals

productionMode = False
if (os.environ.get('DEPLOY_ENV') == 'production'):
    productionMode = True

app = Flask(__name__)

if (productionMode):
    dbUri = os.environ['MONGODB_URI']
    db = Database(mongo_host=dbUri)
else:
    db = Database()

signals = Signals()


def generate_cookie(conf):
    salt = os.environ['COOKIE_SALT']
    dk = hashlib.pbkdf2_hmac('sha256', conf['conf_id'].encode(), salt.encode(),
                             100000)
    return str(binascii.hexlify(dk))


@app.route("/", methods=['GET'])
@app.route("/join", methods=['GET'])
def index():
    return render_template("index.html")