Advertisement
1400_SpaceCat

Untitled

Apr 27th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.77 KB | None | 0 0
  1. from mdl_system_ior import CIOR
  2.  
  3. from random import randint
  4. from random import choice
  5.  
  6. from os import system
  7. from os import name
  8. from os import open
  9. # from os import ctermid
  10. from os import O_RDONLY
  11. from os import close
  12. from sys import stdout
  13. from subprocess import Popen
  14.  
  15. from time import strftime
  16.  
  17. from time import sleep
  18. import platform
  19. import shutil
  20. import itertools
  21. import threading
  22. import time
  23. import locale
  24.  
  25. class CColors:
  26.     try:
  27.         from colorama import init
  28.         from colorama import Fore
  29.         from colorama import Back
  30.         from colorama import Style
  31.    
  32.     except ImportError:
  33.         sblack    = ""
  34.         sred      = ""
  35.         sgreen    = ""
  36.         syellow   = ""
  37.         sblue     = ""
  38.         swhite    = ""
  39.  
  40.         bgblack   = ""
  41.         bgred     = ""
  42.         bggreen   = ""
  43.         bgyellow  = ""
  44.         bgblue    = ""
  45.         bgmagenta = ""
  46.         bgwhite   = ""
  47.  
  48.         stbright  = ""
  49.         stnormal  = ""
  50.  
  51.         none      = "" #---N O T H I N G---#
  52.    
  53.     else:
  54.  
  55.         init()
  56.  
  57.         sblack    = Fore.BLACK
  58.         sred      = Fore.RED
  59.         sgreen    = Fore.GREEN
  60.         syellow   = Fore.YELLOW
  61.         sblue     = Fore.BLUE
  62.         swhite    = Fore.WHITE
  63.  
  64.         bgblack   = Back.BLACK
  65.         bgred     = Back.RED
  66.         bggreen   = Back.GREEN
  67.         bgyellow  = Back.YELLOW
  68.         bgblue    = Back.BLUE
  69.         bgmagenta = Back.MAGENTA
  70.         bgwhite   = Back.WHITE
  71.  
  72.         stbright  = Style.BRIGHT
  73.         stnormal  = Style.NORMAL
  74.  
  75.         none      = "" #---N O T H I N G---#
  76.         endc      = Style.RESET_ALL
  77.  
  78. class CTools:
  79.     def FClearSaves():
  80.         if name in ("nt","dos","ce"):
  81.             (stdout,stderr) = Popen("os_nt_saves_clear.bat",cmd=r".").communicate()
  82.         elif name == "posix":
  83.             system("chmod +x os_nix_saves_clear.sh && ./os_nix_saves_clear.sh")
  84.  
  85.     def FPopen(fileName):
  86.         if name in ("nt","dos","ce"):
  87.             (stdout,stderr) = Popen(fileName,cmd=r".").communicate()
  88.         elif name == "posix":
  89.             system("chmod +x %s && ./%s" % (fileName,fileName))
  90.  
  91.     currentTime = strftime("%H:%M:%S")
  92.     currentDateDMY = strftime("%d/%m/%y")
  93.     currentDateMDY = strftime("%m/%d/%y")
  94.     currentLocale = locale.getdefaultlocale()[0]
  95.  
  96.     # def FCallFunction(key,*fs):
  97.     #   for i in fs:
  98.     #       fs[key]()
  99.  
  100.     def FCheckEmptyBlock(listName):
  101.         for key,value in listName:
  102.             for item in value:
  103.                 print("%d:\tFull Block\t[%s]" % (key,item) if item != '' else print('%d:\tEMPTY BLOCK\t[ ]' % key))
  104.    
  105.     def FTerminalSize():
  106.         import os
  107.         env = os.environ
  108.        
  109.         def ioctl_GWINSZ(fd):
  110.             try:
  111.                 import fcntl, termios, struct, os
  112.                 cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
  113.             '1234'))
  114.             except:
  115.                 return
  116.             return cr
  117.         cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
  118.         if not cr:
  119.             try:
  120.                 fd = os.open(os.ctermid(), os.O_RDONLY)
  121.                 cr = ioctl_GWINSZ(fd)
  122.                 os.close(fd)
  123.             except:
  124.                 pass
  125.         if not cr:
  126.             cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
  127.  
  128.         return int(cr[1]), int(cr[0])
  129.  
  130. class CMagic(CColors):
  131.     #class with the small and good anon. functions#
  132.     if name in ("nt","dos","ce"):
  133.         FClearScreen = lambda: system("cls")
  134.     elif name == "posix": FClearScreen = lambda: system("clear")
  135.    
  136.     FSleep = lambda s: sleep(s)
  137.     FPressKey = lambda e: input(""+e)
  138.     FExit = lambda m: exit(m)
  139.  
  140. class CShow(CTools,CColors):
  141.     #<show function>(CColors.FONT_COLOR_NAME,CColor.BACKGROUND_COLOR_NAME,text,options for delay)#
  142.     def FShowDelay(fontColor,backgroundColor,textArray,delayArray,delayEnd,pressKeyValue):
  143.         textArray = [t for t in textArray]
  144.        
  145.         if name in ("nt","dos","ce"):
  146.             for i in range(len(textArray)):
  147.                 print(fontColor+backgroundColor+textArray[i]+CColors.endc,end="")
  148.                 sleep(delayArray)
  149.  
  150.         elif name == "posix":
  151.             for i in range(len(textArray)):
  152.                 stdout.write(fontColor+backgroundColor+textArray[i]+CColors.endc,end="")
  153.                 stdout.flush()
  154.                 sleep(delayArray)
  155.  
  156.         if pressKeyValue == 0:
  157.             sleep(delayEnd)
  158.  
  159.         elif pressKeyValue == 1:
  160.             input(fontColor+backgroundColor+CIOR.dictIO[CTools.currentLocale]["gameInput"]["gamePressKey"]+CColors.endc)
  161.  
  162.         elif pressKeyValue == 2:
  163.             input("<...>")
  164.  
  165.     def FShowInMiddle(fontColor,backgroundColor,*textArray):
  166.         columns = shutil.get_terminal_size().columns
  167.         for i in textArray:
  168.             # center = "{0}".center(columns).format(i)
  169.             center = "{0}".center(CTools.FTerminalSize()[0]-20).format(i)
  170.             print(fontColor+backgroundColor+center)
  171.  
  172.     def FShowLoad(fontColor,backgroundColor,textLoading,countLoading,delayArray,delayEnd,loadingValue):
  173.         for i in countLoading:
  174.             if loadingValue == 0:
  175.  
  176.                 print(fontColor+backgroundColor+textLoading+i+CColors.endc,end="")
  177.                 system("clear")
  178.                 sleep(delayArray)
  179.  
  180.             elif loadingValue == 1:
  181.                 print(fontColor+backgroundColor+CIOR.dictIO["gameOutput"]["gameLoading"]+i+CColors.endc,end="")
  182.                 system("clear")
  183.                 sleep(delayArray)
  184.  
  185.         sleep(delayEnd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement