Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE PinDetect
die.cpp
00001 /** 00002 Author: Kevin Lin 00003 Title: Lab 4 00004 Date: October 22 2021 00005 Description: Source file of a dice object 00006 00007 **/ 00008 00009 #include "die.h" 00010 00011 00012 Die::Die(){ 00013 value = 1; 00014 } 00015 00016 Die::Die(int val){ 00017 value = val; 00018 } 00019 00020 void Die::setValue(int val){ 00021 value = val; 00022 } 00023 00024 int Die::getValue(){ 00025 return value; 00026 } 00027 //Public Methods 00028 void Die::rollDie(){ 00029 value = rand()%6+1; 00030 } 00031 00032 void Die::displayOneDice(int pos, uLCD_4DGL& screen){ 00033 int yPos = 42*(((pos-1)/3)+1)-21; 00034 int xPos = 42*(((pos-1)%3)+1)-21; 00035 00036 int width = 20; 00037 00038 screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00039 screen.filled_circle(xPos ,yPos, 5, BLACK); 00040 } 00041 00042 void Die::displayTwoDice(int pos, uLCD_4DGL& screen){ 00043 int yPos = 42*(((pos-1)/3)+1)-21; 00044 int xPos = 42*(((pos-1)%3)+1)-21; 00045 00046 int width = 20; 00047 00048 00049 screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00050 screen.filled_circle(xPos+12,yPos+12,5,BLACK); 00051 screen.filled_circle(xPos-12,yPos-12,5,BLACK); 00052 } 00053 00054 void Die::displayThreeDice(int pos, uLCD_4DGL& screen){ 00055 int xPos = 42*(((pos-1)/3)+1)-21; 00056 int yPos = 42*(((pos-1)%3)+1)-21; 00057 00058 int width = 20; 00059 00060 screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00061 screen.filled_circle(xPos+12,yPos+12, 5 ,BLACK); 00062 screen.filled_circle(xPos,yPos, 5 ,BLACK); 00063 screen.filled_circle(xPos - 12,yPos - 12, 5,BLACK); 00064 } 00065 00066 void Die::displayFourDice(int pos, uLCD_4DGL& screen){ 00067 int yPos = 42*(((pos-1)/3)+1)-21; 00068 int xPos = 42*(((pos-1)%3)+1)-21; 00069 00070 int width = 20; 00071 00072 screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00073 screen.filled_circle(xPos+12 , yPos+12,5, BLACK); 00074 screen.filled_circle(xPos + 12, yPos - 12, 5, BLACK); 00075 screen.filled_circle(xPos - 12, yPos + 12, 5, BLACK); 00076 screen.filled_circle(xPos - 12, yPos - 12, 5, BLACK); 00077 } 00078 00079 void Die::displayFiveDice(int pos, uLCD_4DGL& screen){ 00080 int yPos = 42*(((pos-1)/3)+1)-21; 00081 int xPos = 42*(((pos-1)%3)+1)-21; 00082 00083 int width = 20; 00084 00085 screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00086 screen.filled_circle(xPos,yPos,5 , BLACK); 00087 screen.filled_circle(xPos+12, yPos+12, 5, BLACK); 00088 screen.filled_circle(xPos+12,yPos-12, 5, BLACK); 00089 screen.filled_circle(xPos-12,yPos+12,5,BLACK); 00090 screen.filled_circle(xPos-12,yPos-12,5,BLACK); 00091 } 00092 00093 void Die::displaySixDice(int pos, uLCD_4DGL& scr){ 00094 int yPos = 42*(((pos-1)/3)+1)-21; 00095 int xPos = 42*(((pos-1)%3)+1)-21; 00096 00097 int width = 20; 00098 00099 scr.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); 00100 scr.filled_circle(xPos-12,yPos,5,BLACK); 00101 scr.filled_circle(xPos+12,yPos,5,BLACK); 00102 scr.filled_circle(xPos+12,yPos+12,5,BLACK); 00103 scr.filled_circle(xPos+12,yPos-12,5,BLACK); 00104 scr.filled_circle(xPos-12,yPos+12,5,BLACK); 00105 scr.filled_circle(xPos-12,yPos-12,5, BLACK); 00106 } 00107 00108 //display Die based on value 00109 void Die::displayDie(int position, uLCD_4DGL& screen){ 00110 if(value == 1) { 00111 displayOneDice(position,screen); 00112 } 00113 if(value == 2){ 00114 displayTwoDice(position,screen); 00115 } 00116 if(value == 3){ 00117 displayThreeDice(position,screen); 00118 } 00119 if(value == 4){ 00120 displayFourDice(position,screen); 00121 } 00122 if(value == 5) { 00123 displayFiveDice(position,screen); 00124 } 00125 if(value == 6){ 00126 displaySixDice(position,screen); 00127 } 00128 } 00129 00130 00131 00132 00133 00134 00135 00136
Generated on Tue Jul 25 2023 16:17:08 by
1.7.2