示例#1
0
def draw_initial_display(MAP, player, len_x, len_y, discoverd):
    dis.fill(white)
    message(dis, head_font_size, f"{player.getName()}", blue, white, 10, 0)
    message(dis, head_font_size, f"Health: {player.getHealth()}", green, white,
            100, 0)
    message(dis, head_font_size, f"Fins: {player.hasFins()}", black, white,
            300, 0)
    pygame.draw.rect(dis, darkblue,
                     [0, head_font_size, (len_x * block_size), 5])

    for i in range(len_x):
        for j in range(len_y):
            if [i, j] not in discoverd:
                pygame.draw.rect(
                    dis, gray, [(block_size * i),
                                (block_size * (len_y - j - 1)) +
                                (head_font_size + 5), block_size, block_size])

    message(dis, normal_font_size, f"{player.getName()}", black, white,
            (block_size * player.getCordinate().getX()) + 20,
            (block_size * (len_y - player.getCordinate().getY() - 1)) + 25 +
            (head_font_size + 5))

    for cordinate in discoverd:
        if MAP.getCordinate(cordinate[0], cordinate[1]).hasObject():
            message(
                dis, normal_font_size,
                f"{MAP.getCordinate(cordinate[0], cordinate[1]).getObject().getName()}",
                black, white, (block_size * cordinate[0]) + 20,
                (block_size *
                 (len_y - cordinate[1] - 1)) + 5 + (head_font_size + 5))

    pygame.display.update()
