0% encontró este documento útil (0 votos)
400 vistas3 páginas

Juego de la Oca: Reglas y Casillas

Este documento describe un programa que simula el juego del parchís. Define las reglas del juego como el número de casillas, las variables para llevar el recuento de las tiradas y partidas, y las funciones para tirar los dados, moverse por el tablero, verificar si se ganó, y jugar partidas múltiples. Al final, muestra la partida con menos tiradas necesarias para ganar.

Cargado por

jelin94121
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
400 vistas3 páginas

Juego de la Oca: Reglas y Casillas

Este documento describe un programa que simula el juego del parchís. Define las reglas del juego como el número de casillas, las variables para llevar el recuento de las tiradas y partidas, y las funciones para tirar los dados, moverse por el tablero, verificar si se ganó, y jugar partidas múltiples. Al final, muestra la partida con menos tiradas necesarias para ganar.

Cargado por

jelin94121
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

from random import randint

TOTAL_CASILLAS = 10
MATCHES = []
INDEX = 0
CONTINUE = True

# MATCH VARIABLES
CURRENT_CASILLA = 0
TIRADAS_TOTALES = 0
LAST_DADO_RESULT = 0

def incrementIndex():
global INDEX
INDEX += 1

def incrementTirada():
global TIRADAS_TOTALES
TIRADAS_TOTALES += 1

class Match:
# Clase objeto de una partida

def __init__(self, index, tiradasTotales):


self.index = index
self.tiradasTotales = tiradasTotales

def getTiradas(match):
return match.tiradasTotales

def preguntarCasillas():
global TOTAL_CASILLAS
tempCasillas = input("Cuantas casillas (10 a 100): ")

if not tempCasillas.isnumeric():
printError("No has escrito un numero entre 10 y 100.")
preguntarCasillas()
return

TOTAL_CASILLAS = int(tempCasillas)

if not TOTAL_CASILLAS >= 10 or not TOTAL_CASILLAS <= 100:


printError("No has escrito un numero entre 10 y 100.")
preguntarCasillas()
return

print("Establecidas casillas del tablreo a " + str(TOTAL_CASILLAS))

# Se pasa como valor el valor del dado


def sendCurrentCasillaMessage(int, oca):
if oca == False:
print("He sacado un " + str(int) + " y voy a la casilla " + str(CURRENT_CASILLA))
else:
print("De oca en oca y tiro porque me toca. Voy a la casilla " + str(CURRENT_CASILLA))

def finish():
global TIRADAS_TOTALES, INDEX, LAST_DADO_RESULT, CURRENT_CASILLA
print("He ganado con " + str(TIRADAS_TOTALES) + " tiradas de dado.")
match = Match(INDEX, TIRADAS_TOTALES)
MATCHES.append(match)
questNext()

def checkFinish(FINAL_CASILLA: int, TOTAL_CASILLAS: int):


if FINAL_CASILLA == TOTAL_CASILLAS:
finish()
return

def processThrow(int):
global CURRENT_CASILLA, TOTAL_CASILLAS, LAST_DADO_RESULT
FINAL_CASILLA = CURRENT_CASILLA + int

oca = False

if (FINAL_CASILLA % 5) == 0 and not FINAL_CASILLA == TOTAL_CASILLAS:


FINAL_CASILLA += 5
oca = True

if int == 6 and LAST_DADO_RESULT == 6:


print("Quién mucho corre pronto para. Voy a la casilla 0")
CURRENT_CASILLA = 0
LAST_DADO_RESULT = 0
return

if FINAL_CASILLA > TOTAL_CASILLAS:


TO_REST = FINAL_CASILLA - TOTAL_CASILLAS
CURRENT_CASILLA = TOTAL_CASILLAS - TO_REST
sendCurrentCasillaMessage(int, oca)
return

LAST_DADO_RESULT = int
CURRENT_CASILLA = FINAL_CASILLA
sendCurrentCasillaMessage(int, oca)

checkFinish(FINAL_CASILLA, TOTAL_CASILLAS)

def throwDado():
incrementTirada()
randomDado = randint(1, 6)
processThrow(randomDado)

def questNext():
global CONTINUE
cont = input("¿Quieres jugar otra? (s/n): ")
if str(cont) == "n":
CONTINUE = False
elif str(cont) == "s":
CONTINUE = True
else:
questNext()

def startMatch():
global CURRENT_CASILLA, TOTAL_CASILLAS, TIRADAS_TOTALES,
LAST_DADO_RESULT
incrementIndex()
print("EMPIEZA PARTIDA " + str(INDEX))
print("Estoy en la casilla 0")
while not CURRENT_CASILLA >= TOTAL_CASILLAS:
throwDado()
CURRENT_CASILLA = 0
TIRADAS_TOTALES = 0
LAST_DADO_RESULT = 0

def printError(msg):
print("ERROR: " + msg)

preguntarCasillas()

while CONTINUE:
startMatch()

MATCHES.sort(key=getTiradas)
bestMatch = MATCHES[0]
print("*** Mejor partida: la " + str(bestMatch.index) + ", con solo " + str(bestMatch.tiradasTotales)
+ " tiradas de dado ***")

También podría gustarte