Python Forum
game of the goose - dice problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
game of the goose - dice problem
#1
Hello everyone, sorry if i did some things wrong in this post but this is my first one. Also english is not my primary language so ignore my grammar mistakes, we are only 15 years old. We just started learning python in school and we dont get much help from our teacher, so in the beginning of our assignment we are already stuck at something. Our dice is working and only one unit is moving, the other wont. We tried several things to make it happen but nothing works. We could really use some help right now. Here is our code (ignore the hashtags, its dutch for our teacher). this is in pygame by the way.

# Eelke Laan en Koop Lammertsma Ganzenbord
import pygame, random

# ---------- Globale variabelen ----------


# Bord afbeelding
bord = pygame.image.load("ganzenbord.png")
# coordinaten van de vakjes

# de \ op het einde van elke regel zorgt ervoor dat we deze lange regel over

# meerdere regels kunnen verdelen zonder dat python in de war raakt

vakjes = [[160, 683], [286, 683], [356, 683], [415, 683], [482, 683], [545, 683], \
 \
          [618, 683], [692, 683], [758, 683], [828, 643], [895, 598], [937, 549], [965, 489], \
 \
          [982, 430], [982, 353], [968, 283], [944, 220], [905, 167], [833, 111], [744, 66], \
 \
          [664, 62], [597, 62], [536, 62], [464, 62], [398, 62], [335, 62], [265, 66], [198, 94], \
 \
          [142, 129], [104, 174], [83, 227], [65, 283], [65, 367], [83, 435], [116, 491], [160, 535], \
 \
          [216, 570], [282, 587], [342, 587], [405, 587], [468, 587], [536, 587], [615, 587], \
 \
          [692, 587], [755, 578], [816, 528], [863, 458], [877, 402], [874, 335], [856, 283], \
 \
          [804, 202], [737, 160], [632, 157], [545, 157], [468, 157], [394, 157], [328, 157], \
 \
          [265, 167], [195, 223], [167, 325], [188, 403], [221, 454], [282, 482], [413, 456]]

beurt = (0)
worp = (0)
# pion posities
posities = [0, 0]

# ---------- Pygame initialisatie ----------

# Pygame initialiseren (is altijd bij het begin van gebruik pygame)
pygame.init()

# Afmetingen van het spelscherm instellen (in pixels [breedte, hoogte])
# En het spelscherm maken (en opslaan in een variabele screen)
WINDOW_SIZE = [1050, 754]
screen = pygame.display.set_mode(WINDOW_SIZE)

# Titel van spelscherm instellen:
pygame.display.set_caption("Eelke en Koops geweldige bordspel")

# Deze boolean laat ons spel straks in een oneidige loop lopen totdat er op
# het kruisje wordt geklikt om af te sluiten (deze zet dan done op True)
done = False

# We maken een pygame Clock object. Deze is nodig om de verversingssnelheid
# (framerate) van het scherm te beheren
clock = pygame.time.Clock()

# ---------- Hoofdloop van het programma ----------
while not done:

    # --- Check gebeurtenissen (zoals muiskliks e.d.) ---

    for event in pygame.event.get():
        if event.type == pygame.QUIT:  # het kruisje is aangeklikt
            done = True  # het spel moet eindigen dus we zetten done op true
        elif event.type == pygame.KEYDOWN:
            # er is een toets ingedrukt, we kijken welke en ondernemen actie
            if event.key == pygame.K_SPACE:
                print("knop: spatie")

                worp = random.choice([1, 2, 3, 4, 5, 6])
                posities[beurt] += worp #verzet pion

                #verzin iets slims om de beurt door te geven aan de volgende speler


    # --- Teken de graphics (nog buiten beeld) ---

    screen.fill((255, 255, 255))  # begin met een witte achtergrond

    bordrect = bord.get_rect()  # vraag afmetingen (rectangle) van het bordplaatje op
    screen.blit(bord, bordrect)  # teken het bord

    # teken pionnen als gekleurde cirkels op de coordinaten van de waar ze staan:
    speler1_x = vakjes[posities[0]][0]
    speler1_y = vakjes[posities[0]][1]
    speler1_kleur = (0, 255, 0)  # groen
    pygame.draw.circle(screen, speler1_kleur, (speler1_x, speler1_y), 10)

    speler2_x = vakjes[posities[1]][0] + 3
    speler2_y = vakjes[posities[1]][1] + 3
    speler2_kleur = (255, 0, 0)  # blauw
    pygame.draw.circle(screen, speler2_kleur, (speler2_x, speler2_y), 10)

    # --- Ververs het beeldscherm met nieuwe graphics ---

    clock.tick(60)  # Zet de limiet op 60 frames per seconde en
    pygame.display.flip()  # Ververs het beeldscherm met de bijgewerkte versie

# ---------- Afsluiting ----------
pygame.quit()
url of the game of goose: [Image: url?sa=i&url=https%3A%2F%2Fcommons.wikim...AdAAAAABAW]

if you have any questions about the language or something else, please reply.
Reply
#2
The problem is that beurt is not being updated between turns. So the program thinks that it is player 0 turn every time.
Reply
#3
(Apr-07-2020, 04:40 PM)TomToad Wrote: The problem is that beurt is not being updated between turns. So the program thinks that it is player 0 turn every time.

Where do you expect it to be updated? It's assigned (a value of 0) on line 33, and it's referenced on line 73. But there are no other lines that mention the variable, so it's never modified..
Reply
#4
the code we uploaded is made by our teacher and is correct. the problem is that we dont know how how to give the turn to the second player. the code for the turn switch isnt written. so we asked you if you can write the code that we miss.
Reply
#5
(Apr-11-2020, 12:33 PM)koop Wrote: so we asked you if you can write the code that we miss
Haha. No this is definitively homework, we are not going to do your homework. We only help in finding the solution. Your teacher wrote:
(Apr-06-2020, 01:17 PM)koop Wrote: #verzin iets slims om de beurt door te geven aan de volgende speler
Meaning: "make up something clever to pass on to the next player". TomToad and bowlofred told you exactly where "beurt" is used, so now it is your turn to use that knowledge.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Stacking Problem in a game. HelloTobi22 2 960 Aug-05-2022, 09:48 AM
Last Post: HelloTobi22
  While loop not ending (Best of 10 dice game) K3nidi 3 1,457 Jul-09-2022, 09:53 AM
Last Post: K3nidi
  Problem with my pong game code Than999 8 3,762 May-15-2022, 06:40 AM
Last Post: deanhystad
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,504 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Guessing game problem IcodeUser8 7 3,521 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Python Hangman Game - Multiple Letters Problem t0rn 4 4,537 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Dice game Mazzo76 1 1,945 Feb-26-2019, 11:55 AM
Last Post: Larz60+
  Making a percentile dice roller and dice roller Fixer243 2 3,201 Sep-30-2018, 12:18 PM
Last Post: gruntfutuk
  Dice Throwing Game in Python (I have a problem) yuseinali 1 3,084 Jun-22-2017, 10:22 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020