2012/13

 
 

Deadline: 4pm Tuesday 30th October ’12

Example Output

Detailed Requirements


The full requirements are given (below):


  1. 1.Each game should alternate between starting with either noughts or crosses.  A game can be reset by pressing a “Restart Game” button (which can also be used to alternate the starting player).  This should be irrespective of who won the previous game.


  1. 2.A status label beneath the main playing area should provide information to the players.  In particular, it should:

  2. Indicate when the human player should start the game.

  3. Indicate the winner when the game has been won.

  4. Warn that an illegal move has been attempted (such as the user selecting a space already occupied by a game-token.

  5. Indicate if a stalemate condition has occurred.


  1. 3.A game-token should appear on the board at the position where the finger was lifted.  This should be either the nought or cross image, depending on which player made the move.  This image should be position the images manually, using a CGContext (see below) onto a view. 

            Do not use UIImages on the board.


  1. 4.A “Grouped” style table view should be used to keep track of who won what game.  Stalemate games can be ignored (they do not need to be tracked).  Each table cell should state the game number, and which player won, with the first game at the top of the table.  Do not worry about automatically scrolling to the end of the table.


  1. 5.The application should be created with the following characteristics:

  2. a.Each class you create should be prefixed with your username.

  3. b.Use ARC to manage memory.

  4. c.DO NOT use storyboards.

  5. d.DO NOT include Unit Tests.

  6. e.Create a single view app project.

  7. f.Set the target device as iPad.

  8. g.Name your project TicTacToe2012

  9. h.Select only landscape orientations for your project.

  

This assignment contributes 10% to your overall mark for COMP327. The code should compile without warning or errors.  In addition, all of the source and resource files should be included in your project.


You should implement a UIView class, called prefixGameAreaView that is responsible for displaying the board and counters.  The game itself should be managed using a prefixViewController instance, subclassed from a UIViewController and the game model should be handled by the (supplied) Game model.


You can use any version of Xcode 4.4 (including the recently released Xcode 4.5) running under any version of iOS 6. 


Marking Scheme

The purpose of this assignment is to demonstrate that you know how to develop native iPhone app using the Model-View-Controller design pattern.  You do not need to hand in any design documentation but your code MUST be well commented so that it explains what is happening in the code.  The following marking scheme will be used to assess each submission:


  1. View Controller: (50 marks total)

  2. Demonstrate an understanding of using IBOutlets and IBActions, by drawing the main view, including an instance of the GameAreaView, status label, and “Restart Game” button, and managing this using a view-controller (10 marks)

  3. Capturing touch events and positioning the correct game-tokens in the Game Model, including detecting illegal moves (10 marks)

  4. Detecting the end of a winning game, and congratulating the winner (10 marks)

  5. Managing the device to make a move and alternating the starting player (10 marks)

  6. Maintaining scores for each player using a tableView and its delegates (10 marks)


  1. GameAreaView: (30 marks total)

  2. Draw the game lines, and counters on the board based on the status of the Game Model. (20 marks)

  3. Draw a line representing the winning line if a game is won (10 marks)


  1. General: (20 marks total)

  2. Adhering to all of the requirements and submission guidelines, and including all resources and sources in your submission (10 marks)

  3. Design/Style and Layout (10 marks)


Hints

Most of what you need has already been covered in the labs or lecture notes.  The following provides a few additional hints for this assignment.  Other hints are also included in the Game Model header file.


  1. 1.Images can be stored as resources within a project, and then accessed locally by the project without using a file system (which can be problematic on the iPhone) or accessing them from the web.  The following method illustrates how an image could be scaled and drawn on a view:


- (void)drawCounterAtPosition:(int)position isNought:(BOOL)noughtType {

   

    CGPoint myPoint;

    CGRect bounds = [self bounds];              // Get the size of the view

   

    // Divide the view into cells, based on the boardSize (which has been set elsewhere to 3)

    CGSize cellSize = CGSizeMake(bounds.size.width/boardSize, bounds.size.height/boardSize);

   

    // Note that this assumes that the images have been stored as UIImage properties

    UIImage *myImage = (noughtType?[self noughtImage]:[self crossImage]);

    CGSize imageSize = [myImage size];

   

    double scaleFactor = MAX(imageSize.width/cellSize.width, imageSize.height/cellSize.height);

   

    // This draws the images in the top left of the cell, but scaled to the size of the cell

    // (maintaining its aspect ratio

   

    myPoint.x = (cellSize.width * (position % boardSize));

    myPoint.y = (cellSize.height * (position / boardSize));

   

    UIImage *tempImage = [UIImage imageWithCGImage:[myImage CGImage] scale:scaleFactor orientation:UIImageOrientationUp];


    [tempImage drawAtPoint:myPoint];

}


  1. 2.The above method assumes the existence of a class variable “boardSize”, and the properties “noughtImage” and “crossImage”.  Images can be loaded from the application bundle by calling the UIImage method imageNamed:.  The following code fragment retrieves the gameAreaView property, and sets the images in that instance using two other properties:


        // Load in necessary resources

        [[self gameAreaView] setNoughtImage:[UIImage imageNamed:@"nought.png"]];

        [[self gameAreaView] setCrossImage:[UIImage imageNamed:@"cross.png"]];


  1. 3.A good solution will always avoid hard-coding locations in views.  Think about how the board is partitioned with respect to the bounds of the view.  The following method converts touch locations into positions, by determining the size of the view by querying its bounds.  You can test this by resizing your view and seeing if your code still works.


// Returns -1 if no valid position was found

- (NSInteger) getPositionFromTouch:(UITouch *)touch inView:(UIView *)myView {

    int boardSize = [gameModel getBoardSize];

   

    CGPoint touchPoint = [touch locationInView:myView];

    CGRect myViewsBounds = [myView bounds];

   

    // Check if the touch is still within the bounds of this view

    if ((touchPoint.x > 0) && (touchPoint.x < myViewsBounds.size.width) &&

        (touchPoint.y > 0) && (touchPoint.y < myViewsBounds.size.height)) {

       

        CGSize cellSize = CGSizeMake(myViewsBounds.size.width/boardSize,

                                     myViewsBounds.size.height/boardSize);

       

        return (boardSize * (int) (touchPoint.y / cellSize.height))

                            + (int) (touchPoint.x /  cellSize.width);

    }

    return -1;

}



SUBMISSION INSTRUCTIONS


Firstly, check that you have adhered to the following list:


  1. 1.Your project should be self contained within a single zip file containing all of the files in the XCode project. The file's name MUST be 'TicTacToe2012.zip'.  Ensure that all of your source files and resources are included in the project (hint, unpack it in a different directory and check it still builds).

  2. 2.Your project is developed within XCode, not some other language or environment.

  3. 3.Your program compiles and runs on a machine within the computer science department’s Mac Lab, either under Xcode 4.4, using the iOS SDK 6 (recently released) or an earlier version. If you have developed your code elsewhere (e.g. your own mac), ensure that it also works on our system before submission. It is your responsibility to check that you can log onto the department’s system well in advance of the submission deadline.

  4. 4.Your program does not bear undue resemblance to anybody else's! Electronic checks for code similarity will be performed on all submissions and instances of plagiarism will be severely dealt with. The rules on plagiarism and collusion are explicit: do not copy anything from anyone else’s code, do not let anyone else copy from your code and do not hand in 'jointly developed' solutions. 

 

To submit your solution you must SUBMIT IT ELECTRONICALLY, and adhere to the following instructions:


Electronic submission:

  1. Your code must be submitted to the departmental electronic submission system at: http://cgi.csc.liv.ac.uk/cgi-bin/submit.pl?module=comp327


  1. You need to login in to the above system and select ‘Assignment 1’ from the drop-down menu.  You then locate the file containing your program that you wish to submit, check the box stating that you have read and understood the university’s policy on plagiarism and collusion, then click the ‘Upload File’ button.


Work will be accepted only if it is submitted electronically following the above instructions.


Finally, please remember that it is always better to hand in an incomplete piece of work, which will result in some marks being awarded, as opposed to handing in nothing, which will guarantee a mark of 0 being awarded.  Demonstrators will be on hand during the COMP327 practical sessions to provide assistance, should you need it.