Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Classes/Controllers/GameViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "GoBoardView.h"
#import "MessageView.h"
#import "RootViewController.h"
#import "PastMovesViewController.h"
#import "GameStatusProtocol.h"

enum BoardState {
Expand All @@ -25,6 +26,7 @@ enum BoardState {
IBOutlet UIScrollView *scrollView;
IBOutlet UIBarButtonItem *undoButton;
IBOutlet UIBarButtonItem *zoomOutButton;
IBOutlet UIBarButtonItem *historyButton;
IBOutlet UIBarButtonItem *confirmButton;
IBOutlet UIBarButtonItem *passButton;
IBOutlet UIBarButtonItem *resignButton;
Expand All @@ -43,6 +45,7 @@ enum BoardState {
@property(nonatomic) BoardState boardState;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *undoButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *zoomOutButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *historyButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *confirmButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *passButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *resignButton;
Expand All @@ -52,6 +55,7 @@ enum BoardState {

- (IBAction)undoMove;
- (IBAction)zoomOut;
- (IBAction)showHistory;
- (IBAction)confirmMove;
- (IBAction)pass;
- (IBAction)resign;
Expand Down
18 changes: 15 additions & 3 deletions Classes/Controllers/GameViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation GameViewController
@synthesize boardState;
@synthesize undoButton;
@synthesize zoomOutButton;
@synthesize historyButton;
@synthesize confirmButton;
@synthesize passButton;
@synthesize resignButton;
Expand Down Expand Up @@ -57,6 +58,7 @@ - (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *tempScrollView=(UIScrollView *)self.scrollView;
tempScrollView.contentSize=CGSizeMake(self.boardView.bounds.size.height, self.boardView.bounds.size.width);
JWLog(@"%f %f", self.boardView.bounds.size.height, self.boardView.bounds.size.width);
currentZoomScale = 1.0;
self.navigationItem.title = [NSString stringWithFormat:@"vs. %@", [game opponent]];
}
Expand All @@ -65,7 +67,7 @@ - (void)updateBoard {
if ([self.board canUndo]) {
[self.navigationItem setRightBarButtonItem:[self undoButton] animated:YES];
} else {
[self.navigationItem setRightBarButtonItem:nil animated:YES];
[self.navigationItem setRightBarButtonItem:self.historyButton animated:YES];
}
[[self confirmButton] setEnabled:[self.board canSubmit]];
[[self passButton] setEnabled:[self.board canPassOrResign]];
Expand Down Expand Up @@ -99,7 +101,8 @@ - (CGRect)zoomRectForScrollView:(UIScrollView *)theScrollView withScale:(float)s
// the size of the rect grows.
zoomRect.size.height = theScrollView.frame.size.height / scale;
zoomRect.size.width = theScrollView.frame.size.width / scale;

JWLog(@"%f %f %f %f", theScrollView.frame.size.height, theScrollView.frame.size.width, zoomRect.size.height, zoomRect.size.width);

// choose an origin so as to get the right center.
zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
Expand All @@ -111,7 +114,7 @@ -(void)lockZoom
{
maximumZoomScale = self.scrollView.maximumZoomScale;
minimumZoomScale = self.scrollView.minimumZoomScale;

JWLog(@"currentZoomScale: %f", currentZoomScale);
self.scrollView.maximumZoomScale = currentZoomScale;
self.scrollView.minimumZoomScale = currentZoomScale;
}
Expand Down Expand Up @@ -142,6 +145,15 @@ - (IBAction)zoomOut {
[self zoomOut:[self.boardView center]];
}

- (IBAction)showHistory {
PastMoveViewController *pastMoveViewController = [[PastMoveViewController alloc] initWithNibName:@"PastMoveView" bundle:nil];
[pastMoveViewController setMoveNumber:self.board.moveNumber - 1];
[pastMoveViewController setGame:game];
[self.navigationController pushViewController:pastMoveViewController animated:YES];
[pastMoveViewController release];

}

- (void)playedMove {
[self hideSpinner:YES];
if (self.delegate) {
Expand Down
46 changes: 46 additions & 0 deletions Classes/Controllers/PastMoveViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// PastMoveViewController.h
// DGSPhone
//
// Created by Frank Prößdorf on 9/4/12.
// Copyright (c) 2012 Justin Weiss. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Game.h"
#import "Move.h"
#import "GoBoardView.h"
#import "MessageView.h"
#import "RootViewController.h"
#import "PastMovesViewController.h"
#import "GameStatusProtocol.h"

@interface PastMoveViewController : RootViewController <LoginProtocol> {
Game *game;
int moveNumber;
int maxMoveNumber;
FuegoBoard *board;
IBOutlet GoBoardView *boardView;
IBOutlet UIScrollView *scrollView;
IBOutlet UIBarButtonItem *previousButton;
IBOutlet UIBarButtonItem *nextButton;
float maximumZoomScale;
float minimumZoomScale;
float currentZoomScale;
}

@property(nonatomic, retain) Game *game;
@property(nonatomic, assign) int moveNumber;
@property(nonatomic, assign) int maxMoveNumber;
@property(nonatomic, retain) FuegoBoard *board;
@property(nonatomic, retain) IBOutlet GoBoardView *boardView;
@property(nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *previousButton;
@property(nonatomic, retain) IBOutlet UIBarButtonItem *nextButton;
@property(nonatomic, assign) id <GameStatusProtocol> delegate;

- (IBAction)previousMove;
- (IBAction)nextMove;

@end

135 changes: 135 additions & 0 deletions Classes/Controllers/PastMoveViewController.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//
// PastMoveViewController.m
// DGSPhone
//
// Created by Frank Prößdorf on 9/4/12.
// Copyright (c) 2012 Justin Weiss. All rights reserved.
//

#import "PastMoveViewController.h"

@implementation PastMoveViewController

@synthesize game;
@synthesize moveNumber;
@synthesize maxMoveNumber;
@synthesize board;
@synthesize boardView;
@synthesize scrollView;
@synthesize previousButton;
@synthesize nextButton;
@synthesize delegate = _delegate;


- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *tempScrollView = (UIScrollView *)self.scrollView;
JWLog(@"%f %f", self.boardView.bounds.size.height, self.boardView.bounds.size.width);
tempScrollView.contentSize = CGSizeMake(self.boardView.bounds.size.height,
self.boardView.bounds.size.width);
self.navigationItem.title = [NSString stringWithFormat:@"Move %d", [self moveNumber]];
}

- (void)updateBoard {
[self.navigationItem setRightBarButtonItem:nil animated:YES];

if([self moveNumber] > 1) {
[self.previousButton setEnabled:true];
} else {
[self.previousButton setEnabled:false];
}

if([self moveNumber] < [self maxMoveNumber]) {
[self.nextButton setEnabled:true];
} else {
[self.nextButton setEnabled:false];
}

[self.boardView setNeedsDisplay];
}

- (CGRect)zoomRectForScrollView:(UIScrollView *)theScrollView withScale:(float)scale withCenter:(CGPoint)center {

CGRect zoomRect;

zoomRect.size.height = theScrollView.frame.size.height / scale;
zoomRect.size.width = theScrollView.frame.size.width / scale;

zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);

return zoomRect;
}

- (void)zoomToScale:(float)scale center:(CGPoint)center animated:(bool)animated {
CGRect zoomRect = [self zoomRectForScrollView:[self scrollView] withScale:scale withCenter:center];
[self.scrollView zoomToRect:zoomRect animated:animated];
}

- (void)changeMove {
[self.board goToMove: [self moveNumber]];
[self updateBoard];
self.navigationItem.title = [NSString stringWithFormat:@"Move %d", [self moveNumber]];
}

- (IBAction)previousMove {
[self setMoveNumber: [self moveNumber] - 1];
[self changeMove];
}

- (IBAction)nextMove {
JWLog(@"%d", [self moveNumber]);
[self setMoveNumber: [self moveNumber] + 1];
JWLog(@"%d", [self moveNumber]);
[self changeMove];
}

- (void)handleGoBoardTouch:(UITouch *)touch inView:(GoBoardView *)view {}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.boardView;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

FuegoBoard *theBoard = [[FuegoBoard alloc] initWithSGFString:[game sgfString]];
[self setMaxMoveNumber:[self moveNumber]];
[theBoard goToMove:[self moveNumber]];
[[self boardView] setBoard:theBoard];
[self setBoard:theBoard];
[theBoard release];

if([self.board size] > 13) {
[self zoomToScale:0.5 center:[[self boardView] center] animated:NO];
}

[self updateBoard];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.boardView setBoard:nil];
self.board = nil;
}

- (void)viewDidUnload {
self.boardView = nil;
self.previousButton = nil;
self.nextButton = nil;
[super viewDidUnload];
}


- (void)dealloc {
self.game = nil;
[super dealloc];
}


@end
2 changes: 2 additions & 0 deletions Classes/Models/DGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "Game.h"
#import "NewGame.h"
#import "GameList.h"
#import "Player.h"

#ifndef LOGIC_TEST_MODE
#import "ASIHTTPRequest.h"
Expand Down Expand Up @@ -40,6 +41,7 @@ typedef void (^ASIHTTPRequestBlock)(ASIHTTPRequest *request, NSString *responseS

- (void)addGame:(NewGame *)game onSuccess:(void (^)())onSuccess;
- (void)getCurrentGames:(void (^)(NSArray *gameList))onSuccess;
- (void)getCurrentPlayer:(void (^)(Player *player))onSuccess;
- (void)getSgfForGame:(Game *)game onSuccess:(void (^)(Game *game))onSuccess;
- (void)getWaitingRoomGames:(void (^)(GameList *gameList))onSuccess;
- (void)getWaitingRoomGameDetailsForGame:(NewGame *)game onSuccess:(void (^)(NewGame *game))onSuccess;
Expand Down
2 changes: 2 additions & 0 deletions Classes/Models/FuegoBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
- (NSString *)comment;
- (bool)gameEnded;
- (int)size;
- (void)goToMove:(int)moveNumber;
- (NSArray *)moves;
- (NSArray *)orderedMoves;
- (int)moveNumber;

// The most recently played move
Expand Down
74 changes: 62 additions & 12 deletions Classes/Models/FuegoBoard.mm
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,72 @@ - (Move *)currentMove {
}
}

- (void)goToMove:(int)moveNumber {
int numberOfMoves = [self moveNumber];

if (numberOfMoves > moveNumber) {
while (numberOfMoves > moveNumber) {
numberOfMoves -= 1;

if (goGame->CanGoInDirection(SgNode::PREVIOUS)) {
goGame->GoInDirection(SgNode::PREVIOUS);
}
}
} else {
while (numberOfMoves < moveNumber) {
numberOfMoves += 1;

if (goGame->CanGoInDirection(SgNode::NEXT)) {
goGame->GoInDirection(SgNode::NEXT);
}
}
}
}

- (NSArray *)moves {
NSMutableArray *moves = [NSMutableArray array];

if (self.moveNumber <= [self handicap] + 1) {
return nil;
}

for (GoBoard::Iterator it(goGame->Board()); it; ++it) {
Move *move = [[Move alloc] init];
move.col = SgPointUtil::Col(*it);
move.row = SgPointUtil::Row(*it);
move.boardSize = [self size];
if (goGame->Board().Occupied(*it)) {
move.player = [self playerForSgPlayer:goGame->Board().GetStone(*it)];
[moves addObject:move];
}
[move release];
}

return moves;
}

- (NSArray *)orderedMoves {
NSMutableArray *moves = [NSMutableArray array];

for (GoBoard::Iterator it(goGame->Board()); it; ++it) {
Move *move = [[Move alloc] init];
move.col = SgPointUtil::Col(*it);
move.row = SgPointUtil::Row(*it);
move.boardSize = [self size];
if (goGame->Board().Occupied(*it)) {
move.player = [self playerForSgPlayer:goGame->Board().GetStone(*it)];
[moves addObject:move];
}
[move release];
int numberOfMoves = self.moveNumber;

if (numberOfMoves <= [self handicap] + 1) {
return nil;
}

return moves;
const SgNode *currentNode = goGame->CurrentNode();

for (int i = numberOfMoves; i > 1; i -= 1) {
Move *move = [self moveFromNode:goGame->CurrentNode()];

if(move) {
[moves addObject:move];
goGame->GoInDirection(SgNode::PREVIOUS);
}
}

goGame->GoToNode(currentNode);

return moves;
}

- (int)moveNumber {
Expand Down
Loading