- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我在做游戏。我希望人们运行 main.py 然后他们会看到一个带有选项的小菜单。自动提款机我收到错误消息。
所以这是 3 个文件:
ascii.py:
#-------------------------------------------------------------------------------
# Name: ascii
# Purpose: To create all the ascii art and graphic tools for the game:
# "you wake up..."
#
# Author: William Bryant
#
# Created: 15/12/2013
# Copyright: (c) William 2013
#-------------------------------------------------------------------------------
import time
import os
WOODEN_DOOR = """ ______________________________
/_____/_____/_____/_____/_____/
._. ._.
| | | |
|_| ______ ______ |_|
|-| /__1__/ /__2__/ |-| ___________
| | | | || ||| ||||
|_| |_| || ||| ||||
._. ._. ||_||| ||||
| | | | _||_|||_||||_
|_| ______ |_|
|-| /__3__/ |-|
| | /\ | |
|_| \/ |_|
._. ._. _____
| | | | ____________________________|_____|
|_| ______ ______ |_| | |______________________________| |
|-| /__4__/ /__5__/ |-| | | | |
| | | | |_| |_|
|_| |_| 17615.5 x 2
____________________________________________________________________
/_____/ /_____/__/_____/ /_____/ /_____/ /_____/ /_____/ /_____/
/_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/"""
#Error message if user executes the wrong file.
if __name__ == '__main__':
print("[ERROR]: Do not run this file. Run main.py - this file should not be executed!")
time.sleep(4)
exit()
#Clear function
def clear():
"""
Clears the console screen using the built in commands on a operating
system (here linux and windows)
"""
os.system(['clear','cls', "^L"][os.name == 'nt'])
#"Wake up..." title/banner at the start
def ywu_banner(num_of_times):
"""
Prints You wake up...(the game name) in ascii code big letters into a
console and clears the screen using the clear function above and reprints
the message to make the dots at the end appear to be moving.
"""
print("__ __ _")
time.sleep(0.25)
print("\ \ / / | |")
time.sleep(0.25)
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
time.sleep(0.25)
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
time.sleep(0.25)
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ _ ")
time.sleep(0.25)
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_|_)")
time.sleep(0.25)
print(" | | ")
time.sleep(0.25)
print(" |_| ")
time.sleep(0.25)
clear()
for foo in range(num_of_times):
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .___/")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ _ ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_|_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
menu_start = """
_____________ _____________
| | | |
| *start* | | exit |
|_____________| |_____________|
"""
menu_exit = """
_____________ _____________
| | | |
| start | | *exit* |
|_____________| |_____________|
"""
主要.py:
#-------------------------------------------------------------------------------
# Name: main.py
# Purpose: An RPG (Roll playing game) where you wake up in a room and have
# to figure out text based puzzles to escape.
# The whole game will be done in a terminal (Shell) and will be
# completely text and ascii code. This will be the main file.
#
# Author: William Bryant
#
# Created: 15/12/2013
# Copyright: (c) William Bryant 2013
#-------------------------------------------------------------------------------
import time
import ascii
import quests
import msvcrt
#The function that starts/restarts the game
def start():
"""
Calls all the functions to start the game/ restart the game
"""
ascii.clear()
#Display a cool banner
ascii.ywu_banner(2)
options()
time.sleep(0.7)
ascii.clear()
#Game text.
game_text()
def init():
state = "start"
print(ascii.menu_start)
move = msvcrt.getch()
enter = False
while enter == False:
move
if move == b'\r' and state == 'start':
enter = True
start()
elif move == b'\r' and state == 'exit':
enter = False
exit()
elif move == b'K' or move == b'M' and state == "start":
ascii.clear()
print(ascii.menu_exit)
state = "exit"
move
elif move == b'K' or move == b'M' and state == "exit":
ascii.clear()
print(ascii.menu_start)
state = "start"
#The text which is the main story line after the banner which gives the player
#A sense of what the setting is about
def game_text():
"""
Prints out a bit of text 2 lines down and clears the screen every 4 or so
seconds.
"""
time.sleep(5)
print("\n\nYour eyes gentally and gradually, open")
time.sleep(4)
ascii.clear()
time.sleep(2)
print("\n\nYou slowly gather your senses and sit up...")
time.sleep(4.5)
ascii.clear()
time.sleep(2)
print("\n\nYou look around the room, and try to make sense of the")
print("environment you are in and to your surprise, you realise your in some")
print("sort of a prison cell!")
time.sleep(12.5)
ascii.clear()
time.sleep(2)
print("\n\nYou place your hand on the wall...")
time.sleep(3)
ascii.clear()
time.sleep(2)
print("\n\n... It feels like some sort of metal.")
time.sleep(4)
ascii.clear()
time.sleep(2)
print('\n\n"How did I get here?", \nYou think to yourself')
time.sleep(4)
ascii.clear()
time.sleep(2)
quests.accept_quest("Find a way out. Do you accept? ")
time.sleep(10)
ascii.clear()
ascii.clear()
time.sleep(2)
print("\nYou see a wooden door next to your bed with 5 buttons and a handel... ")
time.sleep(10)
ascii.clear()
time.sleep(2)
print("\n\nYou the figure out that it's some sort of combination lock.")
time.sleep(4)
ascii.clear()
time.sleep(2)
quests.door_lock_quest()
time.sleep(2)
print("\nThe door makes a click, you twist the handle anti-clockwise and it slides open")
time.sleep(4)
ascii.clear()
time.sleep(2)
#if the file is the main file then start the program
if __name__ == '__main__':
init()
和quests.py:
#-------------------------------------------------------------------------------
# Name: quests
# Purpose: To contain quests functions for the game "Yoy wake up..."
#
# Author: William Bryant
#
# Created: 17/12/2013
# Copyright: (c) William Bryant 2013
#-------------------------------------------------------------------------------
import time
import ascii
import main
#Error message if user executes the wrong file.
if __name__ == '__main__':
print("[ERROR]: Do not run this file. Run main.py - this file should not be executed!")
time.sleep(4)
exit()
#Helper function for the quests
def accept_quest(name):
"""
If the player doesn't accept the quest, then the player can't move on. If
they say yes, then they continue through the script. If they say no, then the init
function is called from main.py and they get a message.
"""
answered = False
while answered is False:
quest_accept = input("Quest: " + name)
if quest_accept.upper in ["YES", "ACCEPT"]:
time.sleep(2)
print("\nYou accepted the quest")
answered = True
elif quest_accept.upper in ["NO", "DECLINE"]:
answered = True
time.sleep(2)
ascii.clear()
print("\nYou don't live happily ever after and die.")
time.sleep(5)
ascii.clear()
main.init()
else:
print("Type yes or no. ")
time.sleep(4)
#Function for the first quest: do you want to find a way out?
#Function for the second quest: Mmm lets just the combination..
def door_lock_quest():
"""
If the player answers the right question (35231) then they get to continue,
if not then they get a 'GAME OVER' message and the init() function from main
executes and the game restarts
"""
combination = False
accept_quest("Combination lock. Do you accept? ")
while combination is False:
QUEST_ANSWER2 = input(ascii.WOODEN_DOOR + "\nThe answer may be somewhere in the room, hmmm lets try this combination: ")
if QUEST_ANSWER2 in ["35231", 35231]:
combination = True
elif QUEST_ANSWER2 not in ["35231", 35231]:
combination = False
time.sleep(2)
ascii.clear()
print("GAME OVER!!!\nYou die of hunger and lack of water the next day because you didn't answer correctly and couldn't escape!!!")
time.sleep(7)
ascii.clear()
main.init()
time.sleep(4)
出于某种原因。他们的 key 不起作用。这是我第一次使用 getch()。我有点理解,但不是真的。
[编辑]:哦,我还必须指出我使用的是 Python 3
我是 Xcode 4.4 和 AppleScriptObjC 世界的新手。我正在尝试扩展和试验 Sanderson 和 Rosenthal 所著的“学习 AppleScript”一书中关于 Apple
我完全迷失在 shell 编程中,主要是因为我使用的每个站点都提供不同的工具来进行模式匹配。所以我的问题是使用什么工具在管道流中进行简单的模式匹配。 上下文:我有named.conf 文件,我需要一个
我对 C 很陌生,我一直在尝试用这种数据结构制作一个程序: struct node { char command[100]; char prereq[100][80]; cha
该程序检查用户输入的数字是否为素数。 我的问题在if语句中。由于某些原因,Boolean永远不会切换。如果数字为质数,则只会给出两个结果。 我想念什么? import java.util.Scanne
我只是在学习 Haskell。我认为这会产生一个阶乘函数...... (在 ghci 内) Prelude> let ft 0 = 1 Prelude> let ft n = n * ft (n -
这个问题已经有答案了: Using bitwise OR 0 to floor a number (7 个回答) 已关闭 6 年前。 我试图在 JavaScript 中使用二分搜索来查找数组元素,并且
使用 Signal R,如果尝试发送对象,传递模型的语法是什么? private async void FormLoaded(object sender, RoutedEventArgs e) {
我需要使用 Javascript 生成一个半金字塔数字系列,其中包含输入的起始数字和 html 页面中的行数,并在 html 页面中显示结果。我已经完成了 Java 脚本编写之类的工作。我不明白的是它
为什么函数名重复 示例: lucky :: (Integral a) => a -> String lucky 7 = "LUCKY NUMBER SEVEN!" lucky x = "Sorry
我花了2天的时间在GGTS中使用grails进行Web开发。我正在跟着一本书。本书使用命令行。到目前为止,这很棒,但是现在这本书正在使用webtest。我已经在命令行上安装了webtest,但是如何在
我正在学习 Clojure,到目前为止我无法理解这个小难题,我确信这是非常基本的。 我有这个文件: (ns cloapp.core (:gen-class)) (defn -main "I d
我在获取图像以显示在我的 J Frame 中时遇到问题。我确信我将文件放在正确的位置并且输入了正确的名称。这是代码 import java.awt.Color; import java.awt.Gra
我正在尝试为我正在做的应用程序创建一个登录窗口。我整天都在寻找一个例子,但我似乎找不到任何有帮助的东西。我的基本结构如下: // App.scala object App extends Simple
坦率地说,我是 Java 新手。我正在开发一个项目,我想找到一种基于数字序列创建多项式函数的方法。 无论如何,我的问题是我创建了一个存储序列的数组。我现在想找出元素之间的差异。例如。我想找到这个计算a
现在添加了 xml 和 logcat,现在自定义 View 代码,不幸的是我远离开发计算机所以我无法检查你的建议,@jems,我的自定义 View 的构造函数可能错误?@Falmarri,我认为构建目
我在这里缺少什么?当我单击“h2 a”链接时,.content ol 应该切换。我不明白为什么它不起作用:( $(document).ready(function(){ $(".content ol
我是 Java 新手,我到处寻找,但我没有得到一个简单的概念。 我将两个变量声明为 int。我希望这两个变量对于所有方法都是全局的。在我的第一个方法中,我想从用户输入中获取第一个变量的值。然后我希望第
我正在抓取 IMDB 页面的数据,但当尝试将其写入 CSV 文件时,我只从结果中获取最后一行。 代码下方: from urllib.request import urlopen as uReq fro
自从我学习 C 语言以来,我决定制作一个简单的程序,用于加、减和计算两个变量的乘积。根据用户的输入是1,2还是3来选择加/减/折叠。 #include int main (void) { in
int main(void) { string n = GetString(); if(n!=NULL){ for(int i=0, j=strlen(n); i
我是一名优秀的程序员,十分优秀!