Teaching Announcements
NOTE: This version of the assignment is the full version, and differs slightly from the draft that was prepared for the the Lab Session.
For the second practical assignment you are asked to write a Noughts and Crosses (Tic Tac Toe) application using the iPhone API. You should base your solution on the application produced in Lab 6; which involves producing a Windows-based application for the iPhone. Examples of the final version are given below. If you are unfamiliar with the game (which is also known as “Noughts and Crosses”, then visit the Wikipedia web page.
Your solution should utilise a ViewController to manage the main view, with an associated .xib file in which you design your interface (i.e do not add your interface elements to the MainWindow.xib file). The game-tokens, which indicate each play, should be generated from the following gif images:
These should be included in your project as resources. The jpg images can be obtained by clicking on the images (above). The game should allow two players to take it in turn to select a space on the 3x3 playing area, and position a game-token. The game should proceed until one player wins, or there are no spaces left.
Detailed Requirements
The full requirements are given (below):
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).
2.A status label beneath the main playing area should provide information to the players. In particular, it should:
•Indicate who’s move it is.
•Indicate the winner when the game has been won.
•Warn that an illegal move has been attempted (such as the user selecting a space already occupied by a game-token.
•Indicate when a game is over by announcing who won.
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.
4.A score should be kept to indicate how many games each player has played. This should be incremented after each game where one player won.
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.
Hints
This assignment will involve you using graphics with a view to draw the board and position the game-tokens. You were introduced to the notion of drawing in Lab 6, as well as getting the size of a view (using the method bounds, which returns a CGRect). To draw lines, create a graphics context, and then create a set of lines, before stoking the path they form. The following code fragment draws two parallel lines within a view, to illustrate this:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath (context);
CGContextMoveToPoint (context, 10, 10);
CGContextAddLineToPoint (context, 10, 80);
CGContextMoveToPoint (context, 50, 10);
CGContextAddLineToPoint (context, 50, 80);
CGContextClosePath (context);
[[UIColor blackColor] setStroke];
CGContextDrawPath (context, kCGPathStroke);
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 code fragment illustrates how an image could be loaded from a resource, and then displayed on a view:
UIImage *crossImage = [UIImage imageNamed:@"cross.jpg"];
CGPoint myPoint;
myPoint.x = (w * ((p % 3) + 0.5));
myPoint.y = (h * ((p / 3) + 0.5));
[crossImage drawAtPoint:myPoint];
Finally, create a model to manage what spaces have been filled with what game-token, and manage this within the view-controller. However, also bear in mind that the view for the playing area will also need access to that model to know what to draw and where...!
Marking Scheme
•Drawing the main view, including the board, status label, and “Restart Game” button, and managing this using a view-controller (30 marks)
•Capturing touch events and positioning the correct game-tokens in the playing area, including detecting illegal moves (30 marks)
•Detecting the end of a winning game, and congratulating the winner (20 marks)
•Maintaining scores for each player (10 marks)
•Layout and Design (10 marks)
Note that the position of all of the graphical elements should be calculated automatically by the code, based on their size and the size of the playing area. You may lose marks if you use hard-coded positions (i.e. numbers or coordinates) in your solution.
This assignment contributes 15% to your overall mark for COMP327.
The code should compile without warning or errors. In addition, memory should be managed appropriately.
SUBMISSION INSTRUCTIONS
Firstly, check that you have adhered to the following list:
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 'Solution2.zip' (capital S; lower-case everything else).
2.Your project is developed within XCode, not some other language or environment.
3.Your program compiles and runs on a machine within the computer science department’s Mac Lab, under Xcode 3.2.5, using the iOS SDK 4.2 (recently released). 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.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:
•Your code must be submitted to the departmental electronic submission system at: http://cgi.csc.liv.ac.uk/cgi-bin/submit.pl?module=comp327
•You need to login in to the above system and select ‘Practical 2’ 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.
COMP327 - Practical Assignment 2 2010
25/11/2010
Deadline:
3pm, Monday 6th Dec ’10
Example Output