sitemap link mailform link home

Roulette

Erwartet hier nicht zu viel - aber zum Roulette-Zocken reicht's!

Die Tasten unten links und rechts werden zyklisch abgefragt.

Pollinspiel

Die linke Taste startet die bereits bekannte Musik.Die rechte Taste startet das "Roulette". Cabei wird ein Counter bei Tastendruck hochgezählt und angezeigt. Falls der Counter größer als 36 ist - dann geht es wieder bei 0 los.

Programmlisting


// Ein Roulette-Spiel für den ATTiny2313

# include <stdlib.h>
# include <avr/interrupt.h>
# include "display.h"
# include "delay.h"
# include "nikospiel.c"

// Compiler-Direktiven
// Der Compiler benutzt überall dort, wo "C" steht den Wert 90 usw.
// Dies wird deutlich bei der ARRAY-Definition weiter unten
// Die folenden Defines repräsentieren die Töne der Tonleiter:
# define C 90
# define D 80
# define E 70
# define F 65
# define G 59
# define A 52
# define H 46
# define C1 43
# define P 0 //Pausenkennung

#define LAENGE 10 // Länge des Songs

# define TASTER1 0 // Hängt an Pin 0 vom Port D
# define TASTER2 1 // Hängt an Pin 1 vom Port D

// Diese Werte werden von der Funktion ZahlZuString() benötigt:
#define BASE_DEZ 10 // Dezimalzahlen verwenden
#define STRING_LAENGE_utoa 4
#define STRING_LENGTH_MAX 8

#define LAENGE 10 // Länge des Songs

int Song[LAENGE] = {C, D, E, E, P, D, E, F, F, P}; // ARRAY für den Song

// Eine Funktioin für die Tonausgabe eines kompletten Songs:
int PlayTones(int Array[])
    {
  
    for(int i=0; i<LAENGE; i++)
        {
        if (Array[i] == P)
            {
            Ssleep(1);
            }
        else
            {
            OCR0A=Array[i]; // Tonhöhe festlegen
            TCCR0A=0b00010010; // Ton einschalten
            Ssleep(1);
            TCCR0A=0b00000010; // Ton ausschalten
            }
        }
    return 0;
    }
  
// Brauchen wir, um die Roulette-Zahlen umzuwandeln und auszugeben:
char* ZahlZuString(uint16_t Val, char* String)
{
    uint8_t p;
    uint8_t i = STRING_LAENGE_utoa;
 
    String[i] = '\0';
 
    while(i>0)
    {
        i--;
        String[i] = '0' + Val % BASE_DEZ;
        Val /= BASE_DEZ;
 
        if(String[i]=='0' && Val==0)
        {
            p=i;
            while(p<=STRING_LAENGE_utoa)
            {
                String[p]=String[p+1];
                p++;
            }
 
        }
 
    }
return String;
}


int main(void)

{
AVRInit();
InitDisplay();
ClearDisplay();

SetDisplayCursor(1, 0);
WriteDisplayString("1 MUSIK");
SetDisplayCursor(2, 0);
WriteDisplayString("2 ROULET");

int Tastcounter=0; // Reserviere Speicher für eine Variable
char OutputString[8]; // Wird für Umwanbdlung der Zahlen in Zeichen benötigt

    while(1)
    {
  
    if(PIND & (1<<TASTER1))
        {
        ClearDisplay();
        WriteDisplayString("MUSIK!!!");
        PlayTones(Song); // wird automatisch abspielt aus dem Array
        ClearDisplay();
        SetDisplayCursor(1, 0);
        WriteDisplayString("1 MUSIK");
        SetDisplayCursor(2, 0);
        WriteDisplayString("2 ROULET");
        Ssleep(2);
        }
      
    if(PIND & (1<<TASTER2))
        {
      
        if(Tastcounter>36)
            {
            Tastcounter=0;
            ClearDisplay();
            SetDisplayCursor(1, 0);
            WriteDisplayString("NULL");
            SetDisplayCursor(2, 0);
            WriteDisplayString("Geld weg");
            }
        else
            {
            // Umwandlung int-Zahl zu char-Zeichen:
            ZahlZuString(Tastcounter, OutputString);
            ClearDisplay();
            // Auswertung und Anzeige des "gewürfelten" Wertes
            switch (Tastcounter)
                {
                case 1:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 2:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 3:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 4:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 5:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 6:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 7:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 8:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 9:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 10:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 11:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 12:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 13:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 14:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 15:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 16:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 17:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 18:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 19:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 20:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 21:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 22:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 23:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 24:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 25:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 26:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 27:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 28:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 29:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 30:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 31:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 32:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 33:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 34:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                case 35:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Schwarz");
                    break;
                    }
                case 36:
                    {
                    SetDisplayCursor(1, 0);
                    WriteDisplayString(OutputString);
                    SetDisplayCursor(2, 0);
                    WriteDisplayString("Rot");
                    break;
                    }
                }
            }
        Tastcounter++; // Zähler um 1 erhöhen
        }
    }
}

.

 

Letzte Änderung:
June 21. 2024 19:13:39
«    top    »