import configparser
import pygame as pg
from modules.Swamp import Swamp


class Game:
    def __init__(self, difficulty):
        config = configparser.ConfigParser()
        config.read("conf/config.ini")
        sound = config['Settings']['sound']
        if sound == "True":
            print(sound)
            pg.mixer.init()
            pg.mixer.music.load('styles/background.mp3')
            pg.mixer.music.play(loops=-1)
            pg.init()
        size = 700, 500
        self.screen = pg.display.set_mode(size)
        pg.display.set_caption(difficulty)
        self.swamp = Swamp()
        self.swamp.set_view(120, 160, 35)
        self.swamp.set_book(400, 680, 460, 630)
        self.running = True

    def start(self):
        while self.running:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    self.running = False
                if event.type == pg.MOUSEBUTTONDOWN:
                    self.swamp.get_click(event.pos)
            self.screen.fill((93, 101, 48))
            self.swamp.render(self.screen)
            pg.display.flip()
