CSCI 1480 University of Central Arkansas Bonus Lab (Optional)

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

CSCI 1480

University of Central Arkansas


Bonus Lab (Optional)
opi!" Files - Worth 1#A$$itional (Bonus) Points applied to the lab portion of your grade
(35%). %is assi&n'ent is !o'pletely optional ( it )ill not !ount a&ainst
you if you $o not sub'it it* You can receive up to 5 additional points if you
successfully co!plete it.

%e Bonus Lab 'ust bot% !o'pile an$ run )it%out any un%an$le$
e+!eptions in or$er to re!eive any Bonus ,oints*
-ea$in&" "h. #
*Note: Include the following set of comments at the top of your source code for
all assignments.
//Your Name
//Assignment # (Eample: !onus Assignment"
//!rief description of the purpose of the program (Eample: //#alculates the
area of a s$uare."
Overvie)
$he %onus assign!ent i!ple!ents a ga!e na!ed The Falling Banana Game. $he user is
re&uired to guess letters for a rando!ly selected 'ord si!ilar to the Wheel of Fortune
television ga!e sho'. $he ga!e utili(es data that is stored in a file na!ed words1.txt.
$his file is the sa!e as used in la%)in and consists of *+ uni&ue 'ords placed on each
line as sho'n %elo',
a%ility
account
accu!ulated
accu!ulating
accuracy
--..
'indo's
'ithin
'oll%orn
'or.shop
'or.shops
yello'
$he sa!e set of i!ages used in la%)in that corresponds to the alpha%et is provided in
alpha.(ip. /0a!ples of the i!ages are sho'n %elo',
--
a.bmp b.bmp y.bmp z.bmp - /ach letter is 3#.03#
$he follo'ing class1 !odified fro! la%)in1 Game is used 'hen i!ple!enting this la%.
#ifndef GAME_H
#define GAME_H
#include "GenPoint.h"
class Game
{
private:
char* fileame!
char* "ord!
int* #ananas! $$Arra% of o#&ect num#ers for each #anana ima'e
GenPoint* (e%s_ul! $$Arra% of GenPoint for upper left coordinates
GenPoint* (e%s_lr! $$Arra% of GenPoint for lo"er ri'ht coordinates

pu#lic:
Game)*!
+Game)*!
char* 'et,ileame)*!
void set,ileame)char* fn*!
void set-ord)int rand_no*!
char* 'et-ord)*!
void dra")*!
void pla%)*!
.!
#endif
$he guidelines for !ain involve the follo'ing steps,
. 2eclare Game o%3ect
#.Pro!pt the user for the file na!e containing the 'ords to %e processed.
3. 4nvo.e setFile5a!e !ethod that sets the file5a!e private data field.
*. 6enerate rando! nu!%er %et'een ) and *7
5. 4nvo.e setWord !ethod that selects a rando! 'ord fro! the file and sets the private
data field word.
5. 4nvo.e the draw !ethod that displays the %anana tree1 %ananas1 te0t !essages1 a
colored line1 %lan. rectangles1 and a virtual .ey%oard consisting of the alpha%etic i!ages.
8. 4nvo.e the play !ethod that allo's the user to play the ga!e %y selecting letters. $he
specific rules of the ga!e are given in a su%se&uent section.
$he e0a!ple pro!pt fro! !ain is sho'n %elo',
$he resulting graphics display as created fro! the draw !ethod is sho'n,
$he draw !ethod displays the initial scene for the ga!e. $he ele!ents of this initial
scene are created %y the draw !ethod as outlined %elo',
. $he rando!ly selected 'ord for this e0a!ple has 9 letters1 thus 9 'hite rectangle are
displayed starting fro! ())1#5)) each 'ith 'idth of 3# and height of 3#.
#. : %anana for each letter of the rando!ly selected 'ord is also displayed in the %anana
tree - 9 %ananas for this e0a!ple - alt%ou&% only . bananas are visible. /ach %anana is
%anana;tree.%!p
())1))
()1+))
"olor, (#)51#81#+)
())1#5))
())13)))
(*))1)))
%anana.%!p
(#5185)
%anana.%!p
(3#185)
nu!%ered fro! ) to N-1 'here N is the length of the 'ord. /ach even nu!%ered %anana
is displayed at (#5185) using the i!age banana.bmp. /ach o$$ nu!%ered %anana is
displayed at (3#185) using the i!age banana1.bmp. Banana i'a&es are t%erefore
sta!ke$ on top of ea!% ot%er / only $isplayin& t%e 'ost re!ently $isplaye$ o$$0even
banana*
3. $he te0t infor!ation indicating the nu!%er of %ananas is sho'n at (*))1))).
*. $he bananatree.bmp i!age is displayed at ())1))
5. $he virtual .ey%oard consists of #8 i!ages - a.bmp thru z.bmp. /ach i!age has the
di!ensions of 3#03#. $he i!age a.bmp is displayed at ())13))). /ach su%se&uent i!age
is displayed 'ith an offset of 33 in the x direction.
,layin& t%e 1a'e
$he user can %egin playing the Falling Banana Game after the initial scene for the ga!e
is displayed %y invo.ing the dra' the scene. $he user plays the ga!e %y selecting (i.e.1
!li!"ing) on letters of the virtual .ey%oard. For e0a!ple1 suppose the user clic.s on the #
%utton. $he resulting display is sho'n %elo',
$he letter of # of the virtual .ey%oard is grayed out indicating that it cannot %e used
again. :ll occurrences of the letter # 'ithin the rando!ly selected 'ord are displayed at
the corresponding 'hite rectangles. $he letter / occurs in # locations for the e0a!ple
given a%ove. $he e0a!ple 'ord %egins 'ith the letter / and has the letter / in the 8
position. <uppose the user clic.s on the letter $ as sho'n %elo',
$he letter $ is not found in the 'ord. $he last %anana added - =8 - falls fro! the even
(left) side as sho'n a%ove. >se mo%e&b'e!t in order to !a.e the %anana fall. $he letter $
is also grayed out. $he %anana is re!oved once it reaches the ground (y-coordinate ?
95) and the nu!%er of %ananas re!aining is e&ual to 8. $he resulting display once the
%anana reaches the ground is sho'n %elo',
Banana falls fro! even
(left) side. $he %anana
!oves fro! (#5185) to
(#51 95)
5ote the total nu!%er of %ananas has %een decre!ented %y . <uppose the user clic.s on
the letter (. ( 'as not found in the 'ord1 and the %anana falls fro! the odd (right) side
this ti!e as sho'n %elo',
Banana falls fro! odd
(right) side fro! (3#185)
to (3#195)
@nce the %anana has fallen to the ground (y-coordinate ? 95)1 the nu!%er of %ananas is
again decre!ented as sho'n %elo',
$he ga!e continues as the player clic.s on the letters that he %elieves are in the 'ord.
$he results for clic.ing on "151A141>1W1$1B are sho'n %elo',
5ote only %anana is left %ecause the user has in!orre!tly guessed 8 letters. @nly one letter
re!ains in the 'ord as 'ell. <uppose the user guesses the letter ) as sho'n %elo',
$he player is also pro!pted to play the ga!e again as sho'n %elo',
>pon entering CyD1 the console is cleared along 'ith the graphics 'indo'. : ne'
rando!ly selected 'ord is selected and the dra' !ethod displays the follo'ing scene,
$he user plays the ga!e as %efore. <uppose the user cannot guess the 'ord as sho'n
%elo', (only %anana left)
4f the player clic.s on #1 the last %anana falls and the follo'ing is displayed,
$he user can then e0it the progra! %y entering CnD.
2ata 3iel$ 2es!ription
char* fileame!
$he na!e of the file containing the 'ords used %y the ga!e. For our la%1 it 'ill %e
words1.txt.
char* "ord!
$he rando!ly selected 'ord fro! the file containing the 'ord. <et %y the
void set-ord)int rand_no*!
!ethod.
int* #ananas! $$Arra% of o#&ect num#ers for each #anana ima'e
2yna!ically allocated array of integers containing the o%3ect nu!%er for each displayed
%anana. $his array should %e allocated and set %y the dra" !ethod.
GenPoint* (e%s_ul! $$Arra% of GenPoint for upper left coordinates
: dyna!ically allocated array of 6enPoints containing the upper left coordinate for each
displayed i!age (i.e.1 letter) of the virtual .ey%oard. >seful for detecting 'hich letter 'as
pressed. Parallel array 'ith (e%s_lr. $his array should %e allocated and initiali(ed %y
the dra" !ethod.
GenPoint* (e%s_lr!
: dyna!ically allocated array of 6enPoints containing the lo'er right coordinate for
each displayed i!age (i.e.1 letter) of the virtual .ey%oard. >seful for detecting 'hich
letter 'as pressed. Parallel array 'ith (e%s_ul. $his array should %e allocated and
initiali(ed %y the dra" !ethod.
4et%o$s 2es!ription
Game)*!
2efault "onstructor. <ets datafields to 5>EE.
char* 'et,ileame)*!
6etter for fileame field.
void set,ileame)char* fn*!
<etter for fileame field.
void set-ord)int rand_no*!
<etter for "ord data field. $his !ethod perfor!s the follo'ing steps.
. @pens a file associated 'ith the fileame data field for reading (input)
#. $ests the file strea! to assure it is opened correctly
3. Beads one 'ord at a ti!e fro! the file
*. :ccu!ulates a counter for the nu!%er of 'ords in the file
5. <tops reading once the counter is e&ual to input para!eter rand_no
8. :ssigns the "ord data field to rando!ly selected 'ord
char* 'et-ord)*!
6etter for the "ord data field.
void dra")*!
2ra's the initial scene for a rando!ly selected 'ord as sho'n on page 3.
void pla%)*!
:llo's the user to play the Falling Banana 6a!e %ased on the rulesFscenarios outlined on
pages * thru ). $he user plays the ga!es %y perfor!ing the follo'ing steps,
. $he player guesses letters in the 'ord %y clic.ing on i!ages (i.e.1 letters) of the virtual
.ey%oard.
#. 2isplay all occurrences of the clic.ed letter in the corresponding 'hite rectangles
located a%ove the virtual .ey%oard.
3. : %anana is dropped fro! the tree for each guessed letter that is not found.
*. $he player looses once the total nu!%er of %ananas in the tree is ).
5. $he player 'ins if he correctly guesses all letters in the 'ord.
5%at you Sub'it
<u%!it all source code via Blac.%oard.
1ui$elines
You 'ill %e graded according to the follo'ing guidelines,
You are re&uired to su%!it all source (.cpp) files via Blac.%oard.
Your source file should %e ade&uately co!!ented and !ust contain the re&uired
header at its top.

You might also like