Recitation Class ix
Recitation Class IX
Content Style Pointer
Content n Style n Pointer
Style Some examples in Yahtzee Graphies Yindow ☒ File Edit Help Roll Dice Categories 1 2 Ones Twos Threes Fours Fives Sixs Upper Score Upper Bonus (35) Three of a Kind Four of a Kind Full House (25) Small Straight (30) Large Straight(40) Yahtzee!(50) ? Chance Lower Score TOTAL 1's turn!Click"Roll Dice"button to roll the dice
Style n Some examples in Yahtzee
#include Example 1 #include“assignment6,h“ using namespace std: /Constant definition * #define MAX_PLAYER 4 #define江加13 #define SELECTABLE -1 #define MAX_DICE 5 #define ITEMS 17 #define YAHTZEE_POINT 50 #define LARGE_STRAIGHT_POINT 40 #define SMALL_STRAIGHT_POINT 30 #define FULL HOUSE_POINT 25 #define FOUR OF A KIND 4 #define THREE OF A红D3 #define YAHTZEE 5 #define FIRST_DICE 0 #define SECOND_DICE 1 #define MIDDLE DICE 2 #define FOURTH DICE 3 #define FIFTH DICE 4 #define LARGE STRAIGHT 5 #define SMALL_STRAIGHT 4 #define DICE MAX 6 #define MINIMIZE_BONUS_POINT 63 #define BONUS POINT 35 #define RECORD_NUMBER 10 #define NAME_LONGEST 10 #define TITLE_POINT 18 #define LIST POINT 15 #define NUMBER LLX 1 #define HALF 2 #define NAME LLX 2 #define SCORE_LLX 5 #define TITLE_LLY 3.5 #define LIST LLY START 3 #define LIST_LLY_BETWEEN 0.25 /Put your function prototype here * /global data obiects defined for vou
Example 1
KandomT randlice: Example 1 //RandomT randDice(0): YahtzeeGraphicsAppT gameWindow (7.0,4.5): /Main Function //getInfo()is used to get the information static void getInfo(string name[],int AnPlayer): //rollDice is used to get the random points of five dices static void rollDice(int diceArray[]): /*initial(bool....)is used to turn all players'boolen of all categories to false *and this would bu useful to prevent user to choose a category whitch has been chosen 米 static void initial (bool blnCategory[][13]): /*initial(int....)is used to innitialize all scores to 0*/ static void initial(int score[][17]); /*reRoll is used to reRoll the categories chosen by user*/ static void reRoll(bool blnFixedDice[],int diceArray[]): /*getScoreO is used to get the score of a certain category*/ static int getScore(int diceArray[],categoryT category): //getScoreUp O is used in the function getScore.It is used to return the Upper scores static int getScoreUp (int diceArray[],categoryT category): //getScoreDown()is used in the function getScore.It is used to return the Lower scores static int getScoreDown(int diceArray[]): /*the following 4 functions are used to simplify the play0 function. *the play()function has been divided into 5 major parts. *these functions are signed by "G"at last. static void rollDiceG(int player,string name[],int diceArray[],bool blnFixedDice[]): static void checkCategoryG(int player,categoryT &category,bool blnCategory[][13]): static void UpdateScorecardG(int player,categoryT &category,int diceArray[],int score[][17]): static void doBonusG(int score[][17],int nPlayer): static void showResult (int score[][17],string name[]): woid main (void) gameWindow.initGraphics ( gamewindow.play 0:
Example 1
Example 1 void YahtzeeGraphicsAppT:play string name[4]: int nPlayer,diceArray[5],score[4][17]: bool blnFixedDice[5],blnCategory[4][13]: initial (blnCategory): initial(score): categoryT category: getInfo (name,nPlayer): SetUpGame (name,nPlayer): for (int n=0;n 13;nt+) for (int player =0:player nPlayer:player++) rollDiceG (player,name,diceArray,blnFixedDice): checkCategoryG(player,category,blnCategory): UpdateScorecardG(player,category,diceArray,score): doBonusG(score,nPlayer): showResult (score,name): void getInfo(string name[],int &nPlayer) do nPlayer gameWindow.readInt("You may play Yahtzee with up to 4 players.nHow many will be playing while (nPlayer 4): for (int i =0:i nPlayer:it+) do cout name[i]: while (name[i].lengthO 10): } void initial (bool blnCategory[][13])
Example 1
voia initial (Dool DInLategoryLJLI3JJ Example 1 for (int j=0:j<4:j++) for (int i=0:i <13;i+t) blnCategory[j][i]false; void initial(int score[][17]) for (int i=0;i<4;i++) for (int j=0;j<17:j++) score[i][j]0; } void rollDice(int diceArray[]) for (int i=0;i<5;it+) diceArray[i]=randDice.nextInteger(1,6); } void reRoll(bool blnFixedDice[],int diceArray[]) for (int i =0;i <5;itt) { if (blnFixedDice[i]=false) diceArray[i]randDice.nextInteger (1,6): } int getScoreUp(int diceArray[],categoryT category) int score 0; for (int i=0;i<5:i+t)\ if (diceArray[i]==(int)category +1) score +diceArray[i]:
Example 1
T44+uuGw64wU+aaa·7 Example 2 #include "assignment6.h" using namespace std: /Constant definition * #define MAX_PLAYER 4 #define灯o13 #define SELECTABLE -1 #define MAX DICE 5 #define ITEMS 17 #define YAHTZEE_POINT 50 #define LARGE_STRAIGHT_POINT 40 #define SMALL STRAIGHT POINT 30 #define FULL HOUSE POINT 25 #define FOUR_OF_AT证4 #define THREE0F_A江D3 #define YAHTZEE 5 #define FIRST DICE 0 #define SECOND DICE 1 #define MIDDLE DICE 2 #define FOURTH DICE 3 #define FIFTH DICE 4 #define LARGE STRAIGHT 5 #define SMALL STRAIGHT 4 #define DICE_MAX 6 #define MINIMIZE BONUS_POINT 63 #define BONUS POINT 35 #define RECORD NUMBER 10 #define NAME LONGEST 10 #define TITLE POINT 18 #define LIST POINT 15 #define NUMBER LLX 1 #define HALF 2 #define NAME LLX 2 #define SCORE LLX 5 #define TITLE LLY 3.5 #define LIST_LLY_START 3 #define LIST LLY BETWEEN 0.25 1m 1
Example 2
YahtzeeGraphicsAppT gameWindow (7.0,4.5); Example 2 void main (void) gameWindow.initGraphics O: gameWindow.printLine("you may play the Yahtzee with up to 4 player."endl,"How many will be playing int nPlayer,player,dice,n: int diceArray[MAX_DICE],score[KIND][MAX_PLAYER],upper_score [MAX_PLAYER],upper_bonus [MAX_PLAYER],1ow string playerNames [MAX_PLAYER]: bool blnFixedDice[MAX_DICE],finish; categoryT category: do nPlayer=gameWindow.readInt("the number should range from [1 to 4]:"): while (nPlayer 4 nPlayer <1); for (player=0:player nPlayer:player++) gameWindow.printLine ("Player's #"player+1,s name.Your name should be less than "NAME_LONGES playerNames[player]=gameWindow.readString(":") } for(player=0:player MAX_PLAYER:player++)/f??§?? upper_bonus [player]=0; total[player]=0: for (n=0:n KIND:n++) score[n][player]=0: isEmpty[n][player]=1: SetUpGame (playerNames,nPlayer): while(!finish) for (player=0:player nPlayer:player++) yprintf(playerNames[player]+ms turn.Click-Roll Dice-botton to roll the dice")://?7??8? WaitForPlayerToClickRoll(player,playerNames): 4
Example 2
Displaylice ldiceArrayJ: Example 2 yprintf(playerNames[player]+"select the dice you want to re-roll and click-Roll Again-"):! WaitForPlayerToSelectDice (blnFixedDice,diceArray): for (dice=0:dice 5;dice++) if(!blnFixedDice[dice]==true) diceArray[dice]=randDice.nextInteger (1,6): DisplayDice(diceArray): yprintf(playerNames[player]+"select the dice you want to re-roll and click-Roll Again-"):/ WaitForPlayerToSelectDice (blnFixedDice,diceArray): for (dice=0:dice 5;dice++) if(!blnFixedDice[dice]==true) diceArray[dice]=randDice.nextInteger (1,6): } DisplayDice(diceArray): yprintf(playerNames[player]+"select a category")://6????? category=WaitForPlayerToSelectCategory(player): while(isEmpty[category][player]==0) category=WaitForPlayerToSelectCategory(player): if(isEmpty[category][player]==1) break; isEmpty[category][player]=0: if (MagicCheckCategory(diceArray,category)==true)//??????? switch (category) case 0:case 1:case 2:case 3:case 4:case 5: for (dice=0:dice 5:dice++) if(diceArray[dice]==1+category) score[category][player]+=diceArray[dice]:
Example 2