Exemplo n.º 1
0
    def attack(self, target):
        options = ["dagger", "bow", "ability"]
        print(
            "What do you want to do?\n"
            "Use Dagger, Bow or Ability"
        )
        while True:
            choice = inputs.check_input(options)
            if choice != False:
                break

        if choice == "dagger":
            self.stab(target)

        elif choice == "bow":
            self.shoot(target)

        elif choice == "ability":
            options = ["rapidshot", "back"]
            print(
                "What ability do you want to use?\n"
                "'Rapidshot': Shoot the target 3 times\n"
                "'back': to go back to previous menue "
            )
            while True:
                ability = inputs.check_input(options)
                if ability != False:
                    break

            if ability == "rapidshot":
                self.rapidhot_attack(target)

            elif ability == "back":
                self.attack(target)
Exemplo n.º 2
0
def create_functions(fileName, function, delimiter='', classMethod=False):
    """
	Arguments: file to write to, function to write, add extra delimeter if class method, boolean for class method or not
	Purpose:
		writes the functions/method to the file
		will add arguments and return values to functions/methods
	Return: N/A
	"""

    argumentString = raw_input("Enter argument(s) for " + FUNCTION + function +
                               ENDC + ': ')

    argumentList = check_input(argumentString)

    argumentString = ','.join(argumentList)

    if classMethod == True:
        if argumentList == []:
            argumentString = 'self'
        else:
            argumentString = 'self,' + argumentString

    fileName.write('def ' + function + '(' + argumentString + ')' + ':')

    returnString = raw_input("Enter return value(s) for " + FUNCTION +
                             function + ENDC + ': ')

    returnValueList = check_input(returnString)

    if returnValueList == []:
        fileName.write('\n\t' + delimiter +
                       'pass # remove this and replace with the function body')
    else:

        if not classMethod:
            returnString = ','.join(returnValueList)
            fileName.write('\n\t' + delimiter + 'return ' + returnString)
        else:
            classReturnValueList = []

            for value in returnValueList:
                # value = 'self.'+value.replace(' ','')
                value = value.replace(' ', '')
                classReturnValueList.append(value)

            returnString = ','.join(classReturnValueList)
            fileName.write('\n\t' + delimiter + 'return ' + returnString)

    fileName.write('\n\n')
    def _click_start(self):
        while True:
            dialog = inputs.RadioAPP()
            dialog.show()
            
            if dialog.ok_clicked():
                self._column = dialog.column_width()
                self._row = dialog.row_height()
                self._first_move = dialog.First_Move()
                self._top_setting = dialog.TopSetting()
                self._how_to_win = dialog.HowToWIN()

                connection = inputs.check_input([self._column, self._row, self._first_move, self._top_setting, self._how_to_win])
                if connection == False:
                    self._message.set('Invalid Inputs')
                    continue
                else:
                    self._column = connection[0]
                    self._row = connection[1]
                    self._first_move = connection[2]
                    self._top_setting = connection[3]
                    self._how_to_win = connection[4]
                    self._message.set("{}'s turn".format((self._first_move).capitalize()))
                    break
            elif dialog.cancel_clicked():
                self._message.set('Canceled')
                return None
                break

        self._board = state_logic.makeNewBoard(self._row, self._column)
        state_logic.get_board(self._board, self._row, self._column, self._top_setting)

        self._redraw()
Exemplo n.º 4
0
    def _click_start(self):
        while True:
            dialog = inputs.APP()
            dialog.show()
            
            if dialog.ok_clicked():
                self._column = dialog.column_width()
                self._row = dialog.row_height()
                self._first_move = dialog.First_Move()
                self._top_setting = dialog.TopSetting()
                self._how_to_win = dialog.HowToWIN()

                connection = inputs.check_input([self._column, self._row, self._first_move, self._top_setting, self._how_to_win])
                if connection == False:
                    self._message.set('Invalid Inputs')
                    continue
                else:
                    self._column = connection[0]
                    self._row = connection[1]
                    self._first_move = connection[2]
                    self._top_setting = connection[3]
                    self._how_to_win = connection[4]
                    self._message.set("{}'s turn".format((self._first_move).capitalize()))
                    break
            elif dialog.cancel_clicked():
                self._message.set('Canceled')
                return None
                break

