I am participating in the Mid-Autumn Festival Creative Submission Contest. Please see: Mid-Autumn Festival Creative Submission Contest for details.

WangScaler: A writer with heart.

Declaration: uneducated, if there is a mistake, kindly correct.

This is a word game, simple and easy to use, the overall design is at the beginning of the 3 * 3 map, random brush moon plate, each moon plate has moon cakes, Hou Yi turned to all the moon cakes on the map, into the next map (3+2) * 3+2) continue to look for.

In order to increase the difficulty of the challenge, the player is not reminded which is the moon, which is similar to the flip board in childhood. Only when you flip the board, you can know whether it is the moon. At the same time, every step you take, the health is reduced by 1, and you can recover all the health in your birthplace earth.

With the expansion of the map, the initial 30 HP is definitely not enough, so you can increase the HP by increasing the level of the character through experience, and increase the HP by 30 per level.

At the same time, there are monster attacks, although the blood will drop, but also can increase a large number of experience points, in order to reduce the difficulty, but also added god, to save the player.

figure

Character attributes

According to the above description, It can be known that the basic attributes of a character are name, HP, maxHp, the number of moon cakes picked up by the current map (moonCake), the number of all moon cakes owned by the current map (maxMoonCake), the number of moon cakes picked up by all levels (allMoonCake), and the character’s level (L) Evel), character experience value (XP), current character level promotion experience threshold (xpForNextLevel), current character location abscess (locationX), current character ordinate (locationY), current map plate ID(locationID), the current map has been explored exploredAreas

player = {
    'name': 'r'.'hp': 10.# HP
    'maxHp': 10.'moonCake': 0.# many mooncakes
    'maxMoonCake': 10.'allMoonCake': 0.'level': 1.# grade
    'xp': 0.# experience
    'xpForNextLevel': 30.'locationX': 0.'locationY': 0.'locationID': 0.# Current position
    'exploredAreas': 1  # Number of explorations
}
Copy the code

Character’s behavior

  • The original character is in the center of the map, so each time the map is refreshed, the length and width are increased by +2 to ensure that the square has a center point. Also reset the number of mooncakes in the current level to 0.

    def initPlayer(self, mapSize) :
        self.locationX = math.floor((mapSize - 1) / 2)
        self.locationY = math.floor((mapSize - 1) / 2)
        self.locationID = math.floor(math.pow(mapSize, 2) / 2) + 1
        Initialize the number of moon cakes in the current level
        self.moonCake = 0
    Copy the code
  • Since the number of moons per map plate is brushed randomly, the maximum number of mooncakes that can be picked up should be calculated after the map is initialized

    def initMaxMoonCake(self) :
        self.maxMoonCake = 0
        for i in range(0, mapSize):
            for j in range(map_Num - (i + 1) * mapSize, map_Num - i * mapSize):
                if (gameMap[j + 1].type= ='the moon'):
                    self.maxMoonCake = self.maxMoonCake + 1
        if self.maxMoonCake == 0:
            Map(mapSize, mapSize, self.locationID)
            self.exploredAreas = 1
            self.initMaxMoonCake()
    Copy the code
  • Move a character. Each time you move a character on unexplored terrain, you get -1 health. If you move to the right on the right boundary, you go back to the left boundary, and the same goes for the other directions.

    # Move around the map.
    def movePlayer(self, direction) :
        if direction == 'w':
            if self.locationY + 1 <= mapSize - 1:
                self.locationY += 1
                self.locationID += mapSize
            else:
                self.locationY = 0
                self.locationID = (self.locationID + mapSize) - map_Num
        elif direction == 's':
            if self.locationY - 1> =0:
                self.locationY -= 1
                self.locationID -= mapSize
            else:
                self.locationY = mapSize - 1
                self.locationID = (self.locationID - mapSize) + map_Num
        elif direction == "d":
            if self.locationX + 1 <= mapSize - 1:
                self.locationX += 1
                self.locationID += 1
            else:
                self.locationX = 0
                self.locationID -= mapSize - 1
    ​
        else:
            if self.locationX - 1> =0:
                self.locationX -= 1
                self.locationID -= 1
            else:
                self.locationX = mapSize - 1
                self.locationID += mapSize - 1
        map.description()
        if gameMap[self.locationID].explored == False:
            self.hp -= 1
    Copy the code
  • Increase experience. When experience reaches the maximum threshold of the current level, you level up, and increase the upper health and experience limits.

    # Add experience
    def addXp(self, num) :
        self.xp += num
        print('\n You gain %s experience points. ' % (num))
        if self.xp >= self.xpForNextLevel:
            self.level += 1
            self.maxHp += 5
            self.xpForNextLevel = (self.level) * 20
            print('Congratulations, you've upgraded - it's %s now! Max health increased by 5, remember to return to Earth in time for zen recovery oh ' % self.level)
    Copy the code
  • Increase the volume

    def healHp(self) :
        print('You have increased health by %s. ' % (self.maxHp - self.hp))
        self.hp = self.maxHp
    Copy the code
  • Pick up the moon cake

    def addMoonCake(self, num) :
        self.moonCake += num
        self.allMoonCake += num
        print('\n%s has picked up %s moon cakes. Also need to pick up %s mooncakes' % (self.name, num, self.maxMoonCake - self.moonCake))
    Copy the code

