Skip to content

Instantly share code, notes, and snippets.

@IanMcT
Created October 3, 2016 10:08
Show Gist options
  • Save IanMcT/648122ef95f81af601bfb9ff50d00945 to your computer and use it in GitHub Desktop.
Save IanMcT/648122ef95f81af601bfb9ff50d00945 to your computer and use it in GitHub Desktop.
starting code for card game to model OOP.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.1 (C:\Program Files\Python35\python.exe)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/oopics4uunit2.iml" filepath="$PROJECT_DIR$/.idea/oopics4uunit2.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
class Card:
def __init__(self,v):
self.__v = v
if v >= 0 and v < 52:
self.suit = self.__suits[v//13]
self.face = self.__faces[v%13]
def __str__(self):
return self.face + "\tof\t" + self.suit
__suits = ("Clubs","Diamonds","Hearts","Spades")
__faces = ("Ace ","Deux","Three","Four","Five","Six ","Seven","Eight","Nine","Ten ","Jack","Queen","King")
from Card import Card
import random
class Deck:
def __init__(self):
self.__current_card = 0
self.__cards = []
for x in range(52):
self.__cards.append(Card(x))
def __str__(self):
temp = ""
for x in range(52):
temp += str(self.__cards[x]) + "\n"
return temp.rstrip()
def shuffle(self):
self.__current_card=0
for x in range(52):
temp_index = random.randint(0,52-1)
temp = self.__cards[temp_index]
self.__cards[temp_index] = self.__cards[x]
self.__cards[x] = temp
def deal_card(self):
if self.__current_card < 52:
self.__current_card += 1
return self.__cards[self.__current_card-1]
from Card import Card
from Deck import Deck
d = Deck()
print(d.deal_card())
print(d.deal_card())
#print(d)
#print("*"*20)
#d.shuffle()
#print(d)
#for x in range(52):
# c = Card(x)
# print(c)
# print(c.suit)
#print(dir(Card))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment