Vinnaren i pepparkakshustävlingen!
2006-04-25, 19:05
  #1
Medlem
Jag har problem med att skapa det klassiska spelet Wumpus. Jag har fastnat. och om det är ngn som vill så få ni gärna hjälpa mig... Här är filen : http://esnips.com/webfolder/b71bfe95...d-39999a9e36d0
Man måste logga in för att få den och om det är ngn som inte orkar med det så kan ni gärna maila mig så skickar jag den direkt.

Här är min kod oxå:
Kod:
# -*- coding: cp1252 -*-
#Belzebub
#Conny Ledin

import random
from Tkinter import *

#creates a room class
class room(object):#,trap):
    def __init__(self, trap):
        self.trap = trap
    #inserts content in rooms
    def get_trap():
        return trap

#creates a room list with content
room_list = []
#0=Nothing, 1=fire trap, 2=acid trap, 3=teleporter, 4=belzebub
trap_list = [0,0,0,0,0,0,0,0,0,1,1,2,2,3,3,3,3,3,3,4]
random.shuffle(trap_list)
for i in range(0,20):
    r = room(trap_list[i])
    room_list.append(r)
    
#creates a list with rooms
nextto_list1 = range(0,20)

#shuffles the list with rooms for movement in east/west direction
random.shuffle(nextto_list1)

#shuffles another list with rooms for movement in north/south direction
nextto_list2 = random.shuffle (nextto_list1)

root = Tk()

#creates GUI
class application(Frame):

    def __init__(self, master):
        #creates frame
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        Label(self,text = "Whats your next move?").grid(row = 0, column = 0, sticky = W)
        Label(self, text = "Choose one: ").grid(row = 1, column = 0, sticky = W)
        self.choice = StringVar()
        #creates text box
        self.results_txt = Text(self, width = 60, height = 10, wrap = WORD)
        self.results_txt.grid(row = 7, column = 0, columnspan = 4)
        #creates radiobutton for north
        Radiobutton(self, text = "Go North",
                    variable = self.choice,
                    value = "north",
                    command = self.move
                    ).grid(row = 2, column = 0, sticky = W)
        #creates radiobutton for east
        Radiobutton(self, text = "Go East",
                    variable = self.choice,
                    value = "east",
                    command = self.move
                    ).grid(row = 3, column = 0, sticky = W)
        #creates radiobutton for south
        Radiobutton(self, text = "Go South",
                    variable = self.choice,
                    value = "south",
                    command = self.move
                    ).grid(row = 4, column = 0, sticky = W)
        #creates radiobutton for west
        Radiobutton(self, text = "Go West",
                    variable = self.choice,
                    value = "west",
                    command = self.move
                    ).grid(row = 5, column = 0, sticky = W)
        #creates radiobutton for shooting
        Radiobutton(self, text = "Deploy bomb",
                    variable = self.choice,
                    value = "shoot",
                    command = self.shoot
                    ).grid(row = 6, column = 0, sticky = W)

    #creates a function for movement 
    def move(self):
        message = ""
        message += self.choice.get()
        print message
        if message == "north":
            direction = 2
            next_room()
            current_room = next_room
            message = "You enter the next room to the north "
            message += str(current_room)
        if message == "south":
            direction = -2
            next_room()
            current_room = next_room
            message = "You enter the next room to the south "
            message += str(current_room)
        elif message == "east":
            direction = 1
            next_room()
            current_room = next_room
            message = "You enter the next room to the east "
            message += str(current_room)
        elif message == "west":
            direction = -1
            next_room()
            current_room = next_room
            message = "You enter the next room to the west "
            message += str(current_room)
        self.results_txt.delete(0.0, END)
        self.results_txt.insert(0.0, message)
        root.title("Chasing Belzebub")
    #creates a function for shooting
    def shoot(self):
        message = ""
        message += self.choice.get()
        print message
##      if message == "shoot":
##          belzebub.die()

#creates a randomized grid with rooms that the player can move trough
def next_room():#direction, current_room):
    #east/west
    current_room = 1
    direction = 1
    if current_room == 0 and direction == -1:
        next_room = nextto_list1[19]
    elif current_room == 19 and direction == 1:
        next_room = nextto_list1[0]
    elif direction == 1 or direction == -1:
        next_room = nextto_list1[current_room + direction]
    #north/south
    elif current_room == 0 and direction == -2:
        next_room = nextto_list2[19]
    elif current_room == 19 and direction == 2:
        next_room = nextto_list2[0]
    elif direction == 2:
        next_room = nextto_list2[current_room + 1]
    elif direction == -2:
        next_room = nextto_list2[current_room - 1]
    return next_room
    
###creates a player class
##class player(object):
##    def __init__(self):
##
##    #all the ways the player can die and GAME OVER displays
##    def die(self, fire_trap, acid_trap, belzebub):
##        if acid_trap.kill:
##            print "Im sorry to say that you have melted./n"
##            "Better luck next time/n"
##            "GAME OVER!"
##        elif fire_trap.kill:
##            print "Oh my! Your hair is on fire./n"
##            "GAME OVER!"
##        elif belzebub.kill:
##            print "Belzebub got you, have a lovely time in HELL!/n"
##            "GAME OVER"
##                
###creates a fire trap class
##class fire_trap(object):
##    def __init__(self):
##    #ser till att spelaren dör
##    def kill(self, player):
##        player.die()
##
###creates a fire trap class
##class acid_trap(object):
##    def __init__(self):
##    #ser till att spelaren dör
##    def kill(self, player):
##        player.die()
##
###creates a Belzebub class
##class belzebub(object):
##    def __init__(self):
##    #ser till att spelaren dör
##    def kill(self, player):
##        player.die()
##    ##ser till att belzebub dör
##    def die(self, player):
##        if bomb
####        
def main():
    
    app = application(root)
    root.mainloop()

##    for i in nextto_list1 or nextto_list2:
##        #skapa ett rum
        
main()

[slängde in code-taggar /Mod]
Citera
2006-04-25, 20:13
  #2
Medlem
luulens avatar
Nu kan jag inte Python men jag kan svara åt personerna som KAN.

- Använd code-block.
- Vad är problemet? Det är svårt att svara om det inte finns någon fråga.
- m.m.
Citera
2006-04-25, 20:39
  #3
Medlem
Vad är code-block? Det finns en beskrivning av mina problem här. Sorry för att jag inte bifogade det tidigare. http://groups.google.com/group/comp....gBQ0eEX6D8zw50
Citera
2006-04-26, 14:04
  #4
Medlem
upp
Citera
2006-04-26, 15:09
  #5
Medlem
Stockos avatar
Slängde in code-taggar i ditt första inlägg. Och ge fan i att bumpa trådar.

/Mod
Citera

Stöd Flashback

Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!

Stöd Flashback