예제 #1
0
def get_lists(objects):
    #for object in objects:
    #todo: 게임중
    #packed = DataStruct.pack_enemy_data(object)
    #packed = struct.pack('=fff', object.x, object.y, object.alive)
    #client_socket.sendall(packed)
    #packed = struct.pack('fff', object.x, object.y, object.alive)
    #DataStruct.pack_enemy_data(object)
    Player_packed = DataStruct.pack_player_data(objects)
    print(DataStruct.unpack_player_data(Player_packed))
    client_socket.sendall(Player_packed)
예제 #2
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            State.C_Game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                State.C_Game_framework.quit()
            elif (event.type) == (SDL_KEYDOWN):
                packed_data = DataStruct.pack_boolean(True)
                GameData.client_socket.send(packed_data)
                packed_data = GameData.client_socket.send(
                    DataStruct.boolean_size)
                if DataStruct.unpack_boolean(packed_data):
                    State.C_Game_framework.change_state(State.C_Title_state)
예제 #3
0
def PACK_DATA_Enemy(objects):
    #todo: 게임중
    #for objects in object:
        #DataStruct.pack_enemy_data(objects)
        #Enemy_packed =
        #print(Enemy_packed)
        #client_socket.sendall(packed)
    Enemy_packed = DataStruct.pack_enemy_data(objects)
    #print(DataStruct.unpack_enemy_data(Enemy_packed))
    #client_sock.sendall(Enemy_packed)
    return Enemy_packed
예제 #4
0
def create_world():
    global _DS, _player, _Bg, _Enemy1, timer, GameScore, font, _EBullet, _PBullet, _Life, client_socket
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_socket.connect((SERVER_IP_ADDR, SERVER_PORT))
    _player = Player1()
    _Bg = BackGround()
    _DS = DataStruct()
    _Enemy1 = []
    _Life = Life(_player.life)
    timer = Timer()
    GameScore = 0
    font = load_font('ENCR10B.TTF')
    _EBullet = EBullet.get_list()
    _PBullet = PBullet.get_list()
예제 #5
0
 def send_join_room(self, room_number, player_data):
     join_request_data = {
         'room_number': room_number,
         'player_name': player_data['player_name'],
         'player_number': player_data['player_number']
     }
     join_room = data_struct.pack_room_data(join_request_data)
     self.client_socket.send(join_room)
     #방 정보를 모두 불러들이면 구현할필요 없음 (임시)
     packed_room_is_full = self.client_socket.recv(1)
     room_is_full = DataStruct.unpack_room_is_full(packed_room_is_full)
     if(room_is_full):
         #disconnect room
         print("room is full")
     else:
         #connect room
         print("connecting")
         pass
예제 #6
0
def enter():
    global _BG, _WAND, font, game_data, selection_image
    font = load_font('..\ENCR10B.TTF')
    _BG = C_LobbyBG()
    _WAND = Wand()
    selection_image = load_image('..\Background\Image_Lobby_Select.png')

    game_data = C_Game_data.GameData
    tcp_controller = TcpContoller()
    client_sock = tcp_controller.tcp_client_init()
    game_data.client_socket = client_sock

    packed_player_number = client_sock.recv(DataStruct.integer_size)
    player_number = DataStruct.unpack_integer(packed_player_number)

    game_data.player_number = player_number

    reset_lobby()
예제 #7
0
def enter():
    global _BG, _WAND, font, game_data, selection_image, room_is_full_image, game_is_started_image, bgm
    font = load_font('Resource\ENCR10B.TTF')
    _BG = C_LobbyBG()
    _WAND = Wand()
    selection_image = load_image('Resource\Image_Lobby_Select.png')
    room_is_full_image = load_image('Resource\Image_Room_full.png')
    game_is_started_image = load_image('Resource\Image_Room_Started.png')
    bgm = load_music('Resource\BGM.mp3')
    bgm.set_volume(64)
    bgm.repeat_play()
    game_data = C_Game_data.GameData
    tcp_controller = TcpContoller()
    client_sock = tcp_controller.tcp_client_init()
    game_data.client_socket = client_sock

    packed_player_number = client_sock.recv(DataStruct.integer_size)
    player_number = DataStruct.unpack_integer(packed_player_number)

    game_data.player_number = player_number

    reset_lobby()
예제 #8
0
def recv_leader_board():
    packed_leader_board_count = GameData.client_socket.recv(
        DataStruct.integer_size)
    leader_board_count = DataStruct.unpack_integer(packed_leader_board_count)
    for i in range(leader_board_count):
        packed_leader_bard = GameData.client_socket.recv(
            struct.calcsize('30s 30s 30s 30s i'))
        unpack_leader_board = struct.unpack('30s 30s 30s 30s i',
                                            packed_leader_bard)
        leader_board = (
            'p1 ',
            unpack_leader_board[0].decode('ascii').rstrip('\x00'),
            'p2 ',
            unpack_leader_board[1].decode('ascii').rstrip('\x00'),
            'p3 ',
            unpack_leader_board[2].decode('ascii').rstrip('\x00'),
            'time ',
            unpack_leader_board[3].decode('ascii').rstrip('\x00'),
            'score ',
            unpack_leader_board[4],
        )
        leader_board_list.append(leader_board)
    print(leader_board_list)
