1 Python版蚊子大作战源代码-德赢Vwin官网 网

Python版蚊子大作战源代码

描述

 Python灭蚊小游戏源代码,超解压的灭蚊小游戏,通过消灭蚊子赚钱,屏幕里的蚊子不被消灭就会被蚊子吸血,通过商店购买血包、血瓶、血桶、回血针来使自己回血,也可以在商店购买不同的灭蚊工具:高级灭蚊拍、灭蚊喷课剂、灭蚊灯、提高房间温度等来提高灭蚊效率,可对游戏音效、全屏、语言进行设置。

    游戏玩法,移动鼠标,找准蚊子单击左键将其消灭。游戏中按Esc键来选择使用不同的道具,游戏中先按Esc键再按空格键即可进入主菜单页面(可由此进入商店),进行游戏道具的购买。

    直接运行main.py即可。

    完整Python版蚊子大作战源代码下载地址:

https://download.csdn.net/download/weixin_42756970/86794102

    游戏主菜单页面:

 

设置

游戏设置

 

设置

游戏商店
 

 

设置

游戏道具选择

 

设置

游戏
 

 

设置

核心程序代码

ort os
import tkinter.messagebox

import nathlib as nlib
import sys
import time

version_name = "snapshot_015"  # DO NOT FORGET TO CHANGE FILEMANAGER CONSTANTS !!!
version_number = 1

debug_mouse = False

if os.path.isfile("latest.log"):
    try:
        os.remove('latest.log')
    except Exception as e:
        nlib.log("Couldn't remove latest.log : {}".format(str(e)), "warn")
if not os.path.isfile("enable_logs.txt"):
    with open("enable_logs.txt", "w") as file:
        file.write("# Enable logging ? "yes" or "no"nDefaults to "no"to avoid unnecessary log file rewriting.n"
                   "You should let this parameter to "no" unless you have an error.nno")
enable_logs = "latest.log"
with open("enable_logs.txt", "r") as file:
    if file.readlines()[3].startswith("no"):
        enable_logs = None

nlib.start_logs(enable_logs)
nlib.log("Launching game version {0} ...".format(version_name), "info")


def exception_handler(type, value, traceback):
    nlib.log("{0}: {1}".format(repr(value).split("(")[0], value), "critical", 'main')
    from tkinter import Tk, messagebox
    root = Tk()
    root.attributes("-topmost", True)
    root.withdraw()
    messagebox.showerror("An error occurred", "{}: {}".format(repr(value).split("(")[0], value))
    root.destroy()
    sys.exit()


enable_exception_handler = False
if enable_exception_handler:
    sys.excepthook = exception_handler
enable_hash_checking = False  # Should only be enabled when released !!!

if enable_hash_checking:
    import hashlib

    hashes = [["LICENSE", "d5dc6d638156797c63fffd4bc908a3ec380e37d051996284736c6222438f3c9a"],
              ["nathlib.py", "e85f2234f4a8907d56f73a984a39b6fbcb8aa54e5bc82b62f11ad684eed83fa3"],
              ["README.MD", "70c728ac19b13ff9a343743ee5cf821d8dfea5d253201efbabbfc284d3951702"],
              ["settings_window.py", "17ca489a5fea4fe8243f6c6a4eaeaae8a004e9e10c0516bb4889688d7f02ecf2"],
              ["scripts/util/FileManager.py", "1c2c2e18c473429a0d3c1ee607adc1055eed3efe64bb5b1776b0eaff9acae0a3"],
              ["scripts/util/default/lang/en_US.py", "e32c190196fcbb4e55d07e5bc99d9f665fd9b7f9bf1dd98d72ffd04f2d0481c1"]
        ,
              ["scripts/util/default/lang/fr_FR.py", "b105710bdec2b292ebb3b8fa8782601c3786c1f3b9cb4a9d9410926d2dce280c"]
              ]

    for _hash in hashes:

        sha256_hash = hashlib.sha256()
        with open(_hash[0], "rb") as f:
            # Read and update hash string value in blocks of 4K
            for byte_block in iter(lambda: f.read(4096), b""):
                sha256_hash.update(byte_block)
            if sha256_hash.hexdigest() == _hash[1]:
                nlib.log("Successfully checked hash for '{0}'".format(_hash[0]), "info")
            else:
                nlib.log("File '{0}' got a different hash than expected !nExpected '{1}',nGot '{2}' !"
                         .format(_hash[0], _hash[1], sha256_hash.hexdigest()), "fatal")
                time.sleep(1)
                sys.exit()
else:
    nlib.log("Skipping hash checking !", "warn")

# Importation des modules

# try:
print("------------------------------Pygame--Details--------------------------")
import pygame

print("-----------------------------------------------------------------------")
import time
import random
import math
import tkinter as tk
from tkinter import simpledialog
import pygame.gfxdraw  # necessary as pygame doesn't load it by default !
from settings_window import open_settings
import ptext
import operator

# except ImportError:
# print("[ERROR]: Failed to import modules !")
# from sys import exit

# exit()

