Würfelpoker programmieren?

2 Antworten

Genau so ein Spiel habe ich programmiert aber es ist in Visual Basic. Den Teil mit den Würfen erkennen kann ich dir liefern:

a() stellt ein Array der 5 gewürfelten Zahlen dar.

  Private Function is3Pasch(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        is3Pasch = False
        If a(1) = a(2) And a(1) = a(3) Then
            is3Pasch = True
        End If

        If a(2) = a(3) And a(2) = a(4) Then
            is3Pasch = True
        End If

        If a(3) = a(4) And a(3) = a(5) Then
            is3Pasch = True
        End If


    End Function

    Private Function isFool(ByVal a() As Integer) As Boolean
        Array.Sort(a)

        If a(1) = a(2) And a(1) = a(3) And a(4) = a(5) Then
            isFool = True
            Exit Function
        End If

        If a(1) = a(2) And a(3) = a(4) And a(3) = a(5) Then
            isFool = True
            Exit Function
        End If

        isFool = False
    End Function


    Private Function isPoker(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        If a(1) = a(2) And a(1) = a(3) And a(1) = a(4) Then
            isPoker = True
            Exit Function
        End If
        If a(2) = a(3) And a(2) = a(4) And a(2) = a(5) Then
            isPoker = True
            Exit Function
        End If

        isPoker = False
    End Function

    Private Function isKlStr(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        isKlStr = False
        If a(1) = 1 And a(2) = 2 And a(3) = 3 And a(4) = 4 Then
            isKlStr = True
        End If
        If a(1) = 1 And a(2) = 1 And a(3) = 2 And a(4) = 3 And a(5) = 4 Then
            isKlStr = True
        End If
        If a(1) = 1 And a(2) = 2 And a(3) = 2 And a(4) = 3 And a(5) = 4 Then
            isKlStr = True
        End If
        If a(1) = 1 And a(2) = 2 And a(3) = 3 And a(4) = 3 And a(5) = 4 Then
            isKlStr = True
        End If
        If a(1) = 2 And a(2) = 2 And a(3) = 3 And a(4) = 4 And a(5) = 5 Then
            isKlStr = True
        End If
        If a(1) = 2 And a(2) = 3 And a(3) = 4 And a(4) = 5 Then
            isKlStr = True
        End If
        If a(1) = 3 And a(2) = 4 And a(3) = 5 And a(4) = 6 Then
            isKlStr = True
        End If
        If a(1) = 2 And a(2) = 3 And a(3) = 4 And a(4) = 4 And a(5) = 5 Then
            isKlStr = True
        End If
        If a(1) = 3 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 6 Then
            isKlStr = True
        End If
        If a(1) = 1 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 5 Then
            isKlStr = True
        End If
        If a(1) = 1 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 6 Then
            isKlStr = True
        End If

    End Function

    Private Function isStrasse(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        If a(1) = a(2) Then
            isStrasse = False
            Exit Function
        End If
        If a(2) = a(3) Then
            isStrasse = False
            Exit Function
        End If
        If a(3) = a(4) Then
            isStrasse = False
            Exit Function
        End If
        If a(4) = a(5) Then
            isStrasse = False
            Exit Function
        End If
        If a(1) = 1 And a(5) = 6 Then
            isStrasse = False
            Exit Function
        End If
        isStrasse = True
    End Function

    Private Function is50(ByVal a() As Integer) As Boolean
        If a(1) = a(2) And a(1) = a(3) And a(1) = a(4) And a(1) = a(5) Then
            is50 = True
        Else
            is50 = False
        End If
    End Function

    Private Function isOnePair(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        isOnePair = False
        If a(1) = a(2) Then isOnePair = True
        If a(2) = a(3) Then isOnePair = True
        If a(3) = a(4) Then isOnePair = True
        If a(4) = a(5) Then isOnePair = True
    End Function

    Private Function isTwoPair(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        isTwoPair = False
        If a(1) = a(2) And a(3) = a(4) Then isTwoPair = True
        If a(1) = a(2) And a(4) = a(5) Then isTwoPair = True
        If a(2) = a(3) And a(4) = a(5) Then isTwoPair = True
    End Function

    Private Function isTreeOfKind(ByVal a() As Integer) As Boolean
        Array.Sort(a)
        isTreeOfKind = False
        If a(1) = a(2) And a(1) = a(3) Then isTreeOfKind = True
        If a(2) = a(3) And a(2) = a(4) Then isTreeOfKind = True
        If a(3) = a(4) And a(3) = a(5) Then isTreeOfKind = True
    End Function

Bild zum Beitrag

Woher ich das weiß:eigene Erfahrung
 - (Computer, Spiele und Gaming, programmieren)
steve123600 
Fragesteller
 04.12.2020, 00:00

hat leider nicht geholfen :/

0

du kannst mit der rand() funktion und modulo rechnung würfeln simulieren

steve123600 
Fragesteller
 03.12.2020, 21:16

ok. Aber der würde dann ja random zahlen rausspucken. Bei mir ist der Fall, dass ich die Augenzahlen per Hand eingebe

Und wenn ich dann zum Beispiel 4 4 4 4 4 eingebe soll dann Grand erscheinen

0
antwortjabitte  03.12.2020, 21:22
@steve123600

ok, zahlen kannst du mit scanf() in z.b. ein array einlesen und dann gehst du mit ner for oder while schleife drüber und prüfst ob alle aufeinanderfolgenden (nachbarn) gleich sind, wenn ja dann sind alle zahlen gleich

0
steve123600 
Fragesteller
 03.12.2020, 21:38
@antwortjabitte

Wie genau kann ich das dann schreiben ? Ich hatte angefangen mit for(i=0;i < 6;i++) und dann ein if Befehl. Was kann ich da dann jetzt eingeben damit ich Grand erhalte ?

0
antwortjabitte  04.12.2020, 14:39
@steve123600
int arr[6];
for(int i=0; i<6; ++i) scanf("%d",&arr[i]);
// Überprüfen kannst Du auch mit ner for oder while Schleife, aber das packst Du schon. 
0
steve123600 
Fragesteller
 04.12.2020, 18:15
@antwortjabitte

#include <stdio.h>

int main(){

       const int Wuerfel = 5;

       int a[Wuerfel];

       int i

//Eingabe der Augenzahl

       printf("Programm Wuerfelspiel\n");

       for(i=0;i < Wuerfel;i++){

               printf("Wuerfel %i: \n",i+1);

               scanf("%i",&a[i]);

               }

//Ausgabe

       printf("Die Ausgabe sieht dann so aus:\n");

       printf("Es wurde gewuerfelt:\n");

       printf("Wuerfel \t1\t2\t3\t4\t5\n");

       printf("Augenzahl\t%i\t%i\t%i\t%i\t%i\n",a[0],a[1],a[2],a[3],a[4]);

//Auswertung des Ereignisses

       int j = a[0];

       for(j = 0; j < Wuerfel;j++){

               if(j == a[i]){

                       i++;

               }

       }

return 0;

}

Das ist mein aktueller code

0
antwortjabitte  04.12.2020, 20:49
@steve123600

das überprüfen kannst du mit einer laufvariable mach die von 0 bis einschließlich Wuerfel-2 geht, den Rest findest du schon selber raus

0