Python-炸弹人【附完整源码】

炸弹人

炸弹人是童年的一款经典电子游戏,玩家控制一个类似"炸弹人"的角色,这个角色可以放置炸弹,并在指定的时间内引爆它们消灭敌人以达到目标,此游戏共设有两节关卡,代码如下:

运行效果:方向键控制上下左右, 点击空格键丢炸弹
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

一:主程序:

import sys
import cfg
import random
import pygame
from modules import *'''游戏主程序'''
def main(cfg):# 初始化pygame.init()pygame.mixer.init()pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.play(-1, 0.0)screen = pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('炸弹人')# 开始界面Interface(screen, cfg, mode='game_start')# 游戏主循环font = pygame.font.SysFont('Consolas', 15)for gamemap_path in cfg.GAMEMAPPATHS:# -地图map_parser = mapParser(gamemap_path, bg_paths=cfg.BACKGROUNDPATHS, wall_paths=cfg.WALLPATHS, blocksize=cfg.BLOCKSIZE)# -水果fruit_sprite_group = pygame.sprite.Group()used_spaces = []for i in range(5):coordinate = map_parser.randomGetSpace(used_spaces)used_spaces.append(coordinate)fruit_sprite_group.add(Fruit(random.choice(cfg.FRUITPATHS), coordinate=coordinate, blocksize=cfg.BLOCKSIZE))# -我方Herocoordinate = map_parser.randomGetSpace(used_spaces)used_spaces.append(coordinate)ourhero = Hero(imagepaths=cfg.HEROZELDAPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser, hero_name='ZELDA')# -电脑Heroaihero_sprite_group = pygame.sprite.Group()coordinate = map_parser.randomGetSpace(used_spaces)aihero_sprite_group.add(Hero(imagepaths=cfg.HEROBATMANPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser, hero_name='BATMAN'))used_spaces.append(coordinate)coordinate = map_parser.randomGetSpace(used_spaces)aihero_sprite_group.add(Hero(imagepaths=cfg.HERODKPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser, hero_name='DK'))used_spaces.append(coordinate)# -炸弹bombbomb_sprite_group = pygame.sprite.Group()# -用于判断游戏胜利或者失败的flagis_win_flag = False# -主循环screen = pygame.display.set_mode(map_parser.screen_size)clock = pygame.time.Clock()while True:dt = clock.tick(cfg.FPS)for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit(-1)# --↑↓←→键控制上下左右, 空格键丢炸弹elif event.type == pygame.KEYDOWN:if event.key == pygame.K_UP:ourhero.move('up')elif event.key == pygame.K_DOWN:ourhero.move('down')elif event.key == pygame.K_LEFT:ourhero.move('left')elif event.key == pygame.K_RIGHT:ourhero.move('right')elif event.key == pygame.K_SPACE:if ourhero.bomb_cooling_count <= 0:bomb_sprite_group.add(ourhero.generateBomb(imagepath=cfg.BOMBPATH, digitalcolor=cfg.YELLOW, explode_imagepath=cfg.FIREPATH))screen.fill(cfg.WHITE)# --电脑Hero随机行动for hero in aihero_sprite_group:action, flag = hero.randomAction(dt)if flag and action == 'dropbomb':bomb_sprite_group.add(hero.generateBomb(imagepath=cfg.BOMBPATH, digitalcolor=cfg.YELLOW, explode_imagepath=cfg.FIREPATH))# --吃到水果加生命值(只要是Hero, 都能加)ourhero.eatFruit(fruit_sprite_group)for hero in aihero_sprite_group:hero.eatFruit(fruit_sprite_group)# --游戏元素都绑定到屏幕上map_parser.draw(screen)for bomb in bomb_sprite_group:if not bomb.is_being:bomb_sprite_group.remove(bomb)explode_area = bomb.draw(screen, dt, map_parser)if explode_area:# --爆炸火焰范围内的Hero生命值将持续下降if ourhero.coordinate in explode_area:ourhero.health_value -= bomb.harm_valuefor hero in aihero_sprite_group:if hero.coordinate in explode_area:hero.health_value -= bomb.harm_valuefruit_sprite_group.draw(screen)for hero in aihero_sprite_group:hero.draw(screen, dt)ourhero.draw(screen, dt)# --左上角显示生命值pos_x = showText(screen, font, text=ourhero.hero_name+'(our):'+str(ourhero.health_value), color=cfg.YELLOW, position=[5, 5])for hero in aihero_sprite_group:pos_x, pos_y = pos_x+15, 5pos_x = showText(screen, font, text=hero.hero_name+'(ai):'+str(hero.health_value), color=cfg.YELLOW, position=[pos_x, pos_y])# --我方玩家生命值小于等于0/电脑方玩家生命值均小于等于0则判断游戏结束if ourhero.health_value <= 0:is_win_flag = Falsebreakfor hero in aihero_sprite_group:if hero.health_value <= 0:aihero_sprite_group.remove(hero)if len(aihero_sprite_group) == 0:is_win_flag = Truebreakpygame.display.update()clock.tick(cfg.FPS)if is_win_flag:Interface(screen, cfg, mode='game_switch')else:breakInterface(screen, cfg, mode='game_end')'''run'''
if __name__ == '__main__':while True:main(cfg)

