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@0:8ee41d0deef7, 2021-10-26 (annotated)
- Committer:
- klin315
- Date:
- Tue Oct 26 05:10:36 2021 +0000
- Revision:
- 0:8ee41d0deef7
- Child:
- 1:3cd6e5938144
ok
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| klin315 | 0:8ee41d0deef7 | 1 | #include "die.h" |
| klin315 | 0:8ee41d0deef7 | 2 | |
| klin315 | 0:8ee41d0deef7 | 3 | |
| klin315 | 0:8ee41d0deef7 | 4 | //Constructors |
| klin315 | 0:8ee41d0deef7 | 5 | Die::Die(){ |
| klin315 | 0:8ee41d0deef7 | 6 | value = 1; |
| klin315 | 0:8ee41d0deef7 | 7 | } |
| klin315 | 0:8ee41d0deef7 | 8 | |
| klin315 | 0:8ee41d0deef7 | 9 | Die::Die(int val){ |
| klin315 | 0:8ee41d0deef7 | 10 | value = val; |
| klin315 | 0:8ee41d0deef7 | 11 | } |
| klin315 | 0:8ee41d0deef7 | 12 | |
| klin315 | 0:8ee41d0deef7 | 13 | void Die::setValue(int val){ |
| klin315 | 0:8ee41d0deef7 | 14 | value = val; |
| klin315 | 0:8ee41d0deef7 | 15 | } |
| klin315 | 0:8ee41d0deef7 | 16 | |
| klin315 | 0:8ee41d0deef7 | 17 | int Die::getValue(){ |
| klin315 | 0:8ee41d0deef7 | 18 | return value; |
| klin315 | 0:8ee41d0deef7 | 19 | } |
| klin315 | 0:8ee41d0deef7 | 20 | //Public Methods |
| klin315 | 0:8ee41d0deef7 | 21 | void Die::rollDie(){ |
| klin315 | 0:8ee41d0deef7 | 22 | value = rand()%6+1; |
| klin315 | 0:8ee41d0deef7 | 23 | } |
| klin315 | 0:8ee41d0deef7 | 24 | |
| klin315 | 0:8ee41d0deef7 | 25 | void Die::displayOneDice(int pos, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 26 | int yPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 27 | int xPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 28 | |
| klin315 | 0:8ee41d0deef7 | 29 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 30 | |
| klin315 | 0:8ee41d0deef7 | 31 | screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 32 | screen.filled_circle(xPos ,yPos, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 33 | } |
| klin315 | 0:8ee41d0deef7 | 34 | |
| klin315 | 0:8ee41d0deef7 | 35 | void Die::displayTwoDice(int pos, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 36 | int yPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 37 | int xPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 38 | |
| klin315 | 0:8ee41d0deef7 | 39 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 40 | |
| klin315 | 0:8ee41d0deef7 | 41 | |
| klin315 | 0:8ee41d0deef7 | 42 | screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 43 | screen.filled_circle(xPos+12,yPos+12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 44 | screen.filled_circle(xPos-12,yPos-12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 45 | } |
| klin315 | 0:8ee41d0deef7 | 46 | |
| klin315 | 0:8ee41d0deef7 | 47 | void Die::displayThreeDice(int pos, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 48 | int xPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 49 | int yPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 50 | |
| klin315 | 0:8ee41d0deef7 | 51 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 52 | |
| klin315 | 0:8ee41d0deef7 | 53 | screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 54 | screen.filled_circle(xPos+12,yPos+12, 5 ,BLACK); |
| klin315 | 0:8ee41d0deef7 | 55 | screen.filled_circle(xPos,yPos, 5 ,BLACK); |
| klin315 | 0:8ee41d0deef7 | 56 | screen.filled_circle(xPos - 12,yPos - 12, 5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 57 | } |
| klin315 | 0:8ee41d0deef7 | 58 | |
| klin315 | 0:8ee41d0deef7 | 59 | void Die::displayFourDice(int pos, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 60 | int yPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 61 | int xPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 62 | |
| klin315 | 0:8ee41d0deef7 | 63 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 64 | |
| klin315 | 0:8ee41d0deef7 | 65 | screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 66 | screen.filled_circle(xPos+12 , yPos+12,5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 67 | screen.filled_circle(xPos + 12, yPos - 12, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 68 | screen.filled_circle(xPos - 12, yPos + 12, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 69 | screen.filled_circle(xPos - 12, yPos - 12, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 70 | } |
| klin315 | 0:8ee41d0deef7 | 71 | |
| klin315 | 0:8ee41d0deef7 | 72 | void Die::displayFiveDice(int pos, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 73 | int yPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 74 | int xPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 75 | |
| klin315 | 0:8ee41d0deef7 | 76 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 77 | |
| klin315 | 0:8ee41d0deef7 | 78 | screen.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 79 | screen.filled_circle(xPos,yPos,5 , BLACK); |
| klin315 | 0:8ee41d0deef7 | 80 | screen.filled_circle(xPos+12, yPos+12, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 81 | screen.filled_circle(xPos+12,yPos-12, 5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 82 | screen.filled_circle(xPos-12,yPos+12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 83 | screen.filled_circle(xPos-12,yPos-12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 84 | } |
| klin315 | 0:8ee41d0deef7 | 85 | |
| klin315 | 0:8ee41d0deef7 | 86 | void Die::displaySixDice(int pos, uLCD_4DGL& scr){ |
| klin315 | 0:8ee41d0deef7 | 87 | int yPos = 42*(((pos-1)/3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 88 | int xPos = 42*(((pos-1)%3)+1)-21; |
| klin315 | 0:8ee41d0deef7 | 89 | |
| klin315 | 0:8ee41d0deef7 | 90 | int width = 20; |
| klin315 | 0:8ee41d0deef7 | 91 | |
| klin315 | 0:8ee41d0deef7 | 92 | scr.filled_rectangle(xPos-width, yPos-width, xPos+width, yPos+width, WHITE); |
| klin315 | 0:8ee41d0deef7 | 93 | scr.filled_circle(xPos-12,yPos,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 94 | scr.filled_circle(xPos+12,yPos,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 95 | scr.filled_circle(xPos+12,yPos+12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 96 | scr.filled_circle(xPos+12,yPos-12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 97 | scr.filled_circle(xPos-12,yPos+12,5,BLACK); |
| klin315 | 0:8ee41d0deef7 | 98 | scr.filled_circle(xPos-12,yPos-12,5, BLACK); |
| klin315 | 0:8ee41d0deef7 | 99 | } |
| klin315 | 0:8ee41d0deef7 | 100 | |
| klin315 | 0:8ee41d0deef7 | 101 | //display Die based on value |
| klin315 | 0:8ee41d0deef7 | 102 | void Die::displayDie(int position, uLCD_4DGL& screen){ |
| klin315 | 0:8ee41d0deef7 | 103 | if(value == 1) { |
| klin315 | 0:8ee41d0deef7 | 104 | displayOneDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 105 | } |
| klin315 | 0:8ee41d0deef7 | 106 | if(value == 2){ |
| klin315 | 0:8ee41d0deef7 | 107 | displayTwoDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 108 | } |
| klin315 | 0:8ee41d0deef7 | 109 | if(value == 3){ |
| klin315 | 0:8ee41d0deef7 | 110 | displayThreeDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 111 | } |
| klin315 | 0:8ee41d0deef7 | 112 | if(value == 4){ |
| klin315 | 0:8ee41d0deef7 | 113 | displayFourDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 114 | } |
| klin315 | 0:8ee41d0deef7 | 115 | if(value == 5) { |
| klin315 | 0:8ee41d0deef7 | 116 | displayFiveDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 117 | } |
| klin315 | 0:8ee41d0deef7 | 118 | if(value == 6){ |
| klin315 | 0:8ee41d0deef7 | 119 | displaySixDice(position,screen); |
| klin315 | 0:8ee41d0deef7 | 120 | } |
| klin315 | 0:8ee41d0deef7 | 121 | } |
| klin315 | 0:8ee41d0deef7 | 122 | |
| klin315 | 0:8ee41d0deef7 | 123 | |
| klin315 | 0:8ee41d0deef7 | 124 | |
| klin315 | 0:8ee41d0deef7 | 125 | |
| klin315 | 0:8ee41d0deef7 | 126 | |
| klin315 | 0:8ee41d0deef7 | 127 | |
| klin315 | 0:8ee41d0deef7 | 128 | |
| klin315 | 0:8ee41d0deef7 | 129 |