Ejemplo n.º 1
0
def test_valid():
    game = Game((1))
    block_list = [Block("enemy", [80, 40]), Block("enemy", [40, 40])]
    new_block = Block("enemy", [120, 120])
    assert game.validate_position(block_list, new_block)
    new_block = Block("enemy", [70, 40])
    assert not (game.validate_position(block_list, new_block))
Ejemplo n.º 2
0
    def __init__(self):
        state = PongState()
        Game.__init__(self, state)

        self.addGameObject(PlayerPaddle(self.canvas))
        self.addGameObject(EnemyPaddle(self.canvas))
        self.addGameObject(Ball(self.canvas))
        self.addGameObject(ScoreBox(self.canvas))
Ejemplo n.º 3
0
def main():
    game = Game()
    last_move = 'something'
    while True:
        move = game.generate_move()
        print(move)
        if last_move == '' and move == '':
            # Game Finished!
            break
        last_move = move
Ejemplo n.º 4
0
    def start_game(self, map_to_load: str):
        self.root.destroy()
        logger.info("Start Game")
        map_path = map_to_load
        logger.info("The map_path to load is " + map_path)

        level = Game.LevelParser(map_path).get_level()

        logger.debug("The loaded Level is " + level.__str__())

        new_game = Game.Game(level)
       #new_game.level = level
        new_game.execute()
Ejemplo n.º 5
0
def main():
    myGame = Game()

    while myGame.playing:
        myGame.view()
        myGame.accept_input()
        myGame.control()
Ejemplo n.º 6
0
 def test_board_setup(self):
     game = Game(6, Mode.suspicion)
     show = [["back", "back", "back", "back", "back"], \
             ["back", "back", "back", "back", "back"], \
             ["back", "back", "center", "back", "back"], \
             ["back", "back", "back", "back", "back"], \
             ["back", "back", "back", "back", "back"]]
     board = game.get_board()
     self.assertEqual(show, board.show())
     tile = board.get_tile(2, 3)
     self.assertRaises(IndexError, board.get_tile, 3, 6)
     self.assertRaises(IndexError, board.get_tile, 7, 4)
     self.assertIsInstance(tile, Tile)
     board.turn_all_tiles()
     self.assertTrue("exit" not in board[0][2] and board[1][1:3] \
         and board[2] and board[3][1:3]and board[4][2])
Ejemplo n.º 7
0
def run(width, height, num_bombs):
    pygame.init()
    game = Game(width, height, num_bombs)
    player = Player()
    win = pygame.display.set_mode((width * 32, height * 32))

    running = True
    while running:
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
                quit()

        player.update(events, game)
        game.draw(win)
Ejemplo n.º 8
0
    def build(self, listbox: tkinter.Listbox):
        if listbox.curselection().__len__() > 0:
            logger.debug("Building " + listbox.get(listbox.curselection()[0]))

            self.tile.construction = Game.Construction(self.game, self.tile.rel_pos_tuple,
                                                       listbox.get(listbox.curselection()[0]))
            self.level.constructions.append(self.tile.construction)
            self.back_to_main_frame()
Ejemplo n.º 9
0
def step_impl(context):
	game_list = []

	for row in context.table:

		elenco = []
		idiomas = []
		game = Game(row['NAME'], row['RELEASE DATE'], row['DEVELOPER'], row['RATE'])
		game_list.append(game)

	context.games = game_list
Ejemplo n.º 10
0
    def buttons_click(self, x, y, wd, hg, mouse, click):

        if x + wd > mouse[0] > x and y + hg > mouse[1] > y:

            if click[0] == 1:

                # Intenta conectar 2 jugadores
                self.connect_player()
                # Si la partida no tiene 2 jugadores, se elimina la partida creada y la pantalla se refresca
                self.verify_multi_out()

                Game(self.display, self.user, self.num_match)
Ejemplo n.º 11
0
def main():
    """
    Main function of quoridor. 
    Create a game instance and launch game rounds.
    """
    startTime = time.time()
    time_to_run = int(
        sys.argv[1]) * 60  #time you want program to run for in minutes
    game = Game(
        [  # 2 or 4
            My_Bot("Justin"),
            My_Bot1("Alain")
            #BuilderBot("Benoit"),
            #BuilderBot("Clément"),
            #Human("Pierre")
            #RandomBot("Justin"),

            #RandomBot("Nick")
        ],
        totalFenceCount=20,
        cols=9,
        rows=9)
    game.start(startTime, time_to_run)  # rounds
    game.end()

    global TRACE
Ejemplo n.º 12
0
def main():
    """
    Main function of quoridor.
    Create a game instance and launch game rounds.
    """
    players, rounds, cols, rows, totalFenceCount, squareSize = readArguments()

    game = Game(players, cols, rows, totalFenceCount, squareSize)
    game.start(rounds)
    game.end()

    global TRACE
    print("TRACE")
    for i in TRACE:
        print("%s: %s" % (i, TRACE[i]))
