Esempio n. 1
0
    def placeStairs(self):
        stairs = []
        startRoom = self.rooms[0]
        endRoom = self.rooms[-1]

        x, y = startRoom.randomPointWithinRoom

        stairs.append(Coords(x, y))

        self.grid[y][x] = choice([
            ALL_TILE_DICT['TERRAIN_DOWN_STAIR'], ALL_TILE_DICT['TERRAIN_STAIR']
        ])

        x, y = endRoom.randomPointWithinRoom

        stairs.append(Coords(x, y))

        self.grid[y][x] = choice([
            ALL_TILE_DICT['TERRAIN_UP_STAIR'], ALL_TILE_DICT['TERRAIN_STAIR']
        ])

        for r in self.rooms[1:-1]:
            if randFloat() < 1.0 / 3.0:
                x, y = r.randomPointWithinRoom
                self.grid[y][x] = choice([
                    ALL_TILE_DICT['TERRAIN_STAIR'],
                    ALL_TILE_DICT['TERRAIN_UP_STAIR'],
                    ALL_TILE_DICT['TERRAIN_DOWN_STAIR']
                ])
                stairs.append(Coords(x, y))

        for r in self.rooms:
            if randFloat() < 0.2:
                x, y = r.randomPointWithinRoom
                if self.grid[y][x] not in {
                        ALL_TILE_DICT['TERRAIN_STAIR'],
                        ALL_TILE_DICT['TERRAIN_UP_STAIR'],
                        ALL_TILE_DICT['TERRAIN_DOWN_STAIR']
                }:
                    self.grid[y][x] = choice([
                        ALL_TILE_DICT['TERRAIN_STAIR'],
                        ALL_TILE_DICT['TERRAIN_UP_STAIR'],
                        ALL_TILE_DICT['TERRAIN_DOWN_STAIR']
                    ])
                    stairs.append(Coords(x, y))
        return stairs
Esempio n. 2
0
    def placePillars(self):
        def leftToRightPillars(h, v):

            for p in range(self.leftEdge + 1, v - 1, 2):
                yield tuple([p, self.topEdge + 1])
                yield tuple([p, self.bottomEdge - 2])
            for p in range(self.rightEdge - 2, v, -2):
                yield tuple([p, self.topEdge + 1])
                yield tuple([p, self.bottomEdge - 2])

        def topToBottomPillars(h, v):
            for p in range(self.topEdge + 1, h - 1, 2):
                yield tuple([self.leftEdge + 1, p])
                yield tuple([self.rightEdge - 2, p])
            for p in range(self.bottomEdge - 2, h, -2):
                yield tuple([self.leftEdge + 1, p])
                yield tuple([self.rightEdge - 2, p])

        v, h = self.verticalLenght, self.horizontalLength
        vertPercent = v / (v + h)
        horizPercent = h / (v + h)

        if randFloat() < vertPercent * 0.75:

            halfPoint = self.topEdge + round(v / 2)
            self._pillarSpots += list(topToBottomPillars(halfPoint, halfPoint))

        if randFloat() < horizPercent * 0.75:

            halfPoint = self.leftEdge + round(h / 2)
            self._pillarSpots += list(leftToRightPillars(halfPoint, halfPoint))

        if len(self._pillarSpots) > 0:
            for p in self._pillarSpots:
                try:
                    self._spawnSpots.remove(p)
                except ValueError:
                    pass
Esempio n. 3
0
def decipher(cipherTxt, key):
    plainTxt = ""
    keyPos = []
    for k in key:
        keyPos.append(ascii_uppercase.find(k))
    i = 0
    for x in cipherTxt:
        if i == len(keyPos):
            i = 0
        pos = ascii_uppercase.find(x) - keyPos[i]
        if pos < 0:
            pos += 26
        for z in range(pos + 1):
            q = ascii_uppercase[z]
            print('\b' + q, end='', flush=True)
            sleep(randFloat(0, 0.01))
        plainTxt += q
        i += 1
        print('\b' * (len(plainTxt)) + plainTxt, end='', flush=True)
    print('\b' * len(plainTxt), end='')
    return plainTxt
Esempio n. 4
0
def cipher(plainTxt, key):
    cipherTxt = ""
    keyPos = []
    for k in key:
        keyPos.append(ascii_uppercase.find(k))
    i = 0
    for x in plainTxt:
        if i == len(keyPos):
            i = 0
        pos = ascii_uppercase.find(x) + keyPos[i]
        if pos > 25:
            pos = pos - 26
        for z in range(pos + 1):
            q = ascii_uppercase[z]
            print('\b' + q, end='', flush=True)
            sleep(randFloat(0, 0.01))
        cipherTxt += q
        print('\b' * (len(cipherTxt)) + cipherTxt, end='', flush=True)
        i += 1
    print('\b' * len(cipherTxt), end='')
    return cipherTxt
Esempio n. 5
0
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 18:38:33 2020

@author: MOHANA D
"""
#Please generate a random float where the value is between 10 and 100 using Python math module.
from random import uniform as randFloat
print(randFloat(10, 100))

#or

import random
val = random.uniform(10, 100)
print(val)
Esempio n. 6
0
    def poulateWeighted(self, num, weight=2):
        self.population += num
        for i in range(0, num):
            x = round((1 - randFloat()**weight) * (len(self.list) - 1))

            self.list[x] += 1