def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Rock Paper Scissors")
    screen.fill(settings.bg_color)
    rock = Rock(settings, screen)
    paper = Paper(settings, screen)
    scissors = Scissors(settings, screen)
    myfont = pygame.font.SysFont("monospace", 30)
    while True:
        label = myfont.render("Choose either rock, paper or scissors", 1, (0,0,0))
        screen.blit(label, (250, 100))
        # check events here
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                check_collision(rock,paper,scissors,mouse_x,mouse_y,settings)
        rock.blitme()
        paper.blitme()
        scissors.blitme()

        pygame.display.flip()
Esempio n. 2
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                     (globals.CANVAS_DIMS[1] / 9) * 4)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 7,
                     (globals.CANVAS_DIMS[1] / 9))),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                     (globals.CANVAS_DIMS[1] / 9) * 4))
     ]
     self.RangedEnemies = [
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                      (globals.CANVAS_DIMS[1] / 9) * 3))
     ]
     self.Rocks = [
         Rock(((globals.CANVAS_DIMS[0] / 3) * 2,
               (globals.CANVAS_DIMS[1] / 2))),
         Rock(((globals.CANVAS_DIMS[0] / 9) * 7,
               (globals.CANVAS_DIMS[1] / 5) * 2)),
         Rock(((globals.CANVAS_DIMS[0] / 7) * 2,
               (globals.CANVAS_DIMS[1] / 6) * 5)),
         Rock(((globals.CANVAS_DIMS[0] / 5) * 3,
               (globals.CANVAS_DIMS[1] / 9) * 2))
     ]
     self.Gates = [Gate(2, 1, 0), Gate(1, 1, 2)]
     self.Room = Room()
Esempio n. 3
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                     (globals.CANVAS_DIMS[1] / 9) * 3)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 6,
                     (globals.CANVAS_DIMS[1] / 9) * 4)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                     (globals.CANVAS_DIMS[1] / 9) * 7)),
         SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 8,
                          (globals.CANVAS_DIMS[1] / 9) * 1))
     ]
     self.RangedEnemies = [
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                      (globals.CANVAS_DIMS[1] / 9) * 8)),
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 6,
                      (globals.CANVAS_DIMS[1] / 9) * 1))
     ]
     self.Rocks = [
         Rock(((globals.CANVAS_DIMS[0] / 7) * 2,
               (globals.CANVAS_DIMS[1] / 3) * 1)),
         Rock(((globals.CANVAS_DIMS[0] / 5) * 4,
               (globals.CANVAS_DIMS[1] / 5) * 3)),
         Rock(((globals.CANVAS_DIMS[0] / 7) * 3,
               (globals.CANVAS_DIMS[1] / 3) * 2))
     ]
     self.Gates = [Gate(3, 2, 1), Gate(0, 2, 3), Gate(1, 2, 4)]
     self.Room = Room()
Esempio n. 4
0
    def setup(self):

        print("-- start level")

        self.bg = Background(self)
        self.ship = Ship(self)

        self.init_world()
        self.init_ship()
        self.init_lights()
        self.init_camera()

        self.mouse_collision = MouseCollision(self)
        self.ship_collision = ShipCollision(self)

        self.rock1 = Rock(self, 5, 5)
        self.rock2 = Rock(self, -5, 6)
        self.rock3 = Rock(self, -5, 3)

        #self.joypad = Joypad()

        # Tasks
        self.taskMgr.add(self.update, 'update')
        self.taskMgr.add(self.bg.update, 'updateBackground')
        self.taskMgr.add(self.ship.update, 'updateShip')
Esempio n. 5
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5, (globals.CANVAS_DIMS[1] / 9) * 2)),
                          MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 8, (globals.CANVAS_DIMS[1] / 9) * 7))]
     self.RangedEnemies = []
     self.Rocks = [Rock(((globals.CANVAS_DIMS[0] / 6) * 2, (globals.CANVAS_DIMS[1] / 8) * 3)),
                   Rock(((globals.CANVAS_DIMS[0] / 9) * 7, (globals.CANVAS_DIMS[1] / 5) * 4))]
     self.Gates = [Gate(0, 0, 1)]
     self.Room = Room()