The map

Use global variables to store each small area.

Describe the terrain

def description(self) :
    isExplored = "Explored"
    if gameMap[player.locationID].explored == False:
        isExplored = "Unexplored"
    if gameMap[player.locationID].type= ='the earth':
        print("\n Current position:" + gameMap[player.locationID].type)
    print("(X: " + str(player.locationX) + ", Y: " + str(
        player.locationY) + ") Region status:" + isExplored + "." + str(
        player.locationID) + "Area no.")
Copy the code

area

Every detailed area of the map

Regional attribute

Area ID(mapID), x-coordinate of the area (x), y-coordinate of the area (Y), Type of the area (type), Tags explored or not (ExpoRED)

class Area:
    areaTpye = ["Venus"."Jupiter"."Mercury"."Mars"."Saturn"."The moon"."Uranus"."Neptune"]
    explored = False
    mapID = 0
    x = 0
    y = 0
    type = "The moon"
​
    def __init__(self, id, x, y) :
        self.mapID = id
        self.x = x
        self.y = y
        self.type = random.choice(self.areaTpye)
Copy the code

god

God used to redeem the player

God attributes

Type of God, restoreBlood of God

The monster

Monsters are used to attack the player and give the player a large amount of experience

The monster properties

Monster type (Type), Monster attack value (hitBlood), Monster experience (XP)

The source code

The source address

import math
import random


