3

Ok, so at my school we are required to do a Senior project, and I decided I would try and pick up on programing. To start out, I decided to start taking VEX classes, which taught me a bit of basic "C" language. I wanted to make a game for my actual project, so I decided to make one of those stupid maze games where you have to avoid touching the walls with your mouse. I have it to the point where it will load the actual map when I hover over the ready button, but the actual game won't finish beyond there. This is my code so far, and I am confused because after loading the maze, the program won't do what it's supposed to when I touch the wall or when I touch the finish point.

import pygame
from pygame import *
pygame.init()

done = False

getready = image.load('ready.png')
backdrop = image.load('map.png')
goon = image.load('continue.png')
maze2 = image.load('map2.png')
loose = image.load('loose.png')
screen = display.set_mode((700, 500))
display.set_caption('Maze Game')
event.set_grab(1)

while done == False:
    screen.blit(getready, (0, 0))
    display.update()

    for e in event.get():
        if e.type == KEYUP:
            if e.key == K_ESCAPE:
                done = True

    if screen.get_at((mouse.get_pos())) == (0, 0, 0):
        while done == False:
            screen.blit(backdrop, (0, 0))
            display.update()

            if screen.get_at((mouse.get_pos())) == (0, 0, 0):
                print("You touched the wall!")
                done = True

            elif screen.get_at((mouse.get_pos())) == (0, 255, 0):

                screen.blit(goon, (0, 0))
                display.update()

                if e in event.get():
                    if e.type == KEYUP:
                        if e.key == K_y:

                            screen.blit(maze2, (0, 0))
                            display.update()

                            if e in event.get():
                                if e.type == KEYUP:
                                    if e.key == K_y:
                                        done = True

                            if screen.get_at((mouse.get_pos())) == (0, 0, 0):
                                screen.blit(victory, (0, 0))
                                display.update()
                                time.sleep(3)


            for e in event.get():
                if e.type == KEYUP:
                    if e.key == K_ESCAPE:
                        done = True

pygame.quit()

I know this probably is really crude code, but keep in mind I'm just starting, and that any helpful input is appreciated :)

UPDATE: I send my cousin the code, and he changed it to this:

 import pygame
 from pygame import *
 pygame.init()

 done = False
 done2 = False

 ref = image.load('ready.png')
 loose = image.load('loose.png')
 cntnu = image.load('continue.png')
 goon = 0
 screen = display.set_mode((700, 500))
 display.set_caption('Maze Game')
 event.set_grab(1)

 while done == False:
     screen.blit(ref, (0, 0))
     display.update()
     done2 = False

     for e in event.get():
         if e.type == KEYUP:
            if e.key == K_ESCAPE:
                 done = True           
         if screen.get_at((mouse.get_pos())) == (0, 0, 0):

             ref = image.load('map.png')
             done2 = True

         if screen.get_at((mouse.get_pos())) == (1, 0, 0):

             screen.blit(loose, (0, 0))
             display.update()
             done2 = True
             time.wait(2000)
             done = True

         if screen.get_at((mouse.get_pos())) == (0, 255, 0):
             screen.blit(cntnu, (0, 0))
             display.update()
             time.wait(3000)

 pygame.quit()

The problem was not in my code actualy, just in my python folder. I re-installed python (with a new installer) and it works fine. Thanks for every ones help :)

Chris Merrell
  • 31
  • 1
  • 4

2 Answers2

0

it seems from your vague question that you don't get enough feedback from your program to localize and fix bugs, and that could be the actual problem you might want to address.

You can benefit a lot from using tools that can let you run the code line by line and inspect the state of each variable, so you can easily figure out when and why your program does not behave as you expected. I would recommend this discussion on StackOverflow (as well as references therein) of different debugging approaches.

Besides using a code debugger, it might be a good idea to start using a logger to print debugging information during the program execution at the desired level of specificity. You can get more information about loggers from the link above, or you can just google for it -- I'm sure there you will find tons of tutorials once you know what to look for.

Community
  • 1
  • 1
Marat Talipov
  • 13,064
  • 5
  • 34
  • 53
  • Ok, so I guess I was too vague, the problem is that after the first loop, when I put my mouse on the black dot, the program pulled up the maze like I wanted it to. AFTER that, if I touched the walls, it was supposed to show a game over screen, but it doesn't. All the code is based on my mouse touching a color. For instance when I touch green, it should move on to the next maze. When I touch black it should pull up the game over screen. But after the first time I touch black to get my cursor in the right place, it pulls up the map, and thereafter does not sense anything. That is my problem. – Chris Merrell Jan 09 '15 at 02:31
  • Hi Chris, I didn't mean to offend you--sorry if it sounded like that. I can't install pygame on my laptop for some reason, so I'll give it another try later on another computer. – Marat Talipov Jan 12 '15 at 03:44
  • Oh, i wasnt offended, i just wanted to clarify :) – Chris Merrell Jan 13 '15 at 04:35
0

Update: I fixed the problem. It turns out that my code was working fine the whole time. The problem was actually with my python library. I re installed everything and it worked fine.

Chris Merrell
  • 31
  • 1
  • 4