Created
October 11, 2016 21:17
-
-
Save IanMcT/1afafc6ea12857c41d388de51d5a3ce2 to your computer and use it in GitHub Desktop.
Grade 12 War Card Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="InspectionProjectProfileManager"> | |
<settings> | |
<option name="PROJECT_PROFILE" value="Project Default" /> | |
<option name="USE_PROJECT_PROFILE" value="true" /> | |
<version value="1.0" /> | |
</settings> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="InspectionProjectProfileManager"> | |
<profile version="1.0"> | |
<option name="myName" value="Project Default" /> | |
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> | |
<option name="ignoredErrors"> | |
<list> | |
<option value="W29" /> | |
<option value="E501" /> | |
<option value="W29" /> | |
<option value="E501" /> | |
<option value="W29" /> | |
<option value="E501" /> | |
<option value="W29" /> | |
<option value="E501" /> | |
<option value="W29" /> | |
<option value="E501" /> | |
<option value="W29" /> | |
<option value="E501" /> | |
</list> | |
</option> | |
</inspection_tool> | |
</profile> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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-32\python.exe)" project-jdk-type="Python SDK" /> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/grade12oop.iml" filepath="$PROJECT_DIR$/.idea/grade12oop.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Card: | |
def __init__(self,v): | |
self.__id = v | |
self.__faceValues = ["Ace", "Two", "Three","Four","Five","Six ","Seven","Eight","Nine","Ten ","Jack","Queen","King"] | |
self.__suits = ["Clubs", "Diamonds", "Hearts", "Spades"] | |
def getFace(self): | |
return self.__faceValues[self.__id%13] | |
def getSuit(self): | |
return self.__suits[self.__id//13] | |
def __str__(self): | |
output = self.getFace() + " of " + self.getSuit() | |
return output | |
def getFaceAsNumber(self): | |
return self.__id%13 | |
def __gt__(self, other): | |
return self.__id%13>other.__id%13 | |
def __lt__(self, other): | |
return self.__id%13<other.__id%13 | |
def __eq__(self, other): | |
return self.__id%13==other.__id%13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Card import Card | |
from Deck import Deck | |
from Hand import Hand | |
d = Deck() | |
d.shuffle() | |
h1 = Hand() | |
h2 = Hand() | |
max = 52//2 | |
for i in range(max): | |
h1.getCard(d.deal_card()) | |
h2.getCard(d.deal_card()) | |
for j in range(max): | |
c1 = h1.deal_card() | |
c2 = h2.deal_card() | |
if c1>c2: | |
print(c1,"vs",c2,"Player 1 gets the point") | |
elif c2>c1: | |
print(c1,"vs",c2,"Player 2 gets the point") | |
else: | |
print(c1,"vs",c2,"Tie - next winner gets this point") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Card import Card | |
class Hand: | |
def __init__(self): | |
self.__current_card = 0 | |
self.__cards = [] | |
def getCard(self, c): | |
self.__cards.append(c) | |
def __str__(self): | |
temp = "" | |
for x in range(len(self.__cards)): | |
temp += str(self.__cards[x]) + "\n" | |
return temp.rstrip() | |
def deal_card(self): | |
if self.__current_card < len(self.__cards): | |
c = self.__cards[self.__current_card] | |
self.__cards.remove(self.__cards[self.__current_card]) | |
return c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment