示例#1
0
    def init_population(self):

        current_grid = self.world.world_grid

        for _ in range(0, HUMANS):
            x = rnd.randint(0, GLOBAL_X - 1)
            y = rnd.randint(0, GLOBAL_Y - 1)
            is_sick = create_chance(0.01)
            if not current_grid[x, y]:
                current_grid[x, y] = Human(x, y, is_sick)
    def run(self):
        step = ''

        while (step != 'q'):

            human_01 = Human('male', rd())
            human_01.introduce_yourself()

            human_02 = Human('divers', rd())
            human_02.planet = 'Jupiter'
            human_02.introduce_yourself()

            human_01.change_gender('trans', True)

            stud_chosen = ran(self.students)
            print(f"{stud_chosen.name}, you are the choosen one!")

            step = input("'q' for exit: ")
示例#3
0
	def test_zombie_birth_when_human_die(self):
		"""check if when a zombie die, a new zombie birth"""
		old_count = len(list(Zombie.instances))
		new_human = Human(Area(1,Grid()))
		new_human.die()
		self.assertEqual(old_count+1	, len(list(Zombie.instances)))
示例#4
0
	def test_human_die(self):
		"""check if when a zombie die is correctly removed from instances"""
		old_count = len(list(Human.instances))
		new_human = Human(Area(1,Grid()))
		new_human.die()
		self.assertEqual(old_count, len(list(Human.instances)))
示例#5
0
	def test_move_function(self):
		"""check if the area before & after move is different"""
		birth_area = Area(1,Grid())
		human = Human(birth_area)
		human.move()
		self.assertNotEqual(birth_area.id, human.area.id)
示例#6
0
from classes.hospital import Hospital
from classes.human import Human

hospital = Hospital(1, 1, 10, 8)

peter = Human(10, 5, True)
print(peter)
hospital.accommodate_patient(peter)

print(peter)
示例#7
0
map_humans = np.vectorize(grid_to_array_sick)
update_humans = np.vectorize(update_human)
update_grid = np.vectorize(world.update)


sickness = {
    True: 2,
    False: 1,
}

for p in range(0, HUMANS):
    x = rnd.randint(0, GLOBAL_X - 1)
    y = rnd.randint(0, GLOBAL_Y - 1)
    is_sick = create_chance(0.1)
    if not grid[x, y]:
        grid[x, y] = Human(x, y, is_sick, sickness[is_sick])


fig, axs = plt.subplots(ncols=2)
fig = plt.gcf()
fig.show()
fig.canvas.draw()
colors = ['#FFFFFF', '#3EB24E', '#7FFF00', '#B3B3B3', '#CC0000']

time_line = {}

collected_humans = map_humans(grid)
start_pop = sum(list(count_humans(collected_humans).values()))
for idx in range(TIME_RANGE):
    collected_humans = map_humans(grid)
    if not count_humans(collected_humans).get(1):
