Python Forum
[PyGame] snakes & ladders
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] snakes & ladders
#1
Hi, I'm quite new to pygame & I've been messing around with a few little things on it, but the other day we were set homework to make snakes & ladders on python, and I wanted to try and see if I could make it on pygame. I've done the code for it as a text based game.

I'm not too sure how to go about it. I wanted to know if (a) the use of dictionaries is the best way to do the grid, and (b) if it is, how do i get it to show the counter at the right coordinates based on the player's score? Also, if there's a simpler way to do it, please point me the right direction - I honestly just want to learn pygame a bit more at this point.

Thank you :)

import pygame, random

playGame = True

pygame.init()
screen = pygame.display.set_mode((600, 500))

places = {
    1 : [10, 410],
    2 : [110, 410],
    3 : [210, 410],
    4 : [310, 410],
    5 : [410, 410],
    6 : [510, 410],
    7 : [510, 310],
    8 : [410, 310],
    9 : [310, 310],
    10 : [210, 310],
    11 : [110, 310],
    12 : [10, 310],
    13 : [10, 210],
    14 : [110, 210],
    15 : [210, 210],
    16 : [310, 210],
    17 : [410, 210],
    18 : [510, 210],
    19 : [510, 110],
    20 : [410, 110],
    21 : [310, 110],
    22 : [210, 110],
    23 : [110, 110],
    24 : [10, 110],
    25 : [10, 10],
    26 : [110, 10],
    27 : [210, 10],
    28 : [310, 10],
    29 : [410, 10],
    30 : [510, 10]}
    

score = [2, 0]
currentPlayer = 0

background = pygame.image.load('board.png').convert()
playerOne = pygame.image.load('player1.png')
playerTwo = pygame.image.load('player2.png')

while playGame:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            playGame = False

    screen.blit(background, (0, 0))
    
    screen.blit(playerOne, ((places[score[currentPlayer]([0])]), (places[score[currentPlayer]([1])])))

    pygame.display.flip()

pygame.quit()
Reply


Messages In This Thread
snakes & ladders - by mzmingle - Oct-26-2017, 04:31 PM
RE: snakes & ladders - by metulburr - Oct-26-2017, 09:58 PM
RE: snakes & ladders - by mzmingle - Oct-27-2017, 08:18 AM
RE: snakes & ladders - by Windspar - Oct-27-2017, 06:23 PM
RE: snakes & ladders - by mzmingle - Oct-27-2017, 07:04 PM

Forum Jump:

User Panel Messages

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