class Player:
    def __init__(self) :
        self.name = 'his'
        self.hp = 10  # HP
        self.maxHp = 10
        self.moonCake = 0  # many mooncakes
        self.maxMoonCake = 10
        self.allMoonCake = 0
        self.level = 1  # grade
        self.xp = 0  # experience
        self.xpForNextLevel = 30
        self.locationX = 0
        self.locationY = 0
        self.locationID = 0  # Current position
        self.exploredAreas = 1  # Number of explorations
        print("\n Your name is Houyi. Your health is full (%s points) and you have %s mooncakes. Your task is to find 100 moon cakes and take them to find the lady of the Moon in your mind." % (self.hp, self.moonCake))
        print("\n You are now a level 1 character and need %s experience to level up. We gain more maximum health by doing so. You gain experience in exploration and combat." % self.xpForNextLevel)
        print("\n Your adventure begins with the earth, every step you move will drop a drop of blood oh, pay attention to the change of blood volume, secretly tell you, find the surprise bug, can quickly complete the game...")

    def initPlayer(self, mapSize) :
        self.locationX = math.floor((mapSize - 1) / 2)
        self.locationY = math.floor((mapSize - 1) / 2)
        self.locationID = math.floor(math.pow(mapSize, 2) / 2) + 1
        Initialize the number of moon cakes in the current level
        self.moonCake = 0

    def initMaxMoonCake(self) :
        self.maxMoonCake = 0
        for i in range(0, mapSize):
            for j in range(map_Num - (i + 1) * mapSize, map_Num - i * mapSize):
                if (gameMap[j + 1].type= ='the moon'):
                    self.maxMoonCake = self.maxMoonCake + 1
        if self.maxMoonCake == 0:
            Map(mapSize, mapSize, self.locationID)
            self.exploredAreas = 1
            self.initMaxMoonCake()

    def hitEnter(self) :
        input("\n Enter to continue.")

    def getAction(self) :
        print('\n Available command ')
        actionString = ""
        if gameMap[self.locationID].explored == False:
            actionString += "\nx = Looking for mooncakes."
        if gameMap[self.locationID].type= ='the earth' and self.hp < self.maxHp:
            actionString += "\nr = Zen recovery."
        print(actionString)
        print('W = north, S = south, A = west, d = east.')
        print('I = view moon cake')
        print('c = View role status')
        choice = input('Please enter the command and press Enter').lower()
        print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- wangscaler -- -- -- -- -- -- -- -- -- -- after yi every month -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n \ n")
        if choice == "i":
            print("You are currently carrying: %s mooncakes" % self.allMoonCake)
            print("Current map pick up %s moon cakes:" % self.moonCake)
        # mobile
        elif choice == "w" or choice == "a" or choice == "d" or choice == "s":
            self.movePlayer(choice)
        # Explore the area
        elif choice == "x":
            if gameMap[self.locationID].explored == False:
                self.exploredAreas += 1
                if gameMap[self.locationID].type= ='the moon':
                    print('\n You found a moon cake, one step closer to chang 'e oh ')
                    self.addMoonCake(1)
                    self.addXp(self.level)
                sumNum = random.randrange(1.4)
                if sumNum == 1:
                    print("My God, you've met a monster!")
                    aMonster = monster()
                    damage = aMonster.hitBlood
                    print("You got it." + str(damage) + "A little hurt.")
                    self.hp -= damage
                    if self.hp > 0:
                        self.addXp(aMonster.xp)
                elif sumNum == 2:
                    luck = random.randrange(1.3)
                    aGod = god()
                    if luck == 1:
                        print("Wow, what luck! \n")
                        recovery = aGod.restoreBlood
                        if (self.maxHp - self.hp >= recovery):
                            print("%s helped you recover." + str(recovery) + "A little hurt." % aGod.type)
                            self.hp += recovery
                        elif (self.maxHp == self.hp):
                            print('With %s blessing, demons fear you more. \n' % aGod.type)
                        else:
                            print('%s' has restored you to full health. \n' % aGod.type)
                            self.hp = self.maxHp
                    else:
                        print('Unfortunately % S didn't talk to you. \n' % aGod.type)
                else:
                    print('This is barren land, not even bird droppings! ')
                    self.addXp(1)
                gameMap[self.locationID].explored = True
            else:
                print("The old man of the land jumped out:" The land has been hollowed out by you, there are no moon cakes.")
        elif choice == "r" and gameMap[self.locationID].type= ='the earth' and self.hp < self.maxHp:
            self.healHp()
        elif choice == 'c':
            print(self.name + '/ level:' + str(self.level) + "Level EXPERIENCE:" + str(self.xp) + "Point (still needed" + str(
                self.xpForNextLevel - self.xp) + "Upgrade point")
            print("Health:" + str(self.hp) + "Point (Maximum health:" + str(self.maxHp) + ")")
        elif choice == 'map':
            print('Oh, you've found a hidden bug! You can go through the customs smoothly! \n')
            for i in range(0, mapSize):
                for j in range(map_Num - (i + 1) * mapSize, map_Num - i * mapSize):
                    print(gameMap[j + 1].type + '(' + str(gameMap[j + 1].mapID).zfill(2) + ') ', end=' ')
                print('\n')
        else:
            print('Sorry, I don't know what you're talking about. ')

    # Move around the map.
    def movePlayer(self, direction) :
        if direction == 'w':
            if self.locationY + 1 <= mapSize - 1:
                self.locationY += 1
                self.locationID += mapSize
            else:
                self.locationY = 0
                self.locationID = (self.locationID + mapSize) - map_Num
        elif direction == 's':
            if self.locationY - 1> =0:
                self.locationY -= 1
                self.locationID -= mapSize
            else:
                self.locationY = mapSize - 1
                self.locationID = (self.locationID - mapSize) + map_Num
        elif direction == "d":
            if self.locationX + 1 <= mapSize - 1:
                self.locationX += 1
                self.locationID += 1
            else:
                self.locationX = 0
                self.locationID -= mapSize - 1

        else:
            if self.locationX - 1> =0:
                self.locationX -= 1
                self.locationID -= 1
            else:
                self.locationX = mapSize - 1
                self.locationID += mapSize - 1
        map.description()
        if gameMap[self.locationID].explored == False:
            self.hp -= 1

    # Add experience
    def addXp(self, num) :
        self.xp += num
        print('\n You gain %s experience points. ' % (num))
        if self.xp >= self.xpForNextLevel:
            self.level += 1
            self.maxHp += 5
            self.xpForNextLevel = (self.level) * 20
            print('Congratulations, you've upgraded - it's %s now! Max health increased by 5, remember to return to Earth in time for zen recovery oh ' % self.level)

    def addMoonCake(self, num) :
        self.moonCake += num
        self.allMoonCake += num
        print('\n%s has picked up %s moon cakes. Also need to pick up %s mooncakes' % (self.name, num, self.maxMoonCake - self.moonCake))

    def healHp(self) :
        print('You have increased health by %s. ' % (self.maxHp - self.hp))
        self.hp = self.maxHp


class monster:
    monsterType = ["Sun Wukong"."Pig Eight Quit"."Sand monk".Bone fairy.The King of golden Horns."The King of Silver Horns".The Bull King.Red Boy]

    def __init__(self) :
        self.type = random.choice(self.monsterType)
        self.hitBlood = random.randrange(1.5 * player.level)
        self.xp = random.randrange(0.5 * player.level)
        print('\n%s appears in front of you. \n' % self.type)
        if self.type= ="Pig Eight Quit":
            self.hitBlood = self.hitBlood * 2


class god:
    godType = [Guanyin Bodhisattva."Golden cicada".The Jade Emperor.Tathagata Buddha."God"]

    def __init__(self) :
        self.type = random.choice(self.godType)
        self.restoreBlood = random.randrange(1.3 * player.level)
        print('\n%s appears in front of you. \n' % self.type)


class Area:
    areaTpye = ["Venus"."Jupiter"."Mercury"."Mars"."Saturn"."The moon"."Uranus"."Neptune"]
    explored = False
    mapID = 0
    x = 0
    y = 0
    type = "The moon"

    def __init__(self, id, x, y) :
        self.mapID = id
        self.x = x
        self.y = y
        self.type = random.choice(self.areaTpye)


class Map:
    def __init__(self, rows, columns, locationID) :
        row = 0
        col = 0
        area = 1
        for r in range(0, rows):
            for c in range(0, columns):
                theArea = Area(area, col, row)
                gameMap[area] = theArea
                if gameMap[area].mapID == locationID:
                    gameMap[area].type = 'the earth'
                    gameMap[area].explored = True
                area += 1
                area += 1
            row += 1
            col = 0

    def description(self) :
        isExplored = "Explored"
        if gameMap[player.locationID].explored == False:
            isExplored = "Unexplored"
        if gameMap[player.locationID].type= ='the earth':
            print("\n Current position:" + gameMap[player.locationID].type)
        print("(X: " + str(player.locationX) + ", Y: " + str(
            player.locationY) + ") Region status:" + isExplored + "." + str(
            player.locationID) + "Area no.")


if __name__ == '__main__':
    Initialize the game map and game area
    gameMap = {}
    mapSize = 3
    map_Num = math.floor(math.pow(mapSize, 2))
    player = Player()
    player.initPlayer(mapSize)
    map = Map(mapSize, mapSize, player.locationID)
    still_alive = True
    player.initMaxMoonCake()
    map.description()
    player.hitEnter()
    while still_alive:
        player.getAction()
        if player.exploredAreas == map_Num or player.moonCake >= player.maxMoonCake:
            print("You found all the moon cakes on the map! \n Now enter a brand new map to continue to find moon cakes...")
            player.hitEnter()
            mapSize = mapSize + 2
            map_Num = math.floor(math.pow(mapSize, 2))
            player.initPlayer(mapSize)
            gamemap = {}
            map = Map(mapSize, mapSize, player.locationID)
            player.exploredAreas = 1
            player.initMaxMoonCake()
            map.description()
            if player.hp <= 0:  # Player death
                print("\n Very regrettably, also arrived in the western paradise, did not get together with chang e.")
                still_alive = False
            if player.allMoonCake >= 100:
                print("\n You finally get together with your chang 'e.")
                still_alive = False
        if player.hp <= 0:  # Player death
            print("\n It's a pity that you arrived in the western paradise and could not get together with Chang 'e.")
            still_alive = False
        if player.allMoonCake >= 100:
            print("\n You finally get together with your chang 'e.")
            still_alive = False
Copy the code

The last

There may be a lot of bugs in the middle, welcome to give correction and modification. Adapted on the basis of word play.

Come all come, click “like” and then go!

Follow WangScaler and wish you a promotion, a raise and no bucket!