示例#8
0
def main():
    pygame.init()

    # generate windows game
    # configure windows size
    # Title Game and Icone
    pygame.display.set_icon(ICONE)
    pygame.display.set_caption("Nadir, Save mac_gyver !!")
    screen = pygame.display.set_mode((450, 450))

    #Loading screen welcome
    screen.blit(BLACK_GROUND, (0, 0))
    screen.blit(WELCOME, (-2, 35))

    #+++++++++++The Main Loop+++++++##
    MAIN_LOOP = True
    while MAIN_LOOP:

        #refresh the screen
        pygame.display.flip()

        #++++++++The Welcome LOOP+++++++++##
        WELCOME_LOOP = True
        while WELCOME_LOOP:

            #LOOP Speed Limit
            pygame.time.Clock().tick(30)

            for event in pygame.event.get():
                #Quit the program
                if event.type == QUIT:
                    print("See you next time !")
                    MAIN_LOOP = False
                    WELCOME_LOOP = False
                    GAME_LOOP = False

                #Quit Welcome loop to enter in game loop
                if event.type == KEYDOWN and event.key == K_RETURN:

                    #######WELCOME TO THE GAME##########
                    ###SOUNDTRACK.stop()
                    screen.blit(BACKGROUND, (0, 0))
                    pygame.display.flip()
                    time.sleep(1)

                    WELCOME_LOOP = False
                    GAME_LOOP = True

                    #Load the game's map
                    FILE = "ressource/lab.txt"

        print("Menu terminé, passage au jeu.")

        if FILE != "":  #We make sure that the file really exists and is not empty
            #load the background
            screen.blit(BACKGROUND, (30, 30))

            #generate the labyrinth
            labyrinthe = Labyrinthe(FILE)
            labyrinthe.generate()
            labyrinthe.display(screen)

            # Pour le moment on met les items de côté.
            #Get the items in the labyrinthe

            seringue = Item("seringue", SERINGUE, labyrinthe)
            seringue.locate_item()
            seringue.pin_items()
            ether = Item("ether", ETHER, labyrinthe)
            ether.locate_item()
            ether.pin_items()
            tube = Item("tube", TUBE, labyrinthe)
            tube.locate_item()
            tube.pin_items()

            #Add arrived icon
            ARRIVED = pygame.image.load(
                "ressource/arrived.JPG").convert_alpha()
            screen.blit(ARRIVED, (390, 420))
            #Add mac_gyver in the Labyrinth with his position
            mac_gyver = Human(labyrinthe)
            screen.blit(MACGYVER_IMAGE, (0, 0))

        #++++++++GAME_LOOP++++++++++++++++++#
        #Initialyse at every game_loop an empty list to put the elements inside
        TOOLS = []
        while GAME_LOOP:
            pygame.time.Clock().tick(30)
            for event in pygame.event.get():

                #Quit the program
                if event.type == QUIT:
                    print("See you next time !")
                    MAIN_LOOP = False
                    GAME_LOOP = False
                elif event.type == KEYDOWN:
                    #Quit the game and go back Home
                    if event.key == K_ESCAPE:
                        GAME_LOOP = False
                    #create event to move player
                    elif event.key == K_RIGHT:
                        mac_gyver.move("right")
                    elif event.key == K_LEFT:
                        mac_gyver.move("left")
                    elif event.key == K_UP:
                        mac_gyver.move("up")
                    elif event.key == K_DOWN:
                        mac_gyver.move("down")

            #Display the game board
            screen.blit(BACKGROUND, (0, 0))
            labyrinthe.display(screen)
            screen.blit(MACGYVER_IMAGE, (mac_gyver.x, mac_gyver.y))
            pygame.display.flip()

            #Add conditionnal display of Element

            #tube.display_item(screen, mac_gyver, TOOLS)
            #seringue.display_item(screen, mac_gyver, TOOLS)
            #ether.display_item(screen, mac_gyver, TOOLS)

            if labyrinthe.grid[mac_gyver.sprite_x][mac_gyver.sprite_y] == "a":

                #The player wins if he collects the tree items
                if mac_gyver.inventory < 3:

                    #+++++DISPLAY GAME OVER++++#
                    screen.blit(GAMEOVER, (150 + 30, 150 + 30))
                    pygame.display.flip()
                    time.sleep(2)
                    #+++++++++++++++++++++++++++++#
                    print("You loose")
                    GAME_LOOP = False
                    #+++++++++++++++++++++++++++++#
                if mac_gyver.inventory == 3:
                    #+++++DISPLAY YOU WIN+++++++++#
                    screen.blit(WIN, (100 + 30, 150 + 30))
                    pygame.display.flip()
                    time.sleep(2)
                    #+++++++++++++++++++++++++++++#
                    print("You win!")
                    GAME_LOOP = False
示例#9
0
from classes.human import Human
from classes.data import Data
from classes.controller import Controller
from sys import argv
from matplotlib import pyplot

if __name__ == '__main__':
    if argv[1] != "--help" and argv[1] != "-h":
        name = "spolki/" + argv[1]
        data = Data(name)
        human = Human(data)
        stock = None

        if len(argv) == 3:
            stock = Controller(data, human, int(argv[2]))  # Jesli argv[3] = 1 to Controller uzyje uzyje lekko
            # ulepszonej wersji wskaźnika a jesli argv[3] > 1 to ulepszonej wersji
        else:
            stock = Controller(data, human)

        stock.stock()

        date = data.getDate()
        # pyplot.figure("Project")
        # pyplot.subplot(2, 1, 1)
        # pyplot.plot(date, data.getClose(), label="Price", color="green")
        # pyplot.ylabel("Price in USD")
        # pyplot.xlabel("Date in yyyy-mm-dd format")
        # pyplot.title("Price")
        # pyplot.legend()
        # pyplot.grid(True)
        # pyplot.subplot(2, 1, 2)