Python Forum
Client Server Game Pygame not responding
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Client Server Game Pygame not responding
#1
Hi everyone, I'm brand new to the community and looking for some help. I've been working on a poker game for a while now. I know my coding is pretty weak, but it's been a fun hobby that I picked up recently. My goal is to have a bunch of raspberry pis with touch screens and one large monitor making up a fully automated poker table. I have big dreams (lol) for this project with hopes of adding in features such as ordering beer from the touchscreen and having a bottle dispensing robot serve you table side. I also play around with very basic robotics so this is something I want to eventually add. Anyhow, I'm getting ahead of myself here. I am totally new to sockets when it comes to programming. I found that using non blocking tcp sockets with fixed length data seems to work for me. I can get the game started and pass/recv data from clients to server. The clients and server react to the data depending on what the value is. My current issue is that the UI/pygame on the server side stops responding once game starts and the sockets are formed. The hand progresses but the UI does not update on the server side. I'll post the server side and client side data below. Thanks in advance to anyone that takes the time to read this. Again, I know my code is pretty weak, so go easy on me.. ;-}

##SERVER SIDE CODE##
#MAIN
import os
from poker import *

global table

pygame.init()
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("D's HomeGame v1.0 - By DHD")

file = 'audio/shesgotthejack.mp3'
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
pygame.event.wait()


def comingSoon():
    coming_soon = True
    while coming_soon:
        gameDisplay.fill(felt)
        largeText = pygame.font.Font('freesansbold.ttf', 45)
        TextSurf, TextRect = text_objects("Cash-Game Option Coming Soon", largeText)
        TextRect.center = ((display_width / 2), (display_height / 2))
        gameDisplay.blit(TextSurf, TextRect)
        pygame.display.update()
        time.sleep(3)
        coming_soon = False


def game_intro():
    intro = True
    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        gameDisplay.fill(felt)
        largeText = pygame.font.Font('freesansbold.ttf', 75)
        TextSurf, TextRect = text_objects("Home-Game Hero", largeText)
        TextRect.center = ((display_width / 2), (display_height / 2))
        gameDisplay.blit(TextSurf, TextRect)

        pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
        pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()

        if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
            pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
            if click[0] == 1:
                sng()
        elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
            pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
            if click[0] == 1:
                comingSoon()
        else:
            pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
            pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

        smallText = pygame.font.Font("freesansbold.ttf", 20)
        textSurf, textRect = text_objects("SnG!", smallText)
        textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
        gameDisplay.blit(textSurf, textRect)

        smallText = pygame.font.Font("freesansbold.ttf", 20)
        textSurf, textRect = text_objects("Cash!", smallText)
        textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
        gameDisplay.blit(textSurf, textRect)

        pygame.display.update()


game_intro()
#Poker
[python]
import socket
import time
import random
import os
import datetime
from settings import *

gameDisplay = pygame.display.set_mode((display_width,display_height))
font_name = pygame.font.match_font('arial')

#################
####METHODS######
#################

def payThatMan_audio():
file = 'audio/payThatMan.mp3'
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
pygame.event.wait()

def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()

def message_display_3(text):
largeText = pygame.font.Font('freesansbold.ttf',16)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 25))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(2)

def message_display_1(text):
table.clearMessage()
largeText = pygame.font.Font('freesansbold.ttf',12)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 55))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(1)

def draw_text(surf, text, size, x,y, color):
font = pygame.font.Font(font_name, size)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.midtop = (x, y)
surf.blit(text_surface, text_rect)

def inpt():
global word
word = ""

gameDisplay.fill(felt)
pygame.display.update()
draw_text(gameDisplay, "Enter Your Name:", 64, display_width / 2, display_height * .1, white)
pygame.display.update()
done = True
while done:


for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()

if event.key == pygame.K_b:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_c:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_d:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_e:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_f:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_g:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_h:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_i:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_j:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_k:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_l:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_m:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_n:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_o:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_p:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_q:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_r:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_s:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_t:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_u:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_v:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_w:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_x:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_y:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_z:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()

if event.key == pygame.K_BACKSPACE:
word = word[:-1]
gameDisplay.fill(felt)
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_RETURN:
time.sleep(.2)
with open("names.txt", "a") as myfile:
myfile.write(word + ',')


done = False

def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()

def message_display_2(text):
largeText = pygame.font.Font('freesansbold.ttf',12)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 65))
gameDisplay.blit(TextSurf, TextRect)

def message_display_3(text):
largeText = pygame.font.Font('freesansbold.ttf',15)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 35))
gameDisplay.blit(TextSurf, TextRect)

def playersThusFar():
gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 50)
TextSurf, TextRect = text_objects("Registered Players:", largeText)
TextRect.center = ((display_width / 2), (30))
gameDisplay.blit(TextSurf, TextRect)
with open("names.txt", "r") as myfile:
for line in myfile:
currentLine = line.split(",")
x = 80
for i in currentLine:
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects(i, largeText)
TextRect.center = ((display_width / 2), (x))
gameDisplay.blit(TextSurf, TextRect)
x += 40





pygame.display.update()

def morePlayersCheck():
playercount = 2
morePlayers = True