二:配置文件 – cfg.py

import os'''屏幕大小'''
SCREENSIZE = (640, 480)
'''块大小'''
BLOCKSIZE = 30
'''FPS'''
FPS = 30
'''游戏地图路径'''
GAMEMAPPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/maps/1.map', 'resources/maps/2.map']]
'''墙路径'''
WALLPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/misc/wall0.png', 'resources/images/misc/wall1.png', 'resources/images/misc/wall2.png']]
'''英雄路径'''
HERODKPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/dk/left.png', 'resources/images/dk/right.png', 'resources/images/dk/up.png', 'resources/images/dk/down.png']]
HEROZELDAPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/zelda/left.png', 'resources/images/zelda/right.png', 'resources/images/zelda/up.png', 'resources/images/zelda/down.png']]
HEROBATMANPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/batman/left.png', 'resources/images/batman/right.png', 'resources/images/batman/up.png', 'resources/images/batman/down.png']]
'''水果路径'''
FRUITPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/misc/banana.png', 'resources/images/misc/cherry.png']]
'''背景路径'''
BACKGROUNDPATHS = [os.path.join(os.getcwd(), path) for path in \['resources/images/misc/bg0.png', 'resources/images/misc/bg1.png', 'resources/images/misc/bg2.png']]
'''爆炸和发射路径'''
BOMBPATH = os.path.join(os.getcwd(), 'resources/images/misc/bomb.png')
FIREPATH = os.path.join(os.getcwd(), 'resources/images/misc/fire.png')
'''背景音乐'''
BGMPATH = os.path.join(os.getcwd(), 'resources/audio/bgm.mp3')
'''一些颜色'''
YELLOW = (255, 255, 0)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

三:素材包 – resources

(1)audio文件:

bgm.mps音乐大家自己去找然后设置就好

(2)images文件:

图片太多了,做不到全部放置,大家根据配置文件自己去弄就好,或者私信我,我单独给大家发

(3)maps文件:

#1.map
xxxxxxxxxxxxx
x00000000000x
x0x0x0x0x0x0x
x00000000000x
x0x0x0x0x0x0x
x00000000000x
x0x0x0x0x0x0x
x00000000000x
x0x0x0x0x0x0x
x00000000000x
xxxxxxxxxxxxx
#2.map
2222222222222222222222222
2wwwww2wwwww2wwwww2wwwww2
2222222222222222222222222
2zz2zz2x1x1x1x1x1x2zz2zz2
2zz2zz2111111111112zz2zz2
2222222x1x1x1x1x1x2222222
2wwwww2111111111112wwwww2
2222222x1x1x1x1x1x2222222
2zz2zz2111111111112zz2zz2
2zz2zz2x1x1x1x1x1x2zz2zz2
2222222222222222222222222
2wwwww2wwwww2wwwww2wwwww2
2222222222222222222222222

四:文件包 – modules

(1)__init__.py

'''初始化'''
from .MAP import mapParser
from .misc import showText, Button, Interface
from .Sprites import Wall, Background, Fruit, Bomb, Hero

(2)MAP.py