示例#2
0
def display_high_score(high_score_list):
    dis.fill(white)
    message(dis, (2 * item_font_size), "High Score", green, white, width // 4,
            (height - item_font_size) // 4)

    for i in range(5):
        message(dis, item_font_size,
                str(i + 1) + ") " + str(high_score_list[i]), blue, white,
                width / 3,
                (height - item_font_size) / 3 + ((1 + i) * item_font_size))

    pygame.display.update()
示例#3
0
def draw_main_menu(item_list, select_item):
    dis.fill(white)
    message(dis, (2 * item_font_size), "Lake Nozama", green, white, width // 4,
            (height - item_font_size) // 4)
    for i in range(len(item_list)):
        if (select_item == i):
            f_colour = white
            bg_colour = blue
        else:
            f_colour = blue
            bg_colour = white
        message(dis, item_font_size, item_list[i], f_colour, bg_colour,
                width // 3,
                ((height - item_font_size) // 3 + ((2 + i) * item_font_size)))
    pygame.display.update()
示例#4
0
def send_smg(nid1, nid2, msg):
    node1=SendMessage.get_node_byID(nid1)
    node2=SendMessage.get_node_byID(nid2)
    path=find_message_path(node1,node2)
    msg=message(node1.nid,node2.nid,msg,path)
    global_v.msg_buffer.append(msg)
    return path
def view_all_message():
    message_list=[]
    mydb.open()
    result = mydb.query_db('select * from message', one=False)
    if result:
        for msg in result:
            m = message(msg['_from'], msg['_to'], msg['msg'], None, msg['createdAt'])
            message_list.append(m)

    mydb.close_db()
    return json.dumps(message_list, default=methodcaller("json"))
示例#6
0
def view_all_message():
    message_list=[]
    mydb.open()
    result = mydb.query_db('select * from message', one=False)
    if result:
        for msg in result:
            m=message(msg['from_id'],msg['to_id'],msg['msg'])
            message_list.append(m)

    mydb.close_db()
    return message_list
示例#7
0
def check_node_in_path(pre_nid, cur_nid):
    inactive_node_list=find_all_inactiveNode()
    # if the path is blocked
    if cur_nid in inactive_node_list:
        # if the msg can't be sent, move the msg in buffer into failed msg list. from id is the last valid
        # node nid in the path
        msg_in_buffer=global_v.msg_buffer[0];
        failed_msg = message(pre_nid, msg_in_buffer._to, msg_in_buffer.msg)
        del global_v.msg_buffer[0]
        global_v.failed_msg.append(failed_msg)
        print 'Block at node '+ str(cur_nid)
        return False
    else:
        msg_in_buffer=global_v.msg_buffer[0];
        path=msg_in_buffer.path.split()
        #  if this node is destination node and is active
        if(path[len(path)-1]==cur_nid):
            msg = message(pre_nid, msg_in_buffer._to, msg_in_buffer.msg)
            send_message(msg_in_buffer._from, msg_in_buffer._to, msg_in_buffer.msg)
            print 'Message from'+ str(global_v._from) +' to ' + str(global_v._to) +' is delivered '
        else:
            print '->' +str(cur_nid)
            return True
def send_msg(nid1, nid2, msg, msgId):
    node1=SendMessage.get_node_byID(nid1)
    if node1==None: return 'from node does not exist'
    node2=SendMessage.get_node_byID(nid2)
    if node2==None: return 'destination node does not exist'

    #  If it is failed msg to be resend , delete it from failed msg list first
    senderId=node1.nid
    path=find_message_path(node1,node2)
    for msg_obj in global_v.failed_msg:
        if msgId==msg_obj.msgId:
            senderId=msg_obj.sender
            global_v.failed_msg.remove(msg_obj)
            break
    msg_pending=message(node1.nid,node2.nid, msg, path,None,senderId, int(msgId))
    global_v.msg_buffer.append(msg_pending)
    return path
def check_node_in_path(pre_nid, cur_nid, msgId):
    inactive_node_list=find_all_inactiveNode()
    print pre_nid
    print cur_nid
    #  if the current node is deleted
    if not verify_node(cur_nid):
        return False

    # if the path is blocked
    if cur_nid in inactive_node_list:
        # if the msg can't be sent, move the msg in buffer into failed msg list. from id is the last valid
        # node nid in the path
        msg_in_buffer=get_msg_byId(msgId);
        # If can't find the msg in the buffer
        if msg_in_buffer==None:
            return False
        for msg_obj in global_v.msg_buffer:
            if msgId==msg_obj.msgId:
                failedMsg=message(pre_nid,msg_obj._to, msg_obj.msg,msg_obj.path,None,msg_obj.sender,msg_obj.msgId, cur_nid, pre_nid)
                global_v.failed_msg.append(failedMsg)
                global_v.msg_buffer.remove(msg_obj)

        print 'Block at node '+ str(cur_nid)
        return False
    else:
        # if current node is active
        msg_in_buffer=get_msg_byId(msgId);
        print msg_in_buffer
        if msg_in_buffer==None:
            # print "Can't find the node, msgId:"+ str(msgId)
            return False
        path=msg_in_buffer.path
        #  if this node is destination node and is active
        if(int(path[len(path)-1])==cur_nid):
            store_message_in_database(int(msg_in_buffer.sender), int(msg_in_buffer._to), str(msg_in_buffer.msg))
            global_v.msg_buffer.remove(msg_in_buffer)
            # print 'Message from '+ str(msg_in_buffer.sender) +' to ' + str(msg_in_buffer._to) +' is delivered '
            return True
        else:
            # print '->' +str(cur_nid)
            return True
示例#10
0
    def add_btn_clicked(self):
        title = self.task_title_line.text()
        if not title:
            message("请先为这个任务设置标题", "error")
            return

        tags_list_str = ";".join([
            self.tags_list_widget.item(i).text()
            for i in range(self.tags_list_widget.count())
            if self.tags_list_widget.item(i).checkState()
        ])

        if self.set_remind_check.isChecked():
            remind_date = "%s %s:%s" % (self.date_edit.text(),
                                        self.hour_combo.currentText(),
                                        self.minute_combo.currentText())
        else:
            remind_date = ""

        if not db_command(
                "SELECT * FROM TasksData WHERE Classify = '%s' AND Title = '%s'"
                % (self.classify_name, title)):
            db_command(
                "INSERT INTO TasksData (Classify,Title,Describe,Tags,Remind,Finish) VALUES ('%s','%s','%s','%s','%s','%s')"
                % (self.classify_name, str(title),
                   str(self.task_plain.toPlainText()), tags_list_str,
                   remind_date, self.finish))

        else:
            db_command(
                "UPDATE TasksData SET Describe = '%s',Tags = '%s',Remind = '%s',Finish = '%s' WHERE Classify = '%s' AND Title = '%s'"
                % (str(self.task_plain.toPlainText()), tags_list_str,
                   remind_date, self.finish, self.classify_name, str(title)))

        self.changed = True

        if self.task_title_line.isEnabled():
            message("任务: %s  - 添加完成。" % self.task_title_line.text(), "success")
        else:
            message("任务: %s  - 修改完成。" % self.task_title_line.text(), "success")
        self.close()
示例#11
0
def display_map_objects(obj, x, y):
    message(dis, normal_font_size, obj, black, white, x, y)
    pygame.display.update()
示例#12
0
def display_popup_messages(msg):
    dis.fill(white)
    message(dis, head_font_size, msg, black, white, width // 3, height // 3)
    pygame.display.update()
    sleep(1)
    pygame.event.clear()