83 lines
1.9 KiB
Python
83 lines
1.9 KiB
Python
|
import random
|
||
|
|
||
|
|
||
|
class GameNumber():
|
||
|
# create game's numbers
|
||
|
#s = {}
|
||
|
#s = set()
|
||
|
|
||
|
# create number set for game
|
||
|
def createNumberSet(self, amount, gamesize):
|
||
|
s = {}
|
||
|
s = set()
|
||
|
while len(s) < gamesize:
|
||
|
# add set as gamesize
|
||
|
s.add(random.randint(0, amount-1))
|
||
|
|
||
|
print(s)
|
||
|
return s
|
||
|
|
||
|
# create game number list
|
||
|
def createGameNumber(self, gameSet):
|
||
|
numbers = []
|
||
|
for k in gameSet:
|
||
|
numbers.append(k)
|
||
|
print(k)
|
||
|
|
||
|
return numbers
|
||
|
|
||
|
|
||
|
class CheckNumber():
|
||
|
# check number whether it is right
|
||
|
#strike = 0
|
||
|
#ball = 0
|
||
|
|
||
|
# compare number between a guess answer and a right answer
|
||
|
def compareNumber(self, gameNumber, guessNumber):
|
||
|
result = []
|
||
|
strike = 0
|
||
|
ball = 0
|
||
|
|
||
|
for i in range(len(gameNumber)):
|
||
|
print(guessNumber)
|
||
|
if guessNumber[i] == gameNumber[i]:
|
||
|
# check number of strke
|
||
|
strike += 1
|
||
|
elif guessNumber[i] in gameNumber:
|
||
|
# check number of ball
|
||
|
ball += 1
|
||
|
|
||
|
# add results of strike and ball
|
||
|
result.append(strike)
|
||
|
result.append(ball)
|
||
|
|
||
|
return result
|
||
|
|
||
|
|
||
|
class InputNumber():
|
||
|
# user inputs numbers
|
||
|
#userGuess = []
|
||
|
#amountNumber = []
|
||
|
|
||
|
def getGameSize(self):
|
||
|
amountNumber = []
|
||
|
amountNumber.append(int(input('put a game size : ')))
|
||
|
amountNumber.append(int(input('put a max of number : ')))
|
||
|
|
||
|
return amountNumber
|
||
|
|
||
|
def getNumber(self, gameSize):
|
||
|
userGuess = []
|
||
|
for i in range(gameSize):
|
||
|
print('put ', i+1, ' of numbers : ', end='')
|
||
|
userGuess.append(int(input()))
|
||
|
|
||
|
return userGuess
|
||
|
|
||
|
|
||
|
class PrintResult():
|
||
|
# print result
|
||
|
|
||
|
def printResult(self, result):
|
||
|
print(result[0], ' strike, ', result[1], ' ball')
|