def setUp(self):
     self.deck = Deck()
     self.deck.populate()
     self.player = Player("Jake")
     self.card = Card("Spades", 10)
     self.card2 = Card("Spades", 10)
     self.card3 = Card("Spades", 5)
Ejemplo n.º 2
0
    async def handle(self, params, message, client, pug):
        if pug.is_in_progress():
            await message.channel.send("Pug currently in progress! Please finish the pug or enter the results with !end [winning team number: 1 or 2] to start a new one.")
            return
        elif pug.is_free():
            pug.start_registering()

        test = len(pug.players)
        player = Player(test,str(test),"@"+str(test), 0, 0, 0, 1200) #get_player(message.author.id)

        if (player == None):
            player = Player(message.author.id, message.author.name, message.author.mention, 0, 0, 0, 1200)
            update_player(player.id, player.name, player.mention, player.games, player.wins, player.losses, player.elo)
        elif player_present(pug.players, player):
            await message.channel.send(player.mention + " already in the pug!")
            return

        if pug.add_player(player):
            await message.channel.send("Beginning game!")
            pug.start_pug()
            await start_draft(message, pug)
            return
        await message.channel.send("Added " + player.mention + " to the pug!")
        playerString = "Players:"
        for p in pug.players:
            playerString += "\n" + p.name
        await message.channel.send(playerString)
class TestPlayer(unittest.TestCase):
    def setUp(self):
        self.deck = Deck()
        self.deck.populate()
        self.player = Player("Jake")
        self.card = Card("Spades", 10)
        self.card2 = Card("Spades", 10)
        self.card3 = Card("Spades", 5)

    def test_has_name(self):
        self.assertEqual("Jake", self.player.name)

    def test_hand_starts_empty(self):
        self.assertEqual(0, len(self.player.hand))

    def test_can_take_card(self):
        self.assertEqual(0, len(self.player.hand))
        new_card = self.deck.deal()
        self.player.take_card(new_card)
        self.assertEqual(1, len(self.player.hand))

    def test_take_card_updates_hand_value(self):
        self.assertEqual(0, self.player.totalHandValue)
        self.player.take_card(self.card)
        self.assertEqual(10, self.player.totalHandValue)

    def test_shows_if_bust(self):
        self.assertEqual(False, self.player.is_bust())
        self.player.take_card(self.card)
        self.player.take_card(self.card2)
        self.player.take_card(self.card3)
        self.assertEqual(True, self.player.is_bust())
Ejemplo n.º 4
0
 def __init__(self):
     self.deck = Deck()
     self.players = []
     self.player = Player("Jake")
     self.dealer = Dealer("Dealer")
     self.no_winner = Player("Error")
     self.players.append(self.player)
     self.players.append(self.dealer)
Ejemplo n.º 5
0
class Game:
    def __init__(self):
        self.deck = Deck()
        self.players = []
        self.player = Player("Jake")
        self.dealer = Dealer("Dealer")
        self.no_winner = Player("Error")
        self.players.append(self.player)
        self.players.append(self.dealer)

    def start(self):
        self.deck.populate()
        self.deck.shuffle()
        self.deal_cards()

        print("You have " + str(self.player.totalHandValue))
        self.take_go(self.player)
        self.dealer.play(self.deck, self.player)

        # winner = self.check_winner()
        print(self.check_winner())

    def deal_cards(self):
        for player in self.players:
            new_card = self.deck.deal()
            new_card2 = self.deck.deal()
            player.take_card(new_card)
            player.take_card(new_card2)

    def take_go(self, player):
        while player.is_bust() == False and player.ended_go is False:
            print(player.name + " currently has " + str(player.totalHandValue))
            player.get_user_input(self.deck)

    def check_winner(self):
        winner = self.dealer

        if (21 - self.player.totalHandValue) < (
                21 - winner.totalHandValue) and self.player.is_bust() is False:
            winner = self.player
        elif self.dealer.is_bust() and self.player.is_bust() is False:
            winner = self.player

        if winner == self.player:
            return "Congratulations, you won!"
        else:
            return "Unlucky, the dealer won!"
