The game Days-of-the-Year is played by two players who take turns naming a date of the year starting from January 1st. On any move, a player may increase the month or the day but not both. Thus, for example, the first player will start the game by naming any day in January (apart from the 1st), or the 1st of any month of the year (apart from January). The player who names December 31st wins - this is the aim of the game. To summarise:
To be 100% clear: this game uses the standard Georgian Calendar (Links to an external site.) year on a non-leap year. That means that February has 28 days only. Point 4 is VERY IMPORTANT! Dates such as the 31st of November do not exist!
The game starts on January 1st, play starts:
Your task is to write an implementation for two human players who share the same computer and keyboard and take turns to play - there is no 'AI' in this.
Because of the varying level of programming expertise amongst you, there are three levels of implementation.
If you attempt this version you do not need to do any checking of input data - you can assume that the users will always enter correct data. That is:
It is acceptable that this version crashes (or otherwise does not work properly) if the users does not enter the expected values, or if they enter integers outside the allowed ranges.
Recommendation: You should all start here to get the bare bones of this game working. Once you've got this figured out, you can leave it at that or move onto level 2.
The second level checks to ensure that the user has entered only expected values, that the integers are in the permitted range, the rules of the game are not broken and it does not crash WHATEVER the user enters. You need to pay close attention to the rules of the game here ... do not allow your code to deadlock! Instead of crashing or deadlocking, it asks the user to re-enter data (so they can put in a correct value if it was a genuine typo or mistake). The error messages must conform to the 'Critical Messages' to achieve the marks (see below).
You do not need to worry if the user force quits the program (i.e.using CTRL+C) I do not want/expect you to handle this.
The final version requires you to work independently to learn how to use features of the language we have not studied at the point this coursework is released. It is intended to reward independent leaning and so I will not answer specific questions related to how to do it, but the information you need is in the course notes. (I will, however, be happy to answer questions clarifying what you are intended to achieve). To meet this level, you need the following capability:
To reach the maximum marks available you must implement the following additional functionality. If adding these functions breaks previous parts specified in level 1 or 2, then you will (potentially) lose more marks than it is possible to gain. The functions are:
That is, if you run the program 'normally', then the program should work with the default start date (1st January) and output. But without making any changes to your code or recompiling it, it should be possible to override the default start date and provide ordinal-based output. It also needs to meet the requirements for Level 2.
To allow for these functions to be marked, I need to tell you how the program will be run to access this feature. It will be run by calling:
java DaysOfTheYear DAY MONTH
where DAY will be an integer from 1-31 and MONTH an integer between 1-12. To avoid repeated code you can assume the input is always in range and a valid date and will never be 31st December (that is, there will always be at least one move possible). For example, if I run java DaysOfTheYear 5 2 the program will start on 5th February.
Messages that your program prints must conform exactly to a specific pattern - because the marking will compare the output of your code with the output they expect, and only exact matches will count.
The messages and the way you print them are chosen so they make sense when you play the game manually. Take note of the case!
These messages are:
Note that you should not print the " (quote) characters in the strings above.
NOTE: these are the ONLY messages your program should output if the input from the user is correct. Any additional 'welcome' messages, or splash screens or anything else should not be included.
Here is an example of the message sequences when playing a very simple game. Messages in bold are entered by the player.
The current date is: 1 of January
It is Player 1's Turn!
Do you want to increase the day or the month? (day or month): day
Which day do you want to pick: 5
The current date is: 5 of January
It is Player 2's Turn!
Do you want to increase the day or the month? (day or month): month
Which month do you want to pick: 2
The current date is: 5 of February
It is Player 1's Turn!
Do you want to increase the day or the month? (day or month): month
Which day do you want to pick: 12
The current date is: 5 of December
It is Player 2's Turn!
Do you want to increase the day or the month? (day or month): day
Which month do you want to pick: 31
The current date is: 31 of December
Player 2 is the winner of the game!
Here is an example of the message sequences when playing a game where incorrect input is given. Messages in bold are entered by the player.
The current date is: 1 of January
It is Player 1's Turn!
Do you want to increase the day or the month? (day or month): asdf
Input invalid, please try again!
day
Which day do you want to pick: 31
The current date is: 31 of January
It is Player 2's Turn!
Do you want to increase the day or the month? (day or month): month
Which month do you want to pick: ghjk
Input invalid, please try again!
12
The current date is: 31 of December
Player 2 is the winner of the game!