while morePlayers:
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 80)
TextSurf, TextRect = text_objects("Any More Players?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (300, 500, 200, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
inpt()
playercount += 1
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
morePlayers = False
time.sleep(.2)
elif mouse[0] > 299 and mouse[0] < 501 and mouse[1] > 499 and mouse[1] < 551:
pygame.draw.rect(gameDisplay, blue, (300, 500, 200, 50))
if click[0] == 1:
playersThusFar()
time.sleep(3)
else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (300, 500, 200, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("YES", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("NO", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("Players Registered Thus Far", smallText)
textRect.center = ((300 + (200 / 2)), (500 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)
pygame.display.update()
if playercount > 8:
morePlayers = False

def blindTimeOptionScreen():
global blind_levels_time
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many minutes between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 60
running = False

elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 20
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 30
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1 HOUR", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Twenty", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Thirty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def blindTimeOptionScreen():
global blind_levels_time
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many minutes between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 60
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 20
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 30
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1 HOUR", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Twenty", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Thirty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def startingBlindsOptionScreen():
global small_blind
global big_blind
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("Where would you like to start the blinds?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
small_blind = 5
big_blind = 10
running = False

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
small_blind = 10
big_blind = 20
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
small_blind = 25
big_blind = 50
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
small_blind = 50
big_blind = 100
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
small_blind = 75
big_blind = 150
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("5 / 10", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("10 / 20", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("25 / 50", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("50 / 100", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("75 / 100", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def startingStackOptionsScreen():
global starting_stack
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("Select the starting stack", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))


mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
starting_stack = 1000
running = False
time.sleep(.2)

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
starting_stack = 5000
running = False
time.sleep(.2)

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
starting_stack = 10000
running = False
time.sleep(.2)

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))


smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1,000", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("10,000", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("5,000", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)


pygame.display.update()

def blindHandOptionScreen():
global blind_levels_hands
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many hands between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 100
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_hands = 25
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_hands = 50
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("One-Hundred", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("Twenty-Five", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Fifty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def blindOptionScreen():
global blinds_up_by
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 40)
TextSurf, TextRect = text_objects("Up the blinds by time or by hands?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blinds_up_by = 'time'
running = False
time.sleep(.2)
blindTimeOptionScreen()

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blinds_up_by = 'hands'
running = False
time.sleep(.2)
blindHandOptionScreen()
else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Time", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Hands", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def createPlayers():
with open("names.txt", "r") as myfile:
for line in myfile:
currentLine = line.split(",")
for i in currentLine:
i = Player(i)
global table
table = Table()

def sng():

open('names.txt', 'w').close() ##delete the contents for the names.txt file
inpt() ## ask for the first 2 players (need at least to for a game)
inpt()
morePlayersCheck() ##check for more players, if yes, enter more name(s) -- can also list current registered plyrs
###if no, then we start the game
with open("names.txt", 'rb+') as filehandle: ##delete the last comma from the names text file
filehandle.seek(-1, os.SEEK_END)
filehandle.truncate()

blindOptionScreen()
time.sleep(.2)
startingStackOptionsScreen()
time.sleep(.2)
startingBlindsOptionScreen()
time.sleep(.2)
createPlayers() ####here we need to create the players based off of the names.txt file.
for p in playerList:
print('trying to create and connect socket to player: ' + p.name)
p.sock.createSocket()
p.sock.connectSocket()
print('socket created and connected for player: ' + p.name)
pygame.mixer.music.stop() ## Here we stop the music when the game starts. Potentially have a different solution
#for music once the game is running.
table.starttime = datetime.datetime.now()
while table.pwc > 1: ## start the game
table.playHand()
time.sleep(2)
gameDisplay.fill(felt) ## game is over, we declare the winner, some messy cleanup of playerList below..
for p in playerList:
print(p.name + str(p.stack))
endofGame = sorted(playerList, key=lambda x: x.stack, reverse=True)
smallText = pygame.font.Font("freesansbold.ttf", 50)
textSurf, textRect = text_objects('SNG complete.', smallText)
textRect.center = (display_width / 2, display_height / 2)
gameDisplay.blit(textSurf, textRect)
smallText = pygame.font.Font("freesansbold.ttf", 50)
textSurf, textRect = text_objects('The winner is: ' + endofGame[0].name, smallText)
textRect.center = (display_width / 2, display_height / 2 + 100)
gameDisplay.blit(textSurf, textRect)
pygame.display.update()
payThatMan_audio()
time.sleep(10)
playerList.clear()

#################
####CLASSES######
#################

class Card:
def __init__(self, value, color):
self.value = value
self.color = color


if self.value == 14 and self.color == 'spades':
self.image = img_AS
self.imagestr = 'img_AS'
elif self.value == 13 and self.color == 'spades':
self.image = img_KS
self.imagestr = 'img_KS'
elif self.value == 12 and self.color == 'spades':
self.image = img_QS
self.imagestr = 'img_QS'
elif self.value == 11 and self.color == 'spades':
self.image = img_JS
self.imagestr = 'img_JS'
elif self.value == 10 and self.color == 'spades':
self.image = img_TS
self.imagestr = 'img_TS'
elif self.value == 9 and self.color == 'spades':
self.image = img_9S
self.imagestr = 'img_9S'
elif self.value == 8 and self.color == 'spades':
self.image = img_8S
self.imagestr = 'img_8S'
elif self.value == 7 and self.color == 'spades':
self.image = img_7S
self.imagestr = 'img_7S'
elif self.value == 6 and self.color == 'spades':
self.image = img_6S
self.imagestr = 'img_6S'
elif self.value == 5 and self.color == 'spades':
self.image = img_5S
self.imagestr = 'img_5S'
elif self.value == 4 and self.color == 'spades':
self.image = img_4S
self.imagestr = 'img_4S'
elif self.value == 3 and self.color == 'spades':
self.image = img_3S
self.imagestr = 'img_3S'
elif self.value == 2and self.color == 'spades':
self.image = img_2S
self.imagestr = 'img_2S'
elif self.value == 14 and self.color == 'heart':
self.image = img_AH
self.imagestr = 'img_AH'
elif self.value == 13 and self.color == 'heart':
self.image = img_KH
self.imagestr = 'img_KH'
elif self.value == 12 and self.color == 'heart':
self.image = img_QH
self.imagestr = 'img_QH'
elif self.value == 11 and self.color == 'heart':
self.image = img_JH
self.imagestr = 'img_JH'
elif self.value == 10 and self.color == 'heart':
self.image = img_TH
self.imagestr = 'img_TH'
elif self.value == 9 and self.color == 'heart':
self.image = img_9H
self.imagestr = 'img_9H'
elif self.value == 8 and self.color == 'heart':
self.image = img_8H
self.imagestr = 'img_8H'
elif self.value == 7 and self.color == 'heart':
self.image = img_7H
self.imagestr = 'img_7H'
elif self.value == 6 and self.color == 'heart':
self.image = img_6H
self.imagestr = 'img_6H'
elif self.value == 5 and self.color == 'heart':
self.image = img_5H
self.imagestr = 'img_5H'
elif self.value == 4 and self.color == 'heart':
self.image = img_4H
self.imagestr = 'img_4H'
elif self.value == 3 and self.color == 'heart':
self.image = img_3H
self.imagestr = 'img_3H'
elif self.value == 2and self.color == 'heart':
self.image = img_2H
self.imagestr = 'img_2H'
elif self.value == 14 and self.color == 'clubs':
self.image = img_AC
self.imagestr = 'img_AC'
elif self.value == 13 and self.color == 'clubs':
self.image = img_KC
self.imagestr = 'img_KC'
elif self.value == 12 and self.color == 'clubs':
self.image = img_QC
self.imagestr = 'img_QC'
elif self.value == 11 and self.color == 'clubs':
self.image = img_JC
self.imagestr = 'img_JC'
elif self.value == 10 and self.color == 'clubs':
self.image = img_TC
self.imagestr = 'img_TC'
elif self.value == 9 and self.color == 'clubs':
self.image = img_9C
self.imagestr = 'img_9C'
elif self.value == 8 and self.color == 'clubs':
self.image = img_8C
self.imagestr = 'img_8C'
elif self.value == 7 and self.color == 'clubs':
self.image = img_7C
self.imagestr = 'img_7C'
elif self.value == 6 and self.color == 'clubs':
self.image = img_6C
self.imagestr = 'img_6C'
elif self.value == 5 and self.color == 'clubs':
self.image = img_5C
self.imagestr = 'img_5C'
elif self.value == 4 and self.color == 'clubs':
self.image = img_4C
self.imagestr = 'img_4C'
elif self.value == 3 and self.color == 'clubs':
self.image = img_3C
self.imagestr = 'img_3C'
elif self.value == 2and self.color == 'clubs':
self.image = img_2C
self.imagestr = 'img_2C'
elif self.value == 14 and self.color == 'diamonds':
self.image = img_AD
self.imagestr = 'img_AD'
elif self.value == 13 and self.color == 'diamonds':
self.image = img_KD
self.imagestr = 'img_KD'
elif self.value == 12 and self.color == 'diamonds':
self.image = img_QD
self.imagestr = 'img_QD'
elif self.value == 11 and self.color == 'diamonds':
self.image = img_JD
self.imagestr = 'img_JD'
elif self.value == 10 and self.color == 'diamonds':
self.image = img_TD
self.imagestr = 'img_TD'
elif self.value == 9 and self.color == 'diamonds':
self.image = img_9D
self.imagestr = 'img_9D'
elif self.value == 8 and self.color == 'diamonds':
self.image = img_8D
self.imagestr = 'img_8D'
elif self.value == 7 and self.color == 'diamonds':
self.image = img_7D
self.imagestr = 'img_7D'
elif self.value == 6 and self.color == 'diamonds':
self.image = img_6D
self.imagestr = 'img_6D'
elif self.value == 5 and self.color == 'diamonds':
self.image = img_5D
self.imagestr = 'img_5D'
elif self.value == 4 and self.color == 'diamonds':
self.image = img_4D
self.imagestr = 'img_4D'
elif self.value == 3 and self.color == 'diamonds':
self.image = img_3D
self.imagestr = 'img_3D'
elif self.value == 2and self.color == 'diamonds':
self.image = img_2D
self.imagestr = 'img_2D'


if self.value < 11:
self.text = str(self.value)
elif self.value == 11:
self.text = 'J'
elif self.value == 12:
self.text = 'Q'
self.text = 'Q'
elif self.value == 13:
self.text = 'K'
elif self.value == 14:
self.text = 'A'

colors = ['heart', 'diamonds', 'spades', 'clubs']
values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]


class Deck:
def __init__(self):
self.cards = []
for value in Card.values:
for color in Card.colors:
self.cards.append(Card(value, color))

def shuffle(self):
random.shuffle(self.cards)
def refresh(self):
self.cards.clear()
self.cards = []
for value in Card.values:
for color in Card.colors:
self.cards.append(Card(value, color))


class Table:
def __init__(self):
self.handcount = 0
self.cards = []
self.sb = small_blind
self.bb = big_blind
self.starttime = datetime.datetime.now()
self.highbid = 0
self.bidraise = 0
self.psb = 1
self.pbb = 2
self.pbutton = 0
self.x = 0
self.y = 0
self.actionOn = playerList[self.y]
self.pwc = len(playerList) # counter to keep track of how many players have chips
self.pih = [] # counter to keep track of how maby players have a hand/cards
self.phcards = 0
self.pot1 = Pot()
self.pot2 = Pot()
self.pot3 = Pot()
self.pot4 = Pot()
self.pot5 = Pot()
self.pot6 = Pot()
self.pot7 = Pot()
self.pot8 = Pot()
self.pot9 = Pot()
self.ap = 0
self.pots = [self.pot1, self.pot2, self.pot3, self.pot4, self.pot5, self.pot6, self.pot7, self.pot8, self.pot9]
self.pot = self.pots[self.ap]


playerList[0].coords = coordsP0
playerList[0].ip = '192.168.86.86'
playerList[0].port = 8089
playerList[0].sock = Socket(playerList[0].name, playerList[0].port, playerList[0].ip)
playerList[1].coords = coordsP1
playerList[1].ip = '192.168.86.86'
playerList[1].port = 8090
playerList[1].sock = Socket(playerList[1].name, playerList[1].port, playerList[1].ip)
if len(playerList) > 2:
playerList[2].coords = coordsP2
if len(playerList) > 3:
playerList[3].coords = coordsP3
if len(playerList) > 4:
playerList[4].coords = coordsP4
if len(playerList) > 5:
playerList[5].coords = coordsP5
if len(playerList) > 6:
playerList[6].coords = coordsP6
if len(playerList) > 7:
playerList[7].coords = coordsP7
if len(playerList) > 8:
playerList[8].coords = coordsP8

def upBlinds(self):
self.bb = self.bb * 2
self.sb = self.sb * 2

def betGUI(self):
amount = 0
running = True
while running:
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.blit(img_chip10, (150, 150))
gameDisplay.blit(img_chip25, (230, 150))
gameDisplay.blit(img_chip100, (310, 150))
gameDisplay.blit(img_chipallin, (390, 150))
gameDisplay.blit(img_chipclear, (470, 150))
gameDisplay.blit(img_chipsubmit, (550, 150))
gameDisplay.blit(img_cancel, (630, 150))
smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("BET: " + str(amount), smallText)
textRect.center = (400, 420)
gameDisplay.blit(textSurf, textRect)

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 229 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 10
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 229 and mouse[0] < 309 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 25
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)
if mouse[0] > 309 and mouse[0] < 389 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 100
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 389 and mouse[0] < 469 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount = self.actionOn.stack
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 469 and mouse[0] < 549 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount = 0
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 549 and mouse[0] < 629 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
self.actionOn.bidd(amount)
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 629 and mouse[0] < 709 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
running = False
self.clearBetButtons()
time.sleep(.1)

if self.actionOn.action == 2:
self.x += 1
running = False
self.clearBetButtons()

self.updateGUI()

def clearBetButtons(self):
pygame.draw.rect(gameDisplay, felt, (142, 145, 590, 75), 0)

def printActionButtons(self):

running = True
while running:
if self.actionOn.action == 2:
self.x += 1
running = False
if self.actionOn.action != 2:
self.actionOn.sock.sendit(pactiononu)

self.actionOn.sock.data = self.actionOn.sock.connection.recv(10)


print('found some data, here it is ' + str(self.actionOn.sock.data))
print('the data that was recieved was -- ' + str(len(self.actionOn.sock.data)) + ' bytes')

if 'fold' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has folded')
self.actionOn.fold()
self.x += 1
running = False
if 'call' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has called')
self.actionOn.call()
running = False
if 'check' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has checked')
self.actionOn.check()
running = False



# print('preflop action buttons')
# print('the action is on ' + self.actionOn.name)
# time.sleep(.1)
# running = True
# while running:
# for event in pygame.event.get():
# # print(event)
# if event.type == pygame.QUIT:
# pygame.quit()
# quit()
# pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (275, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (400, 450, 100, 50))
#
# mouse = pygame.mouse.get_pos()
# click = pygame.mouse.get_pressed()
#
# ###PEEK AT CARDS (player who the action is on)
# if mouse[0] > self.actionOn.coords[0] - 1 and mouse[0] < self.actionOn.coords[0] + 70 and mouse[1] > \
# self.actionOn.coords[1] - 1 and mouse[1] < self.actionOn.coords[1] + 90:
# if click[0] == 1:
# # print('click worked, you clicked on your card, peek time')
# gameDisplay.blit(self.actionOn.cards[0].image, self.actionOn.coords)
# gameDisplay.blit(self.actionOn.cards[1].image,
# [self.actionOn.coords[0] + 70, self.actionOn.coords[1]])
# pygame.display.update()
# else:
# gameDisplay.blit(img_cardback, self.actionOn.coords)
# gameDisplay.blit(img_cardback, [self.actionOn.coords[0] + 70, self.actionOn.coords[1]])
#
# if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
# pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
# if click[0] == 1:
# # print('click worked, you clicked on call')
# self.actionOn.call()
#
# time.sleep(.1)
# elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
# pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
# if click[0] == 1:
# # print('click worked, you clicked on check')
# self.actionOn.check()
#
# time.sleep(.1)
#
#
#
#
#
# else:
# pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (400, 450, 100, 50))
# pygame.draw.rect(gameDisplay, white, (275, 450, 100, 50))
#
# if mouse[0] > 399 and mouse[0] < 501 and mouse[1] > 449 and mouse[1] < 501:
# pygame.draw.rect(gameDisplay, blue, (400, 450, 100, 50))
# if click[0] == 1:
# self.actionOn.fold()
# time.sleep(.1)
# running = False
# self.clearBetButtons()
#
# elif mouse[0] > 275 and mouse[0] < 376 and mouse[1] > 449 and mouse[1] < 501:
# pygame.draw.rect(gameDisplay, blue, (275, 450, 100, 50))
# if click[0] == 1:
# self.betGUI()
# time.sleep(.1)
# running = False
#
# elif self.actionOn.action == 2:
# self.x += 1
# print('printActionButtons just incremented x by 1')
# running = False
# self.clearBetButtons()
#
# smallText = pygame.font.Font("freesansbold.ttf", 20)
# textSurf, textRect = text_objects("CALL", smallText)
# textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
# gameDisplay.blit(textSurf, textRect)
#
# smallText = pygame.font.Font("freesansbold.ttf", 15)
# textSurf, textRect = text_objects("BET/RAISE", smallText)
# textRect.center = ((275 + (100 / 2)), (450 + (50 / 2)))
# gameDisplay.blit(textSurf, textRect)
#
# smallText = pygame.font.Font("freesansbold.ttf", 20)
# textSurf, textRect = text_objects("FOLD", smallText)
# textRect.center = ((400 + (100 / 2)), (450 + (50 / 2)))
# gameDisplay.blit(textSurf, textRect)
#
# smallText = pygame.font.Font("freesansbold.ttf", 20)
# textSurf, textRect = text_objects("CHECK!", smallText)
# textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
# gameDisplay.blit(textSurf, textRect)
#
# pygame.display.update()

def blinds(self):
for player in playerList:
if player.stack > 0:
player.action = 1
self.pih.append(player)
if len(self.pih) > 2:
##First we place the button
buttonnochips = True
while buttonnochips:
if self.pbutton > len(playerList) - 1:
self.pbutton = 0
if playerList
Reply
#2
Hi Guys, I'm sorry about the first post. I thought I could put in several python sections using the python tags. Hopefully I get it right this time. Also it's quite a bit of code so hopefully there's no limit to the amount of code that I can insert. I'll be putting in 3 py files worth of code and separating them with comments. Main, Poker, and Settings. I'll make the comments for the sections bold to hopefully make it easier to see.

Hi everyone, I'm brand new to the community and looking for some help. I've been working on a poker game for a while now. I know my coding is pretty weak, but it's been a fun hobby that I picked up recently. My goal is to have a bunch of raspberry pis with touch screens and one large monitor making up a fully automated poker table. I have big dreams (lol) for this project with hopes of adding in features such as ordering beer from the touchscreen and having a bottle dispensing robot serve you table side. I also play around with very basic robotics so this is something I want to eventually add. Anyhow, I'm getting ahead of myself here. I am totally new to sockets when it comes to programming. I found that using non blocking tcp sockets with fixed length data seems to work for me. I can get the game started and pass/recv data from clients to server. The clients and server react to the data depending on what the value is. My current issue is that the UI/pygame on the server side stops responding once game starts and the sockets are formed. The hand progresses but the UI does not update on the server side. I'll post the server side and client side data below. Thanks in advance to anyone that takes the time to read this. Again, I know my code is pretty weak, so go easy on me.. ;-} If the client side code is needed I can surely upload that as well.

[python]
##########
##MAIN####
##########

import os
from poker import *

global table

pygame.init()
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("D's HomeGame v1.0 - By DHD")

file = 'audio/shesgotthejack.mp3'
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
pygame.event.wait()


def comingSoon():
coming_soon = True
while coming_soon:
gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 45)
TextSurf, TextRect = text_objects("Cash-Game Option Coming Soon", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(3)
coming_soon = False


def game_intro():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 75)
TextSurf, TextRect = text_objects("Home-Game Hero", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
sng()
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
comingSoon()
else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("SnG!", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Cash!", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()


game_intro()

##########
##POKER###
##########

import socket
import time
import random
import os
import datetime
from settings import *

gameDisplay = pygame.display.set_mode((display_width,display_height))
font_name = pygame.font.match_font('arial')

#################
####METHODS######
#################

def payThatMan_audio():
file = 'audio/payThatMan.mp3'
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
pygame.event.wait()

def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()

def message_display_3(text):
largeText = pygame.font.Font('freesansbold.ttf',16)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 25))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(2)

def message_display_1(text):
table.clearMessage()
largeText = pygame.font.Font('freesansbold.ttf',12)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 55))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(1)

def draw_text(surf, text, size, x,y, color):
font = pygame.font.Font(font_name, size)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.midtop = (x, y)
surf.blit(text_surface, text_rect)

def inpt():
global word
word = ""

gameDisplay.fill(felt)
pygame.display.update()
draw_text(gameDisplay, "Enter Your Name:", 64, display_width / 2, display_height * .1, white)
pygame.display.update()
done = True
while done:


for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()

if event.key == pygame.K_b:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_c:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_d:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_e:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_f:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_g:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_h:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_i:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_j:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_k:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_l:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_m:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_n:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_o:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_p:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_q:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_r:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_s:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_t:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_u:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_v:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_w:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_x:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_y:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_z:
word += (chr(event.key))
gameDisplay.fill(felt)
word = word.upper()
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()

if event.key == pygame.K_BACKSPACE:
word = word[:-1]
gameDisplay.fill(felt)
draw_text(gameDisplay, str(word), 64, display_width / 2, display_height * .5, white)
draw_text(gameDisplay, "Enter your name:", 64, display_width / 2, display_height * .2, white)
pygame.display.update()
if event.key == pygame.K_RETURN:
time.sleep(.2)
with open("names.txt", "a") as myfile:
myfile.write(word + ',')


done = False

def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()

def message_display_2(text):
largeText = pygame.font.Font('freesansbold.ttf',12)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 65))
gameDisplay.blit(TextSurf, TextRect)

def message_display_3(text):
largeText = pygame.font.Font('freesansbold.ttf',15)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width / 2),(display_height - 35))
gameDisplay.blit(TextSurf, TextRect)

def playersThusFar():
gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 50)
TextSurf, TextRect = text_objects("Registered Players:", largeText)
TextRect.center = ((display_width / 2), (30))
gameDisplay.blit(TextSurf, TextRect)
with open("names.txt", "r") as myfile:
for line in myfile:
currentLine = line.split(",")
x = 80
for i in currentLine:
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects(i, largeText)
TextRect.center = ((display_width / 2), (x))
gameDisplay.blit(TextSurf, TextRect)
x += 40





