Java代写:CSE1100WordLink


代写WordLink这个小游戏。游戏类似成语接龙,只不过换成了使用给定字典中的英文单词接龙。

Objectives

The aim of this assignment is to practise analysing a problem in an object-
oriented manner, and designing and implementing an object-oriented solution.

Problem Description

WordLink is an English vocabulary game for two players. Players are required
to present English words in turns, and the first character of the word must be
the same as the last character of the previous word. For example, while player
A and player B are playing the game, if A presents the word “grass”, then B
has to give a word starting with ‘s’ which is the last character of “grass”.
If B presents “sunny”, then A needs to supply a word starting with ‘y’. A word
cannot be used twice in one game. The game can continue until one of the
players loses. There are four scenarios in which a player loses the game.

  1. the player cannot find a word to continue the game.
  2. the player has presented a word which starts with a different character.
  3. the player has supplied a repeated word.
  4. the spelling of the word is incorrect
    In any case, if one player is lost, then the other player wins the game. A
    number of examples of the game are listed as below.
    Example 1:
    (Player A) “grass” – (Player B) “sunny” – (A) “yellow” – (B) “world” – (A) “dog” – (B) “grass”
    The game is ended and Player A wins.
    Example 2:
    (Player A) “grass” – (Player B) “sunny” – (A) “yellow” – (B) “world” – (A) “dog” – (B) “out”
    The game is ended and Player A wins.
    Example 3:
    (Player A) “grass” – (Player B) “sunny” – (A) “yellow” – (B) “world” – (A) “doog”
    The game is ended and Player B wins.
    In this assignment, you are required to build a program that plays WordLink
    with a kindergarten pupil. The pupil is player A and your program acts as
    player B.
    A text file ( dictionary.txt ) containing a set of English words will be
    provided. You can assume that dictionary.txt contains all English words that a
    kindergarten pupil may know. Words to be used in playing the game must be
    selected from the set.
    Each game should start by letting player A enter a word. Your program then
    needs to validate the word (ie. if the word is included in dictionary.txt ).
    If the word is invalid, then the game is terminated and your program (player
    B) wins; otherwise your program needs to search the dictionary to find and
    enter a proper word. Your program will then let player A to type a word to
    continue the game. This can go back and forth a number of times till either
    your program or player A wins.

Functional and Non-functional Requirements

Your program must satisfy the following functional and non-functional
requirements.

The program should be menu driven. It displays the menu displayed as Figure 1
at the start, and waits for the player to choose a function.
WordLink
A. set the difficulty level
B. display the dictionary
C. insert a word to the dictionary
D. play the game
E. exit
Select a function from the menu :
If A is selected, it allows the player to set a difficulty level.
If B is selected, it displays all words in the dictionary.
If C is selected, it inserts a new word into the dictionary.
If D is selected, it starts playing the game.
If E is selected, it saves all changes to dictionary.txt, and terminates the
program execution.

Set the difficulty level

Your program should provide two difficulty levels for the games - level 1 and
level 2. For the player, level 2 is more difficult than level 1. This is
because all words in dictionary.txt can be selected for playing at level 2,
while level 1 games only use those level 1 words in the text file. At the
start of your program execution, the difficulty level is 1 by default.
If the player chooses to set the difficulty level, your program should prompt
the player and wait for an integer (1 or 2) input. The difficulty level is
then set up.

Display the dictionary

If this function is selected, your program displays on the monitor all words
in the dictionary (including those being added). It displays words level by
level with lower level at the front. Within each level, words are displayed
alphabetically in an ascending order. They should be displayed 7 words in a
line and 5 lines for a screen. The player can press any key to display the
next screen.

Insert a word to the dictionary

The player can insert a new word into the dictionary. To insert a new word,
the player needs to provide the word and the difficulty level. Your program
must check to ensure the absence of the word before adding. If the word is
existing, then insertion cannot be done and the player should be informed.

Play the game

A game starts by your program prompting the player to enter a word. After a
word is entered, your program checks if the word exists in the dictionary. If
it isn’t, then the player loses and the game is over. If it is, then your
program searches the dictionary and selects the first proper word to continue
the game. For instance, if “sad”, “sat”, “saw”, “say”, “sea”, “see”, “she”,
“shy”, “sun” are all available for selection, your program chooses the first
word which is “sad”.

The dictionary

After your program is started, it should read from dictionary.txt to create
the dictionary. The dictionary in your program must be an array of linked
lists shown in Figure 3. Each node represents a word and its level. Words must
be sorted alphabetically in an ascending order on the linked list. If a new
word is added, then the word with its level must be inserted to the linked
list at a proper position.

Bonus Task

Instead of only being able to play against the computer, add a menu option for
a two-player game and implement its functionality.

Code Segments

Below are code segments that must be included in your program.
public class DictionaryNode {
//object of the class represents a single word
protected String word; // word to be stored
private int level; // level of the word
private DictionaryNode next;
public DictionaryNode(String _word, int _level) {
//add your implementation for the constructor
}
//add any other attributes or methods if needed
}
public class ListOfNodes {
//object of the class represents a linked list of words starting
//with a specific character.
private DictionaryNode head = null; //head of the linked list
//add any other attributes or methods if needed
}
public class Dictionary {
//object of the class represents the whole dictionery
private ListOfNodes[] data;
//add any other attributes or methods if needed
}
—|—

Program Development

The following is a suggested breakdown for completing this assignment:

Task 1 Creating the Menu

Create the menu display, collect user’s input and write a method stub for each
menu option. Ensure that the correct function is called.

Task 2 File Handling

In Task 2, you need to consider all issues related to reading the text file
(dictionary.txt) to obtain words and their levels. You can simply display
contents read from the text file to ensure file reading is correctly
conducted.

Task 3 Defining Classes

In this task, implement major classes for the assignment. This includes the
necessary menu and interactions with the player for choosing options etc.

Task 4 Linked Lists

Implement classes required for linked lists and dictionary. Implement methods
(such as insertInOrder, search etc) which are operations associated with the
list and any other methods. Thoroughly test your linked list before
integrating it into your program.


文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录