Exemplo n.º 1
0
    def exit_animation(self):
        """Пропуск анимации"""
        if self.castle_next_turn:
            self.castle_next_turn.kill()
            self.castle_next_turn = 0
        if self.castle_last_turn:
            self.castle_last_turn.kill()
            self.castle_last_turn = 0
        if self.bg_animation:
            self.bg_animation.kill()
            self.bg_animation = 0

        self.bg_animation = Sprite("light95.png")
        self.bg_animation.scale_x = 0.09
        self.bg_animation.scale_y = 0.115
        self.bg_animation.opacity = 0
        self.bg_animation.position = self.BG_ANIMATION_POS[self.move[1] - 1]
        chart.Chart().add(self.bg_animation)

        self.castle_last_turn = Sprite("castle" + str(self.move[0]) + ".png")
        self.castle_last_turn.scale = 1
        self.castle_last_turn.opacity = 0
        self.castle_last_turn.position = self.CENTER_POS
        chart.Chart().add(self.castle_last_turn)

        self.castle_next_turn = Sprite("castle" + str(self.move[1]) + ".png")
        self.castle_next_turn.scale = 1
        self.castle_next_turn.opacity = 0
        self.castle_next_turn.position = self.POS_CENTER_BASE[self.move[1]-1]
        chart.Chart().add(self.castle_next_turn)
Exemplo n.º 2
0
    def reinit(self, move):
        """Происходит реинициализация класса по заданному ходу"""
        self.bg = Sprite("light95.png")
        self.bg.scale_x = 0.09
        self.bg.scale_y = 0.115
        self.bg.position = [self.X_POS, self.Y_POS]
        chart.Chart().add(self.bg)
        self.castle = Sprite('castle' + str(move) + '.png')
        self.castle.scale = 0.8
        self.castle.position = [self.X_POS, self.Y_POS]
        chart.Chart().add(self.castle)
        self.mas_sprite = []
        
        self.move = [(move-1) if move > 1 else 1, move]
        self.castle_last_turn = Sprite("castle" + str(self.move[0]) + ".png")
        self.castle_next_turn = Sprite("castle" + str(self.move[1]) + ".png")

        self.bg_animation = Sprite("light95.png")
        self.bg_animation.scale_x = 0.09
        self.bg_animation.scale_y = 0.115

        chart.Chart().add(self.bg_animation)
        chart.Chart().add(self.castle_last_turn)
        chart.Chart().add(self.castle_next_turn)
        self.bg_animation.opacity = 0
        self.castle_next_turn.opacity = 0
        self.castle_last_turn.opacity = 0
Exemplo n.º 3
0
    def __init__(self, one_unit, i, j):
        super(Army, self).__init__()
        self.i = i
        self.j = j
        self.move = True
        self.player = chart.Chart().get_cell(self.i,
                                             self.j).properties['player']

        self.x = chart.Chart().get_cell(self.i, self.j).center[0]
        self.y = chart.Chart().get_cell(self.i, self.j).center[1]
        self.mas_sprite = [
            'peasant' + str(self.player) + '.png',
            'priest' + str(self.player) + '.png',
            'soldier' + str(self.player) + '.png',
            'knight' + str(self.player) + '.png'
        ]

        self.army = [one_unit]
        self.type_army_global = self.army[0].type_unit
        self.xy = [self.x + self.deviation_x, self.y + self.deviation_y]

        self.sprite = Sprite(self.mas_sprite[self.type_army_global - 1])
        self.sprite.position = self.xy
        self.sprite.scale = 1.4
        chart.Chart().add(self.sprite)

        self.sprite_kletka = []
