Ejemplo n.º 1
0
def EscM_detect_presses():
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            stateMouse = pygame.mouse.get_pressed()
            if stateMouse[0] == 1:
                if Button1.pressed():
                    print("Button 1 pressed")
                    config.window = "Main"
                    config.firsttime = True
                if Button2.pressed():
                    config.window = "MainMenu"
                    config.firsttime = True
                if Button3.pressed():
                    Saving.save()
                    config.window = "MainMenu"
                    config.firsttime = True
                if Button4.pressed():
                    pygame.quit()
                    sys.exit()


        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                config.window = "Main"
                config.firsttime = True


        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
Ejemplo n.º 2
0
def game_intro():
    
    #intro = True

    #while intro:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if NewGame.pressed():
                config.window="PlayerMenu"
            if QuitGame.pressed():
                pygame.quit()
                quit()
            if Settings.pressed():
                config.window="SettingMenu"
            if LoadGame.pressed():
                Saving.load()
                config.window = "Main"
                config.firsttime = True


    #Music.MenuMusic()
    Graphics_game.draw_background()
    NewGame.draw(500,450,config.setDisplay)
    QuitGame.draw(765,780,config.setDisplay)
    LoadGame.draw(600,650,config.setDisplay)
    Settings.draw(615,780,config.setDisplay)
    #Graphics_game.draw_socialmedia((1200,800))
    largeText = pygame.font.SysFont("algerian",135)
    TextSurf, TextRect = text_objects("Frequency", largeText)
    TextRect.center = ((display_width/2),(display_height/3.5))
    config.setDisplay.blit(TextSurf, TextRect)

   # button("New Game",500,450,500,150,green,bright_green,secondscreen)
   # button("Quit",780,780,100,100,red,bright_red,quitgame)
   # button("Load Game",600,650,300,80,yellow,bright_yellow,quitgame)
   # button("Settings",620,780,100,100,blue,bright_blue,quitgame)
        
    #pygame.draw.rect(gameDisplay, red, (500,450,100,50))
    #if 500+100 > mouse[0] > 500 and 450+50 > mouse[1] > 450:
        #pygame.draw.rect(gameDisplay, bright_red, (500,450,100,50))
    #else:
        #pygame.draw.rect(gameDisplay, red, (500,450,100,50))

    #pygame.display.update()
    #clock.tick(15)

#game_intro()
#pygame.quit()
#quit()
Ejemplo n.º 3
0
m.overwrite = True
m.tsave_snapshots = 1000
m.tsnaps = m.tsave_snapshots
m.tdiags = 1000
#m.path=base_path+"/outout2"
fields = ['t', 'q']

# just for testing
m.tmax = m.tmax

ke = []
t = []
k = 1

kmean = 0
Saving.initialize_save_snapshots(m, save_path)

for i in m.run_with_snapshots(tsnapstart=0, tsnapint=2000):

    ke.append(m._calc_ke())
    t.append(m.t)

    if m._calc_cfl() > .3:
        m.dt = m.dt / 5.

    Saving.save_snapshots(m, fields=fields)

