如何找到适合我项目的模块?

时间:2019-05-15 08:29:31

标签: python module pygame

我正试图出于教育目的复制一款名为“ Mastermind”的游戏。 (http://www.webgamesonline.com/mastermind/)下面的控制台游戏是我完成的家庭作业的一部分,我想扩展这个构想,并为我的小项目带来些“生命”。

我想知道经验丰富的游戏开发人员或/和程序员通常如何找到适合其项目的模块。

我尝试使用#superwires模块,该模块是重写的pygame库,可以使入门级程序员更容易理解。但是,似乎该模块不再符合我的需求。

问题:我应该放弃superwires模块并了解pygame模块,因为它更适合于大型项目吗?

import random


code = []
attempts = 3

while len(code) != 4:
    for x in range(4):
        n = random.randint(1, 4)
        code.append(n)

print(code)

pos1 = str(code[0])
pos2 = str(code[1])
pos3 = str(code[2])
pos4 = str(code[3])

answer = str(pos1) + str(pos2) + str(pos3) + str(pos4)

guess = None

while guess != answer:

    positionguess1 = str(input("position 1: "))
    positionguess2 = str(input("position 2: "))
    positionguess3 = str(input("position 3: "))
    positionguess4 = str(input("position 4: "))
    checklist = []
    whitecheck = 0
    redcheck = 0

# Redchecks
    if positionguess1 == pos1:
        redcheck += 1
        checklist.append(positionguess1)

    if positionguess2 == pos2:
        redcheck += 1
        checklist.append(positionguess2)

    if positionguess3 == pos3:
        redcheck += 1
        checklist.append(positionguess3)

    if positionguess4 == pos4:
        checklist.append(positionguess4)
        redcheck += 1


# Whitechecks
    if positionguess1 != pos1 and positionguess1 in answer and positionguess1 not in checklist:
        checklist.append(positionguess1)
        whitecheck += 1

    if positionguess2 != pos2 and positionguess2 in answer and positionguess2 not in checklist:
        checklist.append(positionguess2)
        whitecheck += 1

    if positionguess3 != pos3 and positionguess3 in answer and positionguess3 not in checklist:
        checklist.append(positionguess3)
        whitecheck += 1

    if positionguess4 != pos4 and positionguess4 in answer and positionguess4 not in checklist:
        checklist.append(positionguess4)
        whitecheck += 1

    crackattempt = str(positionguess1) + str(positionguess2) + str(positionguess3) + str(positionguess4)

    print ("You've entered:", crackattempt)

    if crackattempt == answer:
        print ("Amount in wrong position with right value:", whitecheck)
        print("Amount in the right position and the right value:", redcheck)
        print ("cracked the code, you win")
    elif attempts == 0:
        print ("you lose.")
        break
    elif crackattempt != answer:
        print ("Wrong! Try again.")
        print("Amount in wrong position with right value:", whitecheck)
        print("Amount in the right position and the right value:", redcheck)

        attempts -= 1

from superwires import games, color

games.init(screen_width = 480, screen_height = 640, fps = 50)



class Wrapper(games.Sprite):
    """Keeps sprites on screen"""

    def update(self):

        self.x = games.mouse.x
        self.y = games.mouse.y

        if self.left < 0:
            self.left = 0

        if self.right > games.screen.width:
            self.right = games.screen.width

class Redball(Wrapper):

    image = games.load_image("red.png")

    def __init__(self):

        super().__init__(
            image= Redball.image,
            x = 50,
            y = 580
        )
    def update(self):
        if games.keyboard.is_pressed(games.K_1):
            self.x = games.mouse.x
            self.y = games.mouse.y

class Greenball(Wrapper):

    image = games.load_image("green.png")

    def __init__(self):

        super().__init__(
            image = Greenball.image,
            x = 125,
            y = 580
        )
    def update(self):
        if games.keyboard.is_pressed(games.K_2):
            self.x = games.mouse.x
            self.y = games.mouse.y

class Game(object):


    def __init__(self):

        self.score = games.Text(value = 0,
                                size = 30,
                                color = color.white,
                                top = 5,
                                right = games.screen.width - 10,
                                is_collideable = False)
        games.screen.add(self.score)

        self.redball = Redball()
        self.greenball = Greenball()

        games.screen.add(self.redball)
        games.screen.add(self.greenball)


    def play(self):
        """ Play the game. """

        image = games.load_image("background.jpg")
        games.screen.background = image
        games.screen.event_grab = True
        games.screen.mainloop()



def main():

    pythonmind = Game()
    pythonmind.play()

预期结果:Sprite最初应该是不可见的,并且仅在按下键时才可见(NUM 1-6),它应该传递一个值,该值是所选Sprite在一个空框的顶部(可能是Sprite重叠?),并且再次按下该键。 (空格)

仅看上面的示例(单击链接)应该会更容易

0 个答案:

没有答案