##        print(self._column, self._row, self._first_move, self._top_setting, self._how_to_win)

        self._board = state_logic.makeNewBoard(self._row, self._column)
        state_logic.get_board(self._board, self._row, self._column, self._top_setting)
##        print(self._board,self._first_move)
        self._redraw()
Exemplo n.º 5
0
def create_functions(fileName, function, delimiter='', classMethod=False):
	"""
	Arguments: file to write to, function to write, add extra delimeter if class method, boolean for class method or not
	Purpose:
		writes the functions/method to the file
		will add arguments and return values to functions/methods
	Return: N/A
	"""

	argumentString = raw_input("Enter argument(s) for "+FUNCTION+function+ENDC+': ')

	argumentList = check_input(argumentString)

	argumentString = ','.join(argumentList)
	
	if classMethod == True:
		if argumentList == []:
			argumentString = 'self'
		else:
			argumentString = 'self,'+argumentString

	fileName.write('def '+function+'('+argumentString+')'+':')

	returnString = raw_input("Enter return value(s) for "+FUNCTION+function+ENDC+': ')
	
	returnValueList = check_input(returnString)

	if returnValueList == []:
		fileName.write('\n\t'+delimiter+'pass # remove this and replace with the function body')
	else:
		
		if not classMethod:
			returnString = ','.join(returnValueList)
			fileName.write('\n\t'+delimiter+'return '+returnString)
		else:
			classReturnValueList = []
			
			for value in returnValueList:
				# value = 'self.'+value.replace(' ','')
				value = value.replace(' ','')
				classReturnValueList.append(value)
			
			returnString = ','.join(classReturnValueList)
			fileName.write('\n\t'+delimiter+'return '+returnString)

	fileName.write('\n\n')
    def _on_start(self):
        while True:
            dialog = inputs.APP()
            dialog.show()

            if dialog.ok_clicked():
                self._column = dialog.column_width()
                self._row = dialog.row_height()
                self._first_move = dialog.First_Move()
                self._top_setting = dialog.TopSetting()
                self._how_to_win = dialog.HowToWIN()

                connection = inputs.check_input([
                    self._column, self._row, self._first_move,
                    self._top_setting, self._how_to_win
                ])
                if connection == False:
                    self._message.set('Invalid Inputs')
                    continue
                else:
                    self._column = connection[0]
                    self._row = connection[1]
                    self._first_move = connection[2]
                    self._top_setting = connection[3]
                    self._how_to_win = connection[4]
                    self._message.set('Good Inputs')
                    break
            elif dialog.cancel_clicked():
                self._message.set('Invalid Inputs')
                return None
                break

##            else:
##                pass
##            connection = inputs.check_input([self._column, self._row, self._first_move, self._top_setting, self._how_to_win])
##            if connection == False:
##                continue
##            else:
##                self._column = connection[0]
##                self._row = connection[1]
##                self._first_move = connection[2]
##                self._top_setting = connection[3]
##                self._how_to_win = connection[4]
##                break

        print(self._column, self._row, self._first_move, self._top_setting,
              self._how_to_win)

        self._board = state.makeNewBoard(self._row, self._column)
        state.get_board(self._board, self._row, self._column,
                        self._top_setting)
        print(self._board)
        self._redraw()
    def _on_start(self):
        while True:
            dialog = inputs.APP()
            dialog.show()
            
            if dialog.ok_clicked():
                self._column = dialog.column_width()
                self._row = dialog.row_height()
                self._first_move = dialog.First_Move()
                self._top_setting = dialog.TopSetting()
                self._how_to_win = dialog.HowToWIN()

                connection = inputs.check_input([self._column, self._row, self._first_move, self._top_setting, self._how_to_win])
                if connection == False:
                    self._message.set('Invalid Inputs')
                    continue
                else:
                    self._column = connection[0]
                    self._row = connection[1]
                    self._first_move = connection[2]
                    self._top_setting = connection[3]
                    self._how_to_win = connection[4]
                    self._message.set('Good Inputs')
                    break
            elif dialog.cancel_clicked():
                self._message.set('Invalid Inputs')
                return None
                break
            