Ejemplo n.º 13
0
    def save(self):
        input_is_valid = True
        self.input_textfield.entry["bg"] = ColorHex.white

        user_input = self.input_textfield.get_user_input()

        for symbol in self.forbidden_characters:
            if symbol in user_input:
                forbidden_symbols_label = GuiFactoryPack.label(
                    '"/", "\\", "<", ">", ":", """, "|", "?", "*", " ", "." \n are not allowed', master=self)
                forbidden_symbols_label.height = 2
                x = 200 - (forbidden_symbols_label["text"].__len__() / 2)
                forbidden_symbols_label.place(x=x / 2, y=20)

                self.input_textfield.mark_false_input(user_input)
                input_is_valid = False

        if input_is_valid:
            Game.LevelWriter(user_input, self.game.level)
            saved_label = GuiFactoryPack.label("Saved", master=self)
            saved_label.height = 2
            saved_label.place(x=180, y=40)
Ejemplo n.º 14
0
def game_room(lvl, player):  # boucle qui gere un level
    room = lvl.rooms[0]
    continuer = 1
    while continuer:
        return_value = Game.game(room, player)  # lance une room
        if isinstance(
                return_value, Player.Player
        ):  # si un player est return cela veut dire que le player est mort
            return return_value
        elif isinstance(return_value, Porte.Porte
                        ):  # si une porte est return, le player change de room
            for d in lvl.doors:  # on cherche la room suivantes
                if d.id_in == return_value.id_out and d.id_out == return_value.id_in:
                    player.x = d.x
                    player.y = d.y

                    # une fois qu'on a trouve la porte qui correspond, on cherche la salle en rapport
                    for r in lvl.rooms:
                        if r.id == d.id_in:
                            room = r
        else:
            return False
Ejemplo n.º 15
0
    def test_set_turn_and_character_per_player(self):
        game1 = Game(6, Mode.suspicion)
        self.assertEqual(game1.turn, 10)
        self.assertEqual(game1.character, 1)

        game2 = Game(1, Mode.solo)
        self.assertEqual(game2.turn, 8)
        self.assertEqual(game2.character, 4)

        game3 = Game(4, Mode.team)
        self.assertEqual(game3.turn, 10)
        self.assertEqual(game3.character, 1)

        game4 = Game(3, Mode.competition)
        self.assertEqual(game4.turn, 10)
        self.assertEqual(game4.character, 2)

        game5 = Game(3, Mode.cooperation)
        self.assertEqual(game5.turn, 8)
        self.assertEqual(game5.character, 2)

        game6 = Game(5, Mode.cooperation)
        self.assertEqual(game6.character, 1)
Ejemplo n.º 16
0
    parser.add_argument('-p',
                        '--puzzle',
                        help="Puzzle to solve",
                        default=argparse.SUPPRESS)
    parser.add_argument(
        '-g',
        '--generate',
        help="X/Y size of the generated map. (Pointless with -p option)",
        type=int,
        default=0,
        choices=range(1, 10))
    parser.add_argument('-b',
                        '--bench',
                        help="Mode benchmark. Disable visual and game aspect.",
                        action='store_false')
    args = parser.parse_args()

    try:
        puzzle = args.puzzle
    except AttributeError:
        puzzle = None
    finally:
        size = 3 if (args.generate == 0) else args.generate
        iMode = args.bench

    grid = Board(size, puzzle, False)
    solvedGrid = Board(size, puzzle, True)

    game = Game(grid, solvedGrid, grid.lenX, iMode)
    game.run()
Ejemplo n.º 17
0
import pygame as pg
import src.Game as game

if __name__ == '__main__':
    app = game.Game()
    app.game_loop()
    pg.quit()
    quit()
Ejemplo n.º 18
0
from src.Game import *
from src.Board import *

if __name__ == "__main__":
    p1_board = Board()
    p2_board = Board()
    p1 = Player(p1_board)
    p2 = Player(p2_board)
    p1.add_opponent(p2)
    p2.add_opponent(p1)
    ShootyBoats = Game(p1, p2)
    ShootyBoats.run_game()
Ejemplo n.º 19
0
### Aquí debe de comenzar el trabajo
from src.Game import *

Juego = Game(9, 2)
Juego.main()
Ejemplo n.º 20
0
def run_game():
    g = Game()
    g.execute()
Ejemplo n.º 21
0
from src import Game
from src import GameState

from src import Button

gs = GameState()
g = Game(gs)

def f():
    print("Clicked!")

width = 14
height = 24
for x in range(0, width):
    for y in range(0, height):
        button = Button(

            g.canvas,
            (x / width, y / height),
            1 / width, 1 / height,
            anchor="NW",
            text="(" + str(x) + "," + str(y) + ")",
            textHighlight=(1, 0, 0)

        )

        g.addGameObject(button)

