Skip to content

Commit

Permalink
add thief, rework how revealing cards works a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 31, 2010
1 parent 45251a6 commit f1afb1b
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 68 deletions.
3 changes: 3 additions & 0 deletions dominion/Classes/KingdomCards.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import "Remodel.h"
#import "Smithy.h"
#import "Spy.h"
#import "Thief.h"
#import "ThroneRoom.h"
#import "Village.h"
#import "Witch.h"
Expand Down Expand Up @@ -53,6 +54,7 @@
Remodel *remodel;
Smithy *smithy;
Spy *spy;
Thief *thief;
ThroneRoom *throneRoom;
Village *village;
Witch *witch;
Expand All @@ -79,6 +81,7 @@
@property (readonly) Remodel *remodel;
@property (readonly) Smithy *smithy;
@property (readonly) Spy *spy;
@property (readonly) Thief *thief;
@property (readonly) ThroneRoom *throneRoom;
@property (readonly) Village *village;
@property (readonly) Witch *witch;
Expand Down
11 changes: 9 additions & 2 deletions dominion/Classes/KingdomCards.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ - (Spy *) spy {
return spy;
}

- (Thief *) thief {
if (!thief) {
thief = [[[Thief alloc] init] retain];
}
return thief;
}

- (ThroneRoom *) throneRoom {
if (!throneRoom) {
throneRoom = [[[ThroneRoom alloc] init] retain];
Expand Down Expand Up @@ -235,14 +242,14 @@ - (Workshop *) workshop {
- (NSMutableArray *) getCards {
return [NSMutableArray arrayWithObjects:self.adventurer, self.bureaucrat, self.cellar, self.chancellor, self.chapel, self.councilRoom, self.feast,
self.festival, self.gardens, self.laboratory, self.library, self.market, self.militia, self.mine, self.moat, self.moneylender, self.remodel,
self.smithy, self.spy, self.throneRoom, self.village, self.witch, self.woodcutter, self.workshop, nil];
self.smithy, self.spy, self.thief, self.throneRoom, self.village, self.witch, self.woodcutter, self.workshop, nil];
}

- (NSMutableArray *) generateKingdomDecks {
// choose 10 cards
NSMutableArray *cards = [self getCards];
NSMutableArray *selectedCards = [NSMutableArray arrayWithCapacity:10];
[selectedCards addObject:self.spy];
[selectedCards addObject:self.thief];
while ([selectedCards count] < 10) {
int random = arc4random() % [cards count];
Card *card = [cards objectAtIndex:random];
Expand Down
15 changes: 6 additions & 9 deletions dominion/Classes/Player.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,18 @@ - (id) init {
- (NSMutableArray *) revealCardsFromDeck: (NSUInteger) numCards {
NSMutableArray *cards = [NSMutableArray arrayWithCapacity:numCards];
NSUInteger toReveal = numCards;
NSUInteger index = 0;
// reveal until we've reached the correct # of cards, or we need to shuffle discard into the draw deck
while (toReveal > 0 && index < self.drawDeck.numCardsLeft) {
[cards addObject:[self.drawDeck cardAtIndex:index]];
while (toReveal > 0 && self.drawDeck.numCardsLeft > 0) {
Card *card = [self.drawDeck draw];
[cards addObject:card];
toReveal--;
index++;
}
if (toReveal > 0) {
[self shuffleDiscardDeckIntoDrawDeck];
}
index = 0;
while (toReveal > 0 && index < self.drawDeck.numCardsLeft) {
[cards addObject:[self.drawDeck cardAtIndex:index]];
toReveal--;
index++;
while (toReveal > 0 && self.drawDeck.numCardsLeft > 0) {
Card *card = [self.drawDeck draw];
[cards addObject:card];
}
return cards;
}
Expand Down
3 changes: 1 addition & 2 deletions dominion/Classes/Spy.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butt
// buttonIndex == 0 means put back card onto top of deck
// buttonIndex == 1 means discard card
if (buttonIndex == 0) {
// really we don't have to do anything because we didn't remove the card, we just looked at it and remembered it
[self.thePlayer.drawDeck addCard:self.revealedCard];
} else {
[self.thePlayer.hand removeCard:self.revealedCard];
[self.thePlayer.discardDeck addCard:self.revealedCard];
}
self.thePlayer = nil;
Expand Down
29 changes: 29 additions & 0 deletions dominion/Classes/Thief.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Thief.h
// dominion
//
// Created by Daniel Kador on 12/30/10.
// Copyright 2010 Dorkfort.com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ActionCard.h"
#import "HandViewHelper.h"


@class Player;
@class Card;

@interface Thief : ActionCard <HandViewHelperDelegate, UIAlertViewDelegate> {
Player *thePlayer;
NSMutableArray *revealedCards;
Card *trashedCard;
HandViewHelper *helper;
}

@property (nonatomic, retain) Player *thePlayer;
@property (nonatomic, retain) NSMutableArray *revealedCards;
@property (nonatomic, retain) Card *trashedCard;
@property (nonatomic, retain) HandViewHelper *helper;

@end
124 changes: 124 additions & 0 deletions dominion/Classes/Thief.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// Thief.m
// dominion
//
// Created by Daniel Kador on 12/30/10.
// Copyright 2010 Dorkfort.com. All rights reserved.
//

#import "Thief.h"
#import "Game.h"
#import "Player.h"
#import "Deck.h"
#import "Card.h"
#import "dominionViewController.h"


@implementation Thief

@synthesize thePlayer, revealedCards, trashedCard, helper;

- (NSString *) description {
return @"Each other player reveals the top 2 cards of his deck. If they revealed any Treasure cards, they trash one of them that you choose. You may gain any or all of these trashed cards. They discard the other revealed cards.";
}

- (CardType) cardType {
return ActionAttack;
}

- (NSUInteger) cost {
return 4;
}

- (Boolean) takeAction: (Player *) player {
[self.delegate actionFinished]; // nothing to do on the action phase
return YES;
}

# pragma mark -
# pragma mark GameDelegate implementation

- (void) attackPlayer: (Player *) player {
self.thePlayer = player;
self.revealedCards = [player revealCardsFromDeck:2];
NSMutableArray *cardsToCheck = [NSMutableArray arrayWithArray:revealedCards];
Deck *treasureCards = [[Deck alloc] init];

// are any of them treasure cards?
for (NSUInteger i=0; i<[cardsToCheck count]; i++) {
Card *card = [cardsToCheck objectAtIndex:i];
[player.game setInfoLabel:[NSString stringWithFormat:@"%@ revealed %@.", player.name, card.name]];
if (card.isTreasure) {
[cardsToCheck removeObjectAtIndex:i];
[treasureCards addCard:card];
i--; // since we're removing the card at this index, we need to check this index again in the next loop iteration
}
}
// if any were treasures, present them to current player to decide which one to trash
if (treasureCards.numCardsLeft > 0) {
HandViewHelper *theHelper = [[HandViewHelper alloc] initWithDeck:treasureCards AndController:player.game.controller];
self.helper = theHelper;
[theHelper release];
self.helper.delegate = self;
[self.helper displayHandWithMessage:@"Choose a card to trash."];
} else {
// guess we're done.
if ([self.revealedCards count] > 0) {
// move the revealed cards to discard
for (Card *card in self.revealedCards) {
[player.discardDeck addCard:card];
}
}
self.thePlayer = nil;
self.revealedCards = nil;
self.trashedCard = nil;
self.helper = nil;
[self.delegate attackFinishedOnPlayer];
}
[treasureCards release];
}

# pragma mark -
# pragma mark HandViewHelperDelegate implementation

- (void) cardSelected:(Card *)card {
[self.helper hideEverything];
self.helper = nil;
self.trashedCard = card;
// ask player if they want to gain this card
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.thePlayer.name message:[NSString stringWithFormat:@"Do you want to gain %@?", card.name] delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}

# pragma mark -
# pragma mark UIAlertViewDelegate implementation

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// buttonIndex == 0 means don't gain card
if (buttonIndex == 0) {
// okay, just trash it.
[self.thePlayer.game.trashDeck addCard:self.trashedCard];
} else {
// gain it
[self.thePlayer.game.currentPlayer.discardDeck addCard:self.trashedCard];
}
// now discard the other revealed card(s) regardless of attacker's choice
Boolean foundOne = NO; // in case both revealed cards are the same treasure card. if this happens we've already discarded one.
for (Card *card in self.revealedCards) {
if (card == self.trashedCard && !foundOne) { // only skip if the current card is the same as the trashed card AND we haven't found it yet
foundOne = YES;
continue;
}
// discard
[self.thePlayer.discardDeck addCard:card];
}
// attack's over
self.thePlayer = nil;
self.revealedCards = nil;
self.trashedCard = nil;
self.helper = nil;
[self.delegate attackFinishedOnPlayer];
}

@end
40 changes: 22 additions & 18 deletions dominion/dominion.xcodeproj/dkador.mode1v3
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>67</integer>
<integer>53</integer>
<integer>9</integer>
<integer>2</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 977}, {230, 764}}</string>
<string>{{0, 700}, {230, 764}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
Expand Down Expand Up @@ -317,19 +319,19 @@
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>dominionViewController.m</string>
<string>Thief.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>dominionViewController.m</string>
<string>Thief.m</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>010F77E212CDAFFB00AFE195</string>
<string>010F788B12CDBFEF00AFE195</string>
<key>history</key>
<array>
<string>012EAB0612A3705D0075157C</string>
Expand Down Expand Up @@ -373,7 +375,6 @@
<string>018E08B612C8253B00F2A3FE</string>
<string>018E08B712C8253B00F2A3FE</string>
<string>018E08B812C8253B00F2A3FE</string>
<string>018E08B912C8253B00F2A3FE</string>
<string>018E08BA12C8253B00F2A3FE</string>
<string>018E08BB12C8253B00F2A3FE</string>
<string>018E08BC12C8253B00F2A3FE</string>
Expand All @@ -399,30 +400,33 @@
<string>018E0A9812C869F000F2A3FE</string>
<string>018E0A9912C869F000F2A3FE</string>
<string>010F762812CA5DAF00AFE195</string>
<string>010F762A12CA5DAF00AFE195</string>
<string>010F764812CA5FF200AFE195</string>
<string>010F768512CA650200AFE195</string>
<string>010F768612CA650200AFE195</string>
<string>010F76BD12CA740C00AFE195</string>
<string>010F76BE12CA740C00AFE195</string>
<string>010F76BF12CA740C00AFE195</string>
<string>010F770212CD9EF200AFE195</string>
<string>010F771912CD9FD800AFE195</string>
<string>010F778712CDA6FF00AFE195</string>
<string>010F778812CDA6FF00AFE195</string>
<string>010F779212CDA7D500AFE195</string>
<string>010F77D112CDAF5400AFE195</string>
<string>010F77D212CDAF5400AFE195</string>
<string>010F77D312CDAF5400AFE195</string>
<string>010F77D412CDAF5400AFE195</string>
<string>010F77D512CDAF5400AFE195</string>
<string>010F77D612CDAF5400AFE195</string>
<string>010F77D712CDAF5400AFE195</string>
<string>010F77D812CDAF5400AFE195</string>
<string>010F77D912CDAF5400AFE195</string>
<string>010F77DA12CDAF5400AFE195</string>
<string>010F77DF12CDAFED00AFE195</string>
<string>010F77E012CDAFED00AFE195</string>
<string>010F782012CDB9BB00AFE195</string>
<string>010F782212CDB9BB00AFE195</string>
<string>010F782512CDB9BB00AFE195</string>
<string>010F782812CDB9BB00AFE195</string>
<string>010F783312CDB9EF00AFE195</string>
<string>010F783412CDB9EF00AFE195</string>
<string>010F784312CDBA7900AFE195</string>
<string>010F784412CDBA7900AFE195</string>
<string>010F787212CDBE6000AFE195</string>
<string>010F787312CDBE6000AFE195</string>
<string>010F787412CDBE6000AFE195</string>
<string>010F787C12CDBE9D00AFE195</string>
</array>
</dict>
<key>SplitCount</key>
Expand Down Expand Up @@ -620,13 +624,13 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>010F77DC12CDAF5400AFE195</string>
<string>010F788C12CDBFEF00AFE195</string>
<string>1C530D57069F1CE1000CFCEE</string>
<string>010F763612CA5DAF00AFE195</string>
<string>010F763712CA5DAF00AFE195</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
<string>012EA8EF12A320FF0075157C</string>
<string>1C78EAAD065D492600B07095</string>
<string>/Users/dkador/dev/dominion-iphone/dominion/dominion.xcodeproj</string>
</array>
<key>WindowString</key>
Expand Down Expand Up @@ -1003,7 +1007,7 @@
<key>WindowToolGUID</key>
<string>1C78EAAD065D492600B07095</string>
<key>WindowToolIsVisible</key>
<true/>
<false/>
</dict>
<dict>
<key>Identifier</key>
Expand Down
Loading

0 comments on commit f1afb1b

Please sign in to comment.