##            else:
##                pass
##            connection = inputs.check_input([self._column, self._row, self._first_move, self._top_setting, self._how_to_win])
##            if connection == False:
##                continue
##            else:
##                self._column = connection[0]
##                self._row = connection[1]
##                self._first_move = connection[2]
##                self._top_setting = connection[3]
##                self._how_to_win = connection[4]
##                break
        
        print(self._column, self._row, self._first_move, self._top_setting, self._how_to_win)

    
        self._board = state.makeNewBoard(self._row, self._column)
        state.get_board(self._board, self._row, self._column, self._top_setting)
        print(self._board)
        self._redraw()
Exemplo n.º 8
0
def main_menue():
    print("Welcome to the game!\n"
          "What would you like to do?\n"
          "'Saves': to check for saved characters\n"
          "'Start': to initialize a new character\n"
          "'Quit': To exit the game")
    options = ["saves", "start", "quit"]

    while True:
        choice = inputs.check_input(options)
        if choice != False:
            break
    if choice == "saves":
        # check for saves, print options, run through base loop as save
        # base_loop(save)
        pass
    elif choice == "start":
        base_loop()
    elif choice == "quit":
        exit
    else:
        print("Did you spell that right?\nTry again!\n"
              "To see your options again, type 'options'")
        choice = inputs.check_input(options)
def main():
    '''Game function. '''
    while True:
        connection = inputs.check_input()
        if connection == False:
            continue
        else:
            break

    print('\nColumn: {}'.format(connection[0]),
          '\nRow: {}'.format(connection[1]),
          '\nFirst Turn: {}'.format(connection[2]),
          '\nWB Setting: {}'.format(connection[3]),
          '\nWin by: {}\n'.format(connection[4]))

    column = connection[0]
    row = connection[1]
    turn = connection[2]
    top = connection[3]
    win = connection[4]
    
    board = state.makeNewBoard(row, column)
    state.get_board(board, row, column, top)
    while True:
        if turn == 'black':
            symbol = 'B'
            print_board(board, row)
            scores = state.show_scores(board, row, column)
            print('Black: {}; White: {}'.format(scores[0],scores[1]))
            print("\nIt is {}'s turn, {} is '{}'.".format('Black','Black',symbol))
            move = every_move(board, symbol, row, column)
            print('Your move is at {}.'.format(state.tell_move(move)))
            state.MakeMove(board,symbol, row, column).make_move_for_board(move[0],move[1])
            if state.check_score(state.show_scores(board, row, column)) != (row*column):
                if state.MakeMove(board, 'W', row, column).Flip_pieces() == []:
                    print("!!White has no where to move; it's black turn!!")
                    turn = 'black'
                else:
                    turn = 'white'
            else:
                break
        else:
            symbol = 'W'
            print_board(board, row)
            scores = state.show_scores(board, row, column)
            print('Black: {}; White: {}'.format(scores[0],scores[1]))
            print("\nIt is {}'s turn, {} is '{}'.".format('White','White',symbol))
            move = every_move(board, symbol, row, column)
            print('Your move is at {}.'.format(state.tell_move(move)))
            state.MakeMove(board,symbol, row, column).make_move_for_board(move[0],move[1])
            if state.check_score(state.show_scores(board, row, column)) != (row*column):
                if state.MakeMove(board,'B', row, column).Flip_pieces() == []:
                    print("!!Black has no where to move; it's white turn!!")
                    turn = 'white'
                else:
                    turn = 'black'
            else:
                break

    print_board(board, row)
    scores = state.show_scores(board, row, column)
    print('Black: {}; White: {}'.format(scores[0],scores[1]))
    who_won(scores, win)
