Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.6 kB
65
Indexable
Never
Gameplay:

I think it would benefit from a short pause between your action and the ai action, maybe 500ms, just to make it feel a little more like you are playing a real player. you can do that with time.sleep()

Code Review:

game_interactions.py
line 69: Should be =, not == line 61 to 71: This whole section can be simplified, there is some duplication here.
For example:

mx_within = w_u * 3.3 <= mouse[0] <= w_u * 4.4
my_within_O = h_u * 2.8 <= mouse[1] <= h_u * 3.6
my_within_X = h_u * 3.8 <= mouse[1] <= h_u * 4.6
if event.type == pygame.MOUSEBUTTONDOWN and mx_within and (my_within_O or my_within_X):
    game_settings.x_or_o_ = "o" if my_within_O else "x"
    game_settings.xo_screen_on = False
    game_settings.game_over = False
    game_settings.game_active = True
    gsq.start_game(game_settings, screen, w_u, h_u)

Similar for the other functions on in this file.

game_sequence.py
You have a lot of constants in the code, like 3.6, 4.6 etc these represent the positions of the buttons. These are the same constants that are in game_interactions.py. This is not good practice as if you want to change the values you need to change them in multiple places. These should be set in one place then referenced.

graphics.py
Rather than using the character o, or x for the markers, it would be better to draw these as an x or a circle, because the font character is not really symmetrical and so looks a little messy.

create_finishline can be simplified, it would be better to have a dictionary from win combination to line coordinates, like:

    coordinate_dict = {
        {"[2, 4, 2, 4]", "[4, 6, 2, 4]", "[6, 8, 2, 4]"}: 
            ((w_u * 1.95, h_u * 3.05), (w_u * 7.95, h_u * 3.05)),
        {"[2, 4, 4, 6]", "[4, 6, 4, 6]", "[6, 8, 4, 6]"}: 
            ((w_u * 1.95, h_u * 5.05), (w_u * 7.95, h_u * 5.05)),
    }

line_start, line_end = coordinate_dict[game_settings.current_win_combination]
pygame.draw.line(screen, game_settings.fincolor, line_start, line_end, 8)

game_logic.py
You don't need to do: game_settings.game_active == True, just game_settings.game_active, and in other places

When you have something like:
if condition:
   value = a
else:
   value = b

You can write: value = a if condition else b
That would simplify lines 39 to 42 and other places.

Your ai functions, easy_ai, normal_ai, and hard_ai, are very similar, almost all is duplicate code. This should be refactored so you have some shared_ai function that is called, and only the bits that are different / unique are in the individual functions.