import random
from .Sprites import *'''.map文件解析器'''
class mapParser():def __init__(self, mapfilepath, bg_paths, wall_paths, blocksize, **kwargs):self.instances_list = self.__parse(mapfilepath)self.bg_paths = bg_pathsself.wall_paths = wall_pathsself.blocksize = blocksizeself.height = len(self.instances_list)self.width = len(self.instances_list[0])self.screen_size = (blocksize * self.width, blocksize * self.height)'''地图画到屏幕上'''def draw(self, screen):for j in range(self.height):for i in range(self.width):instance = self.instances_list[j][i]if instance == 'w':elem = Wall(self.wall_paths[0], [i, j], self.blocksize)elif instance == 'x':elem = Wall(self.wall_paths[1], [i, j], self.blocksize)elif instance == 'z':elem = Wall(self.wall_paths[2], [i, j], self.blocksize)elif instance == '0':elem = Background(self.bg_paths[0], [i, j], self.blocksize)elif instance == '1':elem = Background(self.bg_paths[1], [i, j], self.blocksize)elif instance == '2':elem = Background(self.bg_paths[2], [i, j], self.blocksize)else:raise ValueError('instance parse error in mapParser.draw...')elem.draw(screen)'''随机获取一个空地'''def randomGetSpace(self, used_spaces=None):while True:i = random.randint(0, self.width-1)j = random.randint(0, self.height-1)coordinate = [i, j]if used_spaces and coordinate in used_spaces:continueinstance = self.instances_list[j][i]if instance in ['0', '1', '2']:breakreturn coordinate'''根据坐标获取元素类型'''def getElemByCoordinate(self, coordinate):return self.instances_list[coordinate[1]][coordinate[0]]'''解析.map文件'''def __parse(self, mapfilepath):instances_list = []with open(mapfilepath) as f:for line in f.readlines():instances_line_list = []for c in line:if c in ['w', 'x', 'z', '0', '1', '2']:instances_line_list.append(c)instances_list.append(instances_line_list)return instances_list

(3)misc.py

import sys
import pygame'''在屏幕指定位置显示文字'''
def showText(screen, font, text, color, position):text_render = font.render(text, True, color)rect = text_render.get_rect()rect.left, rect.top = positionscreen.blit(text_render, rect)return rect.right'''按钮'''
def Button(screen, position, text, buttoncolor=(120, 120, 120), linecolor=(20, 20, 20), textcolor=(255, 255, 255), bwidth=200, bheight=50):left, top = positionpygame.draw.line(screen, linecolor, (left, top), (left+bwidth, top), 5)pygame.draw.line(screen, linecolor, (left, top-2), (left, top+bheight), 5)pygame.draw.line(screen, linecolor, (left, top+bheight), (left+bwidth, top+bheight), 5)pygame.draw.line(screen, linecolor, (left+bwidth, top+bheight), (left+bwidth, top), 5)pygame.draw.rect(screen, buttoncolor, (left, top, bwidth, bheight))font = pygame.font.SysFont('Consolas', 30)text_render = font.render(text, 1, textcolor)rect = text_render.get_rect()rect.centerx, rect.centery = left + bwidth / 2, top + bheight / 2return screen.blit(text_render, rect)'''游戏开始/关卡切换/游戏结束界面'''
def Interface(screen, cfg, mode='game_start'):pygame.display.set_mode(cfg.SCREENSIZE)if mode == 'game_start':clock = pygame.time.Clock()while True:screen.fill((41, 36, 33))button_1 = Button(screen, (220, 150), 'START')button_2 = Button(screen, (220, 250), 'QUIT')for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit(-1)elif event.type == pygame.MOUSEBUTTONDOWN:if button_1.collidepoint(pygame.mouse.get_pos()):return Trueelif button_2.collidepoint(pygame.mouse.get_pos()):pygame.quit()sys.exit(-1)pygame.display.update()clock.tick(cfg.FPS)elif mode == 'game_switch':clock = pygame.time.Clock()while True:screen.fill((41, 36, 33))button_1 = Button(screen, (220, 150), 'NEXT')button_2 = Button(screen, (220, 250), 'QUIT')for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit(-1)elif event.type == pygame.MOUSEBUTTONDOWN:if button_1.collidepoint(pygame.mouse.get_pos()):return Trueelif button_2.collidepoint(pygame.mouse.get_pos()):pygame.quit()sys.exit(-1)pygame.display.update()clock.tick(cfg.FPS)elif mode == 'game_end':clock = pygame.time.Clock()while True:screen.fill((41, 36, 33))button_1 = Button(screen, (220, 150), 'RESTART')button_2 = Button(screen, (220, 250), 'QUIT')for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit(-1)elif event.type == pygame.MOUSEBUTTONDOWN:if button_1.collidepoint(pygame.mouse.get_pos()):return Trueelif button_2.collidepoint(pygame.mouse.get_pos()):pygame.quit()sys.exit(-1)pygame.display.update()clock.tick(cfg.FPS)else:raise ValueError('Interface.mode unsupport %s...' % mode)