# o = Oval(
#     g.canvas,
#     (.5, .5),
Ejemplo n.º 22
0
from src import Game

if __name__ == '__main__':
    game = Game()
    game.main_loop()
Ejemplo n.º 23
0
import argparse
from src import Game

p = argparse.ArgumentParser(description="TickTacToe Game")

p.add_argument("skip",
               metavar="skip",
               type=bool,
               default=False,
               help="Human Player Name")

a = p.parse_args()

g = Game()
# Skip intro screen
if a.skip:
    g.update_settings({
        "state": 1,
        "human_name": "James",
        "human_figure": "X",
        "computer_name": "Tom",
        "computer_figure": "0",
        "board_size": 3
    })
g.play_game_main()
Ejemplo n.º 24
0
 def test_do_game(self):
     assert Game.do_game(1, self.log, self.bot1, self.bot2, self.pw) == 1
Ejemplo n.º 25
0
from src import Game
import pygame

gamesize = 20
tile_size = 50
control_type = "PLAYER"  # "AI"

color_dict = {
    0: (0, 0, 0),  # black for empty field
    1: (52, 235, 52),  # green for snakepart
    2: (52, 235, 52),  # green for snakehead
    3: (235, 52, 52)  # red for apple
}

if __name__ == "__main__":
    game = Game(size=gamesize)

    pygame.init()
    screen = pygame.display.set_mode(
        (gamesize * tile_size, gamesize * tile_size))
    pygame.display.set_caption("Snake")

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            # key is pressed
            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_UP:
Ejemplo n.º 26
0
Archivo: run.py Proyecto: renton/fossa
from __future__ import print_function
from __future__ import division

import sys
import pygame

pygame.init()

from pygame.locals import *
from src import Fossa, CanvasState, Game


fossa = Fossa()

game = Game()
canvas_state = CanvasState(game.screen)
game.set_start_state(canvas_state)


game.mainloop()
Ejemplo n.º 27
0
import random
import numpy as np
from src import Game
import glob

# create game client
game = Game.Game()

# file to store custom commands
cmd_file = "../private/replies.txt"
lenny_file = "../text-files/lenny.txt"

# get the borg client from broskibot
# client = Parameters.Parameters.client

# command prefix
prefix = "!"


class Replies:
    def __init__(self):
        self.count = 0

    def getreply(self, message):
        msg = message.content
        self.count += 1
        print('messages received: ', self.count)

        # Chat sent in the 'game' channel are sent to Game.py
        # Other commands will not work in the game channel - good or bad thing?
        # MUST receive an array/list
Ejemplo n.º 28
0
def main():
    display = pygame.display.set_mode(
        (config["game"]["height"], config["game"]["width"]))
    pygame.display.set_caption('Rycerz')
    game = Game(display)
    game.loop()
Ejemplo n.º 29
0
                player2Name = input('Choose name for Player 2: ')
                b1 = B.Board(player1Name, 1)
                b2 = B.Board(player2Name, 1)
            elif chosenModeInt == 2:
                player1Name = input('Choose name for Player 1: ')
                b1 = B.Board(player1Name, 1)
                b2 = B.Board('Computer')
            elif chosenModeInt == 3:
                b1 = B.Board('Computer 1')
                b2 = B.Board('Computer 2')
            else:
                configured = False
    else:
        print('Incorrect choice! Try again.')

g = G.Game(b1, b2)
print('\n' * 5,
      '################################ GAME ##############################',
      sep='')
endGame = False
count = 0
while not endGame:
    print('\n\nRound: ', count)
    count += 1
    for i in range(2):
        winner = g.goRound()
        if winner != None:
            endGame = True
            break

count -= 1
Ejemplo n.º 30
0
from src.Catalogue import *
from src.Game import *


if __name__ == '__main__':

	game_A = Game( "Devil May Cry 5", 2019,  "Capcom", "M")
	game_B = Game( "Uncharted 4: A Thief's End", 2016, "Naughtt Dog", "T")
	game_C = Game( "The Legend of Zelda: Breath of the Wild",2017,"Nintendo","E")
	game_D = Game( "Final Fantasy XV", 2016,"Square Enix", "T")
	game_E = Game( "Marvel's Spider-Man",2018,"Insomniac Games","T")

	game_list = [game_A, game_B, game_C, game_D, game_E]

	result, msj = get_game_name(game_list, "Devil")
	print(msj)
	for x in result:
		print(x)
	print("-"*20)

	result, msj, error = get_game_rating(game_list, ["T"])
	print(msj)
	for x in result:
		print(x)
	print("-"*20)

	result, msj, error = get_game_rating(game_list, ["E", "M"])
	print(msj)
	for x in result:
		print(x)
	print("-"*20)