2036 mbed lab4

Dependencies:   4DGL-uLCD-SE PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Die.cc Source File

Die.cc

00001 #include "Die.h"
00002 #include <stdlib.h>
00003 
00004 #include "uLCD_4DGL.h"
00005 extern uLCD_4DGL uLCD;
00006 
00007 DieState Die::getCurrDieState()//setter and getter for state
00008 {
00009     return currDieState;
00010 }
00011 
00012 void Die::setCurrDieState(DieState v)
00013 {
00014     currDieState=v;
00015 }
00016 
00017 
00018 
00019 
00020 void Die::rollDie()
00021 {//function to roll die, only roll if die is in roll state
00022     if(currDieState==ROLL) {
00023         int val=rand()%6+1;
00024         value = val;
00025     }
00026 }
00027 void Die::drawDie()//function to draw die
00028 {
00029     uLCD.rectangle(x1,y1,x2,y2,Color);
00030     if (value==1) {//if statements displaying certain numbers of dots for each number
00031         uLCD.filled_circle(x1+((x2-x1)/2),(y1+(y2-y1)/2), 3, WHITE);
00032     }
00033     if (value==2) {
00034         uLCD.filled_circle(x1+((x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00035         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00036     }
00037     if (value==3) {
00038         uLCD.filled_circle(x1+((x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00039         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00040         uLCD.filled_circle(x1+((x2-x1)/2),(y1+((y2-y1)/2)), 3, WHITE);
00041     }
00042     if (value==4) {
00043         uLCD.filled_circle(x1+((x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00044         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00045         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00046         uLCD.filled_circle(x1+((x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00047     }
00048     if (value==5) {
00049         uLCD.filled_circle(x1+((x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00050         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00051         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00052         uLCD.filled_circle(x1+((x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00053         uLCD.filled_circle(x1+((x2-x1)/2),(y1+((y2-y1)/2)), 3, WHITE);
00054     }
00055     if (value==6) {
00056         uLCD.filled_circle(x1+((x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00057         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00058         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+(3*(y2-y1)/4)), 3, WHITE);
00059         uLCD.filled_circle(x1+((x2-x1)/4),(y1+((y2-y1)/4)), 3, WHITE);
00060         uLCD.filled_circle(x1+((x2-x1)/4),(y1+((y2-y1)/2)), 3, WHITE);
00061         uLCD.filled_circle(x1+(3*(x2-x1)/4),(y1+((y2-y1)/2)), 3, WHITE);
00062 
00063 
00064 
00065     }
00066 
00067 
00068 
00069 }
00070 int Die::getx1()//setters and getters for data members
00071 {
00072     return x1;
00073 }
00074 
00075 int Die::getx2()
00076 {
00077     return x2;
00078 }
00079 
00080 int Die::gety1()
00081 {
00082     return y1;
00083 }
00084 
00085 int Die::gety2()
00086 {
00087     return y2;
00088 }
00089 
00090 int Die::getColor()
00091 {
00092     return Color;
00093 }
00094 
00095 int Die::getValue()
00096 {
00097     return value;
00098 }