(4)Sprites.py

import copy
import random
import pygame'''墙类'''
class Wall(pygame.sprite.Sprite):def __init__(self, imagepath, coordinate, blocksize, **kwargs):pygame.sprite.Sprite.__init__(self)self.image = pygame.image.load(imagepath)self.image = pygame.transform.scale(self.image, (blocksize, blocksize))self.rect = self.image.get_rect()self.rect.left, self.rect.top = coordinate[0] * blocksize, coordinate[1] * blocksizeself.coordinate = coordinateself.blocksize = blocksize'''画到屏幕上'''def draw(self, screen):screen.blit(self.image, self.rect)return True'''背景类'''
class Background(pygame.sprite.Sprite):def __init__(self, imagepath, coordinate, blocksize, **kwargs):pygame.sprite.Sprite.__init__(self)self.image = pygame.image.load(imagepath)self.image = pygame.transform.scale(self.image, (blocksize, blocksize))self.rect = self.image.get_rect()self.rect.left, self.rect.top = coordinate[0] * blocksize, coordinate[1] * blocksizeself.coordinate = coordinateself.blocksize = blocksize'''画到屏幕上'''def draw(self, screen):screen.blit(self.image, self.rect)return True'''水果类'''
class Fruit(pygame.sprite.Sprite):def __init__(self, imagepath, coordinate, blocksize, **kwargs):pygame.sprite.Sprite.__init__(self)self.kind = imagepath.split('/')[-1].split('.')[0]if self.kind == 'banana':self.value = 5elif self.kind == 'cherry':self.value = 10else:raise ValueError('Unknow fruit %s...' % self.kind)self.image = pygame.image.load(imagepath)self.image = pygame.transform.scale(self.image, (blocksize, blocksize))self.rect = self.image.get_rect()self.rect.left, self.rect.top = coordinate[0] * blocksize, coordinate[1] * blocksizeself.coordinate = coordinateself.blocksize = blocksize'''画到屏幕上'''def draw(self, screen):screen.blit(self.image, self.rect)return True'''炸弹类'''
class Bomb(pygame.sprite.Sprite):def __init__(self, imagepath, coordinate, blocksize, digitalcolor, explode_imagepath, **kwargs):pygame.sprite.Sprite.__init__(self)self.image = pygame.image.load(imagepath)self.image = pygame.transform.scale(self.image, (blocksize, blocksize))self.explode_imagepath = explode_imagepathself.rect = self.image.get_rect()# 像素位置self.rect.left, self.rect.top = coordinate[0] * blocksize, coordinate[1] * blocksize# 坐标(元素块为单位长度)self.coordinate = coordinateself.blocksize = blocksize# 爆炸倒计时self.explode_millisecond = 6000 * 1 - 1self.explode_second = int(self.explode_millisecond / 1000)self.start_explode = False# 爆炸持续时间self.exploding_count = 1000 * 1# 炸弹伤害能力self.harm_value = 1# 该炸弹是否还存在self.is_being = Trueself.font = pygame.font.SysFont('Consolas', 20)self.digitalcolor = digitalcolor'''画到屏幕上'''def draw(self, screen, dt, map_parser):if not self.start_explode:# 爆炸倒计时self.explode_millisecond -= dtself.explode_second = int(self.explode_millisecond / 1000)if self.explode_millisecond < 0:self.start_explode = Truescreen.blit(self.image, self.rect)text = self.font.render(str(self.explode_second), True, self.digitalcolor)rect = text.get_rect(center=(self.rect.centerx-5, self.rect.centery+5))screen.blit(text, rect)return Falseelse:# 爆炸持续倒计时self.exploding_count -= dtif self.exploding_count > 0:return self.__explode(screen, map_parser)else:self.is_being = Falsereturn False'''爆炸效果'''def __explode(self, screen, map_parser):explode_area = self.__calcExplodeArea(map_parser.instances_list)for each in explode_area:image = pygame.image.load(self.explode_imagepath)image = pygame.transform.scale(image, (self.blocksize, self.blocksize))rect = image.get_rect()rect.left, rect.top = each[0] * self.blocksize, each[1] * self.blocksizescreen.blit(image, rect)return explode_area'''计算爆炸区域'''def __calcExplodeArea(self, instances_list):explode_area = []# 区域计算规则为墙可以阻止爆炸扩散, 且爆炸范围仅在游戏地图范围内for ymin in range(self.coordinate[1], self.coordinate[1]-5, -1):if ymin < 0 or instances_list[ymin][self.coordinate[0]] in ['w', 'x', 'z']:breakexplode_area.append([self.coordinate[0], ymin])for ymax in range(self.coordinate[1]+1, self.coordinate[1]+5):if ymax >= len(instances_list) or instances_list[ymax][self.coordinate[0]] in ['w', 'x', 'z']:breakexplode_area.append([self.coordinate[0], ymax])for xmin in range(self.coordinate[0], self.coordinate[0]-5, -1):if xmin < 0 or instances_list[self.coordinate[1]][xmin] in ['w', 'x', 'z']:breakexplode_area.append([xmin, self.coordinate[1]])for xmax in range(self.coordinate[0]+1, self.coordinate[0]+5):if xmax >= len(instances_list[0]) or instances_list[self.coordinate[1]][xmax] in ['w', 'x', 'z']:breakexplode_area.append([xmax, self.coordinate[1]])return explode_area'''角色类'''
class Hero(pygame.sprite.Sprite):def __init__(self, imagepaths, coordinate, blocksize, map_parser, **kwargs):pygame.sprite.Sprite.__init__(self)self.imagepaths = imagepathsself.image = pygame.image.load(imagepaths[-1])self.image = pygame.transform.scale(self.image, (blocksize, blocksize))self.rect = self.image.get_rect()self.rect.left, self.rect.top = coordinate[0] * blocksize, coordinate[1] * blocksizeself.coordinate = coordinateself.blocksize = blocksizeself.map_parser = map_parserself.hero_name = kwargs.get('hero_name')# 生命值self.health_value = 50# 炸弹冷却时间self.bomb_cooling_time = 5000self.bomb_cooling_count = 0# 随机移动冷却时间(仅AI电脑用)self.randommove_cooling_time = 100self.randommove_cooling_count = 0'''角色移动'''def move(self, direction):self.__updateImage(direction)if direction == 'left':if self.coordinate[0]-1 < 0 or self.map_parser.getElemByCoordinate([self.coordinate[0]-1, self.coordinate[1]]) in ['w', 'x', 'z']:return Falseself.coordinate[0] = self.coordinate[0] - 1elif direction == 'right':if self.coordinate[0]+1 >= self.map_parser.width or self.map_parser.getElemByCoordinate([self.coordinate[0]+1, self.coordinate[1]]) in ['w', 'x', 'z']:return Falseself.coordinate[0] = self.coordinate[0] + 1elif direction == 'up':if self.coordinate[1]-1 < 0 or self.map_parser.getElemByCoordinate([self.coordinate[0], self.coordinate[1]-1]) in ['w', 'x', 'z']:return Falseself.coordinate[1] = self.coordinate[1] - 1elif direction == 'down':if self.coordinate[1]+1 >= self.map_parser.height or self.map_parser.getElemByCoordinate([self.coordinate[0], self.coordinate[1]+1]) in ['w', 'x', 'z']:return Falseself.coordinate[1] = self.coordinate[1] + 1else:raise ValueError('Unknow direction %s...' % direction)self.rect.left, self.rect.top = self.coordinate[0] * self.blocksize, self.coordinate[1] * self.blocksizereturn True'''随机行动(AI电脑用)'''def randomAction(self, dt):# 冷却倒计时if self.randommove_cooling_count > 0:self.randommove_cooling_count -= dtaction = random.choice(['left', 'left', 'right', 'right', 'up', 'up', 'down', 'down', 'dropbomb'])flag = Falseif action in ['left', 'right', 'up', 'down']:if self.randommove_cooling_count <= 0:flag = Trueself.move(action)self.randommove_cooling_count = self.randommove_cooling_timeelif action in ['dropbomb']:if self.bomb_cooling_count <= 0:flag = Trueself.bomb_cooling_count = self.bomb_cooling_timereturn action, flag'''生成炸弹'''def generateBomb(self, imagepath, digitalcolor, explode_imagepath):return Bomb(imagepath=imagepath, coordinate=copy.deepcopy(self.coordinate), blocksize=self.blocksize, digitalcolor=digitalcolor, explode_imagepath=explode_imagepath)'''画到屏幕上'''def draw(self, screen, dt):# 冷却倒计时if self.bomb_cooling_count > 0:self.bomb_cooling_count -= dtscreen.blit(self.image, self.rect)return True'''吃水果'''def eatFruit(self, fruit_sprite_group):eaten_fruit = pygame.sprite.spritecollide(self, fruit_sprite_group, True, None)for fruit in eaten_fruit:self.health_value += fruit.value'''更新角色朝向'''def __updateImage(self, direction):directions = ['left', 'right', 'up', 'down']idx = directions.index(direction)self.image = pygame.image.load(self.imagepaths[idx])self.image = pygame.transform.scale(self.image, (self.blocksize, self.blocksize))

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/211428.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