Ejemplo n.º 6
0
def get_player(id):
    conn = sqlite3.connect(settings.DB_DIR)
    cur = conn.cursor()
    cur.execute("SELECT * FROM players WHERE Id=?", (id,))
    player = cur.fetchone()
    conn.close()
    if(player == None):
        return None
    return Player(player[0], player[1], player[2], player[3], player[4], player[5], player[6])
Ejemplo n.º 7
0
    def __init__(self):
        self.player = Player(self)
        self.mainModel = MainModel(self.player)
        self.classificationModel = ClassificationModel()
        self.serializationModel = SerializationModel()

        self.mainWindow: IMainWindow = MainWindow()

        self.mainWindow.setMenuController(self)
        self.mainWindow.setOnlineRadiosController(self)
        self.mainWindow.setPlayerController(self)
        self.mainWindow.setMusicController(self)
        self.mainWindow.setAlbumsController(self)

        self.mainModel.addDisplayViewUpdatedListener(self.mainWindow)
        self.player.addPlayerStateUpdatedListener(self.mainWindow)

        self.mainWindow.mainLoop()
Ejemplo n.º 8
0
    def __init__(self):
        super().__init__(c="peace out", header="Start Screen")
        
        # mouse has to be the first item in the list, always or this breaks
        self.elements.append(Sprite(count=2, screen=self.screen))
        self.elements.append(Player(x=400, y=200, x_acc=1, y_acc=1, screen=self.screen,
                                    file_name="Images/character_sswsddddddddxxxxww.png"))
        self.elements.append(Player(x=600, y=200, x_acc=1, y_acc=1, screen=self.screen,
                                    file_name="Images/coffeepot_x.png"))
        self.elements.append(Sprite(count=2, screen=self.screen, x=200, y=200, x_vel=1))
        self.elements.append(Map(self.screen.get_size()))
        self.particles = []
        #self.music = open("resources/Music/space.mp3")
        self.dialogue = Dialogue()

        #pygame.mixer.music.load(self.music)
        #pygame.mixer.music.play(-1)

        pygame.display.update()
Ejemplo n.º 9
0
 def create_new_player(self, name):
     return Player(name)
Ejemplo n.º 10
0
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

max_len=4

logger = logging.getLogger(__name__)

SUGGEST_CARD, GENDER, PHOTO, LOCATION, BIO = range(5)

game = Game(-1001390724742)
conversation_handler = None

for i in range(0, 10):
    game.add_player(Player(i, "user " + str(i)))
game.add_player(Player(237713674, "mikaeel"))


