Python - Creating Hangman Game Screen Programatically

Hi Friends,

Recently I was getting my hands dirty trying to make a simple hangman game in Python using the famous Pygame library.

Though till now i have not yet fully completed the game, But I ended up making the image of the human which is usually hanged in the hangman image programmatically.



I could have done this by directly using 6 images having different different sequences, but thought of keeping the application light weight without using any unnecessary images.

And hence ended up making the human image using Circles and Rectangles.

The python code for the screen is given below:


import pygame,sys
pygame.init();

size=(640,480)
screen=pygame.display.set_mode(size)
pygame.display.set_caption("Hangman Game by Amit")

##Color Definitions
WHITE = (0xFF, 0xFF, 0xFF)
BLACK = (0x00, 0x00, 0x00)



done=False;

##functions
def draw_tree():
    pygame.draw.rect(screen, BLACK, [300, 50, 10, 350]) ##straight line vertical
    pygame.draw.rect(screen, BLACK, [100, 390, 300, 10]) ##base 
    pygame.draw.rect(screen, BLACK, [200, 50, 100, 10]) ##top bar
    pygame.draw.rect(screen, BLACK, [200, 50, 10, 25]) ##hanging rod
    pygame.draw.ellipse(screen, BLACK, [180,75,50,50], 5) ##head
    pygame.draw.rect(screen, BLACK, [200, 125, 10, 150]) ##body
    pygame.draw.line(screen, BLACK, [150, 100], [200, 150], 5) ##left hand
    pygame.draw.line(screen, BLACK, [260, 100], [210, 150], 5) ##right hand
    pygame.draw.line(screen, BLACK, [150, 325], [200, 275], 5) ##left leg
    pygame.draw.line(screen, BLACK, [260, 325], [210, 275], 5) ##right leg

##main loop
while not done:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
           done=True;
    
    screen.fill(WHITE)
    draw_tree();
    pygame.display.flip();
            
print "Exited from Game"
pygame.quit()


I am still working on implementing the full game with game logic, this is just for time being...

Will soon update this post, once the full game is done.

Till then, have a nice day... :) 


No comments

If you liked this blog then Join me at:
Facebook
Twitter