Exemplo n.º 4
0
    def add_podsvet(self):
        '''Добавляет подсветку клеткам'''
        if chart.Chart().get_cell(self.i, self.j).army != None:
            if chart.Chart().get_cell(self.i, self.j).army.player != 0:
                if self.move:
                    for k in range(22):
                        for m in range(11):
                            if self.step(self.i, self.j, k, m):
                                if chart.Chart().get_cell(k, m).army:
                                    if chart.Chart().get_cell(k,m).army.player !=\
                                       chart.Chart().get_cell(self.i,self.j).army.player:
                                        sprite_kletka = Sprite(
                                            'podsvet_attack.png')
                                    else:
                                        sprite_kletka = Sprite('podsvet.png')
                                else:
                                    sprite_kletka = Sprite('podsvet.png')

                                x = chart.Chart().get_cell(k, m).center[0]
                                y = chart.Chart().get_cell(k, m).center[1]
                                sprite_kletka.position = [x, y]
                                self.sprite_kletka.append(sprite_kletka)

                    for i in range(len(self.sprite_kletka)):
                        chart.Chart().add(self.sprite_kletka[i])
Exemplo n.º 5
0
    def merge_unit(self, one_unit, boole='unit'):
        '''Слияние нового войска с армией'''
        count_army = 0
        max_army = chart.Chart().get_cell(self.i,
                                          self.j).properties['capacity']
        for i in range(len(self.army)):
            count_army += self.army[i].count
        if (one_unit.count + count_army) > max_army:
            one_unit.count = max_army - count_army

        if one_unit.count != 0:
            for i in range(len(self.army)):
                if self.army[i].type_unit == one_unit.type_unit and \
                   self.army[i].one_unit_attack == one_unit.one_unit_attack and\
                   self.army[i].one_unit_defense == one_unit.one_unit_defense and\
                   self.army[i].one_unit_hp == one_unit.one_unit_hp:
                    self.army[i].count += one_unit.count
                    break
            else:
                self.army.append(one_unit)
            for i in range(len(self.army)):
                self.army[i].update_all()

        if boole == 'unit':
            self.__update()
Exemplo n.º 6
0
 def draw(self, flag):
     if flag == 1:
         '''Рисует окно'''
         N = 3
         window = Sprite("game_rule.png")
         window.position = [self.X_WINDOW, self.Y_WINDOW]
         window.scale = 0.8
         self.mas_sprite = [window]
         exit = Sprite("exit.png")
         exit.position = [self.X_BTN, self.Y_BTN]
         self.mas_sprite.append(exit)
         self.mas_text = []
         self.mas_test_pos = []
         d = os.path.dirname(__file__)
         interface = os.path.join(d, '../resources')
         interface += '/' + 'rules.txt'
         f = open(interface, 'r', encoding='utf-8')
         x = 130
         y = 650
         for line in f:
             label = cocos.text.Label(line,
                                      font_name='Arial',
                                      font_size=14,
                                      anchor_x='left', anchor_y='center')
             label.position = x, y
             y -= 13
             self.mas_sprite.append(label)
         for object in self.mas_sprite:
             chart.Chart().add(object)
Exemplo n.º 7
0
    def draw_info_army(self, cell):
        """Прорисовка окна информации армии"""
        bg = Sprite("light95.png")
        bg.scale_x = 0.5
        bg.scale_y = 0.115
        bg.position = [self.X_POS_ARMY, self.Y_POS]

        self.mas_sprite.append(bg)
        mas_shift = [-3, -1, 1, 3]
        mas_count = [0]*4
        for unit in cell.army.army:
            for i in range(len(mas_count)):
                if unit.type_unit == i+1:

                    mas_count[i] += unit.count

        for i, g in enumerate(mas_shift):
            unit = Sprite(self.IMAGE_NAME[i] + str(cell.army.player) + ".png")
            unit.scale = 1.5
            unit.position = [self.X_POS_ARMY + self.SHIFT*g - 20, self.Y_POS]
            count = cocos.text.Label(str(mas_count[i]),
                                          font_name='Times New Roman',
                                          font_size=32,
                                          anchor_x='left', anchor_y='center')
            count.position = [self.X_POS_ARMY + self.SHIFT*g - 5, self.Y_POS]
            self.mas_sprite.append(count)
            self.mas_sprite.append(unit)

        for object in self.mas_sprite:
            chart.Chart().add(object)
Exemplo n.º 8
0
 def __init__(self, type_city, type_unit, i, j):
     self.i = i
     self.j = j
     self.gold = 0
     self.building = type_city - 1
     self.type_unit = type_unit
     self.type_city = type_city
     self.stats = self.BASE_STATS
     self.cell = chart.Chart().get_cell(i, j)
