Forexample, todaysomeofthethingsthat I'd liketobiteoffouroneactuallylayingouttheboardin a waythatmakessensenormallyinsolitaire, thingsairlaidoutsuchthatandwe'lllookatGoogleimagesin a second.
Butcardsarelaidoutherein a sequenceatthebottom, thisbottomrowsayingwithonecardthantwocarsthanthreecardsandfourcards, etcetera.
Withonlythetopcardbeingvisible, youget a deckuphereinthetopright, whichisimportant.
Loveto D is a reallyniceframeworkforTootiegamedevelopment.
Yougottaloveto d dotorg's.
WetalkedaboutthisinthelastDreamepisode.
Definitelycheckthatoutifyouhaven't alreadyseenit, whereweimplementeverythingfromscratch, includingparsing a spreadsheetofallourcards, layingoutthegrid, creating a deckclassand a cardclasswhichwecanthenshufflethedeckanddrawcardsfromwhichisveryimportantbecausethisissortofthebackboneofourwholegame.
Soyougetallofthesesortofareastostartlayingoutcardsfromlefttoright, andtheyincreaseingoingtoeinthatdirection, goingtowardstherightoneat a timeattheverytopleft.
Sobystackingeverycard, every a soccerstar, everydiamondcard, everyheart's card, everyclub's card, everyspadescardfrom a stickking.
That's howyouactuallywinthegame.
Andsowhatyou'relookingforwhenyoufirststartis, ofcourse, anace, becauseif I if I findanacewhile I canstackin a CEhereoranacehereanacehere, dependingonwhichsuititisright.
Andthatgivesyoutheabilitytothenlay a twoontopofthatandthen a threeontopofthat.
Andsothisis a refresheronhowthemechanicsofsolitaireworkandsothatwehave a clearpictureofwherewe'regoingasweimplementourgame.
Animportantthingthat I thinkweshouldfirstthinkaboutimplementingispopulatingthesesevencolumnsdownhereinthisbottomrowalsoprobablywanttogetridofthisdrawingthesefiverandomcardson.
I alsoprobablydon't needthisrandomcardthat I canclickaround.
I couldgetridofthatprettysafelywe'reimplementingweimplementedissuchthat I canclicktostartthedrag, andthenit'lljustfollowmymouseandthenclickagainto a newdrag.
Ourundrafted, thecardandsmart 13 18.
Thankyouverymuch.
Oh, thankyouforcoolhairstyle.
Thankyouverymuchforthecar.
Fortheconfident.
I appreciatethat.
Um, so I thinkincard, actually, wemayhavebeendoingthatinhere?
Let's see.
ItmighthavebeeninMaine, actually.
Let's makesure.
Yeah, I thinkYeah, wewewererendering a queenofHearts.
Wewechosetorender a queenofheartsjustas a testtomakesurecardclasswasworking.
Youcanseehereinmydirectory, andthisneedstobeshrunkdown a littlebit.
I cangetridofsomeofthese, butnoticethat I have a inmysourcedirectoryintherepo.
Andifyou'veclonedtheRebo, thenyou'llseethis.
I have a cardclass, whichisjustrepresentativeofwhat a cardis, whichstores a suitanditsstoresoffacevalue, whicharetwoimportantthingsthatweneedtotakeintoconsiderationforalgorithmwillneedtochecktoseeone.
Whenweplace a winningcarddowninoneofourtoptablesuphere, wewanttoenforcethat.
Thecardclassmaintains a referencetoitsface, itssuit, whetherit's hidden, whetherit's pickedupandit's X and Y valuesothatwecanrenderitto a givenplaceonthescreen.
There's also a deckclass, whichjustmaintains a listofcardsthatareallshuffled.
That's whatitis, essentiallyjusttaking a bunchofrandom, basicallyindexingintoourdeckatrandom, puttingitintoanothertemporarydeckandtheneliminatingthatfromthepriordeck, whichsavedus a littlebitofSparCity.
R i u tillmodulerather a filethatyoutold a littlefilewhichhad a fewfunctionsinitforparsingareourtextureforquad, sosplittingitupinthequadsandalsofixingthefactthattheywere a knorderedwhenweparsethem.
AndwealsousedthebeautifultoolcalledStackoverflowtofind a functioncalledDump, whichjustrecursiveleeprints a tablebecause I didn't feellikewritingitfromscratchourselves.
Butallitdoesisjustwritesout a table, dependingonifit's a tableornotupwiththevalue, itnicelyputsbrackets, curlybraces.
Thioatleasttellyouthatyou'reworkingwith a tableandwillRikersillycallitselfandthentostringedgeeachnontablevaluesothatyoucaneventuallyseeyourentirelayoutofdata.
Andthenwehad a resortfunctionthatendedupsortofputtingourcardsintherightplaces.
Sothatis a roughbreakdownofwhatwedidlastweek.
Nowthefirstthingthat I wanttodosothatwere, atleastvisuallyseeingwherewe'regoingandsortofsanitycheckingtheflowofourgame, feelingmoreaccomplishedthanwemightactuallybe, islayingeverythingoutum, onthebottomrow.
So, forexample, inthissecondpileand I'llgototheimagehereinGoogle.
If I takethistooffofthiscardownhere, I canflipthatcardover, andwe'llimplementthiswithrightclick.
Probably I canflipthatcardover, anditbecomes a cardthat I cannowmovewherever I wanttomoveit.
Ifit's a swell, I justrevealedanace.
I couldputitinoneofmywinningpiles.
Ifit's forexampleofblackthree.
Well, I canput a blackthreehereandthenmaybemovethiskingoverherebecauseyouhavethioendup.
Youknow, I believeit's a rulewhereyoucanonLee.
Put a kingontoanemptyslotinyourtableau.
I'm not 100% sureaboutthat.
Actually.
SolitaireMovecardtoemptytableau.
Um, yes.
Ifanyofthetableaupilesareempty, youcouldmove a kingthere.
Right?
Okay, sothat's good.
I'm I amsayingyouithastobe a king.
Soifthere's anemptyslot, let's say I movethistoorighthere.
Let's say I movethatontoanacepileuphere.
Let's say I gotanace.
Putitupthere.
I wasanaceofspades.
Putittoupthereontopoftheaceofspades.
I'm buildingthatthatspadespileup.
Now I havethisblankcardhere.
Let's saylet's saythat's a blackthree.
I movedtheblackthreeontothisfour.
Now I haveanemptytableau.
I canputthiskingoverontothisemptytableau, andnow I'vesortofopenedup a newpilethat I canstartdiggingthrough, andthisissortofthethefundamentalwayofplayingthegame.
Andnotonlyarewegonnaneedtomovecardsaround, butwecanactuallymovepilesofcardsaroundfromourtableaus, sowewillneedsomenotionof a cardpile.
Right?
Andatleastthisishow I wanttoframethegame.
Youcouldframethisin a multitudeofways.
Youdon't necessarilyneedtoabstractedinthisspecificway, but I'm inclinedtosaythat I'm probablygonnawant a cardpileclass.
And, um, thisisallfromscratchingoffthecuff.
Butthisisjusthow I goaboutapproachingproblemslikethisbythinkingabouttheobjectsinmyspacethesortofinteractionsthey'regonnahaveandsortofbuildingupthebuildingblocksthat I'm gonnaendupactuallycomposingtocreatemygameinthisobjectorientedway.
Sothisisgonnabe a cardpile.
Class A cardpile.
Classiskindoflike a deck, butit's notgonnahave a shufflemethod.
It's goingtohaveTheobaldityto, I think, movearoundnecessarily.
Wecouldhaveitsuchthatthisnine, forexample, is a parentoftheeightbelowit.
Andthateightis a parentofthesevenbelowit.
Sothere's alwaysthisdirectchainofparenting, rightwhereyouhave a cardthat's apparentof a carthat's a parentof a cart, kindoflike a list, almostalmostlike a linklist.
Inthemeantime, what I docareaboutlike I saidislayingoutalloftheboardandthentestingourinteractionstesting, parenting, makingsurethat's allworkingsothatwecanstartclickinganddraggingcardsintherightlocations.
Sobacktothecardclass, whichwe'relookingat a pier, wehave a parentthat's gonnabesortofkeptwithinthatclass.
Sothiswillrefertoanyofthecard.
Thiswillreferto a cardirectlyaboveanothercardinthecontextofsolider.
Sothefirsttableau, rememberforlookinglefttorightinthefirsttemplewasgoingtostartwithonecard, so I couldjustsay, um, actually, whatwecandois I cansayselfdotdeck, andthen I wanttodraw a card, right?
Andwhatthisisgonnadoisreturned a cardfromthedeckandremoveitbecausewewanttodraw a cardfromthedeck.
Butwealsowantedtonotbeinthedeckafterwedrawit.
Becauseobviously, ifwedrawcard, butwekeepitinthere, wejustreturn a copyofit.
Well, thenournumbersaregonnabeskewed.
We'renotgoingtodowith 52 cards.
We'regonnabedealingwithinfinitecardsatthatpoint.
Soit's notgonnawork.
BlueBookersays a to D table, makethree D solitarystackedthecardsinthreedimensions, alwayswiththegoodideasBlueBookorkeepingcoming, that's Ah, Thatwouldactuallybeprettycool, though.
So, um, cardindexisgonnabeequaltothisvaluerighthere.
Gonnareplacethatwithcardindex.
I'm goingtodothat.
Andthen I'm goingtosayselfdotcardsatCardIndexisequaltonew, ActuallybetterwouldbetabledotremoveselfdotcardsatCardIndex, which I thinkunderneaththehoodjustdoesdo a newassignment.
JustassignsittoNilstothatway, becauseinlieu, ifyouhave a nilindexinyourtable, iteffectivelyjustcondensesthetablebacktogether.
If I'm rememberingcorrectlyandsotabledon't removeeffectively, justdoesthatexactthing.
Butwewantaswelljustdo.
What's moreconventional.
I thinktabledon't removeselfdotcardsatcardindex.
Soifwedrew a cardinthemiddleofthedeck, thedeckgetssortofcompressedinwardstoaccommodatethat.
Andnowit's nolonger 52 cardslong.
It's 51 cardslong, andwhat I candothenislikeinreturnourcardtoreturn.
Wedon't carewhereitis, Butnotonlydowehave a cardthatwecopiedfromourdeck, weremovedit, andsonowwe'represervingsortofthegameplaymechanicofdrawing a cardfromthedeckveryimportantthingtoconsider.