예제 #9
0
def PACK_DATA_PBULLET(objects):
    Bullet_packed = DataStruct.pack_bullet_data(objects)
    print(DataStruct.unpack_bullet_data(Bullet_packed))
    #client_sock.sendall(Bullet_packed)
    return Bullet_packed
예제 #10
0
def PACK_DATA_Player(objects):
    Player_packed = DataStruct.pack_player_data(objects)
    client_sock.send(Player_packed)

    return Player_packed
예제 #11
0
def update(frame_time):
    global E_NUM ,_Enemy_Data
    #for enemy in _Enemy1:
    #    enemy.update(frame_time, _player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
    '''
    for enemy in _Enemy1 :
        if collide(enemy, _player):
            _player.life -=1
            _Enemy1.remove(enemy)
    for ebullets in _EBullet:
        ebullets.update(frame_time, _player.x, _player.y, _Bg.window_left, _Bg.window_bottom )
        PACK_DATA_PBULLET(ebullets)

    for ebullets in _EBullet :
        if collide(ebullets, _player):
            _player.life -= 1
            _EBullet.remove(ebullets)
    for pbullets in _PBullet:
        PACK_DATA_PBULLET(pbullets)
        pbullets.update(frame_time,)
    for pbullets in _PBullet :
        for enemys in _Enemy1 :
            if collide(pbullets, enemys):
                _PBullet.remove(pbullets)
                _Enemy1.remove(enemys)
    for enemy in _Enemy1 :
        if enemy.alive == 0 :
            _Enemy1.remove(enemy)
    for pbullets in _PBullet :
        if pbullets.alive == 0 :
            _PBullet.remove(pbullets)
    for ebullets in _EBullet :
        if ebullets.alive == 0 :
            _EBullet.remove(ebullets)

#SEND_ENEMY_DATA is ENEMY _X,_Y, TYPE
    E_NUM = struct.unpack('=i', recved_E_NUM)[0]
    for enemy in range(0, E_NUM) :
        _Enemy_packed = client_sock.recv(struct.calcsize('=fffi'))
        _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
        if _Enemy_Data[2] ==1 :
            newEnemy = Enemy1(_Enemy_Data[0],_Enemy_Data[1], _Bg.window_left, _Bg.window_bottom)
        if _Enemy_Data[2] ==2 :
            newEnemy = Enemy2(_Enemy_Data[0],_Enemy_Data[1],_Bg.window_left, _Bg.window_bottom)
        _Enemy1.insert(_Enemy_Data[3], newEnemy)

        print('_Enemy1 : ', _Enemy1)

    for enemy in _Enemy1 :
        enemy.update()
'''
    _player.update(frame_time)
    Player_packed = DataStruct.pack_player_data(_player)
    client_sock.send(Player_packed)



    recved_NUM = client_sock.recv(struct.calcsize('=ii'))
    Recved_Number_Data = struct.unpack('=ii',recved_NUM )
    #SEND_ENEMY_DATA is ENEMY _X,_Y, TYPE
    E_NUM = Recved_Number_Data[0]
    EB_NUM = Recved_Number_Data[1]
    #?
    print('E_NUM ,EB_NUM : ', E_NUM,EB_NUM)
    for i in range(0, E_NUM) :
        _Enemy_packed = client_sock.recv(struct.calcsize('=ffffi'))
        _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
        if _Enemy_Data[2] ==1 :
            newEnemy = Enemy1(_Enemy_Data[0],_Enemy_Data[1],_Enemy_Data[3], _Bg.window_left, _Bg.window_bottom)
            newEnemy.update(frame_time,_player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
        if _Enemy_Data[2] ==2 :
            newEnemy = Enemy2(_Enemy_Data[0],_Enemy_Data[1],_Enemy_Data[3],_Bg.window_left, _Bg.window_bottom)
            newEnemy.update(frame_time,_player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
        _Enemy1.append(newEnemy)

    for i in range(0,EB_NUM) :
        _Bullet_packed = client_sock.recv(struct.calcsize('=fff'))
        _Bullet_Data = DataStruct.unpack_bullet_data(_Bullet_packed)
        if _Bullet_Data[0] == 1:     #EnemyBullet
            newEBullet = EBullet(_Bullet_Data[1],_Bullet_Data[2] )
        newEBullet.update()
        _EBullet.append(newEBullet)
        if _Bullet_Data[0] == 0:     # playerBullet
            pass
예제 #12
0
 def send_ready_state(self, is_ready):
     packed_is_ready = DataStruct.pack_is_game_over(is_ready)
     self.client_socket.send(packed_is_ready)
예제 #13
0
def recv_thread(client_sock):
    global AnotherPlayer, _Enemy1, _EBullet, _Bg, Player_Count, _LifeList, iScore

    _ETEMP = []
    _BTEMP = []
    _PTEMP = []
    _LTEMP = []

    while 1:
        Player_packed = DataStruct.pack_player_data(_player)
        client_sock.send(Player_packed)
        _player.isshoot = False

        #AllPlayerRECVED START
        all_player_packed = client_sock.recv(
            struct.calcsize('=iffffffffffffiiiBBBfffi'))

        unpacked_all_player_data = DataStruct.unpack_all_player_data(
            all_player_packed)
        Player_Count = unpacked_all_player_data['player_count']
        iScore = unpacked_all_player_data['Score']
        for i in range(unpacked_all_player_data['player_count']):
            newLIFE = unpacked_all_player_data['player_life'][i]
            _LTEMP.append(newLIFE)
            if i != MyNumber:
                newPlayer = Player2(
                    unpacked_all_player_data['player_x'][i],
                    unpacked_all_player_data['player_y'][i],
                    unpacked_all_player_data['player_dir'][i],
                    unpacked_all_player_data['player_life'][i],
                    _Bg.window_left, _Bg.window_bottom,
                    GameData.waitting_room_data['player_witch_select'][i])
                _PTEMP.append(newPlayer)
            if i == MyNumber:
                _player.life = unpacked_all_player_data['player_life'][i]
        AnotherPlayer = _PTEMP
        _LifeList = _LTEMP
        if len(_PTEMP) > 0:
            _PTEMP = []
        if len(_LTEMP) > 0:
            _LTEMP = []
        #ALLPlayerRECVED END

        #GAMEOVER RECVED START
        packed_is_game_over = client_sock.recv(struct.calcsize('?'))
        GameData.is_game_over = (struct.unpack('?', packed_is_game_over))[0]
        if (GameData.is_game_over):
            print('game_over')
            return
        #GAMEOVER RECVED END

        recved_NUM = client_sock.recv(struct.calcsize('=ii'))
        Recved_Number_Data = struct.unpack('=ii', recved_NUM)

        recved_IN_Window_NUM = client_sock.recv(struct.calcsize('=ii'))
        Recved_IN_Window_Number_Data = struct.unpack('=ii',
                                                     recved_IN_Window_NUM)
        # SEND_ENEMY_DATA is ENEMY _X,_Y, TYPEUM = 0
        E_NUM = Recved_IN_Window_Number_Data[0]
        EB_NUM = Recved_IN_Window_Number_Data[1]
        # ?

        for i in range(0, E_NUM):
            _Enemy_packed = client_sock.recv(struct.calcsize('=fffi'))
            _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
            if _Enemy_Data[2] == 1:
                newEnemy = Enemy1(_Enemy_Data[0], _Enemy_Data[1],
                                  _Enemy_Data[3], _Bg.window_left,
                                  _Bg.window_bottom)
                #newEnemy.update(_player.x, _player.y, _Bg.window_left, _Bg.window_bottom, State)
            if _Enemy_Data[2] == 2:
                newEnemy = Enemy2(_Enemy_Data[0], _Enemy_Data[1],
                                  _Enemy_Data[3], _Bg.window_left,
                                  _Bg.window_bottom)
                #newEnemy.update(_player.x, _player.y, _Bg.window_left, _Bg.window_bottom, State)
            _ETEMP.append(newEnemy)
        _Enemy1 = _ETEMP
        if len(_ETEMP) > 0:
            _ETEMP = []

        for i in range(0, EB_NUM):
            _Bullet_packed = client_sock.recv(struct.calcsize('=fff'))
            _Bullet_Data = DataStruct.unpack_bullet_data(_Bullet_packed)
            if _Bullet_Data[0] == 1:  # EnemyBullet
                newBullet = EBullet(_Bullet_Data[1], _Bullet_Data[2])

            elif _Bullet_Data[0] == 0:  # playerBullet
                newBullet = PBullet(_Bullet_Data[1], _Bullet_Data[2])
            #newBullet.update()
            _BTEMP.append(newBullet)
        _EBullet = _BTEMP
        if len(_BTEMP) > 0:
            _BTEMP = []
예제 #14
0
import socket
from TCP.C_Pack import DataStruct
from Data import C_StructSet
from Enemy.C_Enemy import Enemy1
from State import C_collision
import struct
_datastruct = DataStruct()
host = "127.0.0.1"
port = 12345
#PointStruct = {'pos_x': 0, 'pos_y': 0}
#pointXY = {'pos_x': Enemy1.returnx(), 'pos_y': Enemy1().returny()}
#print ( 'pointXY[0-1]', pointXY['pos_x'])
#butter = struct.pack("i i 6s",pointXY['pos_x'],pointXY['pos_y'], b'python')

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(butter)
data = s.recv(1024)
s.close()
print('received!', repr(data))