Esempio n. 6
0
    def init_world(self):

        print("-- init world")

        self.bg = Background(self)
        self.bg.draw()

        self.rock1 = Rock(self, 5, 5)
        self.rock2 = Rock(self, -5, 6)
        self.rock3 = Rock(self, -5, 3)

        self.taskMgr.add(self.bg.update, 'updateBackground')
Esempio n. 7
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 3, (globals.CANVAS_DIMS[1] / 9) * 6)),
                          SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5, (globals.CANVAS_DIMS[1] / 9) * 1))]
     self.RangedEnemies = [RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 2, (globals.CANVAS_DIMS[1] / 9) * 3)),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 7, (globals.CANVAS_DIMS[1] / 9))),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 4, (globals.CANVAS_DIMS[1] / 9) * 8)),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 8, (globals.CANVAS_DIMS[1] / 9) * 5))]
     self.Rocks = [Rock(((globals.CANVAS_DIMS[0] / 6) * 1, (globals.CANVAS_DIMS[1] / 8) * 6)),
                   Rock(((globals.CANVAS_DIMS[0] / 9) * 4, (globals.CANVAS_DIMS[1] / 8) * 5))]
     self.Gates = [Gate(3, 4, 2)]
     self.Room = Room()
Esempio n. 8
0
    def addRocks(self, num=10):

        for i in range(num):
            newRock = Rock(world=self)

            newRock.vel = Vector2D.random(newRock.maxSpeed)
            newRock.vel.y = 0

            newRock.pos = self.tank.randomPosition()
            while (self.obstacleOverlapsOtherObstacles(newRock)):
                newRock.pos = self.tank.randomPosition()

            self.obstacles.append(newRock)
Esempio n. 9
0
	def addRocks(self, num=10):

		for i in range(num):
			newRock = Rock(world=self)
			
			newRock.vel = Vector2D.random(newRock.maxSpeed)
			newRock.vel.y = 0

			newRock.pos = self.tank.randomPosition()
			while(self.obstacleOverlapsOtherObstacles(newRock)):
				newRock.pos = self.tank.randomPosition()

			self.obstacles.append(newRock)
Esempio n. 10
0
    def initComponents(self):
        # Rocks
        self.rock = Rock(self.x + constants.CENTER_SCREEN_X, constants.CENTER_SCREEN_Y, self.profile.health * 10 + 50, self.profile.health * 10 + 50, self.profile)

        # Buttons
        self.saveButton = Button("Save", self.x + 700, 0, 100, 50)
        self.shopButton = Button("Shop", self.x + 700, 550, 100, 50)

        # Labels and Dynamic text
        self.gemLabel = Text("Gem:", self.x + 10, 550, constants.WHITE, "Arial", 25)
        self.gemText = Text(str(self.profile.getGemCount()), self.x + 72, 550, constants.WHITE, "Arial", 25)

        self.healthLabel = Text("Health:", self.x + 340, 550, constants.WHITE, "Arial", 25)
        self.healthText = Text(str(self.profile.health), self.x + 422, 550, constants.WHITE, "Arial", 25)
Esempio n. 11
0
class Field:
    def __init__(self, width, height):
        self.width, self.height = width, height
        self.rocks = []
        self.powerups = []
        self.bullets = []
        self.__player = Player()
        self.__rock = Rock()
        self.__powerup = Powerup(PowerupType.no_powerup)
        self.__bullet = Bullet()

    def set_rock_speed(self, new_speed):
        """Sets the rock's speed to the value of new_speed."""
        self.__rock.set_speed(new_speed)

    @property
    def rock_speed(self):
        """Gets the rock's speed."""
        return self.__rock.rock_speed

    @property
    def player_speed(self):
        """Gets the player's speed."""
        return self.__player.player_speed

    @property
    def bullet_speed(self):
        """Gets the bullet's speed."""
        return self.__bullet.bullet_speed

    @property
    def player(self):
        """Gets the player's object."""
        return self.__player

    @property
    def rock(self):
        """Gets the rock's object."""
        return self.__rock

    @property
    def powerup(self):
        """Gets the powerup's object."""
        return self.__powerup

    @property
    def bullet(self):
        """Gets the bullet's speed."""
        return self.__bullet