二叉搜索树——模拟

对于一个无穷的满二叉排序树&#xff08;如图&#xff09;&#xff0c;节点的编号是1,2,3&#xff0c;…。对于一棵树根为X的子树&#xff0c;沿着左节点一直往下到最后一层&#xff0c;可以获得该子树编号最小的节点&#xff1b;沿着右节点一直往下到最后一层&#xff0c;可以…

『亚马逊云科技产品测评』活动征文| 基于etcd实现服务发现

提示&#xff1a;授权声明&#xff1a;本篇文章授权活动官方亚马逊云科技文章转发、改写权&#xff0c;包括不限于在 Developer Centre, 知乎&#xff0c;自媒体平台&#xff0c;第三方开发者媒体等亚马逊云科技官方渠道 背景 etcd 是一个分布式 Key-Value 存储系统&#xff0…

IP地址定位不准确的情况研究

在互联网的浩瀚海洋中&#xff0c;每一台连接到网络的设备都被赋予了一个独特的标识符&#xff0c;这就是IP地址。它就像是我们在线身份的一部分&#xff0c;帮助我们与他人进行通信&#xff0c;获取信息&#xff0c;以及享受各种网络服务。然而&#xff0c;由于各种原因&#…

【LVS实战】04 LVS+Keepalived实现负载均衡高可用

