Example #1
0
    def __init__(self, app):
        super(MainWindow, self).__init__()
        self.app = app
        print('window created')
        self.setWindowIcon(QIcon('img/icon.png'))
        self.setWindowTitle('Kasino')
        self.setPalette(QPalette(Qt.darkGreen))
        self.setup_music()

        self.statusbar = QStatusBar(self)
        self.statusbar.setStyleSheet('background: white')
        self.setStatusBar(self.statusbar)
        self.statusbar.showMessage('Welcome to the Cassino game!')

        self.menubar = QMenuBar(self)
        self.optionsMenu = self.menubar.addMenu('Options')
        self.music_toggle = QAction()
        self.music_toggle.setText('Music')
        self.music_toggle.setShortcut('Ctrl+m')
        self.music_toggle.setCheckable(True)
        self.music_toggle.setChecked(True)
        self.optionsMenu.addAction(self.music_toggle)
        self.music_toggle.triggered.connect(self.toggle_music)

        self.speedGroup = QActionGroup(self)
        self.speedGroup.triggered.connect(self.set_speed)

        self.slow_speed = QAction('Slow', self.speedGroup)
        self.slow_speed.setCheckable(True)
        self.normal_speed = QAction('Normal', self.speedGroup)
        self.normal_speed.setCheckable(True)
        self.fast_speed = QAction('Fast', self.speedGroup)
        self.fast_speed.setCheckable(True)
        self.vfast_speed = QAction('Very Fast', self.speedGroup)
        self.vfast_speed.setCheckable(True)
        self.normal_speed.setChecked(True)

        self.speed_menu = self.optionsMenu.addMenu('Speed')
        self.speed_menu.addActions(self.speedGroup.actions())
        self.menubar.setMouseTracking(False)
        self.setMenuBar(self.menubar)

        self.play_widget = PlayWidget(self)
        self.main_menu = MainMenu(self)
        self.start_menu = StartMenu(self)
        self.widgets = QStackedWidget(self)
        self.widgets.addWidget(self.play_widget)
        self.widgets.addWidget(self.main_menu)
        self.widgets.addWidget(self.start_menu)
        self.widgets.setCurrentWidget(self.main_menu)

        self.setCentralWidget(self.widgets)
        self.setGeometry(25, 50, 1028, 720)

        self.main_menu.startbutton.clicked.connect(self.init_game)
        self.main_menu.loadbutton.clicked.connect(self.load_game)
        self.main_menu.quitbutton.clicked.connect(self.quit)
        self.play_widget.quit_button.clicked.connect(self.quit_to_menu)
        self.play_widget.save_button.clicked.connect(self.save_game)
        self.start_menu.startbutton.clicked.connect(self.start_game)
Example #2
0
File: main.py Project: 1zycodr/blog
def main():
    db = DBService()

    user_repo = UserRepository(db)
    profile_repo = ProfileRepository(db)
    post_repo = PostRepository(db)

    user_controller = UserController(user_repo)
    profile_controller = ProfileController(profile_repo)
    post_controller = PostController(post_repo)

    app = StartMenu(user_controller, profile_controller, post_controller)
    app.show()
Example #3
0
def main():
    """Creates and executes Arkanoid."""
    
    from menu import StartMenu, DieMenu, WinMenu
    
    arkanoid = Arkanoid()
    
    # play the start menu
    start = StartMenu(arkanoid.screen)
    menuResult = start.play(arkanoid)
    if menuResult == 0: pass # play
    elif menuResult == 2: return # quit
    
    # play through the stages
    stageNum = 0
    while True:
    
        # play the stage
        stage = arkanoid.stages[stageNum]
        stageResult = arkanoid.play_stage(stage)

        # stage was one, proceed to next
        if stageResult == 0:
            stageNum += 1
            
            # game has been won!
            if stageNum == len(arkanoid.stages):
                win = WinMenu(arkanoid.screen)
                menuResult = win.play(arkanoid)
                if menuResult == 0: 
                    stageNum = 0
                    arkanoid = Arkanoid()
                elif menuResult == 2: return
        
        # stage was lost, decide if restarting or quitting
        elif stageResult == 1: #lost
            dead = DieMenu(arkanoid.screen)
            menuResult = dead.play(arkanoid)
            if menuResult == 0: # restart
                stageNum = 0
                arkanoid = Arkanoid()
            elif menuResult == 2: return # quit
            
        # user quit game
        elif stageResult == 2: return # quit
        
        else: raise ValueError('Unrecognized stage return code.')