try:
    from scripts.util.FileManager import *

    for x in range(0, lang_number):
        exec("from scripts.util.FileManager import " + lang_files_to_load[x])
except:
    nlib.log("Failed to load resources, aborting ...", "critical")
    sys.exit()

# Initialisation de Pygame

pygame.init()
pygame.font.init()
if settings_list[2]:
    pygame.mixer.init()  # Sons de pygame.

# Definition de la fenêtre

window_x = 1280
window_y = 720
if not settings_list[3]:
    screen = pygame.display.set_mode((window_x, window_y))
else:
    screen = pygame.display.set_mode((window_x, window_y), pygame.FULLSCREEN | pygame.SCALED)
pygame.display.set_caption("NoMoskito!")
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
clock = pygame.time.Clock()
FPS = 60  # yeah, really !

# ressources à charger
shop_blood_bag = pygame.image.load("resources/blood_bag.png").convert_alpha()
shop_blood_bag = pygame.transform.scale(shop_blood_bag, (50, 50))
shop_blood_bottle = pygame.image.load("resources/blood_bottle.png").convert_alpha()
shop_blood_bottle = pygame.transform.scale(shop_blood_bottle, (80, 80))
shop_blood_barrel = pygame.image.load("resources/barrel_blood.png").convert_alpha()
shop_blood_barrel = pygame.transform.scale(shop_blood_barrel, (96, 96))
shop_blood_infusion = pygame.image.load("resources/blood_infusion.png").convert_alpha()
shop_blood_infusion = pygame.transform.scale(shop_blood_infusion, (176, 117))
swatter_pro = pygame.image.load("resources/swatter_pro.png").convert_alpha()
shop_swatter_pro = pygame.transform.scale(swatter_pro, (41, 275))
bzio_ruler = pygame.image.load("resources/imposant_ruler.png").convert_alpha()
shop_bzio_ruler = pygame.transform.scale(bzio_ruler, (128, 128))
pause_bzio_ruler = pygame.transform.rotate(shop_bzio_ruler, 90)
img_heat_wave = pygame.image.load("resources/hot.png").convert_alpha()
shop_heat_wave = pygame.transform.scale(img_heat_wave, (17, 48))
img_spray = pygame.image.load("resources/anti_moskito_spray.png").convert_alpha()
shop_spray = pygame.transform.scale(img_spray, (38, 85))
img_lamp = pygame.image.load("resources/anti_moskito_lamp.png").convert_alpha()
shop_lamp = pygame.transform.scale(img_lamp, (66, 95))
img_wait_bar_1 = pygame.image.load("resources/resource_0.png").convert_alpha()
img_icon = pygame.image.load("resources/resource_2.png").convert_alpha()
img_background = pygame.image.load("resources/resource_1.jpg").convert()
img_logo = pygame.image.load("resources/resource_4.png").convert_alpha()
img_btn_normal = pygame.image.load("resources/resource_5.png").convert()
img_btn_hovered = pygame.image.load("resources/resource_6.png").convert()
img_swatter_1 = pygame.image.load("resources/resource_8.png").convert_alpha()
pause_swatter_1 = pygame.transform.scale(img_swatter_1, (41, 275))
dark_img = pygame.image.load("resources/dark.png").convert_alpha()
init_img = pygame.image.load("resources/init.png").convert()
img_pix_wait_bar = pygame.Surface((1, 13))
img_pix_wait_bar.fill((104, 255, 4))
img_blood_bar = pygame.image.load("resources/resource_9.png").convert_alpha()
btn_font = pygame.font.Font("resources\ComicSansMSM.ttf", 30)
img_pix_blood_bar = pygame.Surface((38, 1))
img_pix_blood_bar.fill((255, 0, 0))
img_moskito_list = [pygame.image.load("resources/mosquito_1.png").convert_alpha(),
                    pygame.image.load("resources/mosquito_2.png").convert_alpha(),
                    pygame.image.load("resources/mosquito_3.png").convert_alpha(),
                    pygame.image.load("resources/mosquito_4.png").convert_alpha()]

shop_bg = pygame.Surface((1180, 660))
pygame.gfxdraw.rectangle(shop_bg, shop_bg.get_rect(), (206, 237, 31))
pygame.gfxdraw.rectangle(shop_bg, pygame.rect.Rect(1, 1, 1178, 658), (206, 237, 31))
pygame.gfxdraw.rectangle(shop_bg, pygame.rect.Rect(2, 2, 1176, 656), (206, 237, 31))
pygame.gfxdraw.box(shop_bg, pygame.rect.Rect(3, 3, 1174, 654), (235, 248, 165))
pygame.gfxdraw.box(shop_bg, pygame.rect.Rect(3, 3, 1174, 50), (220, 242, 96))
pause_bg = pygame.Surface((1280, 720))

shop_btn_ids = {"shop_btn_blood_2": 0,
                "shop_btn_blood_3": 1,
                "shop_btn_blood_4": 2,
                "shop_btn_blood_5": 3,
                "shop_btn_heat_wave": 6,
                "shop_btn_spray": 7,
                "shop_btn_lamp": 8}

