讲解ISCG6421、讲解GUI Programming、辅导C#编程、C#语言辅导
- 首页 >> C/C++编程ISCG6421 – GUI Programming
Page 1 of 9
ISCG6421
GUI Programming
Semester 2, 2018
Assignment 2: Towers of Hanoi
Computer Science
Practice Pathway
Deadline Time: 8:30am
Deadline Date: Monday 29th October 2018
Course Weighting: 20%
Marks: 100
ASSIGNMENT AIMS
The assignment is individual and is intended to help you gain experience with designing and building
C# Windows applications and testing them with requirements-based testing.
Problem statement
The Towers of Hanoi game is a very old game where you have a board with three pegs on it. A set of
differently sized disks is placed on the first peg with the disks being in order with the smallest on the
top. The game is to transfer the disks from the first peg to the third by moving only one disk at a time,
only taking disks from the top of any pile and never putting a larger disk on top of a smaller disk. The
player tries to do this in as few moves as possible.
Requirements
You are provided with a C# starter project that you must use for this assignment. You are to complete
the game so that it:
Uses four disks and three pegs and lets the user drag and drop disks from one peg to another.
Informs the user that the game is over when all of the disks have been transferred to the third peg
o Informs the user whether or not the game has been completed in the minimum number
of moves
Enforces the rules stated above.
Keeps count of the number of moves.
Allows the user to begin a new game.
Stores valid moves.
Allows games (complete or incomplete) to be stored.
Allows the running of stored (incomplete) games.
Allows a completed game to be played from a list of stored moves using animation controlled by a
timer.
Uses the following classes:
A Disk class to store data about the disks
A Board class to control what happens to the disks
A DiskMove class for saving moves
A MainForm class to control the game.
ISCG6421 – GUI Programming
Page 2 of 9
Disk Class
The disk class should store the disk’s diameter, colour, current level and current peg number. The disk
class should have methods that allow access to the data items.
Board Class
The board class should have the following data storage and be responsible for the following
operations:
Data
It stores the constants needed to handle the display of disks
It has a two dimensional array of Disk references that represents the board
It has an ArrayList for storing the moves made
It has a one dimensional array of 4 Disk references for the Disk objects used in the game.
The constructor takes 4 disk references as parameters
public Board(Disk d1, Disk d2, Disk d3, Disk d4)
The 4 Disk references in the constructor are to be used to fill the array of Disk objects
belonging to the Board object.
Operations
The Board class can:
1. Reset the game to the beginning.
2. Check if it is valid to begin a move with a particular Disk (only the top Disk on a peg can move).
public bool CanStartMove(Disk aDisk)
3. Check if it is valid to drop a particular disk on a Peg (drops are only allowed for a Disk that is
smaller than the top Disk on a peg or for an empty peg).
public bool CanDrop(Disk aDisk, int aPeg)
4. Move a disk to a new Peg.
public void Move(Disk aDisk, int newLevel)
5. Save a DiskMove object representing the latest move to the ArrayList of moves. This would be
part of the Move() method.
6. Return a string giving the moves so far, one move per line.
public string AllMovesAsString()
7. Display the current position of the disks. This is done by changing the Top and Left properties
of the disks which in turn changes where the labels show on the screen.
public void Display()
8. Get a reference to the disk that matches a label. This is to be used to find which disk object is
being dragged on the form.
public Disk FindDisk(Label aLabel)
ISCG6421 – GUI Programming
Page 3 of 9
MainForm Class
The MainForm class can:
1. Have private global references for a Board object, the Disk being dragged and the Peg that is
the target of the drop.
2. Have a [Reset] button that creates 4 Disk objects matching the 4 labels and a Board object,
and then position the Disks in the starting position.
3. Check (by asking the Board object) if a move can start when the user does a MouseDown on a
disk label and give an error message if it cannot.
4. Check (by asking the Board object) if a drop can happen on a Peg and only show the
AllowDrop cursor when the mouse is over a Peg if a drop is valid.
5. Display a count of the moves made and show the moves made in a textbox, one line per move.
DiskMove Class
The DiskMove class can:
Store the index of the disk making the move and the new Peg it is dropped on.
Have an AsText () method that gives this information as a string, e.g. “1,2” means that Disk 1
moved to peg 2.
Have two constructors, one that takes two integers (for disk index and peg) as parameters, the
other takes a string in the form “2,1” as its parameter.
ISCG6421 – GUI Programming
Page 4 of 9
Required Tests
This is the minimum number of tests you need in your testing documentation:
1. The program displays the message “You have successfully completed the game with the
minimum number of moves” when all of the disks have been transferred to the third peg with
the minimum number of moves.
2. Interface is displayed correctly when the program runs
3. Valid moves are stored
4. Uses four disks and three pegs and lets the user drag and drop disks from one peg to another.
5. Keeps count of the number of moves.
6. The program displays the message “You have successfully completed the game but not with
the minimum number of moves” when all of the disks have been transferred to the third peg
with more than the minimum number of moves.
7. Enforces the rules
8. Try moving more than one disk at a time
9. Try moving a disk at the bottom of a pile
10. Try moving a disk second from top of a pile
11. Try putting a larger disk on top of a smaller disk.
12. Begin a new game after a game has been started
13. Number of moves set to zero
14. Disks moved back to starting positions
15. Load an incomplete stored game and finish it.
16. Play a completed game from a list of stored moves using animation controlled by a timer.
Please note that your tests can involve more than one step and must be reproducible (i.e. explicit test
data and user actions) and independent of each other (i.e. please do not use the output of one test as
the input to another test.)
Delivery
A soft copy must be uploaded onto Moodle prior to the deadline and it must comprise:
The testing documentation.
ALL files needed to compile and run your application from the Visual Studio Community
2017 environment used in the Department of Computing labs. Please note that you must
submit your assignment in Visual Studio Community 2017. 30 marks will be deducted if
this is not done.
Test Cases
Please using the following format for your test cases
Requirement to test Test Data Input Expected Outcomes Actual Outcomes
Deadline for questions
Please note that there is a deadline for questions on the assignment at 8:30 a.m. on Tuesday 23rd
October 2018. Please make sure that you ask any questions regarding the assignment before this
deadline.
ISCG6421 – GUI Programming
Page 5 of 9
Marking
Marks will be deducted for any requirement (or for multi-part requirements, or each part of a
requirement) that is not fully implemented or has no or insufficient testing documentation.
In the interface behaviour and data processing section, marks will be deducted for any
requirement (or for multi-part requirements, or each part of a requirement) that is not well
covered in the test plan or is reported as working in the test plan but does not work when the
assignment is marked. You are also expected to handle exceptions, using message boxes and
“try and catch” blocks.
Check “Programming Standards for C Sharp Courses” on pages 7 and 8 of this document. The
standards for C# programming in this document MUST be followed. In particular, this includes
putting meaningful comments at the beginning of each and every method in the standard
format as given in the document.
Part Marks Actual
Interface behaviour, and data processing
Interface set up correctly (matches screenshot – see page 8) 10
Uses four disks and three pegs and lets the user drag and drop
disks from one peg to another. 8
Enforces the rules of the game 15
Keeps count of the number of moves. 5
Allows the user to begin a new game. 5
Allows the running of stored moves. 5
Allows the game to be played from a list of stored moves using
animation controlled by a timer.
10
Uses the following classes:
A Disk class to store data about the disks.
A Board class to control what happens to the disks.
A DiskMove class for saving moves.
A MainForm class to control the game. (5)
22
Testing documentation 16
Naming conventions and correct internal documentation 4
Total: 100
Have a query? Want to improve your work?
You could visit:
Student Learning and Achievement for learning advice and support.
The Pacific Centre.
Te Noho Kotahitanga Marae (building 171)
ISCG6421 – GUI Programming
Page 6 of 9
Assignment Delivery
Electronic submission of the assignment is required for ALL assignments. This copy must be
submitted on Moodle prior to 8:30am on the due date.
Assignments submitted after the due date and time without having received an extension through
Special Assessment Circumstances (SAC) will be penalised according to the following:
10% of marks deducted if submitted within 24hrs of the deadline
20% of marks deducted if submitted after 24hrs and up to 48hrs of the deadline
30% of marks deducted if submitted after 48hrs and up to 72hrs of the deadline
No grade will be awarded for an assignment that is submitted later than 72hrs after
the deadline.
Special Assessment Circumstances
A student, who due to circumstances beyond his or her control, misses a test, final exam or an
assignment deadline or considers his or her performance in a test, final exam or an assignment to
have been adversely affected, should complete the Special Assessment Circumstances (SAC) form
available from Student Central.
Within any semester, a student may have only one SAC per course.
When requesting an SAC for an assignment, the SAC must be submitted (along with work completed
to-date) within the time frame of the extension requested; i.e. if the Doctor’s certificate is for one (1)
day, then the SAC and work completed must be submitted within one (1) day.
Assistance to other Students
Students themselves can be an excellent resource to assist the learning of fellow students, but there
are issues that arise in assessments that relate to the type and amount of assistance given by
students to other students. It is important to recognise what types of assistance are beneficial to
another’s learning and also what types of assistance are unacceptable in an assessment.
Beneficial Assistance
Study Groups.
Discussion.
Sharing reading material.
Testing another student’s programming work using the executable code and giving
them the results of that testing.
Unacceptable Assistance
Working together on one copy of the assessment and submitting it as own work.
Giving another student your work.
Copying someone else’s work. This includes work done by someone not on the course.
Changing or correcting another student’s work.
Copying from books, Internet etc. and submitting it as own work. Anything taken
directly from another source must be acknowledged correctly: show the source
alongside the quotation.
ISCG6421 – GUI Programming
Page 7 of 9
Programming Standards for C Sharp Courses
Internal Documentation
Your code is such that other programmers can read it without struggling and your users are not
left guessing as to what to do.
Each class file (including form classes) will begin with comments explaining the purpose of the
class, the author and the date written.
Each method will start with comments that explain what the method does.
Any code which does not have an obvious meaning or which uses a specialized technique is to
be commented. Use blank lines and further comments to identify where parts of a task begin
within a method.
Code will use meaningful variable, class and method names. Components which have event
handler code for any of their events must have meaningful names, Components which have
properties assigned to in code must also have meaningful names. A naming convention that
identifies the type of component involved is recommended. E.g. btnExit, txtStartDate, lblTotal
Layout
Code will be laid out in the style of the example below, using indentation steps of 4 spaces.
Blocks using { and } will use the layout shown here:
///<Summary> method : btnLeapYear_Click
///Check if a date falls in a leap year
///</Summary>
private void btnLeapYear_Click(object sender, System.EventArgs e)
{
DateTime aDate = getDate();
if ( DateTime.IsLeapYear(aDate.Year) )
{
label6.Text = aDate.Year.ToString() + " IS a leap year";
}
else
{
label6.Text = aDate.Year.ToString()
+ " is NOT a leap year";
}
}
Parentheses and spaces will be used to make the meaning clear in arithmetic expressions and
conditions.
sum = (n1 / n2) + n3;
not
sum = n1 / n2 + n3;
nor
sum=n1/n2+n3;
In general, each method will perform a single simple task.
In the final version of your project please delete all sections of code that has been ‘commented
out’
ISCG6421 – GUI Programming
Page 8 of 9
User Interface
Always provide the user with clear instructions explaining what they should do. Areas used for
input must be labelled to explain what input is required. Use hints or tool tips to explain
interface features.
The user must be prevented from entering values or taking actions that the program is unable to
deal with. All input should be validated; any errors found should be reported back to the user with
an error message which clearly and politely explains how to correct the error. The user should be
unable to proceed without correcting invalid input.
ISCG6421 – GUI Programming
Page 9 of 9
Interface Design: Screenshot