Example #4
0
	def __init_canva(self):
		# Canvas object
		self.c = ExCanvas(self.root, width=self.ss.WIDTH, 
							height=self.ss.HEIGHT, background=self.theme["bg"])
		self.c.pack()#expand=True)
		 
		# central line
		self.c.create_line(self.ss.WIDTH//2, 0, self.ss.WIDTH//2, 
							self.ss.HEIGHT, fill=self.theme["line"], tag="line")
							
		self.c.create_ball(self.ss.WIDTH//2, self.ss.HEIGHT//2, self.ss.BALL_RADIUS/2, 
							fill=self.theme["line"], width=0, tag="line")
		
		
		self.__init_players_score()
		
		# Work with Pads
		left_pad_id = self.c.create_rectangle(0, 0, self.ss.PAD_W, 
											self.ss.PAD_H, width=1, 
											fill=self.theme["l_pad"], tag="l_pad")
		 
		right_pad_id = self.c.create_rectangle(self.ss.WIDTH-self.ss.PAD_W, 0, self.ss.WIDTH, 
									  		self.ss.PAD_H, width=1, 
									  		fill=self.theme["r_pad"], tag="r_pad")
								  
		self.left_pad = Pad(left_pad_id, self.c, self.ss, ("w", "s"), Player.LEFT)
		self.right_pad = Pad(right_pad_id, self.c, self.ss, ("Up", "Down"), Player.RIGHT)
		
		self.player = Player(self.left_pad, self.right_pad)
		
		self.ball = Ball(self.c, self.player, self, self.ss, self.theme["ball"])
		
		
		self.buffs = Buffs(self.ss, self)
		
		# Menu creating
		stop_menu_id = self.c.create_window((self.ss.WIDTH/2, self.ss.HEIGHT/2))
		self.stop_menu = StopMenu(stop_menu_id, self)
		self.c.itemconfig(stop_menu_id, window=self.stop_menu, state=HIDDEN)
		
		options_menu_id = self.c.create_window((self.ss.WIDTH/2, self.ss.HEIGHT/2))
		self.options_menu = OptionMenu(options_menu_id, self)
		self.c.itemconfig(options_menu_id, window=self.options_menu, state=HIDDEN)
		
		start_menu_id = self.c.create_window((self.ss.WIDTH/2, self.ss.HEIGHT/2))
		self.start_menu = StartMenu(start_menu_id, self)
		self.c.itemconfig(start_menu_id, window=self.start_menu) 
		
		self.cur_menu = self.start_menu
										  
		self.c.focus_set()
		self.theme.set_canvas(self.c)
		
		self.c.bind("<KeyPress>", self._key_pressed)
		self.c.bind("<KeyRelease>", self._key_released)
		
		self.game_stopped = True
Example #5
0
def main():
   start_menu = StartMenu()
   main_menu = MainMenu()
   mode = 'start'
   user = None

   while True:
      try:
         if mode == 'start':
            user = start_menu.start_logic()
            mode = 'registered'

         elif mode == 'registered':
            main_menu.main_menu_logic()
            mode = 'start'
            
      except UserExitException:
         print('\n\n=================================================\nExiting the programm.\nThank you for using this software and goodbye!')
         exit(0)
Example #6
0
class Main():
    """boucle principale du programme"""
    pygame.init()
    fenetre = pygame.display.set_mode((1920, 1080))  ##, pygame.FULLSCREEN)
    game = 0
    r = "startmenu"
    while r != "stop":
        if r == "start":
            game = Game(fenetre, "tower")
            game.respawn()
            r = game.run()
        elif r == "startmenu":
            startmenu = StartMenu(fenetre)
            r = startmenu.run()
        elif r == "respawn":
            game.respawn()
            r = game.run()
    pygame.quit()
