Dependencies:   Led-libary TextLCD mbed

Committer:
ogris
Date:
Fri Apr 01 13:19:40 2016 +0000
Revision:
17:0e7af2d4cd63
Parent:
16:9a868ab2a5cb
Child:
18:d747cf2de3bf
Alle nummern hinzugef?gt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ladner 0:e97a6a69fe4b 1 #include "mbed.h"
ladner 1:0eaa7682f7e1 2 #include "WS2812B.h"
ladner 13:cb068deacb6c 3 #include "TextLCD.h"
ladner 0:e97a6a69fe4b 4
ladner 0:e97a6a69fe4b 5 I2C i2c(P0_5,P0_4);
ladner 0:e97a6a69fe4b 6 Serial port(P0_19,P0_18);
ladner 0:e97a6a69fe4b 7 BusOut myled(P1_8,P1_9,P1_10,P1_11,P1_0,P1_1,P1_3,P1_4,P1_6,P1_7,P1_12,P1_13);
ladner 0:e97a6a69fe4b 8 AnalogIn ldr(P0_12);
ladner 0:e97a6a69fe4b 9 AnalogIn poti(P0_11);
ladner 1:0eaa7682f7e1 10 //BusOut rgb(P0_9,P1_15,P0_21);
ladner 1:0eaa7682f7e1 11
ladner 1:0eaa7682f7e1 12 RGBOut rgb(P0_21,P0_9,P1_15);
ladner 1:0eaa7682f7e1 13
ladner 1:0eaa7682f7e1 14 InterruptIn Button0(P0_1);
ladner 0:e97a6a69fe4b 15 InterruptIn Button1(P1_16);
ladner 0:e97a6a69fe4b 16 InterruptIn Button2(P0_23);
ladner 1:0eaa7682f7e1 17 InterruptIn Button3(P0_10);
ladner 1:0eaa7682f7e1 18 InterruptIn Button4(P0_15);
ladner 13:cb068deacb6c 19 BusIn btn(P1_16,P0_23,P0_10,P0_15,P0_1);
ladner 0:e97a6a69fe4b 20
ladner 13:cb068deacb6c 21 LedOut Feld (p6);//P6
ladner 13:cb068deacb6c 22 LedOut Home (p7);//P7
ladner 13:cb068deacb6c 23 LedOut Dice (p8);//P8
ladner 13:cb068deacb6c 24 //-> Würfel (ersten 3 LED in Binär-4. LED für 7. Zustand), Spieler, Referenz(auch RGB am board)
ladner 13:cb068deacb6c 25
ladner 13:cb068deacb6c 26 TextLCD lcd(p21, p22, p23, p24, p25, p26,TextLCD::LCD20x4);
ladner 13:cb068deacb6c 27
ladner 13:cb068deacb6c 28 InterruptIn DD_A(p29);//P29
ladner 13:cb068deacb6c 29 InterruptIn DD_B(p30);//P30
ladner 13:cb068deacb6c 30 InterruptIn DD_C(p35);//P35
ladner 13:cb068deacb6c 31 DigitalIn DD_D(p35);
ladner 13:cb068deacb6c 32 BusIn DD(p29,p30);//P29,P30
ladner 13:cb068deacb6c 33
ladner 13:cb068deacb6c 34 //Dice
ladner 1:0eaa7682f7e1 35 Timer Random;
ladner 13:cb068deacb6c 36 Timer RandomDice;
ladner 1:0eaa7682f7e1 37
ladner 1:0eaa7682f7e1 38 Ticker DiceAnim;
ladner 1:0eaa7682f7e1 39 void DiceRun();
ladner 1:0eaa7682f7e1 40 void setDice(char number);
ladner 1:0eaa7682f7e1 41 void DicePrint();
ladner 13:cb068deacb6c 42 void DiceCal(); //umrechning des 7.Zustands in eine Zahl zwischen 1 & 6
ladner 1:0eaa7682f7e1 43 char dicePos = 0;
ladner 1:0eaa7682f7e1 44 char diceEn = 0;
ladner 1:0eaa7682f7e1 45 char diceTick = 0;
ladner 1:0eaa7682f7e1 46 char diceNum = 0;
ladner 1:0eaa7682f7e1 47 int16_t diceDecode [7]= {0x1,0x88,0x89,0xAA,0xAB,0x1BA,0x154};
ladner 13:cb068deacb6c 48 //Game
ladner 1:0eaa7682f7e1 49 #define Feldgrose 10
ladner 1:0eaa7682f7e1 50 #define Spieler 4
ladner 1:0eaa7682f7e1 51 #define Steine 4
ladner 1:0eaa7682f7e1 52
ladner 1:0eaa7682f7e1 53 char PlayPos[Spieler*Steine]; //Zahl zwischen 0 & 47 ((0xC0 -> Spieler)>>2 / 0x03 -> Stein)
ladner 13:cb068deacb6c 54 char Start[Spieler*Steine]; //Enthält den Index für PlayPos (nur das 'normale' Spielfend)
ladner 13:cb068deacb6c 55 char Ziel[Spieler*Steine]; //Enthält den Index für PlayPos (nur das 'normale' Spielfend)
ladner 1:0eaa7682f7e1 56 char Drann; //Spieler, der drann ist
ladner 1:0eaa7682f7e1 57 char count; //Für 6er & mehrfaches Würfeln beim Ansetzen
ladner 1:0eaa7682f7e1 58 char last[Spieler]; //zuletzt benutzte Spielstein, der zuletzt benutzt wurde
ladner 1:0eaa7682f7e1 59 char moglich[Steine];
ladner 1:0eaa7682f7e1 60 char selected; //der aktuell ausgewählte Zug
ladner 1:0eaa7682f7e1 61 char Field[Spieler*Feldgrose]; //Enthält den Index für PlayPos (nur das 'normale' Spielfend)
ladner 1:0eaa7682f7e1 62 void FieldPrint(); //Ausgabe auf Com-Port
ladner 1:0eaa7682f7e1 63 void FieldGenerate(); //Berechnung von PlayPos auf Start, Ziel, Field
ladner 1:0eaa7682f7e1 64 void FeldPrint(); //Ausgabe von Field auf den Led-Streifen (Feld) der Farben
ladner 1:0eaa7682f7e1 65 void GameCal();
ladner 1:0eaa7682f7e1 66 Ticker MoveAnim;
ladner 1:0eaa7682f7e1 67 void MoveRun();
ladner 1:0eaa7682f7e1 68 char MoveShow;
ladner 13:cb068deacb6c 69 void ColorPrint(uint32_t color);
ladner 13:cb068deacb6c 70 //Animations
ladner 13:cb068deacb6c 71 char AnimField[Spieler*Feldgrose];
ladner 13:cb068deacb6c 72 char AnimStart[Spieler*Steine];
ladner 13:cb068deacb6c 73 char AnimZiel[Spieler*Steine];
ladner 13:cb068deacb6c 74 char AnimPos[Spieler*Steine];
ladner 13:cb068deacb6c 75 char AnimDo; //Feld_Animieren,Start Animieren, Ziel Animierenw
ladner 13:cb068deacb6c 76 void AnimCal();
ladner 13:cb068deacb6c 77 //Core Interactions
ladner 13:cb068deacb6c 78 void reset();
ladner 1:0eaa7682f7e1 79 void MoveDo();
ladner 13:cb068deacb6c 80 void moveNext();
ladner 13:cb068deacb6c 81 void moveLast();
ladner 13:cb068deacb6c 82 void DiceStart();
ladner 13:cb068deacb6c 83 void DiceStop();
ladner 13:cb068deacb6c 84 //Button entprellung (funktioniert nicht...)
ladner 13:cb068deacb6c 85 void btn0();
ladner 13:cb068deacb6c 86 void btn1();
ladner 13:cb068deacb6c 87 void btn2();
ladner 13:cb068deacb6c 88 void btn3();
ladner 13:cb068deacb6c 89 void btn4();
ladner 13:cb068deacb6c 90 char btnLast;
ladner 13:cb068deacb6c 91 //Farben
ladner 13:cb068deacb6c 92 uint32_t Farben[Spieler]; //Berechnete Hellichkeiten der Speiler fertig zur Ausgabe...
ladner 13:cb068deacb6c 93 uint32_t Background = 0; //Hintergrund (Leerfeld)
ladner 13:cb068deacb6c 94 uint32_t DiseC = 0x00FF00; //Würfelfarbe
ladner 13:cb068deacb6c 95 void ColorPrint(uint32_t color); //vorher den Header senden (manuell...)
ladner 13:cb068deacb6c 96
ladner 13:cb068deacb6c 97 char DD_last;
ladner 13:cb068deacb6c 98 char DD_d;
ladner 13:cb068deacb6c 99
ladner 13:cb068deacb6c 100 void dreh();
ladner 13:cb068deacb6c 101 void druck();
ladner 13:cb068deacb6c 102
ladner 13:cb068deacb6c 103 void up();
ladner 13:cb068deacb6c 104 void down();
ladner 13:cb068deacb6c 105 void accept();
ladner 13:cb068deacb6c 106 void exit();
ladner 13:cb068deacb6c 107 void print_menu();
ladner 13:cb068deacb6c 108 void print_pos();
ladner 13:cb068deacb6c 109 void print_default();
ladner 13:cb068deacb6c 110 void posUpdate();
ladner 13:cb068deacb6c 111 char ausfuehren(uint32_t postion);
ladner 13:cb068deacb6c 112
ladner 13:cb068deacb6c 113 //string test ("");
ladner 13:cb068deacb6c 114 // "1234567890123456789","1234567890123456789","1234567890123456789","1234567890123456789", ,"1234567890123456789","1234567890123456789","1234567890123456789",
ogris 16:9a868ab2a5cb 115 const char * const text_ln0[] = {"MENU: ","Spiel-Menu: ","Anzeige-Menu: ","Speicher-Menu: ","ERROR ","7.Zustand-Menu: ","Farben-Menu: ","Spiel-Menu: ","Spielregeln-Menu: ","Spielregeln-Menu: ","Hell./Sp.Led-Menu: ","Config-Menu: ","Autplay-zeit ","Autplay-Menu: ","Wurfel-Menu: ","Ofline/Com-Menu: ","Enable/Manuell ","Farben ","Helligkeit Wert ","Sp.Led-Verhalten ","Farbverhalten ","Farbverhalten def ","Helligkeit Wert "};
ogris 16:9a868ab2a5cb 116 const char * const text_ln1[] = {"Spiel ","7.Zustand ","Farben ","Spiel "," ","Disable "," ","Laden ","Taktik 1 ","Smeiszwang <I/0> ","Wert: <wert> ","Laden ","normal ","Zeit ","Farbverhalten ","New "," ","R: ","100% ","Verhalten 1 ","fixe Farbe ","Standart ","100% "};
ogris 16:9a868ab2a5cb 117 const char * const text_ln2[] = {"Anzeige ","Spielregeln ","Hellichkeit/Sp.Led ","Config. "," ","kleinstmoglich ","SP: 1 2 3 4 ","Speichern ","Taktik 2 ","Go Home first <I/0>","Sp.Led-Verhalten ","Speichern ","x2 ","Agro/Taktik ","Farb def ","Reset "," ","G: ","75% ","Verhalten 2 ","Spieler Farbe ","erlaubt ","75% "};
ogris 16:9a868ab2a5cb 118 const char * const text_ln3[] = {"Speicher ","Autoplay ","Wurfel ","Ofline/Com "," ","grostmoglich "," ","Reset ","Taktik 3 ","Ausfahrzwang <I/0> ","Andert: <wert> fehl","Reset ","x4 ","Enable/Manuell ","Hellichkeit ","Com "," ","B: ","50%b ","Verhalten 3 ","3 Farben ","verboten ","50% "};
ogris 17:0e7af2d4cd63 119 char textPos[] = {0x0 ,0x1 ,0x2 ,0x3 ,0x4 ,0x5 ,0x6 ,0x7 ,0x4 ,0x9 ,0xA ,0xB ,0x4 ,0xD ,0xE ,0xF ,0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16,0x17,0x18,0x19,0x12,0x1B,0x1C,0xC,0x14,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x11,0x27,0x28,0x29,0x13,0x2B,0x10,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x16,0x3F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F};
ladner 13:cb068deacb6c 120
ladner 13:cb068deacb6c 121 char VHS = 0;
ladner 13:cb068deacb6c 122 char mSelected[256];
ladner 13:cb068deacb6c 123 char depth = 0;
ladner 13:cb068deacb6c 124 uint32_t postion = 0;//Dafür brauche ich die Methode
ladner 13:cb068deacb6c 125 char mDiceEn = 5;
ladner 13:cb068deacb6c 126
ladner 13:cb068deacb6c 127
ladner 13:cb068deacb6c 128 void btn0()
ladner 13:cb068deacb6c 129 {
ladner 13:cb068deacb6c 130 if((btnLast&0x10)==(btn&0x10))
ladner 13:cb068deacb6c 131 return;
ladner 13:cb068deacb6c 132 else
ladner 13:cb068deacb6c 133 {
ladner 13:cb068deacb6c 134 if((btn&0x10)>0)
ladner 13:cb068deacb6c 135 reset();
ladner 13:cb068deacb6c 136 else
ladner 13:cb068deacb6c 137 /*DoNothing*/;
ladner 13:cb068deacb6c 138 }
ladner 13:cb068deacb6c 139 btnLast=(btnLast&(0x1F-0x10))|(btn&0x10);
ladner 13:cb068deacb6c 140 }
ladner 13:cb068deacb6c 141
ladner 13:cb068deacb6c 142 void btn1()
ladner 13:cb068deacb6c 143 {
ladner 13:cb068deacb6c 144 if((btnLast&0x01)==(btn&0x01))
ladner 13:cb068deacb6c 145 return;
ladner 13:cb068deacb6c 146 else
ladner 13:cb068deacb6c 147 {
ladner 13:cb068deacb6c 148 if((btn&0x01)>0)
ladner 13:cb068deacb6c 149 DiceStart();
ladner 13:cb068deacb6c 150 else
ladner 13:cb068deacb6c 151 DiceStop();
ladner 13:cb068deacb6c 152 }
ladner 13:cb068deacb6c 153 btnLast=(btnLast&(0x1F-0x01))|(btn&0x01);
ladner 13:cb068deacb6c 154 }
ladner 13:cb068deacb6c 155
ladner 13:cb068deacb6c 156 void btn2()
ladner 13:cb068deacb6c 157 {
ladner 13:cb068deacb6c 158 if((btnLast&0x02)==(btn&0x02))
ladner 13:cb068deacb6c 159 return;
ladner 13:cb068deacb6c 160 else
ladner 13:cb068deacb6c 161 {
ladner 13:cb068deacb6c 162 if((btn&0x02)>0)
ladner 13:cb068deacb6c 163 moveNext();
ladner 13:cb068deacb6c 164 else
ladner 13:cb068deacb6c 165 /*DoNothing*/;
ladner 13:cb068deacb6c 166 }
ladner 13:cb068deacb6c 167 btnLast=(btnLast&(0x1F-0x02))|(btn&0x02);
ladner 13:cb068deacb6c 168 }
ladner 13:cb068deacb6c 169
ladner 13:cb068deacb6c 170 void btn3()
ladner 13:cb068deacb6c 171 {
ladner 13:cb068deacb6c 172 if((btnLast&0x04)==(btn&0x04))
ladner 13:cb068deacb6c 173 return;
ladner 13:cb068deacb6c 174 else
ladner 13:cb068deacb6c 175 {
ladner 13:cb068deacb6c 176 if((btn&0x04)>0)
ladner 13:cb068deacb6c 177 moveLast();
ladner 13:cb068deacb6c 178 else
ladner 13:cb068deacb6c 179 /*DoNothing*/;
ladner 13:cb068deacb6c 180 }
ladner 13:cb068deacb6c 181 btnLast=(btnLast&(0x1F-0x04))|(btn&0x04);
ladner 13:cb068deacb6c 182 }
ladner 13:cb068deacb6c 183
ladner 13:cb068deacb6c 184 void btn4()
ladner 13:cb068deacb6c 185 {
ladner 13:cb068deacb6c 186 if((btnLast&0x08)==(btn&0x08))
ladner 13:cb068deacb6c 187 return;
ladner 13:cb068deacb6c 188 else
ladner 13:cb068deacb6c 189 {
ladner 13:cb068deacb6c 190 if((btn&0x08)>0)
ladner 13:cb068deacb6c 191 MoveDo();
ladner 13:cb068deacb6c 192 else
ladner 13:cb068deacb6c 193 /*DoNothing*/;
ladner 13:cb068deacb6c 194 }
ladner 13:cb068deacb6c 195 btnLast=(btnLast&(0x1F-0x08))|(btn&0x08);
ladner 13:cb068deacb6c 196 }
ladner 1:0eaa7682f7e1 197
ladner 1:0eaa7682f7e1 198 void reset()
ladner 1:0eaa7682f7e1 199 {
ladner 1:0eaa7682f7e1 200 MoveAnim.detach();
ladner 1:0eaa7682f7e1 201 DiceAnim.detach();
ladner 1:0eaa7682f7e1 202 for(char i = 0;i<Spieler*Steine;i++)
ladner 1:0eaa7682f7e1 203 PlayPos[i]=i%4;
ladner 13:cb068deacb6c 204 for (char i = 0; i < Spieler; i++)
ladner 13:cb068deacb6c 205 last[i]=0;
ladner 1:0eaa7682f7e1 206 Drann=0;
ladner 1:0eaa7682f7e1 207 diceEn=0;
ladner 2:3a90b20958ff 208 myled = myled&0xF0F;
ladner 1:0eaa7682f7e1 209 DicePrint();
ladner 1:0eaa7682f7e1 210 rgb.set_RGB(0);
ladner 1:0eaa7682f7e1 211 FieldGenerate();
ladner 1:0eaa7682f7e1 212 FieldPrint();
ladner 1:0eaa7682f7e1 213 FeldPrint();
ladner 1:0eaa7682f7e1 214 }
ladner 1:0eaa7682f7e1 215
ladner 1:0eaa7682f7e1 216 void Control()
ladner 1:0eaa7682f7e1 217 {
ladner 1:0eaa7682f7e1 218 while(port.readable ())
ladner 0:e97a6a69fe4b 219 {
ladner 1:0eaa7682f7e1 220 char message = port.getc();
ladner 1:0eaa7682f7e1 221 switch(message)
ladner 1:0eaa7682f7e1 222 {
ladner 1:0eaa7682f7e1 223 case '1':
ladner 1:0eaa7682f7e1 224 setDice(1);
ladner 1:0eaa7682f7e1 225 break;
ladner 1:0eaa7682f7e1 226 case '2':
ladner 1:0eaa7682f7e1 227 setDice(2);
ladner 1:0eaa7682f7e1 228 break;
ladner 1:0eaa7682f7e1 229 case '3':
ladner 1:0eaa7682f7e1 230 setDice(3);
ladner 1:0eaa7682f7e1 231 break;
ladner 1:0eaa7682f7e1 232 case '4':
ladner 1:0eaa7682f7e1 233 setDice(4);
ladner 1:0eaa7682f7e1 234 break;
ladner 1:0eaa7682f7e1 235 case '5':
ladner 1:0eaa7682f7e1 236 setDice(5);
ladner 1:0eaa7682f7e1 237 break;
ladner 1:0eaa7682f7e1 238 case '6':
ladner 1:0eaa7682f7e1 239 setDice(6);
ladner 1:0eaa7682f7e1 240 break;
ladner 1:0eaa7682f7e1 241 case '7':
ladner 1:0eaa7682f7e1 242 setDice(7);
ladner 1:0eaa7682f7e1 243 break;
ladner 1:0eaa7682f7e1 244 case 'A':
ladner 1:0eaa7682f7e1 245 DiceStart();
ladner 1:0eaa7682f7e1 246 break;
ladner 1:0eaa7682f7e1 247 case 'a':
ladner 1:0eaa7682f7e1 248 DiceStop();
ladner 1:0eaa7682f7e1 249 break;
ladner 1:0eaa7682f7e1 250 case 'B':
ladner 1:0eaa7682f7e1 251 moveNext();
ladner 1:0eaa7682f7e1 252 break;
ladner 1:0eaa7682f7e1 253 case 'C':
ladner 1:0eaa7682f7e1 254 moveLast();
ladner 1:0eaa7682f7e1 255 break;
ladner 1:0eaa7682f7e1 256 case 'D':
ladner 1:0eaa7682f7e1 257 MoveDo();
ladner 1:0eaa7682f7e1 258 break;
ladner 13:cb068deacb6c 259 case 'E':
ladner 13:cb068deacb6c 260 exit();
ladner 13:cb068deacb6c 261 break;
ladner 13:cb068deacb6c 262 case 'F':
ladner 13:cb068deacb6c 263 up();
ladner 13:cb068deacb6c 264 break;
ladner 13:cb068deacb6c 265 case 'G':
ladner 13:cb068deacb6c 266 down();
ladner 13:cb068deacb6c 267 break;
ladner 13:cb068deacb6c 268 case 'H':
ladner 13:cb068deacb6c 269 accept();
ladner 13:cb068deacb6c 270 break;
ladner 1:0eaa7682f7e1 271 case 'I':
ladner 13:cb068deacb6c 272 depth=0;
ladner 13:cb068deacb6c 273 mSelected[0]=0;
ladner 13:cb068deacb6c 274 print_default();
ladner 13:cb068deacb6c 275 mDiceEn=5;
ladner 13:cb068deacb6c 276 reset();
ladner 1:0eaa7682f7e1 277 break;
ladner 1:0eaa7682f7e1 278 }
ladner 0:e97a6a69fe4b 279 }
ladner 0:e97a6a69fe4b 280 }
ladner 0:e97a6a69fe4b 281
ladner 1:0eaa7682f7e1 282 int main()
ladner 0:e97a6a69fe4b 283 {
ladner 1:0eaa7682f7e1 284 Random.start();
ladner 1:0eaa7682f7e1 285 //Random.stop();
ladner 1:0eaa7682f7e1 286 //Random.read_us();
ladner 1:0eaa7682f7e1 287
ladner 1:0eaa7682f7e1 288 //Ticker:
ladner 1:0eaa7682f7e1 289 //.attach(&main,[sek]);
ladner 1:0eaa7682f7e1 290 //.attach_us(&main,[micro-sec]);
ladner 1:0eaa7682f7e1 291 //.detach();
ladner 13:cb068deacb6c 292 Button0.mode(PullDown);
ladner 13:cb068deacb6c 293 Button1.mode(PullDown);
ladner 13:cb068deacb6c 294 Button2.mode(PullDown);
ladner 13:cb068deacb6c 295 Button3.mode(PullDown);
ladner 13:cb068deacb6c 296 Button4.mode(PullDown);
ladner 1:0eaa7682f7e1 297
ladner 13:cb068deacb6c 298 DD_A.mode(PullDown);
ladner 13:cb068deacb6c 299 DD_B.mode(PullDown);
ladner 13:cb068deacb6c 300 DD_C.mode(PullDown);
ladner 13:cb068deacb6c 301
ladner 13:cb068deacb6c 302 wait(0.01);
ladner 13:cb068deacb6c 303
ladner 13:cb068deacb6c 304 DD_A.rise(&dreh);
ladner 13:cb068deacb6c 305 DD_A.fall(&dreh);
ladner 13:cb068deacb6c 306 DD_B.rise(&dreh);
ladner 13:cb068deacb6c 307 DD_B.fall(&dreh);
ladner 13:cb068deacb6c 308 DD_C.rise(&druck);
ladner 13:cb068deacb6c 309 DD_C.fall(&druck);
ladner 13:cb068deacb6c 310 DD_last = DD;
ladner 13:cb068deacb6c 311 DD_d=DD_D;
ladner 13:cb068deacb6c 312
ladner 1:0eaa7682f7e1 313 Button0.rise(&reset);
ladner 13:cb068deacb6c 314 Button1.rise(&btn1);
ladner 13:cb068deacb6c 315 Button1.fall(&btn1);
ladner 1:0eaa7682f7e1 316 Button2.rise(&btn2);
ladner 13:cb068deacb6c 317 Button2.fall(&btn2);
ladner 1:0eaa7682f7e1 318 Button3.rise(&btn3);
ladner 13:cb068deacb6c 319 Button3.fall(&btn3);
ladner 1:0eaa7682f7e1 320 Button4.rise(&btn4);
ladner 13:cb068deacb6c 321 Button4.fall(&btn4);
ladner 13:cb068deacb6c 322
ladner 1:0eaa7682f7e1 323 //myled = 0xFFF;
ladner 1:0eaa7682f7e1 324 port.baud(76800);
ladner 1:0eaa7682f7e1 325 port.format(8,Serial::None, 1);
ladner 1:0eaa7682f7e1 326 port.attach(&Control);
ladner 4:2acb70f9cd22 327 /*
ladner 13:cb068deacb6c 328 Farben[0]=0x00FF00;//Rot
ladner 13:cb068deacb6c 329 Farben[1]=0xFF0000;//Blau
ladner 13:cb068deacb6c 330 Farben[2]=0x0000FF;//Grun
ladner 13:cb068deacb6c 331 Farben[3]=0x00FFFF;//Gelb
ladner 13:cb068deacb6c 332 Background = 0; //Schwarz
ladner 13:cb068deacb6c 333 DiseC = 0x00FF00; //Rot
ladner 4:2acb70f9cd22 334 */
ladner 13:cb068deacb6c 335 Farben[0]=0x000800;//Rot
ladner 13:cb068deacb6c 336 Farben[1]=0x080000;//Blau
ladner 13:cb068deacb6c 337 Farben[2]=0x000008;//Grun
ladner 13:cb068deacb6c 338 Farben[3]=0x000808;//Gelb
ladner 13:cb068deacb6c 339 Background = 0; //Schwarz
ladner 13:cb068deacb6c 340 DiseC = 0x000800; //Rot
ladner 13:cb068deacb6c 341 /*
ladner 13:cb068deacb6c 342 Farben[0]=0xFFFFFF;//Weiß
ladner 13:cb068deacb6c 343 Farben[1]=0xFFFFFF;//Weiß
ladner 13:cb068deacb6c 344 Farben[2]=0xFFFFFF;//Weiß
ladner 13:cb068deacb6c 345 Farben[3]=0xFFFFFF;//Weiß
ladner 13:cb068deacb6c 346 Background = 0xFFFFFF;//Weiß
ladner 13:cb068deacb6c 347 DiseC = 0xFFFFFF; //Weiß
ladner 13:cb068deacb6c 348 */
ladner 13:cb068deacb6c 349
ladner 1:0eaa7682f7e1 350 __disable_irq();
ladner 1:0eaa7682f7e1 351 for(char i = 0;i<Spieler;i++)
ladner 1:0eaa7682f7e1 352 {
ladner 1:0eaa7682f7e1 353 Feld.WriteLed(Farben[i]);
ladner 1:0eaa7682f7e1 354 for(char j = 0;j<Feldgrose-1;j++)
ladner 13:cb068deacb6c 355 if((j==(Feldgrose-2))&(i==(Spieler-1)))
ladner 13:cb068deacb6c 356 Feld.WriteLed(0xFFFFFF);
ladner 13:cb068deacb6c 357 else
ladner 13:cb068deacb6c 358 Feld.WriteLed(Background);
ladner 1:0eaa7682f7e1 359 }
ladner 1:0eaa7682f7e1 360 __enable_irq();
ladner 13:cb068deacb6c 361 //reset();
ladner 13:cb068deacb6c 362 print_default();
ladner 1:0eaa7682f7e1 363 while(1) ;
ladner 0:e97a6a69fe4b 364 }
ladner 0:e97a6a69fe4b 365
ladner 1:0eaa7682f7e1 366 void DiceStart()
ladner 1:0eaa7682f7e1 367 {
ladner 1:0eaa7682f7e1 368 if(diceEn==0)
ladner 1:0eaa7682f7e1 369 {
ladner 13:cb068deacb6c 370 RandomDice.start();
ladner 1:0eaa7682f7e1 371 DiceAnim.attach(&DiceRun,0.1);
ladner 1:0eaa7682f7e1 372 diceEn = 1;
ladner 1:0eaa7682f7e1 373 diceTick = 1;
ladner 1:0eaa7682f7e1 374 DicePrint();
ladner 1:0eaa7682f7e1 375 }
ladner 1:0eaa7682f7e1 376 }
ladner 13:cb068deacb6c 377
ladner 1:0eaa7682f7e1 378 void DiceStop()
ladner 0:e97a6a69fe4b 379 {
ladner 1:0eaa7682f7e1 380 if(diceEn==1)
ladner 1:0eaa7682f7e1 381 {
ladner 13:cb068deacb6c 382 if(RandomDice.read_us()> 200)
ladner 1:0eaa7682f7e1 383 {
ladner 1:0eaa7682f7e1 384 DiceAnim.detach();
ladner 1:0eaa7682f7e1 385 diceEn = 2;
ladner 1:0eaa7682f7e1 386 diceTick = 0;
ladner 1:0eaa7682f7e1 387 diceNum = Random.read_us()%7;
ladner 13:cb068deacb6c 388 diceNum = (RandomDice.read_us()+diceNum)%7+1;
ladner 13:cb068deacb6c 389 RandomDice.stop();
ladner 13:cb068deacb6c 390 RandomDice.reset();
ladner 13:cb068deacb6c 391 if(diceNum>=7)
ladner 13:cb068deacb6c 392 DiceCal();
ladner 13:cb068deacb6c 393 //port.printf("LDiceNum:%d\n",diceNum);
ladner 1:0eaa7682f7e1 394 DicePrint();
ladner 1:0eaa7682f7e1 395 GameCal();
ladner 1:0eaa7682f7e1 396 }
ladner 1:0eaa7682f7e1 397 }
ladner 1:0eaa7682f7e1 398 }
ladner 13:cb068deacb6c 399
ladner 13:cb068deacb6c 400 void DiceCal()
ladner 13:cb068deacb6c 401 {
ladner 13:cb068deacb6c 402 if((diceEn==2)||(diceEn==3))
ladner 13:cb068deacb6c 403 {
ladner 13:cb068deacb6c 404 if(diceNum>7)
ladner 13:cb068deacb6c 405 diceNum=7;
ladner 13:cb068deacb6c 406 if(diceNum==7)
ladner 13:cb068deacb6c 407 {
ladner 13:cb068deacb6c 408 diceEn=3;
ladner 13:cb068deacb6c 409 for(char i = 0;i<Steine;i++)
ladner 13:cb068deacb6c 410 if((PlayPos[(Drann<<2)|i]>3)&&(PlayPos[(Drann<<2)|i] < 44))
ladner 13:cb068deacb6c 411 for(char j = 1;j<=6;j++)
ladner 13:cb068deacb6c 412 {
ladner 13:cb068deacb6c 413 char temp = Field[(PlayPos[(Drann<<2)|i]- Steine + Feldgrose * Drann+j) % (Feldgrose*Steine)];
ladner 13:cb068deacb6c 414 if(temp>0)
ladner 13:cb068deacb6c 415 {
ladner 13:cb068deacb6c 416 temp--; //(Spieler<<2)|Stein
ladner 13:cb068deacb6c 417 temp = (temp&0xC)>>2;//Spieler
ladner 13:cb068deacb6c 418 if(temp!=Drann)
ladner 13:cb068deacb6c 419 if(j<diceNum)
ladner 13:cb068deacb6c 420 diceNum=j;
ladner 13:cb068deacb6c 421 }
ladner 13:cb068deacb6c 422 }
ladner 13:cb068deacb6c 423 //PlayPos[(Drann<<2)|i] im Feld suchen, weiter setzen, wenn treffer, der kleiner als diceNum ->setzen von diceNum
ladner 13:cb068deacb6c 424 }//DiceNum == 7
ladner 13:cb068deacb6c 425 if(diceNum==7)
ladner 13:cb068deacb6c 426 diceNum=6;
ladner 13:cb068deacb6c 427 //port.printf("LdiceNum:%d\n",diceNum);
ladner 13:cb068deacb6c 428 }
ladner 13:cb068deacb6c 429 }
ladner 13:cb068deacb6c 430
ladner 1:0eaa7682f7e1 431 void setDice(char number)
ladner 1:0eaa7682f7e1 432 {
ladner 13:cb068deacb6c 433 if(diceEn==4)
ladner 1:0eaa7682f7e1 434 {
ladner 13:cb068deacb6c 435 port.printf("LWarning: diceEn:%d -> Game over\n",diceEn);
ladner 1:0eaa7682f7e1 436 }
ladner 13:cb068deacb6c 437 else if(diceEn<4)
ladner 1:0eaa7682f7e1 438 {
ladner 13:cb068deacb6c 439 port.printf("LdiceEn:%d\n",diceEn);
ladner 13:cb068deacb6c 440 if(diceEn==1)
ladner 13:cb068deacb6c 441 {
ladner 13:cb068deacb6c 442 DiceAnim.detach();
ladner 13:cb068deacb6c 443 diceTick = 0;
ladner 13:cb068deacb6c 444 RandomDice.stop();
ladner 13:cb068deacb6c 445 RandomDice.reset();
ladner 13:cb068deacb6c 446 }
ladner 13:cb068deacb6c 447 diceEn = 2;
ladner 13:cb068deacb6c 448 diceNum = number;
ladner 13:cb068deacb6c 449 if(diceNum>=7)
ladner 13:cb068deacb6c 450 DiceCal();
ladner 13:cb068deacb6c 451 //port.printf("LForceDice:%d\n",diceNum);
ladner 13:cb068deacb6c 452 DicePrint();
ladner 13:cb068deacb6c 453 GameCal();
ladner 13:cb068deacb6c 454 }
ladner 1:0eaa7682f7e1 455 }
ladner 13:cb068deacb6c 456
ladner 1:0eaa7682f7e1 457 void DiceRun()
ladner 1:0eaa7682f7e1 458 {
ladner 1:0eaa7682f7e1 459 if(diceTick)
ladner 1:0eaa7682f7e1 460 {
ladner 1:0eaa7682f7e1 461 diceTick=0;
ladner 1:0eaa7682f7e1 462 if(dicePos<7)
ladner 1:0eaa7682f7e1 463 dicePos++;
ladner 1:0eaa7682f7e1 464 else
ladner 1:0eaa7682f7e1 465 dicePos=0;
ladner 1:0eaa7682f7e1 466 }
ladner 1:0eaa7682f7e1 467 else
ladner 1:0eaa7682f7e1 468 diceTick=1;
ladner 1:0eaa7682f7e1 469 DicePrint();
ladner 0:e97a6a69fe4b 470 }
ladner 0:e97a6a69fe4b 471
ladner 1:0eaa7682f7e1 472 void DicePrint()
ladner 0:e97a6a69fe4b 473 {
ladner 1:0eaa7682f7e1 474 switch(diceEn)
ladner 1:0eaa7682f7e1 475 {
ladner 13:cb068deacb6c 476 case 0: //Schwarz & Drann überschreiben...
ladner 1:0eaa7682f7e1 477 myled=(myled&0xFF0);
ladner 13:cb068deacb6c 478 myled=(myled&0x0FF)|(0x100<<Drann);
ladner 1:0eaa7682f7e1 479 port.printf("W%c%c\n",27,27);
ladner 1:0eaa7682f7e1 480 break;
ladner 13:cb068deacb6c 481 case 1: //Animation
ladner 1:0eaa7682f7e1 482 char dice_help = 0xFF-(1<<dicePos);
ladner 1:0eaa7682f7e1 483 myled=(myled&0xFF0)|(5)|(diceTick<<1);
ladner 1:0eaa7682f7e1 484 //myled = (myled&0xF)|(dice_help<<4);
ladner 1:0eaa7682f7e1 485
ladner 1:0eaa7682f7e1 486 port.printf("W%c%c\n" , 27 + diceTick+((dice_help&0x1F)<<1),27 + ((dice_help& 0xE0)>>5));
ladner 1:0eaa7682f7e1 487 break;
ladner 13:cb068deacb6c 488 case 2://Case 3 = Case 2 ->Anzeigen
ladner 1:0eaa7682f7e1 489 myled=(myled&0xFF0)|(diceNum);
ladner 1:0eaa7682f7e1 490 //myled=myled|0xFF0;
ladner 1:0eaa7682f7e1 491
ladner 1:0eaa7682f7e1 492 port.printf("W%c%c\n" , 27 +(diceDecode[diceNum-1]&0x3F),27 + ((diceDecode[diceNum-1]&0x1C0)>>6));
ladner 1:0eaa7682f7e1 493 break;
ladner 1:0eaa7682f7e1 494 case 3:
ladner 1:0eaa7682f7e1 495 myled=(myled&0xFF0)|(diceNum)|8;
ladner 1:0eaa7682f7e1 496 //myled=myled|0xFF0;
ladner 1:0eaa7682f7e1 497
ladner 1:0eaa7682f7e1 498 port.printf("W%c%c\n" , 27 +(diceDecode[diceNum-1]&0x3F),27 + ((diceDecode[diceNum-1]&0x1C0)>>6));
ladner 1:0eaa7682f7e1 499 break;
ladner 13:cb068deacb6c 500 case 4://Spiel beendet! Animation?
ladner 13:cb068deacb6c 501 myled=(myled&0xFF0);
ladner 13:cb068deacb6c 502 port.printf("W%c%c\n",27,27);
ladner 13:cb068deacb6c 503 break;
ladner 13:cb068deacb6c 504 case 5://Menu
ladner 13:cb068deacb6c 505 break;
ladner 1:0eaa7682f7e1 506 }
ladner 0:e97a6a69fe4b 507 }
ladner 1:0eaa7682f7e1 508
ladner 1:0eaa7682f7e1 509 void FieldGenerate()
ladner 1:0eaa7682f7e1 510 {
ladner 1:0eaa7682f7e1 511 for(char i = 0; i<Spieler*Feldgrose;i++)
ladner 1:0eaa7682f7e1 512 Field[i]=0; //Feld zurücksetzen
ladner 13:cb068deacb6c 513 for (char i = 0; i < Spieler*Steine; i++)
ladner 13:cb068deacb6c 514 {
ladner 13:cb068deacb6c 515 Ziel[i]=0;
ladner 13:cb068deacb6c 516 Start[i]=0;
ladner 13:cb068deacb6c 517 }
ladner 1:0eaa7682f7e1 518
ladner 1:0eaa7682f7e1 519 for(char i = 0; i<Spieler;i++)
ladner 1:0eaa7682f7e1 520 for(char j = 0; j<Steine;j++)
ladner 1:0eaa7682f7e1 521 {
ladner 1:0eaa7682f7e1 522 if (PlayPos[(i<<2)|j] >= Steine)
ladner 1:0eaa7682f7e1 523 {
ladner 13:cb068deacb6c 524 if (PlayPos[(i<<2)|j] >= (Spieler * Feldgrose + Steine))
ladner 1:0eaa7682f7e1 525 {
ladner 13:cb068deacb6c 526 //if (PlayPos[(i<<2)|j] < Steine * Feldgrose+Steine*2)
ladner 13:cb068deacb6c 527 Ziel[(PlayPos[(i<<2)|j] - (Spieler * Feldgrose + Steine))|(i<<2)] = ((i<<2)|j) + 1;
ladner 1:0eaa7682f7e1 528 //Ziel PlayPos[(i<<2)|j] - 44
ladner 1:0eaa7682f7e1 529 }
ladner 1:0eaa7682f7e1 530 else
ladner 1:0eaa7682f7e1 531 Field[(PlayPos[(i<<2)|j]- Steine + Feldgrose * i) % (Steine * Feldgrose)] = ((i<<2)|j) + 1;
ladner 1:0eaa7682f7e1 532 //Feld (PlayPos[(i<<2)|j]- 4 + 10 * i) % 40
ladner 1:0eaa7682f7e1 533 }
ladner 1:0eaa7682f7e1 534 else
ladner 13:cb068deacb6c 535 Start[PlayPos[(i<<2)|j]|(i<<2)] = ((i<<2)|j)+1;
ladner 1:0eaa7682f7e1 536 //start PlayPos[(i<<2)|j]
ladner 1:0eaa7682f7e1 537 }
ladner 1:0eaa7682f7e1 538 }
ladner 1:0eaa7682f7e1 539
ladner 1:0eaa7682f7e1 540 void FieldPrint()
ladner 1:0eaa7682f7e1 541 {
ladner 1:0eaa7682f7e1 542 port.printf("F");
ladner 1:0eaa7682f7e1 543 for(char i = 0;i<Spieler*Steine;i++)
ladner 1:0eaa7682f7e1 544 {
ladner 1:0eaa7682f7e1 545 port.printf("%c",27+PlayPos[i]);
ladner 1:0eaa7682f7e1 546 }
ladner 1:0eaa7682f7e1 547 port.printf("\n");
ladner 1:0eaa7682f7e1 548 }
ladner 1:0eaa7682f7e1 549
ladner 1:0eaa7682f7e1 550 void FeldPrint()
ladner 1:0eaa7682f7e1 551 {
ladner 1:0eaa7682f7e1 552 __disable_irq();
ladner 1:0eaa7682f7e1 553 for(char i = 0;i<Spieler*Feldgrose;i++)
ladner 1:0eaa7682f7e1 554 if(Field[i]>0)
ladner 1:0eaa7682f7e1 555 Feld.WriteLed(Farben[((Field[i]- 1)&0x0C)>>2]);
ladner 1:0eaa7682f7e1 556 else
ladner 13:cb068deacb6c 557 Feld.WriteLed(Background);
ladner 13:cb068deacb6c 558 //char Start[Spieler];
ladner 13:cb068deacb6c 559 //char Ziel[Spieler];
ladner 13:cb068deacb6c 560 char i = 0;
ladner 13:cb068deacb6c 561 char j = 0;
ladner 13:cb068deacb6c 562 while(i < Steine*Spieler)
ladner 13:cb068deacb6c 563 {
ladner 13:cb068deacb6c 564 if(Start[i]>0)
ladner 13:cb068deacb6c 565 Home.WriteLed(Farben[((Start[i]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 566 else
ladner 13:cb068deacb6c 567 Home.WriteLed(Background);
ladner 13:cb068deacb6c 568 i++;
ladner 13:cb068deacb6c 569 }
ladner 13:cb068deacb6c 570 do
ladner 13:cb068deacb6c 571 {
ladner 13:cb068deacb6c 572 if(Ziel[j]>0)
ladner 13:cb068deacb6c 573 Home.WriteLed(Farben[((Ziel[j]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 574 else
ladner 13:cb068deacb6c 575 Home.WriteLed(Background);
ladner 13:cb068deacb6c 576 j++;
ladner 13:cb068deacb6c 577 }while(j < Steine*Spieler);
ladner 1:0eaa7682f7e1 578 __enable_irq();
ladner 0:e97a6a69fe4b 579 }
ladner 1:0eaa7682f7e1 580
ladner 13:cb068deacb6c 581 void AnimCal()
ladner 13:cb068deacb6c 582 {
ladner 13:cb068deacb6c 583 for(char i = 0; i<Spieler*Feldgrose;i++)
ladner 13:cb068deacb6c 584 AnimField[i]=0; //Feld zurücksetzen
ladner 13:cb068deacb6c 585 for (char i = 0; i < Spieler*Steine; i++)
ladner 13:cb068deacb6c 586 {
ladner 13:cb068deacb6c 587 AnimZiel[i]=0;
ladner 13:cb068deacb6c 588 AnimStart[i]=0;
ladner 13:cb068deacb6c 589 }
ladner 13:cb068deacb6c 590 AnimDo=0;//Feld_Animieren,Start Animieren, Ziel Animieren
ladner 13:cb068deacb6c 591
ladner 13:cb068deacb6c 592 //char AnimDo; //Feld_Animieren,Start Animieren, Ziel Animierenw
ladner 1:0eaa7682f7e1 593
ladner 13:cb068deacb6c 594 for (char i = 0; i < Spieler*Steine; i++) //Hauptschleife
ladner 13:cb068deacb6c 595 if(i==((Drann<<2)|selected))
ladner 13:cb068deacb6c 596 {
ladner 13:cb068deacb6c 597 if(moglich[selected]==1)
ladner 13:cb068deacb6c 598 {
ladner 13:cb068deacb6c 599 if(PlayPos[i]<Steine) //nicht Draußsen
ladner 13:cb068deacb6c 600 {
ladner 13:cb068deacb6c 601 AnimDo = AnimDo|3;//Feld&Start
ladner 13:cb068deacb6c 602 AnimPos[i] = Steine; //Ausfahren
ladner 13:cb068deacb6c 603 char temp = Field[Drann*Feldgrose]; //Ansetzfeld wird analysiert
ladner 13:cb068deacb6c 604 if(temp>0)
ladner 13:cb068deacb6c 605 {
ladner 13:cb068deacb6c 606 //myled = myled|temp<<8;
ladner 13:cb068deacb6c 607 temp--; //(Spieler<<2)|Stein
ladner 13:cb068deacb6c 608 AnimPos[temp] = (temp & 0x03); //rücksetzung des Feldes...
ladner 13:cb068deacb6c 609 }
ladner 13:cb068deacb6c 610 }
ladner 13:cb068deacb6c 611 else //Draußen
ladner 13:cb068deacb6c 612 {
ladner 13:cb068deacb6c 613 AnimDo = AnimDo|1; //Feld
ladner 13:cb068deacb6c 614 AnimPos[i] = PlayPos[i]+diceNum;; //Weitersetzen
ladner 13:cb068deacb6c 615 //PlayPos[(Drann<<2)|selected]
ladner 13:cb068deacb6c 616 if(AnimPos[i]<Steine+Spieler*Feldgrose) //noch nicht drinnen
ladner 13:cb068deacb6c 617 {
ladner 13:cb068deacb6c 618 //Field>0
ladner 13:cb068deacb6c 619 char temp = Field[ (AnimPos[i]-Steine+Feldgrose*Drann) % (Feldgrose*Steine) ];
ladner 13:cb068deacb6c 620 if(temp>0)
ladner 13:cb068deacb6c 621 {
ladner 13:cb068deacb6c 622 AnimDo = AnimDo|3;//Feld&Start
ladner 13:cb068deacb6c 623 //myled = myled|temp<<8;
ladner 13:cb068deacb6c 624 temp--; //(Spieler<<2)|Stein
ladner 13:cb068deacb6c 625 AnimPos[temp] = (temp & 0x03); //rücksetzung des Feldes...
ladner 13:cb068deacb6c 626 }
ladner 13:cb068deacb6c 627 }
ladner 13:cb068deacb6c 628 else
ladner 13:cb068deacb6c 629 AnimDo=AnimDo|7;//Feld&Ziel (Start auch wegen Hardware)
ladner 13:cb068deacb6c 630 }
ladner 13:cb068deacb6c 631 }
ladner 13:cb068deacb6c 632 else
ladner 13:cb068deacb6c 633 AnimPos[i] = PlayPos[i]; //Spieler-pos Kopieren, weil es nicht möglich ist...
ladner 13:cb068deacb6c 634 }
ladner 13:cb068deacb6c 635 else
ladner 13:cb068deacb6c 636 AnimPos[i] = PlayPos[i]; //Spieler-pos Kopieren
ladner 13:cb068deacb6c 637 //FieldGenerate -> Anim...
ladner 13:cb068deacb6c 638 for(char i = 0; i<Spieler;i++)
ladner 13:cb068deacb6c 639 for(char j = 0; j<Steine;j++)
ladner 13:cb068deacb6c 640 {
ladner 13:cb068deacb6c 641 if (AnimPos[(i<<2)|j] >= Steine)
ladner 13:cb068deacb6c 642 {
ladner 13:cb068deacb6c 643 if (AnimPos[(i<<2)|j] >= (Spieler * Feldgrose + Steine))
ladner 13:cb068deacb6c 644 {
ladner 13:cb068deacb6c 645 //if (AnimPos[(i<<2)|j] < Steine * Feldgrose+Steine*2)
ladner 13:cb068deacb6c 646 AnimZiel[(AnimPos[(i<<2)|j] - (Spieler * Feldgrose + Steine))|(i<<2)] = ((i<<2)|j) + 1;
ladner 13:cb068deacb6c 647 //AnimZiel AnimPos[(i<<2)|j] - 44
ladner 13:cb068deacb6c 648 }
ladner 13:cb068deacb6c 649 else
ladner 13:cb068deacb6c 650 AnimField[(AnimPos[(i<<2)|j]- Steine + Feldgrose * i) % (Steine * Feldgrose)] = ((i<<2)|j) + 1;
ladner 13:cb068deacb6c 651 //Feld (AnimPos[(i<<2)|j]- 4 + 10 * i) % 40
ladner 13:cb068deacb6c 652 }
ladner 13:cb068deacb6c 653 else
ladner 13:cb068deacb6c 654 AnimStart[AnimPos[(i<<2)|j]|(i<<2)] = ((i<<2)|j)+1;
ladner 13:cb068deacb6c 655 //start AnimPos[(i<<2)|j]
ladner 13:cb068deacb6c 656 }
ladner 13:cb068deacb6c 657 }
ladner 13:cb068deacb6c 658
ladner 13:cb068deacb6c 659 void MoveRun() //Animation (zyklisch)
ladner 0:e97a6a69fe4b 660 {
ladner 1:0eaa7682f7e1 661 if(MoveShow)
ladner 13:cb068deacb6c 662 MoveShow = 0;
ladner 1:0eaa7682f7e1 663 else
ladner 1:0eaa7682f7e1 664 MoveShow = 1;
ladner 13:cb068deacb6c 665
ladner 1:0eaa7682f7e1 666 if(MoveShow>0)
ladner 0:e97a6a69fe4b 667 {
ladner 1:0eaa7682f7e1 668 port.printf("F");
ladner 1:0eaa7682f7e1 669 for(char i = 0;i<Spieler*Steine;i++)
ladner 13:cb068deacb6c 670 {
ladner 13:cb068deacb6c 671 port.printf("%c",27+AnimPos[i]);
ladner 13:cb068deacb6c 672 }
ladner 13:cb068deacb6c 673 port.printf("\n");
ladner 13:cb068deacb6c 674
ladner 13:cb068deacb6c 675 __disable_irq();
ladner 13:cb068deacb6c 676 if((AnimDo&1)>0)
ladner 13:cb068deacb6c 677 {
ladner 13:cb068deacb6c 678 for(char i = 0;i<Spieler*Feldgrose;i++)
ladner 13:cb068deacb6c 679 if(AnimField[i]>0)
ladner 13:cb068deacb6c 680 Feld.WriteLed(Farben[((AnimField[i]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 681 else
ladner 13:cb068deacb6c 682 Feld.WriteLed(Background);
ladner 13:cb068deacb6c 683 }
ladner 13:cb068deacb6c 684 //char Start[Spieler];
ladner 13:cb068deacb6c 685 //char Ziel[Spieler];
ladner 13:cb068deacb6c 686 char i = 0;
ladner 13:cb068deacb6c 687 char j = 0;
ladner 13:cb068deacb6c 688 if((AnimDo&2)>0)
ladner 13:cb068deacb6c 689 {
ladner 13:cb068deacb6c 690 while(i < Steine*Spieler)
ladner 1:0eaa7682f7e1 691 {
ladner 13:cb068deacb6c 692 if(AnimStart[i]>0)
ladner 13:cb068deacb6c 693 Home.WriteLed(Farben[((AnimStart[i]- 1)&0x0C)>>2]);
ladner 1:0eaa7682f7e1 694 else
ladner 13:cb068deacb6c 695 Home.WriteLed(Background);
ladner 13:cb068deacb6c 696 i++;
ladner 1:0eaa7682f7e1 697 }
ladner 13:cb068deacb6c 698 }
ladner 13:cb068deacb6c 699 if((AnimDo&4)>0)
ladner 13:cb068deacb6c 700 {
ladner 13:cb068deacb6c 701 do
ladner 13:cb068deacb6c 702 {
ladner 13:cb068deacb6c 703 if(AnimZiel[j]>0)
ladner 13:cb068deacb6c 704 Home.WriteLed(Farben[((AnimZiel[j]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 705 else
ladner 13:cb068deacb6c 706 Home.WriteLed(Background);
ladner 13:cb068deacb6c 707 j++;
ladner 13:cb068deacb6c 708 }while(j < Steine*Spieler);
ladner 13:cb068deacb6c 709 }
ladner 1:0eaa7682f7e1 710 __enable_irq();
ladner 1:0eaa7682f7e1 711 }
ladner 1:0eaa7682f7e1 712 else
ladner 13:cb068deacb6c 713 {
ladner 1:0eaa7682f7e1 714 FieldPrint();
ladner 13:cb068deacb6c 715 __disable_irq();
ladner 13:cb068deacb6c 716 if((AnimDo&1)>0)
ladner 13:cb068deacb6c 717 {
ladner 13:cb068deacb6c 718 for(char i = 0;i<Spieler*Feldgrose;i++)
ladner 13:cb068deacb6c 719 if(Field[i]>0)
ladner 13:cb068deacb6c 720 Feld.WriteLed(Farben[((Field[i]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 721 else
ladner 13:cb068deacb6c 722 Feld.WriteLed(Background);
ladner 13:cb068deacb6c 723 }
ladner 13:cb068deacb6c 724 //char Start[Spieler];
ladner 13:cb068deacb6c 725 //char Ziel[Spieler];
ladner 13:cb068deacb6c 726 char i = 0;
ladner 13:cb068deacb6c 727 char j = 0;
ladner 13:cb068deacb6c 728 if((AnimDo&2)>0)
ladner 13:cb068deacb6c 729 {
ladner 13:cb068deacb6c 730 while(i < Steine*Spieler)
ladner 13:cb068deacb6c 731 {
ladner 13:cb068deacb6c 732 if(Start[i]>0)
ladner 13:cb068deacb6c 733 Home.WriteLed(Farben[((Start[i]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 734 else
ladner 13:cb068deacb6c 735 Home.WriteLed(Background);
ladner 13:cb068deacb6c 736 i++;
ladner 13:cb068deacb6c 737 }
ladner 13:cb068deacb6c 738 }
ladner 13:cb068deacb6c 739 if((AnimDo&4)>0)
ladner 13:cb068deacb6c 740 {
ladner 13:cb068deacb6c 741 do
ladner 13:cb068deacb6c 742 {
ladner 13:cb068deacb6c 743 if(Ziel[j]>0)
ladner 13:cb068deacb6c 744 Home.WriteLed(Farben[((Ziel[j]- 1)&0x0C)>>2]);
ladner 13:cb068deacb6c 745 else
ladner 13:cb068deacb6c 746 Home.WriteLed(Background);
ladner 13:cb068deacb6c 747 j++;
ladner 13:cb068deacb6c 748 }while(j < Steine*Spieler);
ladner 13:cb068deacb6c 749 }
ladner 13:cb068deacb6c 750 __enable_irq();
ladner 13:cb068deacb6c 751 }
ladner 1:0eaa7682f7e1 752 }
ladner 1:0eaa7682f7e1 753
ladner 1:0eaa7682f7e1 754 void moveNext()
ladner 1:0eaa7682f7e1 755 {
ladner 1:0eaa7682f7e1 756 selected = (selected+1)%Steine;
ladner 1:0eaa7682f7e1 757 for(char i = 0;i<Steine;i++)
ladner 1:0eaa7682f7e1 758 if(moglich[selected]>0)
ladner 1:0eaa7682f7e1 759 break;
ladner 1:0eaa7682f7e1 760 else
ladner 1:0eaa7682f7e1 761 selected = (selected+1)%Steine;
ladner 13:cb068deacb6c 762 AnimCal();
ladner 1:0eaa7682f7e1 763 }
ladner 1:0eaa7682f7e1 764
ladner 1:0eaa7682f7e1 765 void moveLast()
ladner 1:0eaa7682f7e1 766 {
ladner 1:0eaa7682f7e1 767 selected = (selected+3)%Steine;
ladner 1:0eaa7682f7e1 768 for(char i = 0;i<Steine;i++)
ladner 1:0eaa7682f7e1 769 if(moglich[selected]>0)
ladner 1:0eaa7682f7e1 770 break;
ladner 1:0eaa7682f7e1 771 else
ladner 1:0eaa7682f7e1 772 selected = (selected+3)%Steine;
ladner 13:cb068deacb6c 773 AnimCal();
ladner 1:0eaa7682f7e1 774 }
ladner 1:0eaa7682f7e1 775
ladner 1:0eaa7682f7e1 776 void GameCal()
ladner 1:0eaa7682f7e1 777 {
ladner 1:0eaa7682f7e1 778 char drausen = 0; //Ziel
ladner 1:0eaa7682f7e1 779 char feld = 0;
ladner 1:0eaa7682f7e1 780 char drinnen = 0; //start
ladner 2:3a90b20958ff 781 char moglichAny = 1;
ladner 1:0eaa7682f7e1 782 for(char i = 0;i<Steine;i++)
ladner 1:0eaa7682f7e1 783 {
ladner 13:cb068deacb6c 784 if(PlayPos[(Drann<<2)|i]>=Steine)
ladner 0:e97a6a69fe4b 785 {
ladner 13:cb068deacb6c 786 if(PlayPos[(Drann<<2)|i] >= (Steine+Spieler*Feldgrose))
ladner 1:0eaa7682f7e1 787 drausen++;
ladner 1:0eaa7682f7e1 788 else
ladner 1:0eaa7682f7e1 789 feld++;
ladner 0:e97a6a69fe4b 790 }
ladner 1:0eaa7682f7e1 791 else
ladner 1:0eaa7682f7e1 792 drinnen++;
ladner 1:0eaa7682f7e1 793 moglich[i]=0;
ladner 1:0eaa7682f7e1 794 }
ladner 1:0eaa7682f7e1 795 //Berechnung
ladner 2:3a90b20958ff 796 //Ausfahren:
ladner 2:3a90b20958ff 797 //drinnen >0 (Noch Spieler drinnen?)
ladner 2:3a90b20958ff 798 //Startfeld ist von Spieler belegt
ladner 2:3a90b20958ff 799 //Ziel ist frei
ladner 2:3a90b20958ff 800 if((drinnen>0)&&(moglichAny))
ladner 2:3a90b20958ff 801 {
ladner 4:2acb70f9cd22 802 //port.printf("LDrinnen\n");
ladner 2:3a90b20958ff 803 if(((((Field[Feldgrose*Drann]-1) &0x0C) >>2)==Drann)&&(Field[Feldgrose*Drann]>0))
ladner 2:3a90b20958ff 804 {
ladner 4:2acb70f9cd22 805 //port.printf("LAusfahrt Belegt\n");
ladner 2:3a90b20958ff 806 if(((((Field[(Feldgrose*Drann+diceNum)%(Feldgrose*Spieler)]-1) &0x0C) >>2)!=Drann)||(Field[(Feldgrose*Drann+diceNum)%(Feldgrose*Spieler)]==0))
ladner 2:3a90b20958ff 807 {
ladner 4:2acb70f9cd22 808 //port.printf("LZiel frei (Done)\n");
ladner 2:3a90b20958ff 809 moglich[(Field[Feldgrose*Drann]-1) &0x03] = 1;
ladner 2:3a90b20958ff 810 moglichAny=0;
ladner 2:3a90b20958ff 811 }
ladner 2:3a90b20958ff 812 }
ladner 0:e97a6a69fe4b 813 }
ladner 2:3a90b20958ff 814
ladner 2:3a90b20958ff 815 //Ansetzen
ladner 2:3a90b20958ff 816 // 6 gewürfelt
ladner 2:3a90b20958ff 817 //drinnen>0
ladner 2:3a90b20958ff 818 //Start-feld ist nicht von Spieler belegt
ladner 2:3a90b20958ff 819 if((drinnen>0)&&(moglichAny)&&(diceNum==6))
ladner 0:e97a6a69fe4b 820 {
ladner 4:2acb70f9cd22 821 //port.printf("LDrinnen & 6 \n");
ladner 2:3a90b20958ff 822 if(((((Field[Feldgrose*Drann]-1) &0x0C) >>2)!=Drann)||(Field[Feldgrose*Drann]==0))
ladner 1:0eaa7682f7e1 823 {
ladner 4:2acb70f9cd22 824 //port.printf("LAusfahrt frei (Done...Schleife)\n");
ladner 2:3a90b20958ff 825 moglichAny=0;
ladner 1:0eaa7682f7e1 826 for(char i = 0;i<Steine;i++)
ladner 1:0eaa7682f7e1 827 if(PlayPos[(Drann<<2)|i]<Steine)
ladner 1:0eaa7682f7e1 828 moglich[i]=1;
ladner 1:0eaa7682f7e1 829 }
ladner 2:3a90b20958ff 830 }
ladner 2:3a90b20958ff 831
ladner 2:3a90b20958ff 832 //Fahren
ladner 2:3a90b20958ff 833 if(moglichAny)
ladner 2:3a90b20958ff 834 {
ladner 4:2acb70f9cd22 835 //port.printf("LNormal...\n");
ladner 2:3a90b20958ff 836 for(char i = 0;i<Steine;i++)
ladner 0:e97a6a69fe4b 837 {
ladner 13:cb068deacb6c 838 if(PlayPos[(Drann<<2)|i]>=Spieler) //Drausen
ladner 1:0eaa7682f7e1 839 {
ladner 13:cb068deacb6c 840 if((PlayPos[(Drann<<2)|i]+diceNum) < (Steine+Feldgrose*Spieler))//Zeil noch am Feld
ladner 1:0eaa7682f7e1 841 {
ladner 2:3a90b20958ff 842 char temp = Field[(PlayPos[(Drann<<2)|i]- Steine + Feldgrose * Drann+diceNum) % (Feldgrose*Steine)]; //zielfeld
ladner 1:0eaa7682f7e1 843 if(temp>0)
ladner 1:0eaa7682f7e1 844 {
ladner 1:0eaa7682f7e1 845 //myled = myled|temp<<8;
ladner 1:0eaa7682f7e1 846 temp--; //(Spieler<<2)|Stein
ladner 1:0eaa7682f7e1 847 temp = (temp&0xC)>>2;//Spieler
ladner 2:3a90b20958ff 848 if(temp!=Drann) //zielfeld ist nicht ich
ladner 1:0eaa7682f7e1 849 moglich[i]=1;
ladner 1:0eaa7682f7e1 850 }
ladner 2:3a90b20958ff 851 else//Feld ist leer
ladner 1:0eaa7682f7e1 852 moglich[i]=1;
ladner 1:0eaa7682f7e1 853 }
ladner 2:3a90b20958ff 854 else
ladner 2:3a90b20958ff 855 {//Kollisionsberechnung ins Ziel...
ladner 4:2acb70f9cd22 856 if((PlayPos[(Drann<<2)|i]+diceNum)<(Steine*2+ Feldgrose*Spieler))//Schiest nicht über das Ziel hinaus...
ladner 13:cb068deacb6c 857 if(Ziel[(PlayPos[(Drann<<2)|i]-(Steine+Feldgrose*Spieler)+diceNum)|(Drann<<2)]==0)//Zielfeld ist leer (enthält ja nur mich)
ladner 4:2acb70f9cd22 858 moglich[i]=1;
ladner 2:3a90b20958ff 859 }
ladner 1:0eaa7682f7e1 860 }
ladner 1:0eaa7682f7e1 861 }
ladner 1:0eaa7682f7e1 862 }
ladner 2:3a90b20958ff 863
ladner 13:cb068deacb6c 864
ladner 13:cb068deacb6c 865 //Anzeigen der Möglichkeiten & überhaupt möglich?
ladner 2:3a90b20958ff 866 moglichAny=0;
ladner 1:0eaa7682f7e1 867 myled = myled&0xF0F;
ladner 1:0eaa7682f7e1 868 for(char i = 0;i<Steine;i++)
ladner 2:3a90b20958ff 869 {
ladner 1:0eaa7682f7e1 870 myled = myled|(moglich[i]<<i+4);
ladner 1:0eaa7682f7e1 871 moglichAny = moglichAny | moglich[i];
ladner 2:3a90b20958ff 872 }
ladner 13:cb068deacb6c 873
ladner 13:cb068deacb6c 874 if(moglichAny) //Fahren möglich
ladner 1:0eaa7682f7e1 875 {
ladner 1:0eaa7682f7e1 876 selected = (last[Drann]+Steine-1)%Steine;
ladner 1:0eaa7682f7e1 877 moveNext();
ladner 1:0eaa7682f7e1 878 MoveAnim.attach(&MoveRun,0.3);
ladner 1:0eaa7682f7e1 879 }
ladner 13:cb068deacb6c 880 else //Fahren nicht möglich
ladner 1:0eaa7682f7e1 881 {
ladner 13:cb068deacb6c 882 if(feld<=0) //keine am Feld
ladner 1:0eaa7682f7e1 883 {
ladner 13:cb068deacb6c 884 if(count<2)
ladner 4:2acb70f9cd22 885 {
ladner 4:2acb70f9cd22 886 diceEn=0;
ladner 4:2acb70f9cd22 887 count++;
ladner 4:2acb70f9cd22 888 port.printf("LCount: %d\n",count);
ladner 4:2acb70f9cd22 889 }
ladner 0:e97a6a69fe4b 890 }
ladner 13:cb068deacb6c 891 else //Fahren nicht möglich,spieler am Feld & 6 gewürfelt
ladner 13:cb068deacb6c 892 {
ladner 13:cb068deacb6c 893 if(diceNum==6)
ladner 13:cb068deacb6c 894 diceEn=0;
ladner 13:cb068deacb6c 895 }
ladner 1:0eaa7682f7e1 896 }
ladner 1:0eaa7682f7e1 897 }
ladner 1:0eaa7682f7e1 898
ladner 1:0eaa7682f7e1 899 void MoveDo()
ladner 1:0eaa7682f7e1 900 {
ladner 13:cb068deacb6c 901 if((diceEn>1)&&(diceEn<4))
ladner 1:0eaa7682f7e1 902 {
ladner 13:cb068deacb6c 903 if(moglich[selected]==1)
ladner 1:0eaa7682f7e1 904 {
ladner 13:cb068deacb6c 905 if(PlayPos[(Drann<<2)|selected]<Steine) //nicht Draußsen
ladner 1:0eaa7682f7e1 906 {
ladner 13:cb068deacb6c 907 PlayPos[(Drann<<2)|selected] = Steine; //Ausfahren
ladner 13:cb068deacb6c 908 char temp = Field[Drann*Feldgrose]; //Ansetzfeld wird analysiert
ladner 1:0eaa7682f7e1 909 if(temp>0)
ladner 1:0eaa7682f7e1 910 {
ladner 1:0eaa7682f7e1 911 //myled = myled|temp<<8;
ladner 1:0eaa7682f7e1 912 temp--; //(Spieler<<2)|Stein
ladner 1:0eaa7682f7e1 913 PlayPos[temp] = (temp & 0x03); //rücksetzung des Feldes...
ladner 1:0eaa7682f7e1 914 }
ladner 1:0eaa7682f7e1 915 }
ladner 13:cb068deacb6c 916 else //Draußen
ladner 13:cb068deacb6c 917 {
ladner 13:cb068deacb6c 918 PlayPos[(Drann<<2)|selected] += diceNum; //Weitersetzen
ladner 13:cb068deacb6c 919 //PlayPos[(Drann<<2)|selected]
ladner 13:cb068deacb6c 920 if(PlayPos[(Drann<<2)|selected]<Steine+Spieler*Feldgrose) //noch nicht drinnen
ladner 13:cb068deacb6c 921 {
ladner 13:cb068deacb6c 922 //Field>0
ladner 13:cb068deacb6c 923 char temp = Field[ ( PlayPos[(Drann<<2)|selected] - Steine + (Feldgrose * Drann) ) % (Feldgrose*Steine) ];
ladner 13:cb068deacb6c 924 if(temp>0)
ladner 13:cb068deacb6c 925 {
ladner 13:cb068deacb6c 926 //myled = myled|temp<<8;
ladner 13:cb068deacb6c 927 temp--; //(Spieler<<2)|Stein
ladner 13:cb068deacb6c 928 PlayPos[temp] = (temp & 0x03); //rücksetzung des Feldes...
ladner 13:cb068deacb6c 929 }
ladner 13:cb068deacb6c 930 }
ladner 13:cb068deacb6c 931 }
ladner 13:cb068deacb6c 932 //else //nicht möglich
ladner 13:cb068deacb6c 933
ladner 0:e97a6a69fe4b 934 }
ladner 1:0eaa7682f7e1 935 MoveAnim.detach();
ladner 1:0eaa7682f7e1 936 last[Drann]=selected;
ladner 13:cb068deacb6c 937 myled = myled&0xF0F;
ladner 13:cb068deacb6c 938 count = 0;
ladner 13:cb068deacb6c 939 FieldGenerate();
ladner 13:cb068deacb6c 940 //Check for Win!
ladner 13:cb068deacb6c 941 char temp = 0;
ladner 13:cb068deacb6c 942 char j = 0;
ladner 13:cb068deacb6c 943 char running = 1;
ladner 13:cb068deacb6c 944 do
ladner 1:0eaa7682f7e1 945 {
ladner 13:cb068deacb6c 946 temp = 0;
ladner 13:cb068deacb6c 947 for (char i = 0; i < Steine; i++)
ladner 13:cb068deacb6c 948 if (Ziel[(Drann<<2)|i]>0)
ladner 13:cb068deacb6c 949 temp++;
ladner 13:cb068deacb6c 950 if((temp>=4)&&(diceEn>1))
ladner 13:cb068deacb6c 951 port.printf("LSpieler %d hat das Spiel beendet!\n",Drann);
ladner 13:cb068deacb6c 952 if(temp==4)
ladner 13:cb068deacb6c 953 Drann = (Drann+1)%Spieler;
ladner 13:cb068deacb6c 954 else
ladner 13:cb068deacb6c 955 {
ladner 13:cb068deacb6c 956 if(j==0)
ladner 13:cb068deacb6c 957 {
ladner 13:cb068deacb6c 958 if(diceNum<6)
ladner 13:cb068deacb6c 959 Drann = (Drann+1)%Spieler;
ladner 13:cb068deacb6c 960 else
ladner 13:cb068deacb6c 961 running = 0;
ladner 13:cb068deacb6c 962 }
ladner 13:cb068deacb6c 963 else
ladner 13:cb068deacb6c 964 running = 0;
ladner 13:cb068deacb6c 965
ladner 13:cb068deacb6c 966 }
ladner 13:cb068deacb6c 967 diceEn = 0;
ladner 13:cb068deacb6c 968 j++;
ladner 13:cb068deacb6c 969 }while((j<=Spieler)&(running>0));
ladner 13:cb068deacb6c 970 if(running==1)
ladner 13:cb068deacb6c 971 {
ladner 13:cb068deacb6c 972 port.printf("LSpiel beendet!\n");
ladner 13:cb068deacb6c 973 diceEn = 4;
ladner 1:0eaa7682f7e1 974 }
ladner 1:0eaa7682f7e1 975 DicePrint();
ladner 1:0eaa7682f7e1 976 FieldPrint();
ladner 1:0eaa7682f7e1 977 FeldPrint();
ladner 13:cb068deacb6c 978 port.printf("LDrann:%d\n",Drann);
ladner 1:0eaa7682f7e1 979 }
ladner 4:2acb70f9cd22 980 }
ladner 13:cb068deacb6c 981
ladner 4:2acb70f9cd22 982 void ColorPrint(uint32_t color)
ladner 4:2acb70f9cd22 983 {
ladner 4:2acb70f9cd22 984 port.printf("%c%c%c%c\n",27+((color&0xFC0000)>>18),27+((color&0x03f000)>>12),27+((color&0x000FC0)>>6),27+(color&0x00003F));
ladner 13:cb068deacb6c 985 }
ladner 13:cb068deacb6c 986
ladner 13:cb068deacb6c 987 //http://www.repairfaq.org/REPAIR/F_SNES.html
ladner 13:cb068deacb6c 988
ladner 13:cb068deacb6c 989 void dreh()
ladner 13:cb068deacb6c 990 {
ladner 13:cb068deacb6c 991 char temp = DD;
ladner 13:cb068deacb6c 992 if(DD_last == 3)
ladner 13:cb068deacb6c 993 {
ladner 13:cb068deacb6c 994 if(temp == 0)
ladner 13:cb068deacb6c 995 DD_last = 0;
ladner 13:cb068deacb6c 996 }
ladner 13:cb068deacb6c 997 else
ladner 13:cb068deacb6c 998 {
ladner 13:cb068deacb6c 999 if(temp == 3)
ladner 13:cb068deacb6c 1000 {
ladner 13:cb068deacb6c 1001 if(DD_last == 1)
ladner 13:cb068deacb6c 1002 up();
ladner 13:cb068deacb6c 1003 if(DD_last == 2)
ladner 13:cb068deacb6c 1004 down();
ladner 13:cb068deacb6c 1005 }
ladner 13:cb068deacb6c 1006 DD_last = temp;
ladner 13:cb068deacb6c 1007 }
ladner 13:cb068deacb6c 1008 }
ladner 13:cb068deacb6c 1009
ladner 13:cb068deacb6c 1010 void druck()
ladner 13:cb068deacb6c 1011 {
ladner 13:cb068deacb6c 1012 if(DD_D==DD_d)
ladner 13:cb068deacb6c 1013 return;
ladner 13:cb068deacb6c 1014 else if(DD_D)
ladner 13:cb068deacb6c 1015 accept();
ladner 13:cb068deacb6c 1016 DD_d=DD_D;
ladner 13:cb068deacb6c 1017 }
ladner 13:cb068deacb6c 1018
ladner 13:cb068deacb6c 1019 char ausfuehren(uint32_t postion)
ladner 13:cb068deacb6c 1020 {
ogris 14:8f3619df12f1 1021 char out = 1;//0 ende der postion
ogris 14:8f3619df12f1 1022 VHS = 0;
ladner 13:cb068deacb6c 1023 switch (postion)
ladner 13:cb068deacb6c 1024 {
ogris 14:8f3619df12f1 1025 case 0x15:
ogris 14:8f3619df12f1 1026 out = 0;
ogris 14:8f3619df12f1 1027 //zustand 7 aendern
ogris 14:8f3619df12f1 1028 break;
ogris 14:8f3619df12f1 1029 case 0x25:
ogris 14:8f3619df12f1 1030 out = 0;
ogris 14:8f3619df12f1 1031 //zustand kleinstmöglicher zustand
ogris 14:8f3619df12f1 1032 break;
ogris 14:8f3619df12f1 1033 case 0x35:
ogris 14:8f3619df12f1 1034 out = 0;
ogris 14:8f3619df12f1 1035 //zustand groestmoeglich
ogris 14:8f3619df12f1 1036 break;
ogris 14:8f3619df12f1 1037 case 0x19:
ogris 14:8f3619df12f1 1038 out = 0;
ogris 14:8f3619df12f1 1039 //schmeisszwang
ogris 14:8f3619df12f1 1040 break;
ogris 14:8f3619df12f1 1041 case 0x29:
ogris 14:8f3619df12f1 1042 out = 0;
ogris 14:8f3619df12f1 1043 //go home first
ogris 14:8f3619df12f1 1044 break;
ogris 14:8f3619df12f1 1045 case 0x39:
ogris 14:8f3619df12f1 1046 out = 0;
ogris 14:8f3619df12f1 1047 //ausfahrzwang
ogris 14:8f3619df12f1 1048 break;
ogris 14:8f3619df12f1 1049 case 0x17:
ogris 14:8f3619df12f1 1050 out = 0;
ogris 14:8f3619df12f1 1051 //Spiel-Menü:laden
ogris 14:8f3619df12f1 1052 break;
ogris 14:8f3619df12f1 1053 case 0x27:
ogris 14:8f3619df12f1 1054 out = 0;
ogris 14:8f3619df12f1 1055 //Spiel-Menü:speichern
ogris 14:8f3619df12f1 1056 break;
ogris 14:8f3619df12f1 1057 case 0x37:
ogris 14:8f3619df12f1 1058 out = 0;
ogris 14:8f3619df12f1 1059 //Spiel-Menü:reset
ogris 14:8f3619df12f1 1060 break;
ogris 14:8f3619df12f1 1061 case 0x1b:
ogris 14:8f3619df12f1 1062 out = 0;
ogris 14:8f3619df12f1 1063 //Config:laden
ogris 14:8f3619df12f1 1064 break;
ogris 14:8f3619df12f1 1065 case 0x2b:
ogris 14:8f3619df12f1 1066 out = 0;
ogris 14:8f3619df12f1 1067 //Config:speichern
ogris 14:8f3619df12f1 1068 break;
ogris 14:8f3619df12f1 1069 case 0x3b:
ogris 14:8f3619df12f1 1070 out = 0;
ogris 14:8f3619df12f1 1071 //Config:reset
ogris 14:8f3619df12f1 1072 break;
ogris 14:8f3619df12f1 1073 case 0x1f:
ogris 14:8f3619df12f1 1074 out = 0;
ogris 14:8f3619df12f1 1075 //Offline:new
ogris 14:8f3619df12f1 1076 break;
ogris 14:8f3619df12f1 1077 case 0x2f:
ogris 14:8f3619df12f1 1078 out = 0;
ogris 14:8f3619df12f1 1079 //Offline:reset
ogris 14:8f3619df12f1 1080 break;
ogris 14:8f3619df12f1 1081 case 0x3f:
ogris 14:8f3619df12f1 1082 out = 0;
ogris 14:8f3619df12f1 1083 //Offline:com
ogris 14:8f3619df12f1 1084 break;
ogris 14:8f3619df12f1 1085 case 0x6:
ogris 14:8f3619df12f1 1086 VHS = 1;
ogris 14:8f3619df12f1 1087 break;
ogris 14:8f3619df12f1 1088
ladner 13:cb068deacb6c 1089 default:
ladner 13:cb068deacb6c 1090 break;
ladner 13:cb068deacb6c 1091 }
ladner 13:cb068deacb6c 1092 return out;
ladner 13:cb068deacb6c 1093 }
ladner 13:cb068deacb6c 1094
ladner 13:cb068deacb6c 1095 void posUpdate()
ladner 13:cb068deacb6c 1096 {
ladner 13:cb068deacb6c 1097 postion = 0;
ladner 13:cb068deacb6c 1098 for(char i = 0;i<depth-1;i++)
ladner 13:cb068deacb6c 1099 postion = postion|(mSelected[i]<<(i*2));
ladner 13:cb068deacb6c 1100 }
ladner 13:cb068deacb6c 1101
ladner 13:cb068deacb6c 1102 void up()
ladner 13:cb068deacb6c 1103 {
ladner 13:cb068deacb6c 1104 if(depth>0)
ladner 13:cb068deacb6c 1105 {
ladner 13:cb068deacb6c 1106 if(mSelected[depth-1]<1)
ladner 13:cb068deacb6c 1107 {
ladner 13:cb068deacb6c 1108 if(VHS==0)
ladner 13:cb068deacb6c 1109 mSelected[depth-1]=3;
ladner 13:cb068deacb6c 1110 else if(VHS==1)
ladner 13:cb068deacb6c 1111 mSelected[depth-1]=4;
ladner 13:cb068deacb6c 1112 else
ladner 13:cb068deacb6c 1113 mSelected[depth-1]=VHS;
ladner 13:cb068deacb6c 1114 }
ladner 13:cb068deacb6c 1115 else
ladner 13:cb068deacb6c 1116 mSelected[depth-1]--;
ladner 13:cb068deacb6c 1117 print_pos();
ladner 13:cb068deacb6c 1118 }
ladner 13:cb068deacb6c 1119 }
ladner 13:cb068deacb6c 1120
ladner 13:cb068deacb6c 1121 void down()
ladner 13:cb068deacb6c 1122 {
ladner 13:cb068deacb6c 1123 if(depth>0)
ladner 13:cb068deacb6c 1124 {
ladner 13:cb068deacb6c 1125 char temp=3;
ladner 13:cb068deacb6c 1126 if(VHS==0)
ladner 13:cb068deacb6c 1127 temp=3;
ladner 13:cb068deacb6c 1128 else if(VHS==1)
ladner 13:cb068deacb6c 1129 temp=4;
ladner 13:cb068deacb6c 1130 else
ladner 13:cb068deacb6c 1131 temp=VHS;
ladner 13:cb068deacb6c 1132 if(mSelected[depth-1]>(temp-1))
ladner 13:cb068deacb6c 1133 mSelected[depth-1]=0;
ladner 13:cb068deacb6c 1134 else
ladner 13:cb068deacb6c 1135 mSelected[depth-1]++;
ladner 13:cb068deacb6c 1136 print_pos();
ladner 13:cb068deacb6c 1137 }
ladner 13:cb068deacb6c 1138 }
ladner 13:cb068deacb6c 1139
ladner 13:cb068deacb6c 1140 void accept()
ladner 13:cb068deacb6c 1141 {
ladner 13:cb068deacb6c 1142 if(depth>0)
ladner 13:cb068deacb6c 1143 {
ladner 13:cb068deacb6c 1144 postion = 0;
ladner 13:cb068deacb6c 1145 for(char i = 0;i<depth;i++)
ladner 13:cb068deacb6c 1146 postion = postion|(mSelected[i]<<(i*2));
ladner 13:cb068deacb6c 1147 char temp = ausfuehren(postion);
ladner 13:cb068deacb6c 1148 if(temp>0)
ladner 13:cb068deacb6c 1149 {
ladner 13:cb068deacb6c 1150 if(mSelected[depth-1]==0)
ladner 13:cb068deacb6c 1151 {
ladner 13:cb068deacb6c 1152 exit();
ladner 13:cb068deacb6c 1153 return;
ladner 13:cb068deacb6c 1154 }
ladner 13:cb068deacb6c 1155 else
ladner 13:cb068deacb6c 1156 {
ladner 13:cb068deacb6c 1157 mSelected[depth]=1;
ladner 13:cb068deacb6c 1158 depth++;
ladner 13:cb068deacb6c 1159 }
ladner 13:cb068deacb6c 1160 }
ladner 13:cb068deacb6c 1161 }
ladner 13:cb068deacb6c 1162 else
ladner 13:cb068deacb6c 1163 {
ladner 13:cb068deacb6c 1164 depth=1;
ladner 13:cb068deacb6c 1165 mDiceEn = diceEn;
ladner 13:cb068deacb6c 1166 if(mDiceEn==1)
ladner 13:cb068deacb6c 1167 {
ladner 13:cb068deacb6c 1168 DiceAnim.detach();
ladner 13:cb068deacb6c 1169 diceTick = 0;
ladner 13:cb068deacb6c 1170 RandomDice.stop();
ladner 13:cb068deacb6c 1171 mDiceEn=0;
ladner 13:cb068deacb6c 1172 }
ladner 13:cb068deacb6c 1173 if((mDiceEn==2)||(mDiceEn==3))
ladner 13:cb068deacb6c 1174 {
ladner 13:cb068deacb6c 1175 MoveAnim.detach();
ladner 13:cb068deacb6c 1176 MoveShow = 1;
ladner 13:cb068deacb6c 1177 MoveRun();
ladner 13:cb068deacb6c 1178 }
ladner 13:cb068deacb6c 1179 diceEn=5;
ladner 13:cb068deacb6c 1180 DicePrint();
ladner 13:cb068deacb6c 1181 //StartMenu-Anim
ladner 13:cb068deacb6c 1182 }
ladner 13:cb068deacb6c 1183 posUpdate();
ogris 14:8f3619df12f1 1184 port.printf("Lpostion:0x%x\n",postion);
ladner 13:cb068deacb6c 1185 if(depth>0)
ladner 13:cb068deacb6c 1186 {
ladner 13:cb068deacb6c 1187 print_menu();
ladner 13:cb068deacb6c 1188 print_pos();
ladner 13:cb068deacb6c 1189 }
ladner 13:cb068deacb6c 1190 else
ladner 13:cb068deacb6c 1191 print_default();
ladner 13:cb068deacb6c 1192 }
ladner 13:cb068deacb6c 1193
ladner 13:cb068deacb6c 1194 void exit()
ladner 13:cb068deacb6c 1195 {
ladner 13:cb068deacb6c 1196 if(depth>0)
ladner 13:cb068deacb6c 1197 {
ladner 13:cb068deacb6c 1198 depth--;
ladner 13:cb068deacb6c 1199 mSelected[depth]=0;
ladner 13:cb068deacb6c 1200 }
ladner 13:cb068deacb6c 1201 if(depth==0)
ladner 13:cb068deacb6c 1202 {
ladner 13:cb068deacb6c 1203 if(mDiceEn<5)
ladner 13:cb068deacb6c 1204 {
ladner 13:cb068deacb6c 1205 diceEn=mDiceEn;
ladner 13:cb068deacb6c 1206 if((mDiceEn==2)||(mDiceEn==3))
ladner 13:cb068deacb6c 1207 MoveAnim.attach(&MoveRun,0.3);
ladner 13:cb068deacb6c 1208 mDiceEn=5;
ladner 13:cb068deacb6c 1209 }
ladner 13:cb068deacb6c 1210 }
ladner 13:cb068deacb6c 1211 posUpdate();
ogris 14:8f3619df12f1 1212 ausfuehren(postion);
ladner 13:cb068deacb6c 1213 if(depth>0)
ladner 13:cb068deacb6c 1214 {
ladner 13:cb068deacb6c 1215 print_menu();
ladner 13:cb068deacb6c 1216 print_pos();
ladner 13:cb068deacb6c 1217 }
ladner 13:cb068deacb6c 1218 else
ladner 13:cb068deacb6c 1219 print_default();
ladner 13:cb068deacb6c 1220 }
ladner 13:cb068deacb6c 1221
ladner 13:cb068deacb6c 1222 void print_menu()
ladner 13:cb068deacb6c 1223 {
ladner 13:cb068deacb6c 1224 port.printf("DR\n");
ladner 13:cb068deacb6c 1225 lcd.cls();
ladner 13:cb068deacb6c 1226 lcd.locate(1,0);
ladner 13:cb068deacb6c 1227 lcd.printf(text_ln0[textPos[postion]]);
ladner 13:cb068deacb6c 1228 port.printf("D%c%c%s\n",28,27,text_ln0[textPos[postion]]);
ladner 13:cb068deacb6c 1229 lcd.locate(1,1);
ladner 13:cb068deacb6c 1230 lcd.printf(text_ln1[textPos[postion]]);
ladner 13:cb068deacb6c 1231 port.printf("D%c%c%s\n",28,28,text_ln1[textPos[postion]]);
ladner 13:cb068deacb6c 1232 lcd.locate(1,2);
ladner 13:cb068deacb6c 1233 lcd.printf(text_ln2[textPos[postion]]);
ladner 13:cb068deacb6c 1234 port.printf("D%c%c%s\n",28,29,text_ln2[textPos[postion]]);
ladner 13:cb068deacb6c 1235 lcd.locate(1,3);
ladner 13:cb068deacb6c 1236 lcd.printf(text_ln3[textPos[postion]]);
ladner 13:cb068deacb6c 1237 port.printf("D%c%c%s\n",28,30,text_ln3[textPos[postion]]);
ladner 13:cb068deacb6c 1238 }
ladner 13:cb068deacb6c 1239
ladner 13:cb068deacb6c 1240 void print_pos()
ladner 13:cb068deacb6c 1241 {
ladner 13:cb068deacb6c 1242 if (VHS==1)
ladner 13:cb068deacb6c 1243 {
ladner 13:cb068deacb6c 1244 lcd.locate(0,3);
ladner 13:cb068deacb6c 1245 // "--------------------"
ladner 13:cb068deacb6c 1246 lcd.printf(" ");
ladner 13:cb068deacb6c 1247 port.printf("D%c%c \n",27,27+3);
ladner 13:cb068deacb6c 1248
ladner 13:cb068deacb6c 1249 lcd.locate(0,0);
ladner 13:cb068deacb6c 1250 if(mSelected[depth-1]==0)
ladner 13:cb068deacb6c 1251 {
ladner 13:cb068deacb6c 1252 port.printf("D%c%c<\n",27,27);
ladner 13:cb068deacb6c 1253 lcd.putc('<');
ladner 13:cb068deacb6c 1254 }
ladner 13:cb068deacb6c 1255 else
ladner 13:cb068deacb6c 1256 {
ladner 13:cb068deacb6c 1257 port.printf("D%c%c \n",27,27);
ladner 13:cb068deacb6c 1258 lcd.putc(' ');
ladner 13:cb068deacb6c 1259
ladner 13:cb068deacb6c 1260 lcd.locate(4*mSelected[depth-1],3);
ladner 13:cb068deacb6c 1261 lcd.putc('^');
ladner 13:cb068deacb6c 1262 port.printf("D%c%c^\n",27+4*mSelected[depth-1],27+3);
ladner 13:cb068deacb6c 1263 }
ladner 13:cb068deacb6c 1264 }
ladner 13:cb068deacb6c 1265 else
ladner 13:cb068deacb6c 1266 {
ladner 13:cb068deacb6c 1267 for(char i=0;i<4;i++)
ladner 13:cb068deacb6c 1268 {
ladner 13:cb068deacb6c 1269 lcd.locate(0,i);
ladner 13:cb068deacb6c 1270 if((mSelected[depth-1]+0)==i)
ladner 13:cb068deacb6c 1271 {
ladner 13:cb068deacb6c 1272 if(i==0)
ladner 13:cb068deacb6c 1273 {
ladner 13:cb068deacb6c 1274 port.printf("D%c%c<\n",27,i+27);
ladner 13:cb068deacb6c 1275 lcd.putc('<');
ladner 13:cb068deacb6c 1276 }
ladner 13:cb068deacb6c 1277 else
ladner 13:cb068deacb6c 1278 {
ladner 13:cb068deacb6c 1279 port.printf("D%c%c>\n",27,i+27);
ladner 13:cb068deacb6c 1280 lcd.putc('>');
ladner 13:cb068deacb6c 1281 }
ladner 13:cb068deacb6c 1282 }
ladner 13:cb068deacb6c 1283 else
ladner 13:cb068deacb6c 1284 {
ladner 13:cb068deacb6c 1285 port.printf("D%c%c \n",27,i+27);
ladner 13:cb068deacb6c 1286 lcd.putc(' ');
ladner 13:cb068deacb6c 1287 }
ladner 13:cb068deacb6c 1288 }
ladner 13:cb068deacb6c 1289 }
ladner 13:cb068deacb6c 1290 }
ladner 13:cb068deacb6c 1291
ladner 13:cb068deacb6c 1292 void print_default()
ladner 13:cb068deacb6c 1293 {
ladner 13:cb068deacb6c 1294 lcd.cls();
ladner 13:cb068deacb6c 1295 lcd.printf(" Spiel lauft...");
ladner 13:cb068deacb6c 1296 lcd.locate(0,3);
ladner 13:cb068deacb6c 1297 lcd.printf("12345678901234567890");
ladner 13:cb068deacb6c 1298 port.printf("D%c%c Spiel lauft... \n",27,27);
ladner 13:cb068deacb6c 1299 port.printf("D%c%c \n",27,28);
ladner 13:cb068deacb6c 1300 port.printf("D%c%c \n",27,29);
ladner 13:cb068deacb6c 1301 port.printf("D%c%c12345678901234567890\n",27,30);
ladner 0:e97a6a69fe4b 1302 }