Code Monkey home page Code Monkey logo

kwutils's Introduction

KWUtils

Utilities for use in Python Apps
by kwoolter ๐Ÿ’
ยฉ๏ธ 2017

Content

##pick()

def pick(object_type: str, objects: list, auto_pick: bool=False)

Use to ask the user to select and item from a list or cancel if they decide not to pick one.

####Inputs

  • object_type - the type of object that you are going to choose from a list e.g. "Weapon"
  • objects - the list of objects that the user will be asked to pick from
  • auto_pick - if the list only contains 1 item and auto_pick is True then the function automatically returns the only item without user intervention.

####Outputs Returns the selected object from the list or returns None if the user cancelled the selection.

##confirm()

def confirm(question : str):

Use to get the user to respond to a simple Yes/No question.

####Inputs

  • question - a string containing the question that you want the user to answer Yes/No to.

####Outputs Returns True if the user picked Yes and False if the user picked No

##is_numeric()

def is_numeric(s):

####Inputs

  • s - the variable that you want to see is numeric or not

####Outputs The numeric value of s or None if s is not numeric

##Class Colours

class Colours:

Use to store RGB values of common colours for use in graphics apps.
e.g. Colours.BLACK, Colours.RED

##Class HighScoreTable

class HighScoreTable:

Use to track a high score table which can be persisted to file using save() and load() methods.

###Member Variables self.table : []

Contains a sorted list of (name, score) tuples. Access this list if you want to display the contents of the high score table yourself.

###Methods

def __init__(self, name = "default", max_size = 10)

Construct a high score table object.

  • name : The name of the high score table
  • max_size : how many score entries do you want to maintain in the table (default is 10)
def add(self, name : str, score : float):

Add a specified name and score to the high score table. Returns True if the score made it into the high score table.

def is_high_score(self, score):

Check to see if a specified score makes it into the current high score table. Returns True if the score is good enough to get into the current table.

def save(self):

Save the high score table to file called name+".hst" e.g. Zelda.hst

def load(self):

Load a high score table from a file called name+".hst".

def print(self):

Print the high score table.

kwutils's People

Contributors

kwoolter avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.