pygame.display.update()

def morePlayersCheck():
playercount = 2
morePlayers = True

while morePlayers:
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 80)
TextSurf, TextRect = text_objects("Any More Players?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (300, 500, 200, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
inpt()
playercount += 1
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
morePlayers = False
time.sleep(.2)
elif mouse[0] > 299 and mouse[0] < 501 and mouse[1] > 499 and mouse[1] < 551:
pygame.draw.rect(gameDisplay, blue, (300, 500, 200, 50))
if click[0] == 1:
playersThusFar()
time.sleep(3)
else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (300, 500, 200, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("YES", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("NO", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("Players Registered Thus Far", smallText)
textRect.center = ((300 + (200 / 2)), (500 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)
pygame.display.update()
if playercount > 8:
morePlayers = False

def blindTimeOptionScreen():
global blind_levels_time
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many minutes between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 60
running = False

elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 20
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 30
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1 HOUR", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Twenty", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Thirty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def blindTimeOptionScreen():
global blind_levels_time
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many minutes between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_time = 60
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 20
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_time = 30
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1 HOUR", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Twenty", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Thirty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def startingBlindsOptionScreen():
global small_blind
global big_blind
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("Where would you like to start the blinds?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
small_blind = 5
big_blind = 10
running = False

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
small_blind = 10
big_blind = 20
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
small_blind = 25
big_blind = 50
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
small_blind = 50
big_blind = 100
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
small_blind = 75
big_blind = 150
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("5 / 10", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("10 / 20", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("25 / 50", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("50 / 100", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("75 / 100", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def startingStackOptionsScreen():
global starting_stack
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("Select the starting stack", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))


mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
starting_stack = 1000
running = False
time.sleep(.2)

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
starting_stack = 5000
running = False
time.sleep(.2)

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
starting_stack = 10000
running = False
time.sleep(.2)

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))


smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("1,000", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("10,000", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("5,000", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)


pygame.display.update()

def blindHandOptionScreen():
global blind_levels_hands
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 30)
TextSurf, TextRect = text_objects("How many hands between blind levels?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 5
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 10
running = False

elif mouse[0] > 349 and mouse[0] < 451 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (350, 450, 100, 50))
if click[0] == 1:
blind_levels_hands = 100
running = False


elif mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (150, 510, 100, 50))
if click[0] == 1:
blind_levels_hands = 25
running = False
elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 509 and mouse[1] < 561:
pygame.draw.rect(gameDisplay, blue, (550, 510, 100, 50))
if click[0] == 1:
blind_levels_hands = 50
running = False

else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (350, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (150, 510, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 510, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Five", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Ten", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("One-Hundred", smallText)
textRect.center = ((350 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 12)
textSurf, textRect = text_objects("Twenty-Five", smallText)
textRect.center = ((150 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Fifty", smallText)
textRect.center = ((550 + (100 / 2)), (510 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def blindOptionScreen():
global blinds_up_by
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.fill(felt)
largeText = pygame.font.Font('freesansbold.ttf', 40)
TextSurf, TextRect = text_objects("Up the blinds by time or by hands?", largeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)

pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 251 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (150, 450, 100, 50))
if click[0] == 1:
blinds_up_by = 'time'
running = False
time.sleep(.2)
blindTimeOptionScreen()

elif mouse[0] > 549 and mouse[0] < 651 and mouse[1] > 449 and mouse[1] < 501:
pygame.draw.rect(gameDisplay, blue, (550, 450, 100, 50))
if click[0] == 1:
blinds_up_by = 'hands'
running = False
time.sleep(.2)
blindHandOptionScreen()
else:
pygame.draw.rect(gameDisplay, white, (150, 450, 100, 50))
pygame.draw.rect(gameDisplay, white, (550, 450, 100, 50))

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Time", smallText)
textRect.center = ((150 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("Hands", smallText)
textRect.center = ((550 + (100 / 2)), (450 + (50 / 2)))
gameDisplay.blit(textSurf, textRect)

pygame.display.update()

def createPlayers():
with open("names.txt", "r") as myfile:
for line in myfile:
currentLine = line.split(",")
for i in currentLine:
i = Player(i)
global table
table = Table()

def sng():

open('names.txt', 'w').close() ##delete the contents for the names.txt file
inpt() ## ask for the first 2 players (need at least to for a game)
inpt()
morePlayersCheck() ##check for more players, if yes, enter more name(s) -- can also list current registered plyrs
###if no, then we start the game
with open("names.txt", 'rb+') as filehandle: ##delete the last comma from the names text file
filehandle.seek(-1, os.SEEK_END)
filehandle.truncate()

blindOptionScreen()
time.sleep(.2)
startingStackOptionsScreen()
time.sleep(.2)
startingBlindsOptionScreen()
time.sleep(.2)
createPlayers() ####here we need to create the players based off of the names.txt file.
for p in playerList:
print('trying to create and connect socket to player: ' + p.name)
p.sock.createSocket()
p.sock.connectSocket()
print('socket created and connected for player: ' + p.name)
pygame.mixer.music.stop() ## Here we stop the music when the game starts. Potentially have a different solution
#for music once the game is running.
table.starttime = datetime.datetime.now()
while table.pwc > 1: ## start the game
table.playHand()
time.sleep(2)
gameDisplay.fill(felt) ## game is over, we declare the winner, some messy cleanup of playerList below..
for p in playerList:
print(p.name + str(p.stack))
endofGame = sorted(playerList, key=lambda x: x.stack, reverse=True)
smallText = pygame.font.Font("freesansbold.ttf", 50)
textSurf, textRect = text_objects('SNG complete.', smallText)
textRect.center = (display_width / 2, display_height / 2)
gameDisplay.blit(textSurf, textRect)
smallText = pygame.font.Font("freesansbold.ttf", 50)
textSurf, textRect = text_objects('The winner is: ' + endofGame[0].name, smallText)
textRect.center = (display_width / 2, display_height / 2 + 100)
gameDisplay.blit(textSurf, textRect)
pygame.display.update()
payThatMan_audio()
time.sleep(10)
playerList.clear()

#################
####CLASSES######
#################

class Card:
def __init__(self, value, color):
self.value = value
self.color = color


if self.value == 14 and self.color == 'spades':
self.image = img_AS
self.imagestr = 'img_AS'
elif self.value == 13 and self.color == 'spades':
self.image = img_KS
self.imagestr = 'img_KS'
elif self.value == 12 and self.color == 'spades':
self.image = img_QS
self.imagestr = 'img_QS'
elif self.value == 11 and self.color == 'spades':
self.image = img_JS
self.imagestr = 'img_JS'
elif self.value == 10 and self.color == 'spades':
self.image = img_TS
self.imagestr = 'img_TS'
elif self.value == 9 and self.color == 'spades':
self.image = img_9S
self.imagestr = 'img_9S'
elif self.value == 8 and self.color == 'spades':
self.image = img_8S
self.imagestr = 'img_8S'
elif self.value == 7 and self.color == 'spades':
self.image = img_7S
self.imagestr = 'img_7S'
elif self.value == 6 and self.color == 'spades':
self.image = img_6S
self.imagestr = 'img_6S'
elif self.value == 5 and self.color == 'spades':
self.image = img_5S
self.imagestr = 'img_5S'
elif self.value == 4 and self.color == 'spades':
self.image = img_4S
self.imagestr = 'img_4S'
elif self.value == 3 and self.color == 'spades':
self.image = img_3S
self.imagestr = 'img_3S'
elif self.value == 2and self.color == 'spades':
self.image = img_2S
self.imagestr = 'img_2S'
elif self.value == 14 and self.color == 'heart':
self.image = img_AH
self.imagestr = 'img_AH'
elif self.value == 13 and self.color == 'heart':
self.image = img_KH
self.imagestr = 'img_KH'
elif self.value == 12 and self.color == 'heart':
self.image = img_QH
self.imagestr = 'img_QH'
elif self.value == 11 and self.color == 'heart':
self.image = img_JH
self.imagestr = 'img_JH'
elif self.value == 10 and self.color == 'heart':
self.image = img_TH
self.imagestr = 'img_TH'
elif self.value == 9 and self.color == 'heart':
self.image = img_9H
self.imagestr = 'img_9H'
elif self.value == 8 and self.color == 'heart':
self.image = img_8H
self.imagestr = 'img_8H'
elif self.value == 7 and self.color == 'heart':
self.image = img_7H
self.imagestr = 'img_7H'
elif self.value == 6 and self.color == 'heart':
self.image = img_6H
self.imagestr = 'img_6H'
elif self.value == 5 and self.color == 'heart':
self.image = img_5H
self.imagestr = 'img_5H'
elif self.value == 4 and self.color == 'heart':
self.image = img_4H
self.imagestr = 'img_4H'
elif self.value == 3 and self.color == 'heart':
self.image = img_3H
self.imagestr = 'img_3H'
elif self.value == 2and self.color == 'heart':
self.image = img_2H
self.imagestr = 'img_2H'
elif self.value == 14 and self.color == 'clubs':
self.image = img_AC
self.imagestr = 'img_AC'
elif self.value == 13 and self.color == 'clubs':
self.image = img_KC
self.imagestr = 'img_KC'
elif self.value == 12 and self.color == 'clubs':
self.image = img_QC
self.imagestr = 'img_QC'
elif self.value == 11 and self.color == 'clubs':
self.image = img_JC
self.imagestr = 'img_JC'
elif self.value == 10 and self.color == 'clubs':
self.image = img_TC
self.imagestr = 'img_TC'
elif self.value == 9 and self.color == 'clubs':
self.image = img_9C
self.imagestr = 'img_9C'
elif self.value == 8 and self.color == 'clubs':
self.image = img_8C
self.imagestr = 'img_8C'
elif self.value == 7 and self.color == 'clubs':
self.image = img_7C
self.imagestr = 'img_7C'
elif self.value == 6 and self.color == 'clubs':
self.image = img_6C
self.imagestr = 'img_6C'
elif self.value == 5 and self.color == 'clubs':
self.image = img_5C
self.imagestr = 'img_5C'
elif self.value == 4 and self.color == 'clubs':
self.image = img_4C
self.imagestr = 'img_4C'
elif self.value == 3 and self.color == 'clubs':
self.image = img_3C
self.imagestr = 'img_3C'
elif self.value == 2and self.color == 'clubs':
self.image = img_2C
self.imagestr = 'img_2C'
elif self.value == 14 and self.color == 'diamonds':
self.image = img_AD
self.imagestr = 'img_AD'
elif self.value == 13 and self.color == 'diamonds':
self.image = img_KD
self.imagestr = 'img_KD'
elif self.value == 12 and self.color == 'diamonds':
self.image = img_QD
self.imagestr = 'img_QD'
elif self.value == 11 and self.color == 'diamonds':
self.image = img_JD
self.imagestr = 'img_JD'
elif self.value == 10 and self.color == 'diamonds':
self.image = img_TD
self.imagestr = 'img_TD'
elif self.value == 9 and self.color == 'diamonds':
self.image = img_9D
self.imagestr = 'img_9D'
elif self.value == 8 and self.color == 'diamonds':
self.image = img_8D
self.imagestr = 'img_8D'
elif self.value == 7 and self.color == 'diamonds':
self.image = img_7D
self.imagestr = 'img_7D'
elif self.value == 6 and self.color == 'diamonds':
self.image = img_6D
self.imagestr = 'img_6D'
elif self.value == 5 and self.color == 'diamonds':
self.image = img_5D
self.imagestr = 'img_5D'
elif self.value == 4 and self.color == 'diamonds':
self.image = img_4D
self.imagestr = 'img_4D'
elif self.value == 3 and self.color == 'diamonds':
self.image = img_3D
self.imagestr = 'img_3D'
elif self.value == 2and self.color == 'diamonds':
self.image = img_2D
self.imagestr = 'img_2D'


if self.value < 11:
self.text = str(self.value)
elif self.value == 11:
self.text = 'J'
elif self.value == 12:
self.text = 'Q'
self.text = 'Q'
elif self.value == 13:
self.text = 'K'
elif self.value == 14:
self.text = 'A'

colors = ['heart', 'diamonds', 'spades', 'clubs']
values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]


class Deck:
def __init__(self):
self.cards = []
for value in Card.values:
for color in Card.colors:
self.cards.append(Card(value, color))

def shuffle(self):
random.shuffle(self.cards)
def refresh(self):
self.cards.clear()
self.cards = []
for value in Card.values:
for color in Card.colors:
self.cards.append(Card(value, color))


class Table:
def __init__(self):
self.handcount = 0
self.cards = []
self.sb = small_blind
self.bb = big_blind
self.starttime = datetime.datetime.now()
self.highbid = 0
self.bidraise = 0
self.psb = 1
self.pbb = 2
self.pbutton = 0
self.x = 0
self.y = 0
self.actionOn = playerList[self.y]
self.pwc = len(playerList) # counter to keep track of how many players have chips
self.pih = [] # counter to keep track of how maby players have a hand/cards
self.phcards = 0
self.pot1 = Pot()
self.pot2 = Pot()
self.pot3 = Pot()
self.pot4 = Pot()
self.pot5 = Pot()
self.pot6 = Pot()
self.pot7 = Pot()
self.pot8 = Pot()
self.pot9 = Pot()
self.ap = 0
self.pots = [self.pot1, self.pot2, self.pot3, self.pot4, self.pot5, self.pot6, self.pot7, self.pot8, self.pot9]
self.pot = self.pots[self.ap]


playerList[0].coords = coordsP0
playerList[0].ip = '192.168.86.86'
playerList[0].port = 8089
playerList[0].sock = Socket(playerList[0].name, playerList[0].port, playerList[0].ip)
playerList[1].coords = coordsP1
playerList[1].ip = '192.168.86.86'
playerList[1].port = 8090
playerList[1].sock = Socket(playerList[1].name, playerList[1].port, playerList[1].ip)
if len(playerList) > 2:
playerList[2].coords = coordsP2
if len(playerList) > 3:
playerList[3].coords = coordsP3
if len(playerList) > 4:
playerList[4].coords = coordsP4
if len(playerList) > 5:
playerList[5].coords = coordsP5
if len(playerList) > 6:
playerList[6].coords = coordsP6
if len(playerList) > 7:
playerList[7].coords = coordsP7
if len(playerList) > 8:
playerList[8].coords = coordsP8

def upBlinds(self):
self.bb = self.bb * 2
self.sb = self.sb * 2

def betGUI(self):
amount = 0
running = True
while running:
for event in pygame.event.get():
# print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()

gameDisplay.blit(img_chip10, (150, 150))
gameDisplay.blit(img_chip25, (230, 150))
gameDisplay.blit(img_chip100, (310, 150))
gameDisplay.blit(img_chipallin, (390, 150))
gameDisplay.blit(img_chipclear, (470, 150))
gameDisplay.blit(img_chipsubmit, (550, 150))
gameDisplay.blit(img_cancel, (630, 150))
smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("BET: " + str(amount), smallText)
textRect.center = (400, 420)
gameDisplay.blit(textSurf, textRect)

mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()

if mouse[0] > 149 and mouse[0] < 229 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 10
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 229 and mouse[0] < 309 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 25
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)
if mouse[0] > 309 and mouse[0] < 389 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount += 100
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 389 and mouse[0] < 469 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount = self.actionOn.stack
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 469 and mouse[0] < 549 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
amount = 0
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 549 and mouse[0] < 629 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
self.actionOn.bidd(amount)
pygame.draw.rect(gameDisplay, felt, (310, 404, 200, 25), 0)
pygame.display.update()
time.sleep(.1)

if mouse[0] > 629 and mouse[0] < 709 and mouse[1] > 149 and mouse[1] < 216:
if click[0] == 1:
# print('click worked, you clicked on call')
running = False
self.clearBetButtons()
time.sleep(.1)

if self.actionOn.action == 2:
self.x += 1
running = False
self.clearBetButtons()

self.updateGUI()

def clearBetButtons(self):
pygame.draw.rect(gameDisplay, felt, (142, 145, 590, 75), 0)

def printActionButtons(self):

running = True
while running:
if self.actionOn.action == 2:
self.x += 1
running = False
if self.actionOn.action != 2:
self.actionOn.sock.sendit(pactiononu)

self.actionOn.sock.data = self.actionOn.sock.connection.recv(10)


print('found some data, here it is ' + str(self.actionOn.sock.data))
print('the data that was recieved was -- ' + str(len(self.actionOn.sock.data)) + ' bytes')

if 'fold' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has folded')
self.actionOn.fold()
self.x += 1
running = False
if 'call' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has called')
self.actionOn.call()
running = False
if 'check' in str(self.actionOn.sock.data):
print(self.actionOn.name + ' has checked')
self.actionOn.check()
running = False

def blinds(self):
for player in playerList:
if player.stack > 0:
player.action = 1
self.pih.append(player)
if len(self.pih) > 2:
##First we place the button
buttonnochips = True
while buttonnochips:
if self.pbutton > len(playerList) - 1:
self.pbutton = 0
if playerList[self.pbutton].stack == 0:
self.pbutton += 1

else:
buttonnochips = False

##Now that the button is positioned, we can place the sb position
self.psb = self.pbutton + 1
sbnochips = True
while sbnochips:
if self.psb > len(playerList) - 1:
self.psb = 0
if playerList[self.psb].stack == 0:
self.psb += 1

else:
sbnochips = False
# Now that the sb is positioned, we can place the bb position
self.pbb = self.psb + 1
bbnochips = True
while bbnochips:
if self.pbb > len(playerList) - 1:
self.pbb = 0
if playerList[self.pbb].stack == 0:
self.pbb += 1

else:
bbnochips = False
elif len(self.pih) == 2:
buttonnochips = True
while buttonnochips:
if self.pbutton > len(playerList) - 1:
self.pbutton = 0
if playerList[self.pbutton].stack == 0:
self.pbutton += 1

else:
buttonnochips = False
self.pbb = self.pbutton + 1
bbnochips = True
while bbnochips:
if self.pbb > len(playerList) - 1:
self.pbb = 0
if playerList[self.pbb].stack == 0:
self.pbb += 1

else:
bbnochips = False

self.psb = self.pbutton

print('the value of pbutton is ' + str(self.pbutton))
print('the value of psb is ' + str(self.psb))
print('the value of pbb is ' + str(self.pbb))
print(playerList[self.pbutton].name + ' has the button.')
print("The small blind is on " + playerList[self.psb].name + " and the big blind is on " + playerList[
self.pbb].name)
playerList[self.psb].pfbidd(self.sb)
playerList[self.pbb].pfbidd(self.bb)
self.highbid = self.bb
self.bidraise = self.bb
for p in playerList:
print(p.name + ' has actoin attr of ' + str(p.action) + ' and their total in is ' + str(p.totalin))
print(str(table.highbid) + ' is the table.highbid value')

def dealPreFlop(self):
print('in dealPreFlop method now')
for i in range(2):
for player in playerList:
if player.stack > 0:
player.cards.append(deck1.cards[0])
card = 'card'+ deck1.cards[0].imagestr
pcard = card.encode()
player.sock.sendit(pcard)
deck1.cards.pop(0)

def dealFlop(self):
print('dealing flop now')
for i in range(3):
self.cards.append(deck1.cards[0])
deck1.cards.pop(0)
gameDisplay.blit(self.cards[0].image, [200, 300])
pygame.display.update()
gameDisplay.blit(self.cards[1].image, [275, 300])
pygame.display.update()
gameDisplay.blit(self.cards[2].image, [350, 300])
pygame.display.update()
time.sleep(.1)
pygame.display.update()
time.sleep(.1)
print(
'The flop is ' + table.cards[0].text + ' of ' + table.cards[0].color + ', ' + table.cards[1].text + ' of ' +
table.cards[1].color + ', ' + table.cards[2].text + ' of ' + table.cards[2].color)

def dealTurn(self):
self.cards.append(deck1.cards[0])
deck1.cards.pop(0)
gameDisplay.blit(table.cards[3].image, [425, 300])
pygame.display.update()
print('The turn is ' + table.cards[3].text + ' of ' + table.cards[3].color)

def dealRiver(self):
self.cards.append(deck1.cards[0])
deck1.cards.pop(0)
gameDisplay.blit(table.cards[4].image, [500, 300])
pygame.display.update()
print('The river is ' + table.cards[4].text + ' of ' + table.cards[4].color)

def findActionOn(self):
print('starrting findActionOn function')
if self.y + self.x > len(playerList) - 1:
self.y = 0
self.x = 0
actiononnochips =
Reply
#3
I've merged your threads. Please don't create duplicates.

I haven't looked at the content of your posts. You're providing too much code. Slim your code down to the minimum needed to reproduce the issue. That's usually 5-10 lines. There's no way it needs to be >50.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  elif not responding on print EddieG 3 860 Jul-20-2023, 09:44 PM
Last Post: Pedroski55
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 711 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Help with pygame but not an actual game lew247 0 940 Feb-09-2022, 02:25 PM
Last Post: lew247
  creating python server and client in a pc kucingkembar 4 2,000 Nov-29-2021, 01:37 PM
Last Post: kucingkembar
  Real-Time output of server script on a client script. throwaway34 2 2,042 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  How to take the tar backup files form remote server to local server sivareddy 0 1,891 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Pygame Rect Not Responding SomebodyImportant 1 1,506 May-02-2021, 01:27 PM
Last Post: BashBedlam
  IDLE stops responding upon saving tompi1 2 1,921 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  Code is not responding abhishek81py 0 1,486 Jul-07-2020, 12:40 PM
Last Post: abhishek81py
  Python sockets : Client sending to the server nico31780 0 2,319 May-17-2020, 07:56 PM
Last Post: nico31780

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020