View
220
Download
0
Category
Tags:
Preview:
Citation preview
Tulsa .NET User GroupINTRO TO OBJECT ORIENTED PROGRAMMING
DisplayAboutMe(host);>Sean Whitesell
President of Tulsa .NET User Group
Sr. Developer at OpenLink Financial
seanw122@gmail.com @seanw122
Special thanks to…
What is OOP?•Object Oriented Programming•Creation of Classes and Interfaces•Polymorphism
But first, a challenge• POKER HANDS
• Import file
• Each line is cards for both players
• Each line is a round
• Determine winner of each round using poker rules for comparing hands.
• Determine how many times player 1 wins
Player 1 Player 2
Round 1 2C AD JH TC 5S 2S 4H JH 3D 2D
Round 2 6H 7D 8H 9C TS 8D 3S 5D 5C AH
Round 3 4H AS JS QS QC 8C 8H 3S TH 9D
Poker Challenge
•projecteuler.net/problem=54
•Test project file on that page
• Judging by me supplying a new file to your code
• I’ll know how many times player 1 should win
• Judged by correct answer, speed, then code.
•Submit executable and source code.
Example from site
Hand Player 1 Player 2 Winner
1 5H 5C 6S 7S KDPair of Fives 2C 3S 8S 8D TD
Pair of Eights Player 2
2 5D 8C 9S JS AC
Highest card Ace 2C 5C 7D 8S QH
Highest card Queen
Player 1
3 2D 9C AS AH AC
Three Aces 3D 6D 7D TD QD
Flush with Diamonds
Player 2
4
4D 6S 9H QH QCPair of QueensHighest card
Nine
3D 6D 7H QD QSPair of Queens
Highest card Seven
Player 1
5
2H 2D 4C 4D 4SFull House
With Three Fours
3C 3D 3S 9S 9DFull House
with Three Threes
Player 1
Rules for Comparing Hands
High Card: Highest value card.
One Pair: Two cards of the same value.
Two Pairs: Two different pairs.
Three of a Kind: Three cards of the same value.
Straight: All cards are consecutive values.
Flush: All cards of the same suit.
Full House: Three of a kind and a pair.
Four of a Kind: Four cards of the same value.
Straight Flush: All cards are consecutive values of same suit.
Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.
Object
Oriented
Programming
And you
Object
Properties
Dog Cat
Lion Horse
Animal
Houses
Villa
Contacts
Vendors
House
Building “Is A”
Inheritance
House
Room
Composition“Has A”
Room cannot exist without a house
House
Occupant
Aggregation“Has A / An”
The two objects can exist independently.
Public void SolveChallenge(){
var foo = File.OpenText(“C:\\temp\\poker.txt”;
foreach ( var line in foo){
blah blah}
compare each card….
is Royal Flush
is Straight Flush
is Four of a Kind
is Straight
is Three of a Kind
……}
Don't Do
This!
Main Class
Card
Player Hand
Winner
http://faculty.orangecoastcollege.edu/sgilbert/book/03-4-ObjectOrientedConcepts-B/index.html
Polymorphism allows objects to
behave differently
Ship ( IShipMethod)
IShipMethod
USPS
UPS
FedEx
Pay( IPaymentMethod) IPaymentMethod
Visa
Mastercard
PayPal
Recommended