In: Physics
ASSEMBLY LANGUAGE ONLY OR I WILL DOWNVOTE
write a program that will allow a person to play a Guess a C♠rd Game. This section specifies the required functionality of the program. The interface must be a BlueJ Terminal Window, otherwise zero marks will be awarded. Only a simple screen presentation of the game is required; however, more marks will be gained for a game that is easy to follow with clear informative messages to the player. The aim of the Guess a C♠rd Game is for a player to correctly guess a playing card drawn randomly by the computer. The player has a set number of attempts to guess the card. However, they are allocated points at the start of the game and are penalised for each incorrect attempt. The game ends when a correct guess is entered, the points are zero or less, or the player has run out of guesses. The points remaining at the end of the game are counted as the score for the game. The player may play a series of games, with cumulative game results displayed after the final game when the player decides to stop playing. The deck of cards from which the cards are drawn is a standard fifty-two card deck. It has four suits: Hearts♥, Diamonds♦, Clubs♣ and Spades♠. Each suit has thirteen cards: an Ace, which is regarded as number 1 for this game; cards numbered 2 to 10 inclusive. Each suit also three “face cards”: a Jack, number 11 for this game; a Queen, number 12 for this game; and a King, number 13 for this game. Game play The Guess a C♠rd Game begins with a welcome message followed by a message inviting the player to enter their name. The player’s name cannot be blank and can contain only alphabetic characters. Two numbers, the first with a value from 1 to 4 (inclusive) and the second with a value from 1 to 13 (inclusive), are then randomly generated by the program but hidden from the player. The two numbers represent the card drawn from the deck. So, if the random numbers were 2 and 1, this would mean the card drawn was the Ace of Diamonds. The random numbers 4 and 13 would mean the card drawn was the King of Spades … and so on. The player starts each game with a point score of 40 points. They will first guess the suit of the card drawn from the deck. The player will enter a single character to signify their choice of suit: H for Hearts, D for Diamonds, C for Clubs and S for Spades. The player has three attempts to guess the correct suit. Points are deducted from the player’s score each time the player guesses incorrectly. The points deducted during this part of the game are shown in Table 1. Incorrect guess Points deducted 1 st 5 2 nd 10 3 rd 15 Table 1: Point deductions for incorrect guesses for the card suit. For example, 2 incorrect guesses will be 15 points deducted. If the player guesses incorrectly on the first two attempts, a message is displayed informing them so and they are invited to enter another guess. After a third incorrect guess the player is informed once again of their incorrect guess, then shown the correct suit by the program and the game moves to the next phase. If the player guesses correctly, on either of their first, second or third attempts, they are shown a message informing them so and the game also moves to the next phase. After correctly guessing, or failing to guess and been shown the suit of the card drawn from the deck, the player then has four attempts to guess the correct card number. To do this the player will enter an integer value. Points are deducted from the player’s score each time the player guesses incorrectly. The points deducted during this part of the game are shown in Table 2. Incorrect guess Points deducted 1 st 2 2 nd 6 3 rd 12 4 th 20 Table 2: Point deductions for incorrect guesses for the card number. For example, 3 incorrect guesses will be 20 points deducted. The game continues while the player’s points score is greater than 0, until the player guesses correctly, or they have run out of guesses. If the player guesses incorrectly on the first three attempts and they have a points score above 0, the player is shown a message informing them that the correct card number is higher or lower than their last guess. After a fourth incorrect guess the player is shown the correct card number, the game ends, and they lose the game. If the player guesses correctly on any one of their four attempts, they win the game and are shown a message informing them so. At the end of each game, the player is also shown their points score for the game they have just played. They are also asked if they want to play another game. If they choose not to play another game, they are shown the number of games they have played, the number of games they have won and their highest score for the games they played. The program then terminates. Please note that your program must deal with invalid values entered by the player with respect to the data values mentioned in the previous sections. During the running of the game, if the player enters an invalid value for either the card suit or the card number, the program should display a warning message and the player should be invited to enter another number without penalty (the invalid value entered will not be counted as a guess). Program design Your program must demonstrate your understanding of the object-oriented concepts and general programming constructs presented in the course. Students are advised to follow good programming practices and to use loops and appropriate fields where required to ensure good program design. The data type of each field must be chosen carefully and you must be able to justify the choice of the data type. You may want to include comments in the class to state any assumptions made. Each class should also include appropriate accessor and mutator methods for its fields. Validation of values for fields and local variables should also be implemented where appropriate. You should not allow an object of a class to be set to an invalid state. Class designs Your program should consist of at least four classes: Player, Card, Game and RandomNumber. This section gives an outline of these classes with suggested fields and some behaviours. Player class The Player class will specify the attributes and behaviours of a player. An object of the Player class will have the following fields (at least): name – the name of the player. score – the current game score guess – the last suit or number guessed highestScore – the highest game score achieved numberOfGamesPlayed – the total number of games played numberOfGamesWon – the total number of games won The class must also have a non-parameterised (“default”) constructor and parameterised constructor that accepts a value for the name of the player. A Player object should also be able to return its state in the form of a String. Card class The Card class will specify the attributes and behaviours of card. An object of the Card class will have the following fields (at least): suit – the card suit. number – the card number The class must also have a non-parameterised (“default”) constructor and parameterised constructor that accepts values for the suit and number of the card. A Card object should also be able to return its state in the form of a String. Game class The Game class will manage the playing of a game. It will have the following field (at least): cardGamePlayer (an object of type Player) The Game class will have methods to manage the playing of the game. These should include (at least) the following behaviours: • Display a welcome message on the screen. • Request the player to enter their name. • Request the player to enter a suit. • Request the player to enter a card number • Compare the suit entered by a player with the hidden suit. • Compare the number entered by a player with the hidden number. • Display the result of the attempt at guessing the suit. • Display the result of the attempt at guessing the number. • Display the result for the end of a game. • Display the overall result when the player decides to stop playing. Note that all code for input from the terminal or output to the screen must be in the Game class. There should be no code for input from the terminal or output to the screen in any other class. RandomNumber class An object of the RandomNumber class will generate a random number from 1 to a maximum value specified. The maximum value should be specified via a paramaterised constructor.
---- writing the solution in c++ since in ASSEMBLY LANGUAGE it's not possible.
#include <iostream>
#include <string>
using namespace std;
// constants for board size
int const ROW = 7;
int const COL = 10;
// function to print board
void printBoard(char board[ROW][COL]){
for(int i=0; i<ROW; i++){
for(int j=0;j<COL;
j++){
cout << board[i][j] << " ";
}
cout <<
"\n";
}
}
// function to make movement
void movement(char move, int *row, int *col){
switch(move){
case 'U':
if(*row>0)
*row = *row-1;
break;
case 'D':
if(*row<ROW-1)
*row = *row+1;
break;
case 'L':
if(*col>0)
*col = *col-1;
break;
case 'R':
if(*col<COL-1)
*col = *col+1;
break;
}
}
int main ()
{
// variables for rows and columns of gamer,
enemies and treasure
int gamerRow = 0, gamerCol = 0;
int en1Row = 2, en1Col = 6;
int en2Row = 3, en2Col = 5;
int en3Row = 5, en3Col = 6;
int trRow = 6, trCol = 9;
// moves for enemies
char en1Mov = 'U';
char en2Mov = 'D';
char en3Mov = 'L';
// gameBoard
char board[ROW][COL];
// initialize game board
for(int i=0; i<ROW; i++){
for(int j=0;j<COL;
j++){
board[i][j] = '.';
}
}
board[gamerRow][gamerCol] = 'G';
board[en1Row][en1Col] = 'T';
board[en2Row][en2Col] = 'T';
board[en3Row][en3Col] = 'T';
board[trRow][trCol] = 'X';
// print board
printBoard(board);
// loop for move
do{
cout << "Move
\n";
cout <<
"(U)p\n";
cout <<
"(D)own\n";
cout <<
"(L)eft\n";
cout <<
"(R)ight\n";
char move;
cin >> move;
// set positions .
board[gamerRow][gamerCol] = '.';
board[en1Row][en1Col] =
'.';
board[en2Row][en2Col] =
'.';
board[en3Row][en3Col] =
'.';
// move gamer
movement(move,
&gamerRow,&gamerCol);
// set enemies movement
direction, and move enemies
if(en1Row==0)
en1Mov = 'R';
movement(en1Mov,
&en1Row,&en1Col);
if(en2Row==ROW-1)
en2Mov = 'L';
movement(en2Mov,
&en2Row,&en2Col);
if(en3Col==0)
en3Mov = 'U';
movement(en3Mov,
&en3Row,&en3Col);
// check for
hits
if(gamerRow==trRow
&& gamerCol==trCol){
board[gamerRow][gamerCol] = 'W';
cout<<"\nYou got the treasure\n";
break;
}
else if(gamerRow==en1Row
&& gamerCol==en1Col){
board[gamerRow][gamerCol] = 'L';
cout<<"\nYou lost\n";
break;
}
else if(gamerRow==en2Row
&& gamerCol==en2Col){
board[gamerRow][gamerCol] = 'L';
cout<<"\nYou lost\n";
break;
}
else if(gamerRow==en3Row
&& gamerCol==en3Col){
board[gamerRow][gamerCol] = 'L';
cout<<"\nYou lost\n";
break;
}
// set positions
board[gamerRow][gamerCol] = 'G';
board[en1Row][en1Col] =
'T';
board[en2Row][en2Col] =
'T';
board[en3Row][en3Col] =
'T';
// print board
printBoard(board);
}while(1);
printBoard(board);
return 0;
}
Please do like
Thanks