Ejemplo n.º 1
0
def score_Board(value):
    text=pygame.font.SysFont("Comic Sans Ms", 20)
    sur,rec=text_objects("Score: ",text)
    rec.center=(display_width/1.25,display_height/19)
    window.blit(sur,rec)
    pygame.draw.rect(window,WHITE,((display_width/1.2, display_height/26),(85,30)),2)
    score=pygame.font.SysFont("Arial,20",20)
    sur1,rec1=text_objects(str(value),score)
    rec1.center=(display_width/1.15,display_height/18)
    window.blit(sur1,rec1)
Ejemplo n.º 2
0
def message_display(text):
    largeText = pygame.font.Font("freesansbold.ttf", 115)
    TextSurf, TextRect = text_objects(text, largeText)
    TextRect.center = (display_width / 2, display_height / 2)
    window.blit(TextSurf, TextRect)
    pygame.display.update()
    time.sleep(2)
    game_loop()
Ejemplo n.º 3
0
def game_loop():
    name = ""
    word_height = 0
    crashed = False

    while crashed == False:
        for event in pygame.event.get():
            # keep track of events
            print(event)
            events = pygame.event.get()
            textbox.update(events)
            textbox.draw(window)
            print("this")

            # window exiting
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            # user typing display
            if event.type == KEYDOWN:
                if event.unicode.isalpha():
                    name += event.unicode
                elif event.key == K_BACKSPACE:
                    name = name[:-1]
                elif event.key == K_RETURN:
                    name = ""
                show_input(name)

        # word display
        word_display(text_surface, display_width / 2, word_height)

        # update window
        pygame.display.update()
        word_height += 50

        # border
        if word_height > 700:
            print("You've crashed")
            largeText = pygame.font.Font("freesansbold.ttf", 115)
            TextSurf, TextRect = text_objects("You've crashed", largeText)
            TextRect.center = (display_width / 2, display_height / 2)
            window.blit(TextSurf, TextRect)
            pygame.display.update()
            time.sleep(2)
            pygame.quit()
            quit()

        # fps
        clock.tick(2)
Ejemplo n.º 4
0
def mode(msg, x, y, width, height, before_hover_color, after_hover_color):
    # selecting the mode
    if msg=="Learning to Type":
        time_value=sys.maxsize
    elif msg=="I can type better than you":
        time_value=4
    else:
        time_value=2
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    # mouse click and hover on modes
    if x + width > mouse[0] > x and y + height > mouse[1] > y:
        pygame.draw.rect(window, after_hover_color, (x, y, width, height))
        if click[0] == 1 :
            # starting game if clicked
            game_loop(time_value)
    else:
        pygame.draw.rect(window, before_hover_color, (x, y, width, height))
    # blitting the modes
    smallText = pygame.font.SysFont("Arial", 30)
    textSurf, textRect = text_objects(msg, smallText)
    textRect.center = ((x + (width / 2)), (y + (height / 2)))
    window.blit(textSurf, textRect)
Ejemplo n.º 5
0
def show_level(level):
    text = pygame.font.SysFont("Comic Sans Ms", 20)
    sur, rec = text_objects("Level= "+str(level), text)
    rec.center = (100, 40)
    window.blit(sur,rec)
Ejemplo n.º 6
0
def game_loop(time_value):
    input_word = ""
    word_height = 0
    crashed = False
    global display_width
    global display_height

    word_width = random.randint(50, display_width//1.5)
    rand=word_width
    current_score=0
    word = return_word()
    #storing in dictionary
    dct={word:[word_width,word_height]}
    a = timeit.default_timer()
    # loop
    found=False
    window.fill(BLACK)
    level=1
    while crashed == False:
        events = pygame.event.get()
        b=timeit.default_timer()
        #to check time
        print(b-a)
        #time difference for new word
        if b-a>=time_value and found==False:
            new_x=random.randint(50, display_width//1.11)
            new_word=return_word()
            dct[new_word]=[new_x,0]
            found= True
        if found==True:
            #reset time
            a=b
            found=False
        word_display(dct,events,level,current_score)
        for event in events:
            # window exiting
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            # window min/max effect
            if event.type==pygame.VIDEORESIZE:
                display_width, display_height = event.w, event.h
                pygame.display.set_mode((display_width,display_height),pygame.RESIZABLE)
                if(display_width>w):
                    word_width=(display_width/w)*word_width
                else:
                    word_width=rand
        # word display
            if event.type == pygame.KEYDOWN:
                if event.unicode.isalpha():
                    input_word += event.unicode
                elif event.key == pygame.K_BACKSPACE:
                    input_word = input_word[:-1]
                if(event.key==pygame.K_RETURN):
                    if input_word not in dct.keys() :
                        print("failed, your score is :", current_score)
                        pygame.quit()
                        quit()
                    else:
                        if len(lst) == 0:
                            print("Congrats, you have finished the game")
                            pygame.quit()
                            quit()
                        else:
                            print("success")
                            # taking inputted word out of dictionary
                            del dct[input_word]
                            current_score= current_score + len(word)
                            word = return_word()
                            word_width = random.randint(50, display_width//1.05)
                            input_word = ""
                            word_height = 0
                            # adding to dictionary
                            dct[word]=[word_width,word_height]
                            continue

        # update window
        pygame.display.update()
        for val in dct.values():
            val[1]+=0.5
            if val[1] > (display_height / 1.2) - 10:
                print("You've crashed")
                largeText = pygame.font.Font("freesansbold.ttf", 115)
                TextSurf, TextRect = text_objects("You've crashed", largeText)
                TextRect.center = (display_width / 2, display_height / 2)
                window.blit(TextSurf, TextRect)

                pygame.draw.rect(window, WHITE, ((display_width / 10, display_height / 1.1), (display_width / 3, 35)))

                pygame.display.update()
                time.sleep(0.01)
                pygame.quit()
                quit()
        time.sleep(0.01)
        # fps
        clock.tick(200)
Ejemplo n.º 7
0
def message(msg,size):
    largeText = pygame.font.Font("freesansbold.ttf", size)
    TextSurf, TextRect = text_objects(msg, largeText)
    return TextSurf,TextRect