Esempio n. 12
0
 def doors2(self):
     opening_locations = []
     for i in range(8):
         doors = []
         random_num = randint(1, 10)
         if random_num <= 5:
             doors = [1, 2]
         else:
             doors = [2, 1]
         opening_locations.append([sample(range(0, 12), 2), doors])
     wall_location_index = 1
     for x in range(len(opening_locations)):
         for y in range(12):
             if y != opening_locations[x][0][0] and y != opening_locations[
                     x][0][1]:
                 self.tile_objects.append(
                     Rock(self.rock_img, wall_location_index, y))
             if y == opening_locations[x][0][0]:
                 self.tile_objects.append(
                     Leaf(self.leaf_img, wall_location_index, y,
                          opening_locations[x][1][0]))
             elif y == opening_locations[x][0][1]:
                 self.tile_objects.append(
                     Leaf(self.leaf_img, wall_location_index, y,
                          opening_locations[x][1][1]))
         wall_location_index += 2
Esempio n. 13
0
def create_rock(screen, ai_settings, rock_stats, rocks):
    # create a rock and assign its random flag and trajectory slope
    rock_flag = rock_stats.assign_rock()
    slope = rock_stats.assign_slope()
    reward_stats = RewardStats(rock_flag)
    reward_flag = reward_stats.assign_reward()
    new_rock = Rock(screen, ai_settings, rock_flag, slope, reward_flag)
    rocks.add(new_rock)