def start(update, context):
    reply_keyboard = [['Boy', 'Girl', 'Other']]
    keyboard = [
        [InlineKeyboardButton("0", callback_data=str(0)),
         InlineKeyboardButton("4", callback_data=str(5)),
         InlineKeyboardButton("4", callback_data=str(0))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text(
        'Hi! My name is Professor Bot. I will hold a conversation with you. '
        'Send /cancel to stop talking to me.\n\n'
        'Are you a boy or a girl?',
Ejemplo n.º 11
0
def main():
    pygame.init()
    display = (800, 600)
    pygame.display.set_mode(display, DOUBLEBUF | OPENGL)

    gluPerspective(50, (display[0] / display[1]), 0.01, 150.0)
    glTranslatef(-4, -4, 0)

    cube_dict = {}
    x_value = 5
    z_value = -20
    y_value = 0
    player_move_speed = 0.1
    camera_move_speed = 0.3
    player_vertical_speed = 0
    gravity = 0.8
    is_player_grounded = True
    cubes = Cubes()
    cube_dict[0] = cubes.set_vertices(6, 0, -20)

    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    for x in range(7):
        z_value = z_value - 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(8, 12):
        x_value = x_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(13, 14):
        y_value = y_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(15, 18):
        z_value = z_value - 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(19, 21):
        x_value = x_value - 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(22, 23):
        y_value = y_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(24, 27):
        z_value = z_value - 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(28, 30):
        y_value = y_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(31, 34):
        x_value = x_value - 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(35, 36):
        y_value = y_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    for x in range(37, 41):
        z_value = z_value + 2
        cube_dict[x] = cubes.set_vertices(x_value, y_value, z_value)

    object_passed = False

    while not object_passed:
        x_move = 0
        y_move = 0
        z_move = 0
        player_move_x = 0
        player_move_y = 0
        player_move_z = 0
        should_reset = False

        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            x_move = camera_move_speed

        if keys[pygame.K_RIGHT]:
            x_move = -camera_move_speed
        
        if keys[pygame.K_UP]:
            y_move = -camera_move_speed
        
        if keys[pygame.K_DOWN]:
            y_move = camera_move_speed

        if keys[pygame.K_w]:
            player_move_z = -player_move_speed
            z_move = player_move_speed/2


        if keys[pygame.K_s]:
            player_move_z = player_move_speed
            z_move = -player_move_speed/2

        if keys[pygame.K_a]:
            player_move_x = -player_move_speed
            x_move = player_move_speed/2

        if keys[pygame.K_d]:
            player_move_x = player_move_speed
            x_move = -player_move_speed/2

        if keys[pygame.K_r]:
            should_reset = True

        if keys[pygame.K_SPACE] and is_player_grounded:
            is_player_grounded = False
            player_vertical_speed = 10
            player_move_y = player_vertical_speed * 0.1

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        glTranslatef(x_move, y_move, z_move)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        ground = Ground()
        ground.draw()
        
        player_vertical_speed -= gravity
        player_move_y = player_vertical_speed * 0.1

        current_player_pos = get_vertices(cube_dict[0])
        new_pos_x = current_player_pos[0] + player_move_x
        new_pos_y = current_player_pos[1] + player_move_y
        new_pos_z = current_player_pos[2] + player_move_z


        is_collision_x = False
        is_collision_y = False
        is_collision_z = False

        for each_cube in cube_dict:
            if (check_collision([new_pos_x, current_player_pos[1], current_player_pos[2]], get_vertices(cube_dict[40]))) or (check_collision([current_player_pos[0], new_pos_y, current_player_pos[2]], get_vertices(cube_dict[40]))) or (check_collision([current_player_pos[0], current_player_pos[1], new_pos_z], get_vertices(cube_dict[40]))):
                should_reset = True

            if each_cube != 0:
                is_collision_x = True if is_collision_x else check_collision([new_pos_x, current_player_pos[1], current_player_pos[2]], get_vertices(cube_dict[each_cube]))
                is_collision_y = True if is_collision_y else check_collision([current_player_pos[0], new_pos_y, current_player_pos[2]], get_vertices(cube_dict[each_cube]))
                is_collision_z = True if is_collision_z else check_collision([current_player_pos[0], current_player_pos[1], new_pos_z], get_vertices(cube_dict[each_cube]))
            cubes.draw(cube_dict[each_cube])

        if new_pos_y < 0:
            is_player_grounded = True
            player_vertical_speed = 0
            current_player_pos[1] = 0
            new_pos_y = 0

        if not is_collision_y and current_player_pos[1] > 0:
            is_player_grounded = False

        if is_collision_x:
            if player_move_x > 0: new_pos_x = ceil(current_player_pos[0])
            elif player_move_x < 0: new_pos_x = floor(current_player_pos[0])
            else: new_pos_x = current_player_pos[0]

        if is_collision_y:
            if player_move_y > 0 and current_player_pos[1] % 2 >= 1: new_pos_y = ceil(current_player_pos[1])
            elif player_move_y > 0 and current_player_pos[1] % 2 < 1: new_pos_y = floor(current_player_pos[1])
            elif player_move_y < 0:
                is_player_grounded = True
                player_vertical_speed = 0
                new_pos_y = floor(current_player_pos[1])
            else: new_pos_y = current_player_pos[1]

        if is_collision_z:
            if player_move_z > 0: new_pos_z = ceil(current_player_pos[2])
            elif player_move_z < 0: new_pos_z = floor(current_player_pos[2])
            else: new_pos_z = current_player_pos[2]

        cube_dict[0] = cubes.set_vertices(new_pos_x, new_pos_y, new_pos_z)
        if should_reset:
            cube_dict[0] = cubes.set_vertices(6, 0, -20)
            glTranslatef(x_move + 1, 0 , z_move - 15)


        player = Player()
        player.draw(cube_dict[0])
        pygame.display.flip()
Ejemplo n.º 12
0
 def setUp(self):
     self.game = Game()
     self.player = Player("Jake")
     self.deck = Deck()
     self.deck.populate()
Ejemplo n.º 13
0
class MainController(IMenuController, IOnlineRadiosController, IPlayerController, IMusicController, IAlbumsController, IRunnerOnMainThread):

    def __init__(self):
        self.player = Player(self)
        self.mainModel = MainModel(self.player)
        self.classificationModel = ClassificationModel()
        self.serializationModel = SerializationModel()

        self.mainWindow: IMainWindow = MainWindow()

        self.mainWindow.setMenuController(self)
        self.mainWindow.setOnlineRadiosController(self)
        self.mainWindow.setPlayerController(self)
        self.mainWindow.setMusicController(self)
        self.mainWindow.setAlbumsController(self)

        self.mainModel.addDisplayViewUpdatedListener(self.mainWindow)
        self.player.addPlayerStateUpdatedListener(self.mainWindow)

        self.mainWindow.mainLoop()

    def onRadiosOnlineClicked(self):
        self.mainModel.displayRadioSelection()

    def onRadioSelected(self, radio: RadioStation):
        self.mainModel.playRadio(radio)

    def onVolumeSelected(self, volume: int):
        self.player.setVolume(volume)

    def onPredictGenreClicked(self):
        messagebox.showinfo("Information", "Please select music file")
        file = filedialog.askopenfilename()
        if file is None or file == '':
            return

        try:
            genre = self.classificationModel.predictGenre(file)
            messagebox.showinfo("Information", f"Genre: {genre}")
        except Exception as e:
            print(e)
            messagebox.showerror("Error", "Could not predict genre!")

    def onMusicMenuButtonClicked(self):
        self.mainModel.displayMusicSelection()

    def onAlbumsMenuButtonClicked(self):
        self.mainModel.displayAlbumsSelection()

    def onQueueMenuButtonClicked(self):
        self.mainModel.displayQueue()

    def onStatisticsMenuButtonClicked(self):
        self.mainModel.displayStatistics()

    def onSkipDeleteClicked(self, skip: SkipDb):
        self.mainModel.mainModelDeleteSkip(skip)

    def onSkipAddClicked(self, musicPath: str, start: int, end: int):
        self.mainModel.mainModelAddSkip(musicPath, start, end)

    def onMusicDoubleClicked(self, music: Music):
        self.mainModel.addMusicToQueue(music)

    def seekTo(self, percentage: float):
        self.player.seekTo(percentage)

    def onPlayPauseClicked(self):
        self.player.playPause()

    def createAlbum(self, name: str):
        if name is None or name == '':
            messagebox.showwarning('Error', 'Insert album name firstly!')
            return

        success = self.mainModel.createAlbum(name)
        if not success:
            messagebox.showwarning('Error', 'Album with that name already exists!')
            return

    def deleteAlbum(self, name: str):
        self.mainModel.deleteAlbum(name)

    def addMusicToAlbum(self, name: str, musicPath: str):
        error = self.mainModel.addMusicToAlbum(name, musicPath)

        if error is not None:
            messagebox.showwarning('Error', error)
            return

    def removeMusicFromAlbum(self, name: str, musicPath: str):
        error = self.mainModel.removeMusicFromAlbum(name, musicPath)

        if error is not None:
            messagebox.showwarning('Error', error)
            return

    def exportAlbum(self, name: str):
        filename = filedialog.asksaveasfilename(defaultextension='alb', filetypes=[('Album file', ALBUM_EXTENSION)])
        _, extension = os.path.splitext(filename)

        if extension != ALBUM_EXTENSION:
            messagebox.showwarning('Warning', f'Please select file with extension {ALBUM_EXTENSION}')
            return

        self.serializationModel.exportAlbum(name, filename)

    def importAlbum(self):
        filename = filedialog.askopenfilename(defaultextension='alb', filetypes=[('Album file', ALBUM_EXTENSION)])
        _, extension = os.path.splitext(filename)

        if extension != ALBUM_EXTENSION:
            messagebox.showwarning('Warning', f'Please select file with extension {ALBUM_EXTENSION}')
            return

        success = self.serializationModel.importAlbum(filename)
        if not success:
            messagebox.showwarning('Warning', f'Import failed! Possible file corruption!')
            return

        self.mainModel.albumImported()

    def runOnMainThread(self, callable: Callable):
        self.mainWindow.runOnEventLoop(callable)

    def addAlbumToQueue(self, album: AlbumDb):
        self.mainModel.addAlbumToQueue(album)

    def nextTrackClicked(self):
        self.mainModel.nextTrack()

    def changeMusicSelectionModeClicked(self):
        self.mainModel.changeMusicSelectionMode()
Ejemplo n.º 14
0
from Repository.JsonWords import JsonWords
from Models.Player import Player
from Models.RandomWord import RandomWord
from Models.Board import Board
from Views.View import View
from Controllers.Controller import Controller
from random import choice

player = Player(View().ask_name())
View().announce_rules()


def main():
    word = RandomWord(choice(JsonWords().get_words()))

    while "-" in word.random_word or " " in word.random_word:  # avoids words like "water-based" or entries with spaces
        word = RandomWord(choice(JsonWords().get_words()))

    board = Board(player, word)
    view = View()
    controller = Controller(board, view)

    controller.hint()

    while True:
        controller.take_guess()
        controller.handle_guess()
        controller.result()
        controller.check_winner()

        if controller.winner is not None:
Ejemplo n.º 15
0
import threading
import time

from Models.Game import Game
from Models.Player import Player

game = Game(0)
for i in range(0, 10):
    game.add_player(Player(i, "user " + str(i)))


def run_game():
    while len(game.players) > 2:
        print("number of players in this turn: " + str(len(game.players)))
        print("turn started, you can suggest cards")
        time.sleep(20)
        game.start_vote_time()
        print("vote time started, you can vote")
        time.sleep(20)
        print("turn ended")
        game.end_turn()
        game.start_new_turn()


th = threading.Thread(target=run_game)
th.start()

while True:
    print("you can perform query")
    query = input()
    if query.split()[0] == 'suggest_card':
Ejemplo n.º 16
0
textX = 10
textY = 10

def show_score(x,y):
    score = font.render("Score: " + str(score_value), True, (255,255,255))
    screen.blit(score, (x, y))

# Game Over
def game_over_text():
    game_over = game_over_font.render("game over", True, (255,255,255))
    screen.blit(game_over, (width/4, height/4)) 


# # Player
player_img = pygame.image.load("Images/space_invaders.png")
player = Player(width, height-(1.5*64), 0)

# Bullet
bullet_img = pygame.image.load("Images/bullet.png")
bullet = Bullet(0, 480, 0)

# Enemy
enemy_img = pygame.image.load("Images/ufo.png")
enemies = []
num_of_enemies = 10
for i in range(num_of_enemies):
    enemies.append(Enemy(random.randint(0,width-64), random.randint(0,height/4), speedX,40))

# Clock to enable smooth movement
clock = pygame.time.Clock()