Ваше время l oop просто просит игрока снова и снова ничего не делать. Вы должны определить функцию и вызвать эту функцию в то время как l oop после ввода пользователя. была ошибка с вашим синтаксисом, когда вы добавляете или вычитаете один из player_startPoint
см. комментарии к коду.
Это заставит ваш l oop работать так, как задумано, но ваша игра все еще застрянет в бесконечном l oop так как вы добавляете 1, то вычитайте 1 из player_startPoint
каждого l oop
Этот код не очень хорош, есть выделение, которое вы можете сделать, чтобы сделать его лучше. исследование Функции для начала.
# import random and set the range of values between 1 & 2
# remember that zero is the default lowest number when i+1
import pygame
import random
i = int
weather_values = random.randint(1,2)
# These values are used later to define the game state the user will encounter, if sunny move forward +1; if rainy move backwards -1
# These are most of the variables in general
Sunny = int = 1
Rainy = int = 2
player_startPoint = 0
# These values will later be replaced once I figure out how to negate case sensitive
yes = str
Yes = str
yes == Yes
no = str
No = str
No == no
# This prompt starts the game
print("This is the weather game")
# this input is redundent you only ned to call it in the loop
# Ask_string = input("Ask about the weather? (Yes/No): ")
weather_values == Sunny == 1
weather_values == Rainy == 2
#define a function to call when the user inputs an answer
def checkWeather():
global player_startPoint #make player_startPoint global so it can be accessed from within the function
if weather_values == Sunny:
print("Sunny")
player_startPoint + 1
else :
weather_values == Rainy
print("Rainy")
player_startPoint - 1
#The value Ask_string prompts the program to run the mathRand command to get a value of 1 or 2 that print out the weather assigned to either number
if Ask_string == "yes" or "Yes":
#Here we intitute the mathRand function to give the player insight and give them
# An input choice to proceed or stay put based on the forcast
# Printing the variable random abides by the range set and will give you a desired output,
# However, I am not sure if random and weather_values will indentify to the same value going forward if just random is used.
print (weather_values)
else:
print("Maybe later then")
# the sunny and rainy variables allow the program associate a value with the object
if weather_values == Sunny :
player_startPoint += 1 # =+ is an invalid syntax it should be +=
else :
player_startPoint -= 1 # =+ is an invalid syntax it should be +=
#for weather_values in range(1) :
#player_startPoint + 1
#else :
# player_startPoint - 1'
while player_startPoint < 3 :
Ask_string = input("Ask about the weather? (Yes/No): ")
checkWeather() # call checkWeather function after user input
if player_startPoint == 3 :
print(" Congrats! You've weathered the storm! ")