Exemplo n.º 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('file',
                        default='pygenFile',
                        help='name of the file you want to create')
    parser.add_argument('-p',
                        '--path',
                        nargs='?',
                        default='./',
                        help='destination path of the file')
    parser.add_argument('-i',
                        '--imports',
                        nargs='+',
                        help='modules you want to import')
    parser.add_argument('-c',
                        '--classes',
                        nargs='+',
                        help='names of classes you want to create')
    parser.add_argument('-f',
                        '--functions',
                        nargs='+',
                        help='names of functions you want to create')

    parser.add_argument('-fw',
                        '--framework',
                        nargs='?',
                        help='name of python framework')

    args = parser.parse_args()

    fileName = ""
    os.chdir(args.path)

    # begin implementing Framework app files generation
    if args.framework:

        check_root()

        if not check_pip(args.path):

            install_pip()

        if install_package(args.framework):

            currDir = os.path.abspath(os.getcwd())

            filelist = glob.glob('./*')
            newFolder = args.framework + ' App'
            if any(
                    newFolder in s for s in filelist
            ):  #checks to see if file exists in a list of files in current directory
                print WARNING + BOLD + 'Warning!' + ENDC + ' About to overwrite ' + BLUE + args.file + ENDC
                response = raw_input(CYAN + 'Would you like to continue?' +
                                     ENDC + '[y/n] ')
                if response.lower() == 'n':
                    sys.exit()
                else:
                    shutil.rmtree(newFolder)

            # go to directory where generate.py is
            os.chdir(
                os.path.realpath(os.path.abspath(__file__)).replace(
                    'generate.py', '') + '/Framework_Gens')

            repo = os.getcwd()

            supported = False
            for supportedFW in os.listdir(os.getcwd()):
                if supportedFW.find(args.framework) != -1:
                    supported = True
                    break

            os.chdir(currDir)

            if supported:
                command = 'python ' + repo + '/' + supportedFW + ' ' + currDir + ' ' + args.file + '.py'
                subprocess.call(command,
                                shell=True)  # get directory of generate script
                print CYAN + BOLD + 'Created application' + ENDC

            else:
                print 'Framework not supported at this time'
                sys.exit()
        else:
            print 'Error installing ' + args.framework
            sys.exit()

    else:
        if args.file:

            filelist = glob.glob('./*.py')
            newfile = args.file + '.py'
            if any(
                    newfile in s for s in filelist
            ):  #checks to see if file exists in a list of files in current directory
                print WARNING + BOLD + 'Warning!' + ENDC + ' About to overwrite ' + BLUE + args.file + ENDC
                response = raw_input(CYAN + 'Would you like to continue?' +
                                     ENDC + '[y/n] ')
                if response.lower() == 'n':
                    sys.exit()
                else:
                    os.remove(newfile)

            else:
                print 'Creating new file, ' + BLUE + BOLD + newfile

            fileName = open(newfile, 'w')
            fileName.write('# File created using pygen\n')
            fileName.write('#!/usr/bin/env python\n\n')

            if args.imports:

                check_root()

                for module in args.imports:
                    module = module.replace(',', '')

                    moduleExists = check_package(module)

                    if moduleExists:
                        print 'Imported ' + MODULE + module + ENDC
                        fileName.write('import ' + module + '\n')

                    else:

                        if args.path:
                            pipExists = check_pip(args.path)
                        else:
                            pipExists = check_pip()

                        if pipExists:
                            couldInstall = install_package(module)

                            if couldInstall:
                                print 'Imported ' + MODULE + module + ENDC
                                fileName.write('import ' + module + '\n')
                            else:
                                print WARNING + 'ERROR:' + ENDC + ' Module, ' + MODULE + module + ENDC + ', does not exist or could not be downloaded/installed. Did not write to file'

                        else:

                            install_pip()

                            install_package(module)

                            fileName.write('import ' + module + '\n')

                fileName.write('\n')

            if args.classes:

                for className in args.classes:
                    className = className[0].upper() + className[
                        1:]  # uppercase class name
                    fileName.write('class ' + className + ':')

                    dataString = raw_input(
                        'Enter data to be stored in the class, ' + BLUE +
                        BOLD + className + ENDC + ': ')

                    dataList = check_input(dataString)

                    argumentDataList = ['self']

                    for arg in dataList:
                        newArg = arg + '=None'
                        argumentDataList.append(newArg)

                    dataString = ','.join(argumentDataList)
                    fileName.write('\n\tdef __init__(' + dataString + '):')

                    for arg in argumentDataList[1:]:

                        fileName.write(
                            '\n\t\tself.' +
                            arg.replace(' ', '').replace('=None', '') + ' = ' +
                            arg.replace('=None', '').replace(' ', ''))

                    fileName.write('\n\n')

                    methodString = raw_input('Enter the methods of class, ' +
                                             BLUE + BOLD + className + ENDC +
                                             ': ')

                    methodList = check_input(methodString)

                    for method in methodList:
                        fileName.write('\t')
                        create_functions(fileName, method, '\t', True)

            if args.functions:

                for function in args.functions:

                    create_functions(fileName, function)

                fileName.write("def main():\n\tpass")
                fileName.write("\n\nif __name__ == '__main__':\n\tmain()")

            else:
                fileName.write("def main():\n\tpass")
                fileName.write("\n\nif __name__ == '__main__':\n\tmain()")

        fileName.close()
        print 'Successfully created the file, ' + CYAN + args.file + '.py' + ENDC

        # open file generated in default editor
        stderr = ""
        try:
            subprocess.call('open ' + args.file + '.py', shell=True)
            returnCode = subprocess.check_output('open ' + args.file + '.py',
                                                 stderr=subprocess.STDOUT,
                                                 shell=True)
            if returnCode < 0:
                print >> sys.stderr, "Child was terminated by signal", -returnCode
            else:
                print >> sys.stderr, "Child returned", returnCode
        except OSError, e:
            print >> sys.stderr, "Execution failed", e