Exemplo n.º 9
0
    def go(self):
        d = os.path.dirname(__file__)
        beginning = os.path.join(d, '../resources/saving.pickle')
        with open('resources/saving.pickle', 'rb') as f:
            data = pickle.load(f)

        SIZE = 62
        self.map_layer = chart.generate(data, SIZE, 1, 0)
            
        for i in range(len(chart.Chart().cells)):
            for j in range(len(chart.Chart().cells[0])):
                chart.Chart().get_cell(i, j).init_city(i, j, data[i][j])
        
        window_w, window_h = 1300, 800
        chart.Chart().set_view(0, 0, window_w, window_h)
        self.add(chart.BgLayer())
        self.add(chart.Chart())
        self.add(ButtonMap())
        Top_Window().reinit(1) 
Exemplo n.º 10
0
 def on_mouse_press(self, x, y, buttons, modifiers):
     self.button_exit = [1200, 650, 1265, 715]
     if self.button_exit[0] < x < self.button_exit[2] and \
             self.button_exit[1] < y < self.button_exit[3]:
         self.parent.switch_to(0)
         
     self.button_save = [1200, 450, 1265, 515]
     if self.button_save[0] < x < self.button_save[2] and \
             self.button_save[1] < y < self.button_save[3]:
         chart.save('saving', chart.Chart())
Exemplo n.º 11
0
 def __init__(self, x, y):
     super(Hiring_window, self).__init__()
     self.x = x
     self.y = y
     self.mas_sprite = []
     self.mas_label = ["0", "0", "0", "0"]
     self.mas_true_minus = [0, 0, 0, 0]
     self.mas_true_plus = [0, 0, 0, 0]
     self.cell = chart.Chart().get_at_pixel(x, y)
     self.type_cell = self.cell.properties['relief']
     self.player = self.cell.properties['player']
     self.type_unit = self.cell.town.type_unit - 1
     self.draw()
Exemplo n.º 12
0
 def __check_count_armies(self, one_army):
     '''Проверка на возможность слияния двух армий'''
     count1 = 0
     count2 = 0
     max_army = chart.Chart().get_cell(self.i,
                                       self.j).properties['capacity']
     for i in range(len(self.army)):
         count1 += self.army[i].count
     for i in range(len(one_army.army)):
         count2 += one_army.army[i].count
     if (count1 + count2) <= max_army and (self.player == one_army.player\
                                           or one_army.player == 0):
         return True
     else:
         return False
Exemplo n.º 13
0
    def go(self, new=False):
        d = os.path.dirname(__file__)
        beginning = os.path.join(d, '../resources/begining.pickle')
        with open('resources/begining.pickle', 'rb') as f:
            data = pickle.load(f)

        SIZE = 62
        if new:
            # Сюда программа зайдет один раз при инициализации слоев MultiplexLayer
            self.map_layer = chart.generate(data, SIZE)
            Top_Window(1) # Инициализируем Top_Window впервые           
        else:
            self.map_layer = chart.generate(data, SIZE, 0, 0) # Делаем апдейт
            
        for i in range(len(chart.Chart().cells)):
            for j in range(len(chart.Chart().cells[0])):
                chart.Chart().get_cell(i, j).init_city(i, j)
        
        window_w, window_h = 1300, 800
        chart.Chart().set_view(0, 0, window_w, window_h)
        self.add(chart.BgLayer())
        self.add(chart.Chart())
        self.add(ButtonMap())
        Top_Window().reinit(1)
Exemplo n.º 14
0
 def check(i1, j1, i2, j2):
     '''Проверка области и рельефа куда может пойти армия'''
     if i1 == i2 and j1 == j2:
         return False
     elif chart.Chart().get_cell(i2, j2).properties['relief'] == 0:
         return False
     elif abs(i1 - i2) <= 2 and abs(j1 - j2) <= 1:
         return True
     elif i1 == i2 and abs(j1 - j2) <= 2:
         return True
     elif (abs(i1 - i2) <= 1 and j2 - j1 == 2 and i2 % 2 == 0) or\
          (abs(i1 - i2) <= 1 and j1 - j2 == 2 and i2 % 2 == 1):
         return True
     else:
         return False
Exemplo n.º 15
0
    def new_sprite(self):
        '''Добавление нового спрайта для корректной анимации армии'''
        for i in range(len(self.army)):
            if i == 0:
                c = self.army[0].count
                type_unit = self.army[0].type_unit

            elif self.army[i].type_unit == type_unit:
                c += self.army[i].count

            elif self.army[i].count > c:
                c = self.army[i].count
                type_unit = self.army[i].type_unit

        self.sprite = Sprite(self.mas_sprite[type_unit - 1])
        self.sprite.scale = 1.4
        self.sprite.position = self.xy
        chart.Chart().add(self.sprite)
Exemplo n.º 16
0
    def draw(self):
        '''Рисует окно'''
        N = 3
        window = Sprite("light95.png")
        window.position = [self.X_WINDOW, self.Y_WINDOW]
        window.scale = 0.6
        self.mas_sprite = [window]
        gold = Sprite("gold.png")
        gold.scale = 0.25
        shift_pos = 5
        gold.position = [
            self.X_UNIT + self.X_SHIFT * 4 + shift_pos,
            self.Y_UNIT + self.Y_SHIFT * N
        ]
        self.mas_sprite.append(gold)
        gold2 = Sprite("gold.png")
        gold2.scale = 0.25
        gold2.position = [
            self.X_UNIT + self.X_SHIFT * 4 + shift_pos,
            self.Y_UNIT + self.Y_SHIFT * (N - 1)
        ]
        self.mas_sprite.append(gold2)
        shift_gold_pos = 30
        gold_label = cocos.text.Label(str(self.cell.town.gold),
                                      font_name='Times New Roman',
                                      font_size=32,
                                      anchor_x='left',
                                      anchor_y='center')
        gold_label.position = [
            self.X_UNIT + self.X_SHIFT * 4 + shift_gold_pos,
            self.Y_UNIT + self.Y_SHIFT * N
        ]
        self.mas_sprite.append(gold_label)
        ok = Sprite("ok.png")
        ok.position = [self.X_UNIT + self.X_SHIFT * 4.5, self.Y_UNIT]
        self.mas_sprite.append(ok)
        if self.type_cell == self.CITY:
            unit = Sprite(self.IMAGE_NAME[self.type_unit] + str(self.player) +
                          ".png")
            unit.scale = 2
            unit.position = [self.X_UNIT, self.Y_UNIT + self.Y_SHIFT * 3]
            self.mas_sprite.append(unit)
            self.mas_true_minus[0] = bool(int(self.mas_label[0]))
            if self.mas_true_minus[0]:
                minus = Sprite("minus.png")
                minus.scale = 0.7
                minus.position = [
                    self.X_UNIT + self.X_SHIFT, self.Y_UNIT + self.Y_SHIFT * 3
                ]
                self.mas_sprite.append(minus)

            label = cocos.text.Label(self.mas_label[0],
                                     font_name='Times New Roman',
                                     font_size=32,
                                     anchor_x='center',
                                     anchor_y='center')
            label.position = [
                self.X_UNIT + self.X_SHIFT * 2, self.Y_UNIT + self.Y_SHIFT * 3
            ]
            self.mas_sprite.append(label)
            all_costs = int(
                self.mas_label[0]) * self.MAS_COST[N - self.type_unit]
            self.mas_true_plus[0] = all_costs + self.MAS_COST[
                N - self.type_unit] <= self.cell.town.gold
            if self.mas_true_plus[0]:
                plus = Sprite("plus.png")
                plus.scale = 0.7
                plus.position = [
                    self.X_UNIT + self.X_SHIFT * 3,
                    self.Y_UNIT + self.Y_SHIFT * 3
                ]
                self.mas_sprite.append(plus)

        elif self.type_cell == self.BASE:

            all_costs = 0
            for i in range(len(self.mas_label)):
                all_costs += (int(self.mas_label[i]) * self.MAS_COST[N - i])
            for i in range(len(self.IMAGE_NAME)):
                self.mas_true_plus[i] = all_costs + self.MAS_COST[
                    N - i] <= self.cell.town.gold

            for i in range(len(self.IMAGE_NAME)):
                unit = Sprite(self.IMAGE_NAME[i] + str(self.player) + ".png")
                unit.scale = 2
                unit.position = [self.X_UNIT, self.Y_UNIT + self.Y_SHIFT * i]
                self.mas_sprite.append(unit)

                label = cocos.text.Label(self.mas_label[i],
                                         font_name='Times New Roman',
                                         font_size=32,
                                         anchor_x='center',
                                         anchor_y='center')
                label.position = [
                    self.X_UNIT + self.X_SHIFT * 2,
                    self.Y_UNIT + self.Y_SHIFT * i
                ]
                self.mas_sprite.append(label)
                self.mas_true_minus[i] = bool(int(self.mas_label[i]))
                if self.mas_true_minus[i]:
                    minus = Sprite("minus.png")
                    minus.scale = 0.7
                    minus.position = [
                        self.X_UNIT + self.X_SHIFT,
                        self.Y_UNIT + self.Y_SHIFT * i
                    ]
                    self.mas_sprite.append(minus)

                if self.mas_true_plus[N - i]:
                    plus = Sprite("plus.png")
                    plus.scale = 0.7
                    plus.position = [
                        self.X_UNIT + self.X_SHIFT * 3,
                        self.Y_UNIT + self.Y_SHIFT * (N - i)
                    ]
                    self.mas_sprite.append(plus)

        gold2_label = cocos.text.Label(str(all_costs),
                                       font_name='Times New Roman',
                                       font_size=32,
                                       anchor_x='left',
                                       anchor_y='center')
        gold2_label.position = [
            self.X_UNIT + self.X_SHIFT * 4 + shift_gold_pos,
            self.Y_UNIT + self.Y_SHIFT * (N - 1)
        ]
        self.mas_sprite.append(gold2_label)

        for object in self.mas_sprite:
            chart.Chart().add(object)