一、介绍 Keepalived 是一个用于 Linux 平台的高可用性软件。它实现了虚拟路由器冗余协议 (VRRP) 和健康检查功能&#xff0c;可以用于确保在多台服务器之间提供服务的高可用性。Keepalived 可以检测服务器的故障&#xff0c;并在主服务器宕机时&#xff0c;自动将备份服务器提…

哈希表及其基础(java详解)

目录 一、哈希表基础 二、哈希函数的设计 哈希函数的设计原则 三、java中的hashCode 基本数据类型的hashCode使用 自定义类型的hashCode使用 需要注意 四、哈希冲突的处理 链地址法Seperate Chaining 五、实现属于我们自己的哈希表 六、哈希表的动态空间处理和复杂…

10、外观模式(Facade Pattern,不常用)

外观模式&#xff08;Facade Pattern&#xff09;也叫作门面模式&#xff0c;通过一个门面&#xff08;Facade&#xff09;向客户端提供一个访问系统的统一接口&#xff0c;客户端无须关心和知晓系统内部各子模块&#xff08;系统&#xff09;之间的复杂关系&#xff0c;其主要…

vscode插件离线下载

离线下载插件地址&#xff1a;https://marketplace.visualstudio.com/VSCode

SQL server 基线安全加固操作

目录 账号管理、认证授权 ELK-Mssql-01-01-01 ELK-Mssql-01-01-02 ELK-Mssql-01-01-03 ​​​​​​​ ELK-Mssql-01-01-04 ​​​​​​​ ELK-Mssql-01-01-05 ​​​​​​​ELK-Mssql-01-01-06 日志配置 ELK-Mssql-02-01-01 通信协议 ELK-Mssql-03-01-01 ​​​​​…

【i.MX6ULL】linux驱动bh1750模块

I2C-BH1750 1、设备地址 引脚说明 VCC5VGNDGNDSCLPB6SDAPB7ADDRVCC/GND bh1750设备的地址由引脚 ADDR 来决定 ADDR接GND 当ADDR引脚接地时设备bh1750的地址为&#xff1a;0x23(7bit) ADDR接VCC 当ADDR引脚接地时设备bh1750的地址为&#xff1a;0x5c(7bit) 2、工作模式 …

