def __init__(self, numplayers=3): self.roundCount = 0 self.players = [] self.dealer = Player("Dealer") for i in range(numplayers): self.players.append(Player(name=str(i))) self.deck = Deck() self.window = GameWindow()
def play_tic_tac_toe(ai): """ Command function for the buttons to play one round of tic tac toe. Each time a game is played, a new instance of GameWindow should be created. """ game_window = GameWindow() if ai == 0: game_window.run() elif ai == 1: game_window.run(game_window.easy_ai) elif ai == 2: game_window.run(game_window.hard_ai)
def setUp(self): import time from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QHBoxLayout from PyQt5.QtWidgets import QVBoxLayout, QLabel, QPushButton from PyQt5.QtGui import QPixmap, QIcon from PyQt5 import QtCore from PyQt5 import QtGui from WarConstants import WarConstants from Deck import Deck from GameManager import GameManager self.app = QApplication(sys.argv) self.gameMan = GameManager() self.gameWindow = GameWindow(200, 200, 800,500,"War Screen", self.gameMan) return
def RunGame(): # INITIALIZE PYGAME. pygame.init() WIDTH = 1024 HEIGHT = 720 game_window = GameWindow(WIDTH, HEIGHT) pygame.mixer.init() # ENTER THE GAME MAIN LOOP. current_state = MainMenuHandler(game_window) while True: # HANDLE THE CURRENT STATE OF THE GAME. current_state = current_state.Run()
class TestGameWindow(unittest.TestCase): def setUp(self): import time from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QHBoxLayout from PyQt5.QtWidgets import QVBoxLayout, QLabel, QPushButton from PyQt5.QtGui import QPixmap, QIcon from PyQt5 import QtCore from PyQt5 import QtGui from WarConstants import WarConstants from Deck import Deck from GameManager import GameManager self.app = QApplication(sys.argv) self.gameMan = GameManager() self.gameWindow = GameWindow(200, 200, 800,500,"War Screen", self.gameMan) return def tearDown(self): self.gameWindow.close() del self.gameWindow sys.exit(self.app.exec_()) return def test_MoveCardToBack(self): testList = [1,2,3,4] correctTestList = [2,3,4,1] self.assertEquals(self.gameWindow._MoveCardToBack(testList),correctTestList) return
def load(self): folder = 'online' if self.__is_online else 'offline' load_file_name = QFileDialog.getOpenFileName(self, 'Chose Save File', f'saves/{folder}/', 'Save Files (*.save)')[0] if load_file_name == '': return self.load_data = open(load_file_name, 'r').read() if self.__is_online: self.first() else: GameWindow(False, load_file_name, self.__is_online, self.socket, None) self.hide()
def newGame(): character_list_user, combo_list1, name_list = backend.loadCharacters( filepath) random.shuffle(character_list_user) character_list_pc = character_list_user.copy() user_random = random.randint(0, len(character_list_user) - 1) user_char = character_list_user[user_random] pc_random = random.randint(0, len(character_list_user) - 1) pc_char = character_list_user[pc_random] game_window = GameWindow(character_list_user, user_char, character_list_pc, pc_char, combo_list1, name_list)
def main(): global gameWindow gameWindow = GameWindow() global capnam capnam = Capnam(gameWindow) gameWindow.initialiseGame() gameWindow.drawGrid() while True: runGame()
import colorsys from pyglet import resource import math import random from pyglet import window from pyglet import canvas from pyglet.window import key from GameObjects import GameObject, preload_image from math import atan2, degrees from GameWindow import GameWindow platform = pyglet.window.get_platform() display = platform.get_default_display() default_screen = display.get_default_screen() def update(dt): if window.window_exists == False: window.close() pyglet.app.exit() window = GameWindow(default_screen.width, default_screen.height, "Game Final", resizable=False, style=window.Window.WINDOW_STYLE_BORDERLESS) window.set_fullscreen() pyglet.clock.schedule_interval(window.update, window.frame_rate) pyglet.app.run()
from LobbyWindow import LobbyWindow from GameWindow import GameWindow from ResultWindow import ResultWindow from PygameConfig import PygameConfig settings = PygameConfig() while True: Lobby = LobbyWindow(settings) LOBBY_DATA = Lobby.main() Game = GameWindow(LOBBY_DATA, settings) GAME_DATA = Game.main() if not GAME_DATA["computer-solved"]: Result = ResultWindow(GAME_DATA, settings) Result.main() pygame.quit() exit()
def init(): print("Initialising Potatoes...") window = GameWindow(width=1024, height=768) # Load a bunch of resources pyglet.resource.path = ["./resources/images", "./resources/sounds"] pyglet.resource.reindex() # Load Effects System window.effects = Effects(window) # Create Player Object. window.player = PlayerShip(img=pyglet.resource.image("potato.png"), window=window) window.player.change_scale(0.2) window.player.body.position = (100, 200) # Initialise HUD hud = HUD(window.player, window) ship_image = pyglet.resource.image("potato-green.png") ships = [ Ship(img=ship_image, window=window), Ship(img=ship_image, window=window), Ship(img=ship_image, window=window) ] ship_x = 500 ship_y = 100 for ship in ships: ship.body.position = (ship_x, ship_y) ship_x += 200 ship.body.angle = 3.14159 ship.body.angular_velocity = 10 ship.change_scale(0.5) window.space.reindex_shapes_for_body(ship.body) # Kick off the Game's control loop. pyglet.clock.schedule_interval(window.master_update, 1 / 120.0) # Player Boundaries boundaries = [ pymunk.Segment(window.space.static_body, (0, 0), (0, 768), 0.0), pymunk.Segment(window.space.static_body, (1024, 0), (1024, 768), 0), pymunk.Segment(window.space.static_body, (0, 0), (1024, 0), 0), pymunk.Segment(window.space.static_body, (0, 768), (1024, 768), 0) ] for l in boundaries: l.friction = 0.1 l.collision_type = CollisionManager.WORLD window.space.add(boundaries) cm = CollisionManager(window) for shape in window.player.body.shapes: print(shape.collision_type) # TODO - Build something that loads levels. # Background background = pyglet.resource.image("background1.png") background_sprite = pyglet.sprite.Sprite(img=background) background_sprite.batch = window.background_batch background_sprite.x = 0 background_sprite.y = 0 window.background = background_sprite return window
if __name__ == "__main__": app = QApplication(sys.argv) # Setup the game manager class gameMan = GameManager() # Create the start screen to setup the game constants print("Starting setup window") setupWindow = SetupWindow(gameMan, 400, 300, 200, 400, "Setup the Battle") gameMan.PlayerName = setupWindow.PlayerName gameMan.CompName = setupWindow.CompName gameMan.DeckCount = int(setupWindow.DeckCount) # Close the setup window setupWindow.close() print("Setup window closed") #_TestGameManagerSetup(gameMan) #print("Game code has continued") # Setup the gameplay window print("Starting main game window") gameWindow = GameWindow(200, 200, 800, 500, "War Screen", gameMan) gameWindow.close() print("Closed main game window") sys.exit(app.exec_()) print("App exited")
# Copyright (C) 2019 Robert C. Ramsdell III <*****@*****.**> # # mPyre is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # mPyre is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with mPyre. If not, see <https://www.gnu.org/licenses/>. # # Work started on 19 December, 2019 import Controller from GameWindow import GameWindow import pygame if __name__ == "__main__": image_size = 32 size = (30, 30) W = Controller.World(size) GW = GameWindow(W, image_size) GW.mainloop() GW.quit()
#!/usr/bin/python # Projekt PSZT - Gomoku # File contains entry point of the application. # Szymon Jablonski # 10.11.2010 # main.py import sys from PyQt4 import QtGui from PyQt4 import QtCore from GameWindow import GameWindow # Entry point of application. app = QtGui.QApplication(sys.argv) main = GameWindow() main.show() app.exec_()
import pygame, time, sys, random pygame.init() from GameWindow import GameWindow from Snake import Snake from Collectible import Collectible if __name__ == "__main__": window = GameWindow(800, 600) snake = Snake() collectibles = [] clock = pygame.time.Clock() running = True while running: window.window.fill(GameWindow.white) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() #generate new collectibles if not collectibles: collectibles.append(Collectible()) if random.randint( 0, 120 ) == 1: #should generate 1 new collectible every 2 seconds??? collectibles.append(Collectible()) #handles keypresses and moves the snake pressed = pygame.key.get_pressed() if pressed[pygame.K_LEFT] and snake.direction != 'east':
def on_pushSinglePlayerButton_clicked(self): exPipe, inPipe = mp.Pipe() process = ProcessKong(pipe=exPipe) process.start() self.dialog = GameWindow(inPipe) self.dialog.show()
#!/usr/bin/python3 # this is a placeholder file # Viewer import Controller from GameWindow import GameWindow import pygame from pygame.locals import NOEVENT, QUIT if __name__ == "__main__": GW = GameWindow() W = Controller.World() GW.mainloop(W) print(W.G.__dict__) GW.quit()
def run_load_online(self): GameWindow(False, self.load_data, self.__is_online, self.__is_player_first, self.socket) self.hide()
def run(self): GameWindow(True, self.__board_size, self.__is_bot_active, self.__is_player_first, self.__bot_difficulty, self.__is_online, self.socket) self.hide()
class Game: def __init__(self, numplayers=3): self.roundCount = 0 self.players = [] self.dealer = Player("Dealer") for i in range(numplayers): self.players.append(Player(name=str(i))) self.deck = Deck() self.window = GameWindow() def addPlayer(self, player): self.players.append(player) def startRound(self): rows, columns = os.popen('stty size', 'r').read().split() s = "" for i in range(int(columns)): s += "=" print(s) print("ROUND " + str(self.roundCount)) print(s) if self.roundCount % 10 == 0: print(self.deck.calculateCount()) self.askForBets() self.drawCards() print("Dealer cards: " + str(self.dealer.cards)) self.window.drawGameState(self) self.handlePlayers() self.handleDealer() for player in self.players: print("Player " + str(player.name) + " cards: " + str(player.cards)) print("Player " + str(player.name) + " value: " + str(player.evaluate())) print("Dealer" + " cards: " + str(self.dealer.cards)) print("Dealer" + " value: " + str(self.dealer.evaluate())) self.window.drawGameState(self, drawBlank=False) self.handlePayout() self.roundCount += 1 def askForBets(self): for player in self.players: print("Player " + player.name + " has " + str(player.chips) + " chips.") #remove players with 0 chips index = 0 while index < len(self.players): if self.players[index].chips <= 0: self.players.remove(self.players[index]) index+=1 if len(self.players) == 0: print('Game Over!') exit(0) self.playerBets = [0] * len(self.players) for player,index in zip(self.players, range(len(self.players))): bet = -1 while bet == -1: bet = int(input("Player " + str(player.name) + " enter how much you want to bet...")) if bet > player.chips: bet = -1 print('bet was too large!') self.playerBets[index] = bet player.chips -= bet def drawCards(self): #reset all cards self.dealer.hiddencard = None self.dealer.cards.clear() for player in self.players: player.cards.clear() #players for player in self.players: player.hit(self.deck) #dealer hidden self.dealer.hiddencard = self.deck.nextCard() print(self.dealer.hiddencard) #players for player in self.players: player.hit(self.deck) #dealer self.dealer.hit(self.deck) def handlePlayers(self): index = -1 for player in self.players: index += 1 while True: self.window.drawGameState(self) if player.evaluate() == 21: break print("Player " + str(player.name) + " cards: " + str(player.cards)) print("Player " + str(player.name) + " value: " + str(player.evaluate())) choice = input("Player " + str(player.name) + " your move [hit,stand,double]...") if choice == "hit": player.hit(self.deck) if player.evaluate() > 21: print("Player " + str(player.name) + " cards: " + str(player.cards)) print("Player " + str(player.name) + " value: " + str(player.evaluate())) print("Bust!") break #dont let players double if they dont have enough chips if choice == "double": player.chips -= self.playerBets[index] self.playerBets[index] *= 2 player.hit(self.deck) break if choice == "stand": break def handleDealer(self): self.dealer.cards.append(self.dealer.hiddencard) while self.dealer.evaluate() < 17: self.dealer.hit(self.deck) print("Dealer value:", self.dealer.evaluate()) def handlePayout(self): dealer_value = self.dealer.evaluate() if dealer_value > 21: #payout everyone not over 21 player_index = 0 for player in self.players: if player.evaluate() <= 21: player.chips += 2*self.playerBets[player_index] player_index += 1 else: player_index = 0 for player in self.players: if player.evaluate() > self.dealer.evaluate() and player.evaluate() <= 21: player.chips += 2*self.playerBets[player_index] if player.evaluate() == self.dealer.evaluate(): player.chips += self.playerBets[player_index] player_index += 1