Exemplo n.º 11
0
def main():
	parser = argparse.ArgumentParser()
	parser.add_argument('file', default='pygenFile',help='name of the file you want to create')
	parser.add_argument('-p', '--path', nargs='?', default='./', help='destination path of the file')
	parser.add_argument('-i', '--imports', nargs='+', help='modules you want to import')
	parser.add_argument('-c', '--classes', nargs='+', help='names of classes you want to create')
	parser.add_argument('-f', '--functions', nargs='+', help='names of functions you want to create')
	
	parser.add_argument('-fw', '--framework', nargs='?', help='name of python framework')

	args = parser.parse_args()

	fileName = ""
	os.chdir(args.path)

	# begin implementing Framework app files generation
	if args.framework:

		check_root()

		if not check_pip(args.path):
			
			install_pip()

		if install_package(args.framework):

			currDir = os.path.abspath(os.getcwd())

			filelist = glob.glob('./*')
			newFolder = args.framework+' App'
			if any(newFolder in s for s in filelist): 	#checks to see if file exists in a list of files in current directory
				print WARNING+BOLD+'Warning!'+ENDC+' About to overwrite '+BLUE+args.file+ENDC
			 	response = raw_input(CYAN+'Would you like to continue?'+ENDC+'[y/n] ')
			 	if response.lower() == 'n':
			 		sys.exit()
				else:
					shutil.rmtree(newFolder)

			# go to directory where generate.py is
			os.chdir(os.path.realpath(os.path.abspath(__file__)).replace('generate.py', '')+'/Framework_Gens')
			
			repo = os.getcwd()
			
			supported = False
			for supportedFW in os.listdir(os.getcwd()):
				if supportedFW.find(args.framework) != -1:
					supported = True
					break

			os.chdir(currDir)

			if supported:
				command = 'python ' + repo+'/'+supportedFW + ' ' +currDir + ' ' + args.file+'.py'
				subprocess.call(command, shell=True) # get directory of generate script
				print CYAN+BOLD+'Created application'+ENDC

			else:
				print 'Framework not supported at this time'
				sys.exit()
		else:
			print 'Error installing '+args.framework
			sys.exit()


	else:
		if args.file:
			
			filelist = glob.glob('./*.py')
			newfile = args.file+'.py'
			if any(newfile in s for s in filelist): 	#checks to see if file exists in a list of files in current directory
				print WARNING+BOLD+'Warning!'+ENDC+' About to overwrite '+BLUE+args.file+ENDC
			 	response = raw_input(CYAN+'Would you like to continue?'+ENDC+'[y/n] ')
			 	if response.lower() == 'n':
			 		sys.exit()
				else:
					os.remove(newfile)
	
			else:
			 	print 'Creating new file, '+BLUE+BOLD+newfile

			fileName = open(newfile, 'w')
			fileName.write('# File created using pygen\n')
			fileName.write('#!/usr/bin/env python\n\n')

			if args.imports:
				
				check_root()

				for module in args.imports:
					module = module.replace(',', '')

					moduleExists = check_package(module)
					
					if moduleExists:
						print 'Imported '+MODULE+module+ENDC
						fileName.write('import '+module+'\n')

					else:
						
						if args.path:
							pipExists = check_pip(args.path)
						else:
							pipExists = check_pip()

						if pipExists:
							couldInstall = install_package(module)
							
							if couldInstall:
								print 'Imported '+MODULE+module+ENDC
								fileName.write('import '+module+'\n')
							else:
								print WARNING+'ERROR:'+ENDC+' Module, '+MODULE+module+ENDC+', does not exist or could not be downloaded/installed. Did not write to file'
						
						else:
							
							install_pip()

							install_package(module)

							fileName.write('import '+module+'\n')


				fileName.write('\n')

			if args.classes:

				for className in args.classes:
					className = className[0].upper()+className[1:] # uppercase class name
					fileName.write('class '+className+':')

					dataString = raw_input('Enter data to be stored in the class, '+BLUE+BOLD+className+ENDC+': ')

					dataList = check_input(dataString)

					argumentDataList = ['self']

					for arg in dataList:
						newArg = arg+'=None'
						argumentDataList.append(newArg)
						

					dataString = ','.join(argumentDataList)
					fileName.write('\n\tdef __init__('+dataString+'):')

					for arg in argumentDataList[1:]:
						
						fileName.write('\n\t\tself.'+arg.replace(' ', '').replace('=None', '')+' = '+arg.replace('=None', '').replace(' ', ''))

					fileName.write('\n\n')

					methodString = raw_input('Enter the methods of class, '+BLUE+BOLD+className+ENDC+': ')

					methodList = check_input(methodString)

					for method in methodList:
						fileName.write('\t')
						create_functions(fileName, method, '\t', True)


			if args.functions:

				for function in args.functions:

					create_functions(fileName, function)

				fileName.write("def main():\n\tpass")
				fileName.write("\n\nif __name__ == '__main__':\n\tmain()")
			
			else:
				fileName.write("def main():\n\tpass")
				fileName.write("\n\nif __name__ == '__main__':\n\tmain()")
		
		fileName.close()
		print 'Successfully created the file, '+CYAN+args.file+'.py'+ENDC

		# open file generated in default editor
		stderr = ""
		try:
			subprocess.call('open '+args.file+'.py', shell=True)
			returnCode = subprocess.check_output('open '+args.file+'.py', 
												 stderr=subprocess.STDOUT, 
												 shell=True)
			if returnCode < 0:
				print >>sys.stderr, "Child was terminated by signal", -returnCode
			else:
				print >>sys.stderr, "Child returned", returnCode
		except OSError, e:
			print >>sys.stderr, "Execution failed", e