Exemplo n.º 17
0
    def move_army(self, i1, j1):
        '''Перемещает армию по указанной клетке'''
        if self.step(self.i, self.j, i1, j1) and self.move:
            self.delete_podsvet()

            army1 = chart.Chart().get_cell(self.i, self.j).army
            army2 = chart.Chart().get_cell(i1, j1).army

            if army2 != None:
                #Случай для слияния двух армий одного игрока
                if army2.player == army1.player:
                    # Проверка на возможность слияния
                    if self.__check_count_armies(army2):
                        self.x = chart.Chart().get_cell(i1, j1).center[0]
                        self.y = chart.Chart().get_cell(i1, j1).center[1]
                        self.xy = [
                            self.x + self.deviation_x,
                            self.y + self.deviation_y
                        ]

                        chart.Chart().get_cell(i1, j1).army.sprite.do(
                            Delay(self.move_time) +
                            ScaleBy(self.scale_size, self.scale_time) +
                            Reverse(ScaleBy(self.scale_size,
                                            self.scale_time)) + Hide())
                        chart.Chart().get_cell(i1, j1).leave_cell()
                        self.merge_army(army2, False)
                        self.sprite.do(
                            MoveTo(self.xy, self.move_time) + Hide() +
                            Delay(2 * self.move_time) +
                            CallFunc(self.new_sprite))

                        chart.Chart().get_cell(i1, j1).enter_cell(self)
                        chart.Chart().get_cell(self.i, self.j).leave_cell()
                        self.i = i1
                        self.j = j1
                        self.move = False
                    else:
                        self.sprite.do(
                            MoveTo([
                                chart.Chart().get_cell(i1, j1).center[0] +
                                self.deviation_x,
                                chart.Chart().get_cell(i1, j1).center[1] +
                                self.deviation_y
                            ], self.move_time) +
                            Rotate(-self.rotation_degree, self.rotation_time) +
                            Rotate(2 *
                                   self.rotation_degree, self.rotation_time) +
                            Rotate(-self.rotation_degree, self.rotation_time) +
                            MoveTo(self.xy, self.move_time))

                # Сражение двух армий
                else:
                    mas_army = [1, 2]
                    attack_army1, defense_army1, attack_army2, defense_army2 = 0, 0, 0, 0

                    for i in range(len(army1.army)):
                        attack_army1 += army1.army[i].attack
                        defense_army1 += army1.army[i].defense
                    for i in range(len(army2.army)):
                        attack_army2 += army2.army[i].attack
                        defense_army2 += army2.army[i].defense

                    if attack_army1 <= defense_army2 and attack_army2 <= defense_army1:
                        self.x = chart.Chart().get_cell(i1, j1).center[0]
                        self.y = chart.Chart().get_cell(i1, j1).center[1]
                        self.xy = [
                            self.x + self.deviation_x,
                            self.y + self.deviation_y
                        ]
                        self.sprite.do(MoveTo(self.xy, self.move_time))

                        chart.Chart().get_cell(i1, j1).army.sprite.do(
                            Blink(self.blink_times, self.move_time) + Hide())
                        chart.Chart().get_cell(i1, j1).leave_cell()
                        chart.Chart().get_cell(i1, j1).enter_cell(army1)
                        chart.Chart().get_cell(self.i, self.j).leave_cell()
                        self.i = i1
                        self.j = j1
                        self.move = False

                    else:
                        while len(chart.Chart().get_cell(self.i, self.j).army.army) and\
                              len(chart.Chart().get_cell(i1, j1).army.army):
                            self.__attack(chart.Chart().get_cell(self.i, self.j).army,\
                                   chart.Chart().get_cell(i1, j1).army)
                            chart.Chart().get_cell(self.i, self.j).army,\
                            chart.Chart().get_cell(i1, j1).army =\
                            chart.Chart().get_cell(i1, j1).army, \
                            chart.Chart().get_cell(self.i, self.j).army
                            mas_army[0], mas_army[1] = mas_army[1], mas_army[0]

                        if mas_army[0] != 1:
                            chart.Chart().get_cell(self.i, self.j).army,\
                            chart.Chart().get_cell(i1, j1).army =\
                            chart.Chart().get_cell(i1, j1).army, \
                            chart.Chart().get_cell(self.i, self.j).army

                        if len(chart.Chart().get_cell(self.i,
                                                      self.j).army.army):
                            self.x = chart.Chart().get_cell(i1, j1).center[0]
                            self.y = chart.Chart().get_cell(i1, j1).center[1]
                            self.xy = [
                                self.x + self.deviation_x,
                                self.y + self.deviation_y
                            ]
                            self.sprite.do(MoveTo(self.xy, self.move_time))

                            chart.Chart().get_cell(i1,j1).army.sprite.do(Blink(\
                                self.blink_times,self.move_time)+Hide())
                            chart.Chart().get_cell(i1, j1).leave_cell()
                            chart.Chart().get_cell(i1, j1).enter_cell(
                                chart.Chart().get_cell(self.i, self.j).army)
                            chart.Chart().get_cell(self.i, self.j).leave_cell()
                            self.i = i1
                            self.j = j1
                            self.move = False

                        else:
                            self.x = chart.Chart().get_cell(i1, j1).center[0]
                            self.y = chart.Chart().get_cell(i1, j1).center[1]
                            self.xy = [self.x, self.y]
                            self.sprite.do(
                                MoveTo(self.xy, self.move_time) +
                                Blink(self.blink_times, self.move_time) +
                                Hide())
                            chart.Chart().get_cell(self.i, self.j).leave_cell()

            elif army2 == None:
                chart.Chart().get_cell(i1, j1).enter_cell(army1)
                chart.Chart().get_cell(self.i, self.j).leave_cell()
                self.x = chart.Chart().get_cell(i1, j1).center[0]
                self.y = chart.Chart().get_cell(i1, j1).center[1]
                self.xy = [
                    self.x + self.deviation_x, self.y + self.deviation_y
                ]
                self.sprite.do(MoveTo(self.xy, self.move_time))

                self.i = i1
                self.j = j1
                self.move = False