Esempio n. 14
0
 def setup_3(self):
     x = randint(3, 12)
     y = 12
     height = randint(2, 9)
     for i in range(height):
         rock_image = Rock(self.rock_img, x, y)
         y -= 1
         self.tile_objects.append(rock_image)
    def __init__(self, world_width, world_height):
        self.mWorldWidth = world_width
        self.mWorldHeight = world_height
        self.mShip = Ship(world_width//2, world_height//2, world_width, world_height)
        self.mShip.setColor((0, 255, 0))
        self.mRocks = []
        for i in range(10):
            x = random.randint(0, world_width)
            y = random.randint(0, world_width)
            r = Rock(x, y, world_width, world_height)
            num_points = random.randint(5, 10)
            radius = random.randint(10, 20)
            point_list = r.createRandomPolygon(radius, num_points)
            r.setPolygon(point_list)
            r.setColor((0, 0, 255))
            self.mRocks.append(r)

        self.mStars = []
        for i in range(20):
            x = random.randint(0, world_width)
            y = random.randint(0, world_width)
            s = Star(x, y, world_width, world_height)
            self.mStars.append(s)
        self.mBullets = []
        self.mObjects = [self.mShip] + self.mRocks + self.mStars + self.mBullets
Esempio n. 16
0
 def __init__(self, width, height):
     self.width, self.height = width, height
     self.rocks = []
     self.powerups = []
     self.bullets = []
     self.__player = Player()
     self.__rock = Rock()
     self.__powerup = Powerup(PowerupType.no_powerup)
     self.__bullet = Bullet()
Esempio n. 17
0
 def random_rocks(self):
     for i in range(0, 10):
         chosen_x_y = [randint(0, 15), randint(0, 11)]
         while (chosen_x_y[0] * 50 == self.wombat.x and chosen_x_y[1] * 50
                == self.wombat.y) or self.something_on_spot(
                    chosen_x_y[0], chosen_x_y[1]):
             chosen_x_y = [randint(0, 15), randint(0, 11)]
         rock_image = Rock(self.rock_img, chosen_x_y[0], chosen_x_y[1])
         self.tile_objects.append(rock_image)
Esempio n. 18
0
 def doors(self):
     opening_locations = []
     for i in range(8):
         opening_locations.append(randint(0, 11))
     wall_location_index = 1
     for loc in opening_locations:
         for y in range(12):
             if y != loc:
                 self.tile_objects.append(
                     Rock(self.rock_img, wall_location_index, y))
         wall_location_index += 2
Esempio n. 19
0
 def setup_10(self):
     # need to setup wombat in main at the bottom left corner
     final_height = 0
     for i in range(4, 16):
         height = randint(0, 7)
         for j in range(0, height):
             new_rock = Rock(self.rock_img, i, 11 - j)
             self.tile_objects.append(new_rock)
         if i == 15:
             final_height = height
     self.tile_objects.append(Leaf(self.leaf_img, i, 11 - final_height, 1))
Esempio n. 20
0
def init():
    global rocks, player
    player.x = 20
    player.y = 250
    rocks = []
    levelInfo = info.iloc[level]
    for i in range(levelInfo["numrock"]):
        rocks.append(
            Rock(random.randint(300, 500), random.randint(200, 300),
                 random.randint(-5, 5), random.randint(-5, 5),
                 random.randint(20, 50)))
Esempio n. 21
0
def init():
    global rocks
    rocks = []
    try:
        levelInfo = info.iloc[level]
    except:
        global goahead
        goahead = True
    else:
        for i in range(levelInfo["numRock"]):
            rocks.append(
                Rock(random.randint(300, 500), random.randint(200, 300),
                     random.randint(-5, 5), random.randint(-5, 5),
                     random.randint(10, 50)))
Esempio n. 22
0
 def __init__(self, world_width, world_height):
     self.mWorldWidth = world_width
     self.mWorldHeight = world_height
     self.mShip = Ship(self.mWorldWidth // 2, self.mWorldHeight // 2,
                       self.mWorldWidth, self.mWorldHeight)
     self.mRocks = []
     for i in range(10):
         self.mRocks.append(
             Rock(randint(0,
                          self.mWorldWidth), randint(0, self.mWorldHeight),
                  self.mWorldWidth, self.mWorldHeight))
     self.mBullets = []
     self.mStars = []
     for i in range(20):
         self.mStars.append(
             Star(randint(0,
                          self.mWorldWidth), randint(0, self.mWorldHeight),
                  self.mWorldWidth, self.mWorldHeight))
     self.mObjects = [self.mShip]
     for rock in self.mRocks:
         self.mObjects.append(rock)
     for star in self.mStars:
         self.mObjects.append(star)
Esempio n. 23
0
 def add_rock(self, velocity):
     rock = Rock(self.screen, self.person.x, self.person.y,
                 self.person.angle, velocity)
     self.rocks.append(rock)
Esempio n. 24
0
import pygame
import time

from Gridcontainer import GridContainer
from Grid import Grid
from turtle import Turtle
from rock import  Rock
from worm import Worm
from random import randint
from AstarAlgoritmo import aStar
tela =  pygame.display.set_mode([600,480]);
tela.fill([203, 237, 216])
container = GridContainer()
grid = Grid()
tartaruga = Turtle(25,25,(92 + 262),(27+262),(255,255,255))
rock = Rock(25,25,(92 + 262),(27+262),(255,255,255))
worm = Worm(25,25,(92 + 262),(27+262),(255,255,255))
grid.CriandoMatriz();

sprite_group = pygame.sprite.Group()
sprite_group.add(tartaruga)

container.Desenhacontainer(tela)
grid.DesenhaGrid(tela)

tartaruga.setPosicaoInicial(8,8,grid.rectMap)
worm.setWormPosicao(grid.matriz,grid.rectMap,tela)
rock.setRockPosicao(grid.matriz,grid.rectMap,tela)


Esempio n. 25
0
    def __init__(self, screen, timer, custom=False):
        self.screen = screen
        self.timer = timer

        '''Game Mode'''
        if custom != False:  # 0, if no platforms are drawn
            self.custom = True
            if isinstance(custom, list):
                self.customPlatTypes = custom
                self.customNumPlatforms = None
            else:
                self.customNumPlatforms = custom
                self.customPlatTypes = None
        else:
            self.custom = False

        '''Game Mechanics'''
        self.totalGameTime = 1000
        self.gameover = False
        self.gameover_image = None
        self.gameover_rect = None
        self.pause = False
        self.done = False
        font = load.load_font("OpenSans-Semibold", 40)
        self.pause_image = font.render("Paused", True, (236, 247, 255))
        self.pause_rect = self.pause_image.get_rect()
        self.pause_rect.center = self.screen.get_rect().center
        self.exit = True
        self.showFPS = False
        self.noCrashes = False

        '''Background'''
        self.bg = Surface((32, 32))
        self.bgTime = 0
        self.bgColor = Game.bgColor
        self.sundownTime = 0
        self.rainStart = random.randint(0, self.totalGameTime)
        self.rainEnd = self.rainStart + random.randint(150, 500)
        self.rainEndColor = None
        self.darkenTime = (self.rainEnd - self.rainStart) / 3
        self.lightenTime = 2 * (self.rainEnd - self.rainStart) / 3
        self.raining = self.darkening = self.lightening = False
        self.snowing = False
        self.snow = Snow()

        '''Game entities'''
        self.entities = pygame.sprite.Group()
        self.rocks = pygame.sprite.Group()
        self.trees = pygame.sprite.Group()
        self.birds = pygame.sprite.Group()
        self.coins = pygame.sprite.Group()
        self.ice = pygame.sprite.Group()
        self.player = Player()
        self.entities.add(self.player)
        self.coinCount = 0
        self.flyingBirds = []
        self.collectedCoins = []
        self.clouds = None

        '''Score'''
        self.score = Score()
        self.scoreSprite = pygame.sprite.Group()
        self.scoreSprite.add(self.score)

        '''Platforms'''
        self.platforms = []
        self.numPlatforms = 30
        self.generatePlatforms()
        self.createPlatforms()

        '''Camera'''
        self.totalWidth = 1024 * len(self.platformTypes)
        self.totalHeight = 800
        self.camera = Camera(complex_camera, self.totalWidth, self.totalHeight)

        '''Generating obstacles'''
        self.iceCoords = makeIce(self.platforms)
        rockInfo = makeRock(self.platforms)
        self.treeDict = makeTrees(self.platforms)
        self.birdDict = generateBirds(self.platforms)
        self.coinDict = makeCoins(self.platforms)
        (self.rockRects, self.rockCoords, self.rockAngles) = \
            (rockInfo[0], rockInfo[1], rockInfo[2])

        # ROCKS
        offset = 1024
        for item in range(1, len(self.rockRects)):
            currentPlatform = self.platforms[item]
            x = self.rockRects[currentPlatform][0] + offset
            y = self.rockRects[currentPlatform][1]
            angle = self.rockAngles[currentPlatform]
            obstacle = random.choice("001")
            rock = Rock(x, y, angle) if obstacle == "0" else Penguin(
                x, y, angle)
            self.rocks.add(rock)
            offset += 1024

        # ICE
        iceOffset = 0
        for item in range(self.numPlatforms):
            currentPlatform = self.platforms[item]
            x = iceOffset
            ice = Ice(x, 299, currentPlatform, self.iceCoords)
            self.ice.add(ice)
            iceOffset += 1024

        # TREES
        offset = 0
        for item in range(len(self.treeDict)):
            currentPlatform = self.platforms[item]
            treeCoords = self.treeDict[currentPlatform]
            for tree in treeCoords:
                x = offset + tree[0]
                yOffset = random.randint(5, 20)
                y = tree[1] + 300 + yOffset
                tree = Tree(x, y)
                self.trees.add(tree)
            offset += 1024

        # BIRBS & COINS
        offset = 0
        for item in range(self.numPlatforms):
            currentPlatform = self.platforms[item]
            coords = self.birdDict[currentPlatform]
            coinCoords = self.coinDict[currentPlatform]
            if coords != None:
                for point in coords:
                    x = offset + point[0]
                    y = point[1]
                    bird = Bird(x, y, 0)
                    self.birds.add(bird)
            if coinCoords != None:
                for coin in coinCoords:
                    x = offset + coin[0]
                    y = coin[1]
                    coin = Coin(x, y)
                    self.coins.add(coin)
            offset += 1024
Esempio n. 26
0
 def small_wall(self):
     self.tile_objects.append(Rock(self.rock_img, randint(0, 15), 11))
Esempio n. 27
0
 def spawn_rock(self):
     new_rock = Rock()
     self.rocks.add(new_rock)
Esempio n. 28
0
def runGame():
    """Runs the game, duh!"""
    #initialize window and such
    settings = Settings()
    game.init()
    game.font.init()
    screen = game.display.set_mode(
        (settings.screenWidth, settings.screenHeight))
    game.display.set_caption(settings.title)

    character = boy(screen)

    game.display.set_icon(character.image)

    font = Fonts(character)

    total = 2

    #create a path
    pathList = []
    for i in range(0, 20):
        path = Tile('OverworldPath.png',
                    screen.get_rect().centerx,
                    screen.get_rect().bottom - (i * 32), screen, 0)
        pathList.append(path)

    #create a wall
    wallList = []
    for i in range(0, 8):
        for j in range(0, 8, 2):
            wall = Tile('OverworldWall.png',
                        (screen.get_rect().centerx * 1.5) + (i * 32),
                        (screen.get_rect().centery * 1.5) + (j * 32), screen,
                        1)
            wallList.append(wall)
    for i in range(0, 15):
        wall = Tile('OverworldWall.png', 240, 0 + (32 * i), screen, 1)
        wallList.append(wall)
    for i in range(0, 4):
        wall = Tile('OverworldWall.png', 272 + (32 * i), 96 + (32 * i), screen,
                    1)
        wallList.append(wall)

    #generate some rocks
    rockList = []
    for i in range(0, total):
        randX = randint(0, 1200 - 32)
        randY = randint(0, 800 - 32)
        rock = Tile('OverworldRock.png', randX, randY, screen, 1)
        rockList.append(rock)

    usedMinerals = []
    mineral = -1

    bossPresent = False
    bossCounter = 0

    #main loop for game
    while True:
        if len(usedMinerals) % total == 0 and bossPresent == False and len(
                usedMinerals) != 0:
            boss1 = Tile('BossRock.png', 583, 120, screen, 1)
            bossPresent = True
            bossCounter += 1
            while len(rockList) > 0:
                rockList.pop()
            rockList.append(boss1)

        if character.stage == "OVERWORLD":
            character.walkAnimate()
            character.checkCollision(wallList)
            if character.checkCollision(rockList) == True:
                while True:
                    mineral = randint(1, 10)
                    if mineral not in usedMinerals:
                        break
                if bossPresent == True:
                    enemy = Rock(11 * bossCounter, screen)
                else:
                    enemy = Rock(mineral, screen)
                character.stage = "BATTLE"
                character.setBattleImage("Battle.png")
            character.updatePos()
        if character.stage == "BATTLE":
            gf.checkEvents(character, font, enemy, rockList, mineral,
                           usedMinerals, bossPresent)
            gf.updateScreen(settings, screen, character, pathList, wallList,
                            rockList, font, enemy)
        else:
            gf.checkEvents(character, font)
            gf.updateScreen(settings, screen, character, pathList, wallList,
                            rockList, font)
Esempio n. 29
0
class GameScreen(Screen):
    def __init__(self, display, profile, x, y):
        Screen.__init__(self, display)

        # Give screen access to gems and upgrades
        self.profile = profile
        self.x = x
        self.y = y

        self.initComponents()
        self.attachComponents()
    
    # Create the components of the game screen
    def initComponents(self):
        # Rocks
        self.rock = Rock(self.x + constants.CENTER_SCREEN_X, constants.CENTER_SCREEN_Y, self.profile.health * 10 + 50, self.profile.health * 10 + 50, self.profile)

        # Buttons
        self.saveButton = Button("Save", self.x + 700, 0, 100, 50)
        self.shopButton = Button("Shop", self.x + 700, 550, 100, 50)

        # Labels and Dynamic text
        self.gemLabel = Text("Gem:", self.x + 10, 550, constants.WHITE, "Arial", 25)
        self.gemText = Text(str(self.profile.getGemCount()), self.x + 72, 550, constants.WHITE, "Arial", 25)

        self.healthLabel = Text("Health:", self.x + 340, 550, constants.WHITE, "Arial", 25)
        self.healthText = Text(str(self.profile.health), self.x + 422, 550, constants.WHITE, "Arial", 25)

    # Add components to components list
    def attachComponents(self):
        # Rocks
        self.components.append(self.rock)

        # Buttons
        self.components.append(self.saveButton)
        self.components.append(self.shopButton)
        
        # Labels and Dynamic text
        self.components.append(self.gemLabel)
        self.components.append(self.gemText)

        self.components.append(self.healthLabel)
        self.components.append(self.healthText)
    
    # Updates all the components in the screen that change
    def update(self, deltaTime):
        self.profile.handlePassive(deltaTime)

        self.rock.update(deltaTime)
        self.gemText.update(str(self.profile.getGemCount()))
        self.healthText.update(str(self.rock.profile.health))
    
    def checkForComponentClicks(self):
        if self.rock.isBeingClicked() == True:
            self.profile.incrementGems()
        
        if self.saveButton.isBeingClicked() == True:
            # Determine which file will be overwritten based on which save is being pressed
            if self.saveButton.x < constants.SCREEN_WIDTH:
                f = open(constants.PRIMARY_FILE_NAME, "w")
            
            if (self.saveButton.x > constants.SCREEN_WIDTH):
                f = open(constants.SECONDARY_FILE_NAME, "w")
            
            f.write(str(self.profile.getGemCount()) + " ")
            f.write(str(self.profile.getIncrementCount()) + " ")
            f.write(str(self.profile.getPassiveCount()) + " ")
            f.write(str(self.profile.health) + " ")
            f.close()
        
        if self.shopButton.isBeingClicked() == True:
            self.profile.state = State.SHOP_SCREEN
Esempio n. 30
0
#!/usr/bin/env python

import random

from rock import Rock
from paper import Paper
from scissors import Scissors
import var_storage

classes = (Rock, Paper, Scissors)
convert_classes = {'rock': Rock(), 'paper': Paper(), 'scissors': Scissors()}

nbr_of_round = input("How many rounds? ")
print "Game started"
nbr_of_round += 1

for i in range(1, nbr_of_round):
    my_choice = raw_input("Make your choice for round " + str(i) + " : ")

    my_choice = convert_classes.get(my_choice)
    opponent_choice = random.choice(classes)()

    if isinstance(opponent_choice, Rock) is True:
        print "opponent choice is Rock"
        my_choice.attack(rock=True)
    elif isinstance(opponent_choice, Paper) is True:
        print "opponent choice is Paper"
        my_choice.attack(paper=True)
    elif isinstance(opponent_choice, Scissors) is True:
        print "opponent choice is Scissors"
        my_choice.attack(scissors=True)
    def create_random_bodies(self, amount):

        for i in range(amount):
            size = randint(1, 60)
            rock = Rock(size=size)
            self.add_body(rock)