Solution Code: 1AADE
This assignment falls under “Pong Theme” which was successfully solved by the assignment writing experts at My Assignment Services AU under assignment help service.
Task
The assignment is a variation on the Pong theme. The player controls a game paddle positioned near one edge of the terminal window which moves vertically but not horizontally. A ball flies within the playing area
of the game, bouncing off floor and ceiling and one of the walls, but passing through the remaining wall.
Requirements
Your task is to implement the Pong game. Throughout the semester, you have been provided with a number of examples of skeleton code for implementing games with the CAB202 ZDK library. You have also been shown a demo version of the game (see the Topic 3 lecture), which implements some of the
requirements for the assignment. You are not required to use the ZDK library, but you are strongly encouraged to do so.
Game Specification
The game has four levels which entail qualitatively distinct modes of play. Pressing the key labelled 'L' at any time during play advances the level by 1. After Level 4, the level cycles back to Level 1. There is no other way to progress between levels. For all levels, the following basic game functionalities need to be implemented in order for the game to work properly:
1. The game must adapt itself to occupy the full expanse of the terminal window at the time the program starts.
a. You may assume that the width of the terminal window is at least 60 units and the height of the terminal window is at least 10 units.
b. You may assume that the user will not resize the window while the game is running.
2. Help screen is displayed at commencement of game, prior to moving on to game itself.
a. Help screen must show the name and student number, plus a list of keyboard commands required to play the game.
b. Help screen exits when user "Presses any key".
c. Also displayed when user presses 'h'.
d. Also displayed after the game over dialogue, if user has selected “Play again”, before moving on to restart the game.
e. While the help screen is displayed, all other game dynamics are frozen, including the elapsed game time.
3. After help screen at the start (or restart) of game, borders and info panels are displayed. The info panel displays:
a. Lives, initially 10 (or 3, or something reasonable).
b. Score, initially 0.
c. Level, initially 1.
d. Elapsed game time, measured in minutes and seconds, initially 00:00.
4. Ball is spawned at the beginning of play, and re-spawns each time it leaves the playing area, unless the game is over. Ball spawns in two stages. [3 Marks]
a. Countdown (3, 2, 1...) for 0.3 seconds.
b. During the countdown all other game dynamics are frozen, including the elapsed game time.
c. Launch from centre of screen, travelling towards the player’s end of the game in random direction within ±45° of horizontal. The speed of the ball at spawning should be set to some fixed value that yields a playable game, neither too slow nor impossibly fast.
5. Game border and info panel during play
a. Lives are reduced by 1 every time the ball passes out of the play area at the player’s end.
b. Score increments by 1 every time the player’s paddle strikes the ball (or vice versa).
c. Current level accurately reflects state of game.
d. Ball, paddles and other sprites never pass onto or over the boundaries.
e. Elapsed game time is updated in a timely manner once per second.
f. Elapsed game time records time spent in game. While any dialog (help screen, spawn countdown, or game over) is being displayed, the clock is stopped. After a dialog is cleared, elapsed game time resumes from the value it had at the time the dialog opened. That is, the clock is stopped while the game is paused.
6. The player's game paddle:
a. The player controls a paddle which is constrained to move vertically at one side of the playing area.
b. The paddle is placed so that there are exactly two columns of empty space between the paddle and the nearest vertical wall of the playing area.
c. The paddle must never protrude beyond the playing area, overlap the boundary, be obscured (in part or whole) by the boundary, or in any other way not fit properly inside the playing area.
d. The paddle must have a width of 1 screen unit and the height must be the minimum of the two values listed below:
1. 7 screen units, if the height of the terminal window is greater than or equal to 21 units; or
2. screen units, where is the height of the terminal window and
is the height of the game status display status, if the height of the terminal window ( ) is less than 21 units.
The assignment file was solved by professional International Java Language Experts and academic professionals at My Assignment Services AU. The solution file, as per the marking rubric, is of high quality and 100% original (as reported by Plagiarism). The assignment help was delivered to the student within the 2-3 days to submission.
Looking for a new solution for this exact same question? Our assignment help professionals can help you with that. With a clientele based in top Australian universities, My Assignment Services AU’s assignment writing service is aiding thousands of students to achieve good scores in their academics. Our Pong Theme assignment experts are proficient with following the marking rubric and adhering to the referencing style guidelines.
#include
#include
#include
#include
#include
using namespace std;
HANDLE wHnd;
HANDLE rHnd;
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
int PLAYER_BAT_X = 56;
int PLAYER_BAT_Y = 5;
int ROBO_BAT_X = 1;
int ROBO_BAT_Y = 7;
int PONG_BALL_X = 30;
int PONG_BALL_Y = 7;
void HelpDisplay();
void AdjustConsoleDisplay();
void SetScreen(int, int, int, int, int, char **);
void InitializeDisplay(char **&);
void IncrementTimer(int &, int &, int &);
void cls(HANDLE hconsole);
void UpdatePeddel(char **&Board);
void UpdatePongBall(int, int, char**&,int,int);
void UpdateLevel(int Level, char **&);
void ResetCursor();
void ResetGameDisplay();
void AdjustRoboPedal(char **&);
void BringOutRoboBat(char **&);
int main()
{
AdjustConsoleDisplay();
char **ScreenBoard = NULL;
char pressedKey;
int MAX_WEST_LIMIT = 0;
bool East = true;
bool North = false;
bool RoboEnabled = false;
int TimerSec = 0;
int TimerMins = 0;
int Score = 0;
int Lives = 10;
int Level = 1;
int tempTimer = 0;
InitializeDisplay(ScreenBoard);
UpdateLevel(Level,ScreenBoard);
SetScreen(0, 0, 0, 0, 0,ScreenBoard);
while (Lives>-1)
{
if (East)
{
if (ScreenBoard[PONG_BALL_Y][PONG_BALL_X + 1] != '|' && PONG_BALL_X = 56)
{
Lives--;
printf("%s", "\n\nOOPS!! You Lost A Life! Press any key to play again.\n\n");
cin.get();
ResetGameDisplay();
}
else
{
Score++;
East = false;
}
}
else if (!East)
{
if (ScreenBoard[PONG_BALL_Y][PONG_BALL_X - 1] != '|' && PONG_BALL_X > MAX_WEST_LIMIT)
{
UpdatePongBall(PONG_BALL_X, PONG_BALL_Y, ScreenBoard, PONG_BALL_X - 1, PONG_BALL_Y);
if (RoboEnabled)
{
AdjustRoboPedal(ScreenBoard);
PONG_BALL_Y = 10;
}
}
else
{
East = true;
}
}
tempTimer++;
if (tempTimer == 50)
{
TimerSec++;
if (TimerSec == 60)
{
TimerMins++;
TimerSec = 0;
}
tempTimer = 0;
}
if (kbhit())
{
char ch = cin.get();
if (ch == -32)
{
ch = cin.get();
if (ch == 'H')
{
if (PLAYER_BAT_Y>0)
PLAYER_BAT_Y -= 1;
}
else if (ch == 'P')
{
if (PLAYER_BAT_Y < 10)
PLAYER_BAT_Y += 1;
}
}
else if (ch == 'H' || ch == 'h')
{
//help Menu Would be Displayed Here
}
else if (ch == 'L' || ch == 'l')
{
Level++;
if (Level == 2){
MAX_WEST_LIMIT = 1;
RoboEnabled = true;
}
ScreenBoard[PONG_BALL_Y][PONG_BALL_X] = ' ';
ResetGameDisplay();
UpdateLevel(Level, ScreenBoard);
SetScreen(TimerMins, TimerSec, Score, Level, Lives, ScreenBoard);
cin.get();
}
}
ResetCursor();
UpdatePeddel(ScreenBoard);
SetScreen(TimerMins, TimerSec, Score, Level, Lives, ScreenBoard);
}
cls(wHnd);
printf("%s", "You Lost Bitch :D :D xD \n\n!!");
return 0;
}
void cls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
PERR(bSuccess, "GetConsoleScreenBufferInfo");
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten);
PERR(bSuccess, "FillConsoleOutputCharacter");
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
PERR(bSuccess, "ConsoleScreenBufferInfo");
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
PERR(bSuccess, "FillConsoleOutputAttribute");
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
PERR(bSuccess, "SetConsoleCursorPosition");
return;
}
void ResetCursor()
{
COORD coordScreen = { 0, 0 };
SetConsoleCursorPosition(wHnd, coordScreen);
}
void HelpDisplay()
{
}
void InitializeDisplay(char **&DispData)
{
DispData = (char**)malloc(15 * sizeof(char*));
int i = 0;
int j = 0;
for (i = 0; i < 15; i++)
{
DispData[i] = (char*)malloc(60*sizeof(char));
}
}
void SetScreen(int tmMin, int tmSec, int Scr, int Lev, int Liv, char **DispDetails)
{
int i = 0;
for (i = 0; i < 60; i++)
printf("%c",'*');
printf("%c", '\n');
printf("%c", '*');
printf("%s", "Lives : ");
printf("%d", Liv);
printf("%c", '\t');
printf("%s", "Score : ");
printf("%d", Scr);
printf("%c", '\t');
printf("%s", "Level : ");
printf("%d", Lev);
printf("%s", " ");
printf("%s", "Timer : ");
if (tmMin < 10)
printf("%c", '0');
printf("%d", tmMin);
printf("%c", ':');
if (tmSec < 10)
printf("%c", '0');
printf("%d", tmSec);
printf("%c", '*');
printf("%c", '\n');
for (i = 0; i < 60; i++)
printf("%c", '*');
printf("%c", '\n');
int j = 0;
for (i = 0; i < 15; i++)
{
printf("%c", '*');
for (j = 0; j < 58;j++)
printf("%c", DispDetails[i][j]);
printf("%c", '*');
printf("%c", '\n');
}
for (i = 0; i Press H for help. \n\n----> Press L to change Level.");
}
void AdjustConsoleDisplay()
{
wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
rHnd = GetStdHandle(STD_INPUT_HANDLE);
LPCWSTR ttl = L"Ping Pong";
SetConsoleTitle(ttl);
SMALL_RECT windowSize = { 0, 0, 100, 50 };
SetConsoleWindowInfo(wHnd, 1, &windowSize);
COORD bufferSize = { 10, 10 };
SetConsoleScreenBufferSize(wHnd, bufferSize);
}
void UpdatePeddel(char **&Board)
{
for (int i = 0; i < 15; i++)
Board[i][56] = ' ';
Board[PLAYER_BAT_Y + 0][PLAYER_BAT_X] = '|';
Board[PLAYER_BAT_Y + 1][PLAYER_BAT_X] = '|';
Board[PLAYER_BAT_Y + 2][PLAYER_BAT_X] = '|';
Board[PLAYER_BAT_Y + 3][PLAYER_BAT_X] = '|';
Board[PLAYER_BAT_Y + 4][PLAYER_BAT_X] = '|';
}
void UpdatePongBall(int X_Old, int Y_Old, char **&Board, int X_New, int Y_New)
{
Board[Y_Old][X_Old] = ' ';
Board[Y_New][X_New] = '0';
PONG_BALL_X = X_New;
PONG_BALL_Y = Y_New;
}
void UpdateLevel(int Level, char **&DispData)
{
int i = 0;
int j = 0;
for (i = 0; i < 15; i++)
{
for (j = 0; j < 60; j++)
{
DispData[i][j] = ' ';
}
}
if (Level == 4)
{
for (i = 20; i < 40; i++)
{
DispData[5][i] = '=';
DispData[10][i] = '=';
}
}
DispData[PLAYER_BAT_Y + 0][PLAYER_BAT_X] = '|';
DispData[PLAYER_BAT_Y + 1][PLAYER_BAT_X] = '|';
DispData[PLAYER_BAT_Y + 2][PLAYER_BAT_X] = '|';
DispData[PLAYER_BAT_Y + 3][PLAYER_BAT_X] = '|';
DispData[PLAYER_BAT_Y + 4][PLAYER_BAT_X] = '|';
DispData[PONG_BALL_Y][PONG_BALL_X] = '0';
return;
}
void ResetGameDisplay()
{
PONG_BALL_X = 30;
PONG_BALL_Y = 7;
PLAYER_BAT_X = 56;
PLAYER_BAT_Y = 5;
cls(wHnd);
}
void AdjustRoboPedal(char **&Board)
{
for (int i = 0; i < 15; i++)
Board[i][ROBO_BAT_X] = ' ';
if ((ROBO_BAT_Y + 2) < PONG_BALL_Y && (ROBO_BAT_Y + 1) PONG_BALL_Y && (ROBO_BAT_Y - 1)>0)
ROBO_BAT_Y--;
Board[ROBO_BAT_Y - 1][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y - 2][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 0][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 1][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 2][ROBO_BAT_X] = '|';
}
void BringOutRoboBat(char **&Board)
{
ROBO_BAT_X = 1;
ROBO_BAT_Y = 7;
Board[ROBO_BAT_Y - 1][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y - 2][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 0][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 1][ROBO_BAT_X] = '|';
Board[ROBO_BAT_Y + 2][ROBO_BAT_X] = '|';
}
This Pong Theme assignment sample was powered by the assignment writing experts of My Assignment Services AU. You can free download this Pong Theme assessment answer for reference. This solved Pong Theme assignment sample is only for reference purpose and not to be submitted to your university. For a fresh solution to this question, fill the form here and get our professional assignment help.
Trending now
The Student Corner
Subscribe to get updates, offers and assignment tips right in your inbox.
Popular Solutions
Popular Solutions
Request Callback
Doing your Assignment with our resources is simple, take Expert assistance to ensure HD Grades. Here you Go....
🚨Don't Leave Empty-Handed!🚨
Snag a Sweet 70% OFF on Your Assignments! 📚💡
Grab it while it's hot!🔥
Claim Your DiscountHurry, Offer Expires Soon 🚀🚀