Skip to content

Commit

Permalink
Python_Games_version_1.0
Browse files Browse the repository at this point in the history
This is the first version of my python games.
  • Loading branch information
lmanohara committed May 24, 2013
0 parents commit a7027a3
Show file tree
Hide file tree
Showing 6 changed files with 623 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
215 changes: 215 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg
81 changes: 81 additions & 0 deletions PythonGames/GuessTheNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# "Guess the number" game
#Autor Lahiru Manoha

import simplegui
import random

# initialize global
num_range = 100
count = 0

#helper functions
""" default value and function call """
def init():
global num_range
global count
range100()

# define event handlers
""" event handlers for tow buttons and input field """
def range100():
global num_range
global count
count = 7
num_range = random.randrange(0, 101)
print "New game. Range is from 0 to 100 "
print "Number of remaining guesses is 7"
print ""

def range1000():
# button that changes range to range [0,1000) and restarts
global num_range
global count
count = 10
num_range = random.randrange(0, 1001)
print "New game. Range is from 0 to 1000 "
print "Number of remaining guesses is 10"
print ""

# main game logic goes here
""" the logic of the game determine win or lose the game """
def get_input(guess):
global count
match_guess = int(guess)
count = count - 1

if(match_guess == num_range and not(count == 0)):
print "Guess Was", match_guess
print "number of remaining gusses is", count
print "correct!"
print""
init()
elif(match_guess > num_range):
print "Guess Was", match_guess
print "number of remaining gusses is", count
print "Lower!"
print ""
elif(match_guess < num_range):
print "Guess Was", match_guess
print "number of remaining gusses is", count
print "Higher!"
print ""

if(count == 0):
print "number of remaining gusses is 0"
print "You ran out of guesses The number was", num_range
print ""
init()

# create frame
f = simplegui.create_frame("Guess the number", 200, 200)

# register event handlers for control elements
f.add_button("Range is [0, 100)", range100, 200)
f.add_button("Range is [0, 1000)", range1000, 200)
f.add_input("Enter a guess", get_input, 200)

#call when start the game
init()

# start frame
f.start()
Loading

0 comments on commit a7027a3

Please sign in to comment.