Welcome, guest | Sign In | My Account | Store | Cart

Game is not finished yet...

Python, 95 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from random import choice, randrange as rrange, shuffle
from time import sleep, ctime
from sys import getsizeof

class Game:
    def __init__(self):
        self.create_word = ''
        self.word_hint = ''
        self.life = 0
        self.bank = []
        self.fill_word = []
    def set_up(self):
        self.fill_word = []
        self.life = 5
        if self.bank ==[]:
            print("First you need to create some questions")
            self.create()
        else:
            self.main()
    def display1(self,w,n):
        #For view, edit, and delete
        a = str(w).replace('[','')
        b = a.replace(',',':')
        c = b.replace("'",'')
        d = c.replace(']','')
        print(n,d)
    def create(self):
        print("")
        self.create_word = input("What is the word? ")
        self.word_hint = input("Type a hint or description of the word: ")
        print(self.create_word,':',self.word_hint)
        en = input("Does this seem accurate? ").lower()
        if en in ['no','n','nope']:
            self.create()
        else:
            self.bank.append([self.create_word,self.word_hint])
            self.main()
    def view(self):
        print()
        a = 0
        for i in self.bank:
            self.display1(i,a)
            a +=1
    def display2(self,w):
        #For play
        while len(self.fill_word) < len(w):
            self.fill_word.append('_')
        a = str(self.fill_word).replace('[','')
        b = a.replace(',','')
        c = b.replace("'",'')
        d = c.replace(']','')
        print(d)
    def play(self):
        game = True
        word = self.bank[0]
        f = False
        while game==True:
            print("Life Left: ",self.life)
            f = False
            print('Hint: ',word[1])
            self.display2(word[0])
            letter = input(": ")
            a = 0
            while a < len(word[0]):
                if word[0][a]==letter:
                    self.fill_word[a]= letter
                    f = True
                a +=1
            if f==False:
                self.life -=1
            if self.life <0:
                self.game = False
            if '_' not in self.fill_word:
                game = False
        print(word[0])
        print('GAME OVER')

    def main(self):
        print()
        user = input('1.PLAY\n2.CREATE\n3.EDIT\n4.DELETE\n5.VIEW')
        if user=='1':
            self.play()
        elif user=='2':
            self.create()
        elif user=='3':
            pass
        elif user=='4':
            pass
        elif user=='5':
            self.view()
        else:
            print(len(self.bank[0][0]))
            self.display2(self.bank[0][0])
game = Game()
game.set_up()

1 comment

Burak Tandogan 9 years, 4 months ago  # | flag

Check my hangman already uploaded :)