Example #1
0
def main():
    pygame.init()

    #Ouverture de la fenêtre Pygame
    screen = pygame.display.set_mode((WIDTH, HEIGHT))

    # Fill background
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill(BLUE)
    screen.blit(background, (0, 0))

    #generation de la grille
    ma_grille=classes.Grid(NUMBER_PER_LINE, NUMBER_OF_LINE, NUMBER_OF_BOMB)

    #on génère les x*y boutons
    list_button = ma_grille.create_display(screen)

    #Rafraîchissement de l'écran
    pygame.display.flip()

    #Loop until the user clicks the close button.
    done = False
    first_click_done = False

    #on charge une horloge
    #clock = pygame.time.Clock()

    #BOUCLE INFINIE
    while not done:
        #toutes les 10 ms
        clock.tick(10)

        for event in pygame.event.get():
            if event.type == QUIT:
                done = True
            if event.type == MOUSEBUTTONDOWN and event.button == 1:
                #on envoi dans la grille la position du clique et on signale si c'est le 1er clic
                loop_start_time = time.time()
                first_click_done = ma_grille.click(screen, event.pos, first_click_done)
                print("Loop time = ", loop_start_time - time.time())

        #a chaque tour on recup la position souris pour faire de on_hover
        position = pygame.mouse.get_pos()
        for each in list_button:
            each.draw(screen, position)

        pygame.display.flip()
Example #2
0
File: UI.py Project: CaioSR/GUI
import classes
import option

#frameBuffer = {}

root = Tk()

p = []
l = []
po = []
c = []
cur = []
editLines = []
editPoints = []
selected = None
grid = classes.Grid([50, 30])


def selectedBlank(selected):
    if isinstance(selected, classes.Polyline):

        for line in selected.lines:
            for point in line.points:
                point.widget.configure(bg='white')

        if selected.fillment:
            for point in selected.fillment:
                point.widget.configure(bg='white')

    elif isinstance(selected, classes.Circle):
Example #3
0
File: main.py Project: Pjottos/SSMP
import classes
from exceptions import *

boatNames = [
    'Mothership', '4hitthingy', 'Submarine', '3hitthingy', 'Minesweeper'
]

playfield = classes.Grid(0, 10, 10)


def placeBoats(start=0):
    for i, item in enumerate(boatNames):
        if i < start:
            continue
        print(item + ' where?')
        x, y = int(input('x:')), int(input('y:'))
        print(item + ' rotate?')
        rot = int(input('id:'))
        try:
            curBoat = classes.Boat(i, x, y, rot)
            playfield.putBoat(curBoat)
        except (SpaceOccupied, NextToBoat):
            print('wrong placement')
            playfield.removeBoat(curBoat)
            placeBoats(start=i)
        except InvalidTurnID:
            print('turnid from 0 to 3')
            placeBoats(start=i)


placeBoats()
Example #4
0
import socket

import classes
from exceptions import *

boatNames = ['Mothership', '4hitthingy', 'Submarine', '3hitthingy', 'Minesweeper']

playfield = classes.Grid(0, 10, 10)
enemyfield = classes.Grid(1, 10, 10)

def placeBoats(start=0):
    for i, item in enumerate(boatNames):
        if i < start:
            continue
        print(item+' where?')
        x, y = int(input('x:')), int(input('y:'))
        print(item+' rotate?')
        rot = int(input('id:'))
        try:
            curBoat = classes.Boat(i, x, y, rot)
            playfield.putBoat(curBoat)
        except (SpaceOccupied, NextToBoat, InvalidPosition):
            print('wrong placement')
            playfield.removeBoat(curBoat)
            placeBoats(start=i)
        except InvalidTurnID:
            print('turnid from 0 to 3')
            placeBoats(start=i)

placeBoats()
import tkinter as tk
import sys

import classes as cls
import gui
import initialutils

# Set parameters if given
initialutils.set_parameters(sys.argv[1:])

# Initialze data
GRID = cls.Grid()
GRID.add_bombs()

# Create GUI
window = gui.create_main_window()
flag, mine = gui.create_images()
BOARD = gui.create_board(window, GRID, flag, mine)
top_frame = gui.create_top_frame(window, GRID, BOARD)

tk.mainloop()
Example #6
0
# Define some colors

pygame.init()

# Set the width and height of the screen [width, height]
size = (600, 700)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("My Cool Game")

# Loop until the user clicks the close button.
# Used to manage how fast the screen updates
#clock = pygame.time.Clock()

# -------- Main Program Loop -----------
MyGrid = classes.Grid(screen)
done = False
MyGrid.drawgrid()
pygame.display.flip()

while not done:
    # --- Main event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                MyGrid.MoveMovingPiece('L')
                pygame.display.flip()
            if event.key == pygame.K_RIGHT:
                MyGrid.MoveMovingPiece('R')
Example #7
0
#HEURISTIC = 'EUCLIDEAN'
#-------------------------------------

#CORNER_COST = sqrt(2)
CORNER_COST = 1
sequence = [[-1, -1, CORNER_COST], [-1, 0, 1], [-1, 1, CORNER_COST],
            [0, -1, 1], [0, 1, 1], [1, -1, CORNER_COST], [1, 0, 1],
            [1, 1, CORNER_COST]]

#-------------------------------------
# Set input map, and init grid

inputMapName = 'grids/grid_lpa_journal.map'
#inputMapName = 'grids/grid_Dstar_journal.map'
#inputMapName = 'grids/grid_big.map'
gridWorld = classes.Grid(inputMapName, sequence)
MASTER_GRID = classes.Grid(inputMapName, sequence)
#-------------------------------------

alg = ''

H_CELLS = gridWorld.rows
V_CELLS = gridWorld.cols

#--------------------------------------------
# Starting margins for the top header, results sidebar, margin from edges of the screen, margins of each cell, height of text offset
HEADER = 100
RESULTS = 30
OUTSIDE_MARGIN = 30
GRID_MARGIN = 2
TEXT_OFFSET = 5