# Untitled

Dec 3rd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #-------------------------------------------------------------------------- IMPORTS ---------------------------------------------------------------------------
2. import time, random, pickle
3. #------------------------------------------------------------------------ DEFINITIONS -------------------------------------------------------------------------
4. selection = -1
5. money = 0
9. scores = open('scores.pkl', 'rb')
11. scores.close()
12. return highscores
13. #--------------------------------------------------------------------- saveScore FUNCTION ---------------------------------------------------------------------
14. def saveScore(highscores):
15. scores = open('scores.pkl', 'wb')
16. pickle.dump(highscores[:10], scores)
17. scores.close()
18. #---------------------------------------------------------------------- setScore FUNCTION ---------------------------------------------------------------------
19. def setScore(playerName):
20. global money
21. highscores = []
23. highscores.append((money, playerName))
24. highscores = sorted(highscores, reverse=True)
25. saveScore(highscores)
27. #-------------------------------------------------------------------- printScore FUNCTION ---------------------------------------------------------------------
28. def printScore():
29. highscores = []
30. name = []
31. score = []
33. for i in range(10):
34. name.append(highscores[i][1])
35. score.append(highscores[i][0])
36. print "--------------- TOP 10 PLAYERS ---------------"
37. for i in range(10):
38. print str(i + 1) + ". " + name[i] + " " + str(score[i]) + "kn"
39. print "----------------------------------------------"
40. time.sleep(3)
41. return
42. #---------------------------------------------------------------- checkIsNumberInArray FUNCTION ---------------------------------------------------------------
43. def checkIsNumberInArray(i, num, questionNumbers):
44. for x in range(i):
45. if questionNumbers[x] == num:
46. return 1
47. return 0
48. #--------------------------------------------------------------- randomSelectQuestions FUNCTION ---------------------------------------------------------------
49. def randomSelectQuestions(count):
50. questionNumbers = []
51. for i in range(15):
52. while True:
53. num = random.randint(0, count - 1)
54. if checkIsNumberInArray(i, num, questionNumbers) == 0:
55. questionNumbers.append(num)
56. break
57. return questionNumbers
59. def askQuestion(i, quesNum, questions, price):
62. question = questions[quesNum][0]
68.
69. print "Pitanje %d (za %dkn): " % ((i + 1), price) + "\n" + question
70. time.sleep(1)
71. print "a) " + answer1
72. time.sleep(1)
73. print "b) " + answer2
74. time.sleep(1)
75. print "c) " + answer3
76. time.sleep(1)
77. print "d) " + answer4
78. selection = raw_input("Unesite tocan odgovor (a/b/c/d): ")
79. if selection == 'a':
81. elif selection == 'b':
83. elif selection == 'c':
85. elif selection == 'd':
88. print "----------------------------------------------\n" + "Vas odgovor je tocan, trenutno imate %dkn" % price + "\n----------------------------------------------\n"
89. money = price
91. return 1
92. else:
93. print "----------------------------------------------\n" + "Vas odgovor nije tocan!\n=> Tocan odgovor: " + correctAnswer + "\n----------------------------------------------\n"
94. return 0
95. #------------------------------------------------------------------ selectQuestion FUNCTION -------------------------------------------------------------------
96. def selectQuestion(playerName, questions, count):
98. money = 0
100. questionNumbers = randomSelectQuestions(count)
101. for i in range(len(questionNumbers)):
102. if i == 0:
103. price = 100
104. else:
105. price += price
106. if askQuestion(i, questionNumbers[i], questions, price) == 0:
107. break
108. print "----------------------------------------------\n" + "Odgovorili ste tocno na %d od 15 pitanja.\nOsvojili ste %dkn." % (numOfCorrectAnswer, money) + "\n----------------------------------------------\n"
109. setScore(playerName)
110. time.sleep(3)
113. count = 0
114. questions = []
115.
116. openedFile = open("questions.txt", "r")
117. if openedFile.mode == "r":
120. sentence = oneLine.split("#")
121. questions.append(sentence)
122. count += 1
123. selectQuestion(playerName, questions, count)
126. f = open("questions.txt","a+")
127. question = raw_input("Unesite pitanje: ")
128. f.write(question + "#")
129. correctAnswer = raw_input("Unesite odgovor na uneseno pitanje: ")