Example #7
0
class MainWindow(QMainWindow):
    def __init__(self, app):
        super(MainWindow, self).__init__()
        self.app = app
        print('window created')
        self.setWindowIcon(QIcon('img/icon.png'))
        self.setWindowTitle('Kasino')
        self.setPalette(QPalette(Qt.darkGreen))
        self.setup_music()

        self.statusbar = QStatusBar(self)
        self.statusbar.setStyleSheet('background: white')
        self.setStatusBar(self.statusbar)
        self.statusbar.showMessage('Welcome to the Cassino game!')

        self.menubar = QMenuBar(self)
        self.optionsMenu = self.menubar.addMenu('Options')
        self.music_toggle = QAction()
        self.music_toggle.setText('Music')
        self.music_toggle.setShortcut('Ctrl+m')
        self.music_toggle.setCheckable(True)
        self.music_toggle.setChecked(True)
        self.optionsMenu.addAction(self.music_toggle)
        self.music_toggle.triggered.connect(self.toggle_music)

        self.speedGroup = QActionGroup(self)
        self.speedGroup.triggered.connect(self.set_speed)

        self.slow_speed = QAction('Slow', self.speedGroup)
        self.slow_speed.setCheckable(True)
        self.normal_speed = QAction('Normal', self.speedGroup)
        self.normal_speed.setCheckable(True)
        self.fast_speed = QAction('Fast', self.speedGroup)
        self.fast_speed.setCheckable(True)
        self.vfast_speed = QAction('Very Fast', self.speedGroup)
        self.vfast_speed.setCheckable(True)
        self.normal_speed.setChecked(True)

        self.speed_menu = self.optionsMenu.addMenu('Speed')
        self.speed_menu.addActions(self.speedGroup.actions())
        self.menubar.setMouseTracking(False)
        self.setMenuBar(self.menubar)

        self.play_widget = PlayWidget(self)
        self.main_menu = MainMenu(self)
        self.start_menu = StartMenu(self)
        self.widgets = QStackedWidget(self)
        self.widgets.addWidget(self.play_widget)
        self.widgets.addWidget(self.main_menu)
        self.widgets.addWidget(self.start_menu)
        self.widgets.setCurrentWidget(self.main_menu)

        self.setCentralWidget(self.widgets)
        self.setGeometry(25, 50, 1028, 720)

        self.main_menu.startbutton.clicked.connect(self.init_game)
        self.main_menu.loadbutton.clicked.connect(self.load_game)
        self.main_menu.quitbutton.clicked.connect(self.quit)
        self.play_widget.quit_button.clicked.connect(self.quit_to_menu)
        self.play_widget.save_button.clicked.connect(self.save_game)
        self.start_menu.startbutton.clicked.connect(self.start_game)

    def setup_music(self):
        self.music = QMediaPlayer()
        self.playlist = QMediaPlaylist()
        self.playlist.setPlaybackMode(QMediaPlaylist.Loop)
        file_name = "sound/bg.mp3"
        self.media = QMediaContent(QUrl.fromLocalFile(file_name))
        self.playlist.addMedia(self.media)
        self.music.setPlaylist(self.playlist)
        self.music.setVolume(20)
        self.music.play()

    def toggle_music(self):
        if self.music.isMuted():
            self.music.setMuted(False)
            self.statusbar.showMessage('Music on', 5000)
        else:
            self.music.setMuted(True)
            self.statusbar.showMessage('Music off', 5000)

    def set_speed(self, action):
        if action == self.slow_speed:
            self.play_widget.speed = 1
        elif action == self.normal_speed:
            self.play_widget.speed = 3
        elif action == self.fast_speed:
            self.play_widget.speed = 4
        else:
            self.play_widget.speed = 6

    def start_game(self):
        self.play_widget.init_game(
            self.start_menu.extract_info_and_init_game())
        self.widgets.setCurrentWidget(self.play_widget)
        self.statusbar.showMessage('Game launched', 2000)

    def load_game(self):
        path = QFileDialog.getOpenFileName(self, 'Open save file',
                                           QDir.currentPath() + '/sav')[0]
        if path != '':
            game, msg, count = load(path)
            self.play_widget.resume_from_save(game, msg, count)
            self.widgets.setCurrentWidget(self.play_widget)
            self.statusbar.showMessage('Loaded save file', 5000)

    def save_game(self):
        path = QFileDialog.getSaveFileName(self, 'Create save file',
                                           QDir.currentPath() + '/sav')[0]
        if path != '':
            save(path, self.play_widget.game, self.play_widget.export_log(),
                 self.play_widget.move_count)
            self.statusbar.showMessage('Game saved', 5000)

    def init_game(self):
        self.widgets.setCurrentWidget(self.start_menu)
        self.statusbar.showMessage('Starting new game')

    def quit_to_menu(self):
        #Reset playwidget
        self.widgets.removeWidget(self.play_widget)
        speed = self.play_widget.speed
        self.play_widget.setParent(None)
        self.play_widget = PlayWidget(self)
        self.play_widget.speed = speed
        self.widgets.addWidget(self.play_widget)
        self.play_widget.quit_button.clicked.connect(self.quit_to_menu)
        self.play_widget.save_button.clicked.connect(self.save_game)

        self.widgets.setCurrentWidget(self.main_menu)

    def closeEvent(self, *args,
                   **kwargs):  #for handling closing from 'x' button
        self.quit()

    def quit(self):
        print('Exited game. Thanks for playing!\n')
        self.app.exit()
from alpha import Alpha
from alpha_plus import AlphaPlus
from read_from_file import read 
from menu import StartMenu

menu = StartMenu()
menu.create_menubar()
menu.create_file_menu()
#menu.create_edit_menu()
menu.create_help_menu()
menu.create_run_menu()
menu.add_radio_buttons()
menu.show_menu()


'''filename = '../logs/log5'
f = read(filename + '.txt')
print(f)
a = Alpha(f)
print(a)
print("direct succesor:", a.ds)
print("causality:",a.cs)
print("inversion causality:",a.inv_cs)
print("parralell:",a.pr)
print("no relation:",a.ind)

a.create_graph(filename, render=True)'''

'''a = AlphaPlus(f)
print("causality: ", a.cs)
print("inversion causality:",a.inv_cs)
Example #9
0
# -*-coding: utf-8-*-
from socket import *
from Tkinter import *
from menu import StartMenu

s = socket(AF_INET, SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
my_ip = s.getsockname()[0]
s.close()

root = Tk()
menu = StartMenu(root, "Server", my_ip)
root.mainloop()

ip = menu.retrieved_ip
port = int(menu.retrieved_port)


class SocketClient():
    def __init__(self):
        self.host = ip
        self.port = port

        try:
            self.sock = socket(AF_INET, SOCK_STREAM)
            self.sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
            self.sock.connect((self.host, self.port))
            print "Cliente se conectou"

        except:
            print "Falha ao conectar com o servidor"