def set_players(self): self.player1 = Players.Player(self.left + 2, (self.max_height - 1) * self.cell_size + self.top + 2, 1, self.players_sprites) self.player2 = Players.Player( (self.max_width - 1) * self.cell_size + self.left + 2, self.top + 2, 2, self.players_sprites)
def __init__(self, pm=PlayerManager([Players.Player("White", []), Players.Player("Black", [])])): # Declarations self.board = [] self.moves_made = [] self.PM = pm # Player Manager self.PLAYERS = pm.get_players() self.PIECE_DIRECTIONS = {f"{self.PLAYERS[0].get_color()}": 1, f"{self.PLAYERS[1].get_color()}": -1} # Downwards is 1 and Upwards is -1 self.current_player = self.PLAYERS[0] # Main self.move_able = {} self.new_board() self.set_start_pieces() self.selected_piece = None
def main(): #initializing game objects sprite_obj = Sprites.Sprites() player_obj = Players.Player() asteroids_obj = Players.Asteroids() event_handler_obj = AsteroidsGame.Event_Handler(player_obj) draw_handler_obj = AsteroidsGame.Draw_Handler(sprite_obj, player_obj, asteroids_obj) state = 'blank screen' while event_handler_obj['running']: for event in pygame.event.get(): ''' instead of having a huge number of if-branches to assess the events, maybe we can pass the event to an event handler which returns a dictionary/hash table that describes the state of the game/player (i.e. {game_state: True, player_health: 100, etc...}) ''' event_handler_obj.action(event, draw_handler_obj) draw_handler_obj[''] pygame.display.flip() pygame.quit()
def __init__(self): self._board = Board.Board() self._red_player = Players.Player('red') self._blue_player = Players.Player('blue') self._game_over = False self._player_in_check = None self._turn = 'blue' self._captured_pieces = [] self._move_log = [] for i, piece in enumerate(self._red_player.get_player_pieces()): self._board.set_board(self._red_player.get_initial_placements()[i], piece) piece.set_location(self._red_player.get_initial_placements()[i]) for i, piece in enumerate(self._blue_player.get_player_pieces()): self._board.set_board( self._blue_player.get_initial_placements()[i], piece) piece.set_location(self._blue_player.get_initial_placements()[i])
def InitializePlayers(self, stacks, counts): if not stacks: stacks = [1000] * self.Nplayers if not counts: counts = [0] * self.Nplayers players = [] for i, (stack, count) in enumerate(zip(stacks, counts)): players.append(Players.Player(f'Player{i}', stack, count=count)) return players
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle("Main Window") self.player = Players.Player() explorer = FileSystemMediaExplorer("d:\\", self.rootContext, self.player) self.rootContext().setContextProperty('player', self.player) self.rootContext().setContextProperty('mediaListModel', explorer.MediaList) self.rootContext().setContextProperty('mediaExplorer', explorer) # Renders 'view.qml' self.setSource(QUrl.fromLocalFile('QML/main.qml')) # QML resizes to main window self.setResizeMode(QDeclarativeView.SizeRootObjectToView)
def Game(decks, players): # Shuffle the given cards and give them all values card_translate = { "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "10": 10, "J": 10, "Q": 10, "K": 10, "A": 11 } cards = Functions.Shuffle(decks) while len(cards) > (players + 1) * 6: # Players play their turns gcards = [cards[0], cards[1]] del cards[0] del cards[0] player_1 = Players.Player(card_translate, 1, cards, gcards) # Deler's turn gcards = [cards[0], cards[1]] del cards[0] del cards[0] deler = Players.Deler(card_translate, cards, gcards) # For testing, write who won and lost if deler > player_1: print("Player 1 Lost") elif deler < player_1: print("Player 1 Won") else: print("Player 1 tied with the deiler") print( "----------------------------------------------------------------------------" )
def set_players(num_of_players: int): for num in range(num_of_players): players.append(pl.Player(input(f'Player{num+1} Name: ')))
from adventurelib import start, when, set_context import adventurelib import dice, cfg from colorama import init, Fore, Back, Style import descriptions import Players, spells_logic Enemy = None print("Who are you?") hero_name = input("") player = Players.Player(hero_name, ["rock throw", "firebolt"], []) init(convert=True) print(descriptions.intro) #Global commands @when("help") def h(): adventurelib.help() @when("show SOMETHING") def show(something): x = something if x == "spells": print("") print( "Concentration (chance to cast spell) is 1d20 + {} (MIND)".format( player.MIND)) for spell in player.spells: spells_logic.spells[spell].describe() return
chanceFile.close() # Make list of Community Chest cards communityChest = [] ccTop = 0 communityChestFile = open("communityChest.txt", 'r') for line in communityChestFile: communityChest.append(line.strip()) communityChestFile.close() # Function to shuffle a deck when empty random.shuffle(communityChest) ccTop = 0 # players p1 = Players.Player() p2 = Players.Player() p3 = Players.Player() p4 = Players.Player() players = [p1, p2,p3] def rollDice(): global die1, die2 die1 = random.randint(1, 6) die2 = random.randint(1, 6) def drawCommuityChest(player):
import Players # intiates o Pygame pg.init() # window dimensions WINDOW_WIDTH = 700 WINDOW_HEIGHT = 700 win = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pg.display.set_caption("Space Asteroid thing") # game clock clock = pg.time.Clock() # player object player = Players.Player((WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2), win) # creating player sprite group and adding the player player_group = pg.sprite.Group() player_group.add(player) # creating a player bullets sprite group player_bullets = pg.sprite.Group() # Asteroids group asteroids_group = pg.sprite.Group() # font for fpsd font = pg.font.Font(None, 30) # main game loop
def getPlayer(self): if getConst("MODE") != "VS": return Players.Player(1, self.controls, self.getAbilities()) return Players.Player(self.controls, self.controls, self.getAbilities(), pos = [getConst("SCREENSIZE")[0] / 2, getConst("SCREENSIZE")[1] * (self.controls % 2)])
def __init__(self): self.itemID = 0 self.switchState = True self.iAktion = "E" self.altIPos = [0, 0] self.switchCam = False self.kampf = Battle.Kampf() self.itemDa = False self.keyMap = { "left": 0, "right": 0, "forward": 0, "cam-left": 0, "cam-right": 0 } base.win.setClearColor(Vec4(0, 0, 0, 1)) self.environ = loader.loadModel("models/world") self.environ.reparentTo(render) self.environ.setPos(0, 0, 0) self.spieler = Players.Player(Actor("models/box.x")) self.spieler.actor.reparentTo(render) spielerStartPos = (-107.575, 26.6066, -0.490075) self.spieler.actor.setPos(spielerStartPos) self.textObjectSpieler = OnscreenText( text=self.spieler.name + ": " + str(self.spieler.energie) + "/" + str(self.spieler.maxenergie) + " HP", pos=(-0.90, -0.98), scale=0.07, fg=(1, 0, 0, 1)) # Erstellt Gegner self.gegnerStartPos = ([ (-39.1143569946, 25.1781406403, -0.136657714844), (-102.375793457, -30.6321983337, 0.0), (-56.927986145, -34.6329650879, -0.16748046875), (-79.6673126221, 30.8231620789, 2.89721679688), (-4.37648868561, 30.5158863068, 2.18450927734), (22.6527004242, 4.99837779999, 3.11364746094), (-23.8257598877, -7.87773084641, 1.36920166016), (-80.6140823364, 19.5769443512, 4.70764160156), (-75.0773696899, -15.2991075516, 6.24676513672) ]) gegnerPos = random.choice(self.gegnerStartPos) self.gegnerErstellen(gegnerPos) self.textObjectGegner = OnscreenText( text=str(self.gegner.name) + ": " + str(self.gegner.energie) + "/" + str(self.gegner.maxenergie) + " HP", pos=(0.90, -0.98), scale=0.07, fg=(1, 0, 0, 1)) self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) self.item = None # Handling der Usereingaben für Bewegung self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["left", 1]) self.accept("arrow_right", self.setKey, ["right", 1]) self.accept("arrow_up", self.setKey, ["forward", 1]) self.accept("a", self.setKey, ["cam-left", 1]) self.accept("s", self.setKey, ["cam-right", 1]) self.accept("i", self.setKey, ["inventar", 1]) self.accept("arrow_left-up", self.setKey, ["left", 0]) self.accept("arrow_right-up", self.setKey, ["right", 0]) self.accept("arrow_up-up", self.setKey, ["forward", 0]) self.accept("a-up", self.setKey, ["cam-left", 0]) self.accept("s-up", self.setKey, ["cam-right", 0]) self.accept("e", self.iAktionsHandler, ["e"]) self.accept("v", self.iAktionsHandler, ["v"]) self.accept("w", self.iAktionsHandler, ["w"]) taskMgr.add(self.move, "moveTask") taskMgr.add(self.erkenneKampf, "Kampferkennung") taskMgr.add(self.screentexts, "Screentexte") # Menü erstellen self.createMenu() # Kameraeinstellungen base.disableMouse() base.camera.setPos(self.spieler.actor.getX(), self.spieler.actor.getY() + 10, 2) self.collisionInit() self.setAI() # Licht ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight)) # Hintergrund (Himmel) self.setupSkySphere()