基于深度学习CRNN的水表读数识别系统

1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 研究背景与意义 随着科技的不断发展&#xff0c;深度学习技术在各个领域都取得了显著的成果。其中&#xff0c;基于深度学习的图像识别技术在计算机视觉领域具有重要的应用价值。…

Linux 多线程(C语言) 备查

基础 1&#xff09;线程在运行态和就绪态不停的切换。 2&#xff09;每个线程都有自己的栈区和寄存器 1&#xff09;进程是资源分配的最小单位&#xff0c;线程是操作系统调度执行的最小单位 2&#xff09;线程的上下文切换的速度比进程快得多 3&#xff09;从应用程序A中启用应…

制作一个RISC-V的操作系统四-嵌入式开发介绍

文章目录 什么是嵌入式开发交叉编译查看一些GCC文件夹 调试器GDB相关语法命令 模拟器QEMUQEMU的安装和使用项目构造工具MakeMakeFile的构成make的运行 练习4-1练习4-2练习4-3 什么是嵌入式开发 程序跑到开发板上&#xff0c;或者说运行到硬件上 交叉编译 简单理解交叉编译来说…

API自动化测试:如何构建高效的测试流程

一、引言 在当前的软件开发环境中&#xff0c;API&#xff08;Application Programming Interface&#xff09;扮演了极为重要的角色&#xff0c;连接着应用的各个部分。对API进行自动化测试能够提高测试效率&#xff0c;降低错误&#xff0c;确保软件产品的质量。本文将通过实…

LeetCode 每日一题 Day 5【Hard】

2646. 最小化旅行的价格总和 现有一棵无向、无根的树&#xff0c;树中有 n 个节点&#xff0c;按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges &#xff0c;其中 edges[i] [ai, bi] 表示树中节点 ai 和 b~i ~之间存在一条边。 每个节点都关…

OpenResty入门与实践:下载安装、环境变量、常用命令及案例解析

文章目录 一、Openresty下载安装二、设置环境变量三、常用命令四、入门案例五、实践案例1、lua-nginx-module1&#xff09;入门案例2&#xff09;获取Nginx uri中的单一变量3&#xff09;获取Nginx uri中的所有变量 2、Nginx缓存1&#xff09;Nginx全局共享内存缓存2&#xff0…

使用 MITRE ATTCK® 框架缓解网络安全威胁

什么是MITRE ATT&CK框架 MITRE Adversarial Tactics&#xff0c; Techniques&#xff0c; and Common Knowledge&#xff08;ATT&CK&#xff09;是一个威胁建模框架&#xff0c;用于对攻击者用来入侵企业、云和工业控制系统&#xff08;ICS&#xff09;并发起网络攻击…

《PFL》论文阅读笔记

一、概要 随着联邦学习的发展&#xff0c;简单的聚合算法已经不在有效。但复杂的聚合算法使得联邦学习训练时间出现新的瓶颈。本文提出了并行联邦学习&#xff08;parallel federated learning&#xff0c;PFL&#xff09;&#xff0c;通过调换中心节点聚合和广播的顺序。本文…

OpenHarmony亮相MTSC 2023 | 质量效率共进,赋能应用生态发展

11月25日&#xff0c;MTSC 2023第十二届中国互联网测试开发大会在深圳登喜路国际大酒店圆满举行。大会以“软件质量保障体系和测试研发技术交流”为主要目的&#xff0c;旨在为行业搭建一个深入探讨和交流的桥梁和平台。OpenAtom OpenHarmony&#xff08;简称“OpenHarmony”&a…

Spring Boot与Mybatis基础配置(手动写增删改查)

一、 配置 1.新建项目 1.项目基础配置 解释&#xff1a;记得把这个改成start.aliyun.com要不没有java8也就是jdk1.8 2.项目依赖配置 2.配置maven 配置前&#xff1a; 配置后&#xff1a; 3.创建子项目并配置父子项目pom.xml 配置父pom.xml 声明当前项目不是要打成jar包的…

反序列化漏洞详解(二)

目录 pop链前置知识&#xff0c;魔术方法触发规则 pop构造链解释&#xff08;开始烧脑了&#xff09; 字符串逃逸基础 字符减少 字符串逃逸基础 字符增加 实例获取flag 字符串增多逃逸 字符串减少逃逸 延续反序列化漏洞(一)的内容 pop链前置知识&#xff0c;魔术方法触…