sounds_moskitos_list = ["resources/sounds/Single_moskito_1.wav",
                        "resources/sounds/Single_moskito_2.wav",
                        "resources/sounds/Single_moskito_3.wav"]

img_tmp = pygame.Surface((4, 4))
img_tmp.fill((255, 255, 255))
font_a = pygame.font.Font("resources\ComicSansMSM.ttf", 70)

correction_angle = 90

opaque = 1055

spray_sound_obj = pygame.mixer.Sound("resources/sounds/Single_moskito_4.wav")#

pygame.display.set_icon(img_icon)

sprite_group = pygame.sprite.Group()

anti_moskito_spray = 0
moskito_lamp_time = 0

isMenu = True

pause_btn_list = []

# fichier lang

lang = lang_files_names[settings_list[0]]
default_lang = eval(lang)

play_btn_text = btn_font.render(default_lang[0], True, (153, 153, 0))
settings_btn_text = btn_font.render(default_lang[1], True, (153, 153, 0))
font_a_text = font_a.render(default_lang[11], True, (153, 153, 0))


def get_bziocoins():
    return get_better_score()[2]


def get_inventory():
    a = get_better_score()
    return [a[4], a[3]]


def remove_item_from_inventory(inv_list, item_id: int):  # remove 1 item and return the result
    tmp_list = []
    found = False
    for _i in inv_list:
        tmp_list.append(_i)  # simple way to copy two lists in python :/
    for item in range(0, len(inv_list)):
        if inv_list[item] == item_id:
            if not found:
                tmp_list.pop(item)
                found = True
    return tmp_list


def save_bziocoins(bziocoins):
    a = get_better_score()
    overwrite_better_score(a[0], a[1], bziocoins, a[3], a[4])


def save_inventory(inv, buy):  # buy = which swatter you bought.
    a = get_better_score()
    overwrite_better_score(a[0], a[1], a[2], buy, inv)


# definition du joueur
BLOOD = 600
blood_infusion = 0
blood_infusion_total = 0
blood_factor = 0

shop_hovered_id = -1


class Var:
    def __init__(self):
        super(Var, self).__init__()
        self.inventory = []
        self.change_fullscreen = False
        self.bziocoins = get_bziocoins()
        self.last_mouse = (0, 0)
        self.is_settings_to_save = False
        self.IsGamePaused = False
        self.is_update_checked = False
        self.isMenu = True
        self.can_click = True
        self.click_delay = 388
        self.click_rate = 1
        self.blood = BLOOD
        self.moskitos_killed = 0
        self.Playing = False
        self.Final_Menu = False
        self.chrono = 0  # ms
        self.latest_chrono = 0
        self.renew_sound = True
        self.enable_sound = settings_list[2]
        self.btn_hover_list = []
        self.btn_click_list = []
        self.Final_verdict = False
        self.shop = False
        self.best_score = [0, "nobody"]

    def set_value(self, var_name, var_value):
        if var_name == "is_settings_to_save":
            self.is_settings_to_save = var_value
        if var_name == "is_update_checked":
            self.is_update_checked = var_value

    def get_value(self, var_name):
        return eval("self." + var_name)


global_var = Var()
global_var.inventory = get_inventory()[0]


# class Player(pygame.sprite.Sprite):
#     def __init__(self):
#         super().__init__()
#         self.image = img_spaceship
#         self.rect = self.image.get_rect()  # Adapte le taille du personnage a la taille de l'image.
#         self.velocity = [0, 0]
#         self.rect.x = int(window_x / 2.15)
#         self.rect.y = int(window_y / 2.15)


# class Star(pygame.sprite.Sprite):
#     def __init__(self):
#         super().__init__()
#         self.image = img_star
#         self.rect = self.image.get_rect()  # Adapte le taille du personnage a la taille de l'image.
#         self.velocity = [0, 0]
#         self.rect.x = random.randint(0, window_x)
#         self.rect.y = random.randint(0, window_y)
#
#     def walk_with_degrees(self, degree, distance):
#         self.rect.y = int(self.rect.y + (distance * sin(degree)))
#         self.rect.x = int(self.rect.x + (distance * cos(degree)))
#
#     def update(self, angle_in):
#         self.walk_with_degrees(angle_in, 1)
FPS_COUNT = 0


class MoskitoSpawnHandler:
    def __init__(self):
        super(MoskitoSpawnHandler, self).__init__()
        self.time_spent = 0
        self.time_limit = 600
        self.moskito_list = []

    def update(self):
        self.time_spent = self.time_spent + 4
        _tmp = 1
        if global_var.blood < 295:
            _tmp = 2
        if global_var.blood < 196:
            _tmp = 3
        if global_var.blood < 147:
            _tmp = 4
        if self.time_spent > self.time_limit:
            self.time_spent = 0
            for moskito in range(0, random.randint(1, _tmp)):
                self.moskito_list.append(Moskito())
            self.time_limit = self.time_limit - (self.time_limit / 85)
        for msk in self.moskito_list:
            msk.update()

    完整Python版蚊子大作战源代码下载地址:

https://download.csdn.net/download/weixin_42756970/86794102

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分