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 <1 nPlayer >4): for (int i =0:i nPlayer:it+) do cout <"Player #"<i+1 <s name (name should not be more than 10 letter)in"; cin >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