evolvingstats = dict()
evolvingstats[t] = t
evolvingstats[ke] = ke
Ejemplo n.º 4
0
def MapMaker(args, outPrioQueue=None):
    """
    Manages the creation of the specified data.
    
    param: args: A struct like class that provides a field for every possible option.
                 Needed fields and their default values are:
        
                    class Args():
                        
                        pathToImage = None
                        bl = []
                        name = None
                        twoD = False
                        p = True
                        bp = True
                        ba = True
                        s = True
                        minY = 4
                        maxY = 250
                        maxS = 129
                        v = False
                        
          outPrioQueue: A queue.PriorityQueue(). If provided, this will be used as output channel.
                        If None, the output uses print().
                        
    Exception: Raises IOError, VauleError
    """

    #Managing communication with GUI

    prioCounter = itertools.count()

    def print2(tulpe):
        print(tulpe[1])

    if outPrioQueue == None:

        newPrint = print2

    else:

        newPrint = outPrioQueue.put

    #Settings
    if args.v:
        try:
            with open("version") as vFile:
                newPrint((prioCounter.__next__(), vFile.read()))
        except IOError:
            newPrint((prioCounter.__next__(), "Version file not found"))

    newPrint((prioCounter.__next__(), "Setting up"))

    imagePath = os.path.abspath(args.pathToImage)

    if not os.path.isfile(imagePath):
        raise IOError("path does not point at a file")

    if args.n == None:
        imageName = os.path.split(os.path.splitext(imagePath)[0])[1]
    else:
        imageName = re.sub(r'[^a-zA-Z0-9_]', '', args.n)

    if args.twoD:
        mapColorIDDic = MapColorIDGenerator.mapColorIDGenerator2D(args.bl)
    else:
        mapColorIDDic = MapColorIDGenerator.mapColorIDGenerator3D(args.bl)

    positionMatrixMinY = int(args.minY) if args.minY else 4

    positionMatrixMaxY = int(args.maxY) if args.maxY else 250

    if 0 > positionMatrixMinY or positionMatrixMinY > 251:
        raise ValueError("minY is smaller 0 or bigger 251")

    if 4 > positionMatrixMaxY or positionMatrixMaxY > 255:
        raise ValueError("maxY is smaller 4 or bigger 255")

    if positionMatrixMinY >= positionMatrixMaxY - 3:
        raise ValueError(
            "minY and maxY are to close toadd_gether (closer than 4) or minY is bigger than maxY"
        )

    maxSchematicSize = int(args.maxS) if args.maxS else 129

    if maxSchematicSize < 1:
        raise ValueError("maxS is smaller than 1")
    elif maxSchematicSize > 129:
        newPrint((prioCounter.__next__(
        ), "Your schematic size is bigger 129. be careful when importing such large schematics"
                  ))

    newPrint((prioCounter.__next__(), "Finished setting up"))

    #Calculating intermediaries

    newPrint((prioCounter.__next__(), "Calculating rgbMatrix"))
    rgbMatrix = Parsers.imageFileToRGBMatrix(imagePath)
    newPrint((prioCounter.__next__(), "Done"))

    newPrint((prioCounter.__next__(), "Calculating mapColorIDMatrix"))
    mapColorIDMatrix = Parsers.rgbMatrixTomapColorID(rgbMatrix, mapColorIDDic)
    newPrint((prioCounter.__next__(), "Done"))

    if args.bp or args.s:
        newPrint((prioCounter.__next__(), "Calculating positionMatrix"))
        positionMatrix = Parsers.mapColorIDToPositionMatrix(
            mapColorIDMatrix, positionMatrixMinY, positionMatrixMaxY)
        newPrint((prioCounter.__next__(), "Done"))

    if args.s:
        newPrint((prioCounter.__next__(), "Calculating Schematic"))
        tag_Compound_List = Parsers.positionMatrixToTag_CompoundList(
            positionMatrix, mapColorIDDic, positionMatrixMinY,
            positionMatrixMaxY, maxSchematicSize)
        newPrint((prioCounter.__next__(), "Done"))

    #Calculating and saving results

    if args.ba:
        newPrint((prioCounter.__next__(), "Saving AmountTXT"))
        Saving.saveAmountTxT(mapColorIDMatrix, mapColorIDDic, imageName)

    if args.bp:
        newPrint((prioCounter.__next__(), "Saving PositionTXT"))
        Saving.saveBlockPositionTxT(positionMatrix, mapColorIDDic, imageName)

    if args.p:
        newPrint((prioCounter.__next__(), "Saving Image"))
        Saving.saveImage(mapColorIDMatrix, mapColorIDDic, imageName)

    if args.s:
        newPrint((prioCounter.__next__(), "Saving Schematic"))
        Saving.saveSchematic(tag_Compound_List, imageName)

    newPrint((prioCounter.__next__(), "Finished with this image"))
Ejemplo n.º 5
0
def loadButton():
    state = Saving.loadState()
    if state:
        Board.boardState = state[0]
        GameState.s.setCurrentPlayer(state[1])
        GameState.s.setGameState(2)
Ejemplo n.º 6
0
def saveButton():
    board = Board.boardState
    cPlayer = GameState.s.getCurrentPlayer()
    state = (board,cPlayer)
    Saving.saveState(state)