树莓派如何安装程序
树莓派又称卡片式电脑,外形只有信用卡大小 , 却具有电脑的所有基本功能,这就是Raspberry Pi电脑板,中文译名"树莓派"!这一基金会以提升学校计算机科学及相关学科的教育,让计算机变得有趣为宗旨 。
安装树莓派:
1.先将安装好系统的SD卡插入树莓派
2.再将usb接口的键盘和鼠标接上树莓派3.接上HDMI线
4.接上电源线 , 并打开电源
键盘输入"startx"启动图形界面,到此为止你的树莓派就正常启动 。
1.NOOBS (New Out Of Box Software) 是树莓派一个全新的安装系统 , 允许用户更轻松的在树莓派设备上体验不同的 Linux 系统 。该软件安装到一个 4GB 或者更大的 SD 卡,首次启动时提供操作系统的安装选择 。所选择的操作系统已经存在卡中,因此 NOOBS 无需联网下载 OS 映像 。当前版本包含 Raspbian, Pidora 和两个版本的 XBMC 媒体中心软件 。一旦选择,NOOBS 将安装所选系统到卡中剩余空间然后重启开始全新安装 。
前言
Raspbian的系统中包含了Python的编程环境IDE,方便了我们对于python的学习 。个人觉得还是游戏程序能够更好的激发我们的潜力所以,话不多说下面就来使用python编写我们简单的游戏程序吧 。
储备知识
①import 模块:time时间模块、random随机数模块
②列表:[ ]#[]中放入值,与数组很像,但是不同
③def:定义函数
④python的缩进是编程格式的一种,if等都不需要{}括起来,关键看缩进区分
⑤if,while,def函数都要以 “:”开始
游戏概述
一进入游戏 , 主人公就会随机获取一个游戏已经设定的道具 。最开始,主人公站在丛林的边缘,只有左右可?。?左边是个洞穴,右边是沙滩 。
选择左边 , 则开始可以获得手电筒,但是在洞穴中会碰到蛇hp-20,继续向下会到一个未知空间,游戏结束 。
选择右边,会到沙滩 获得凉爽的水hp 70,但是由于没有游泳装备,如果继续选择游泳,会遇到海啸而死亡 。
代码
[python] view plain copy 在CODE上查看代码片派生到我的代码片
#Python Adventure Game
import time
import random
#define variable health point
hp = 30
#define variable object_ to show what the adventurer has
object_=[]
#define variable what the game sets
tools = ["Torch","Rope","Spanner","50HP","10HP"]
#set two acceptable answers ,select any one to end loop
def get_input(prompt,accepted):
while True:
value = https://m.easdo.com/news/input(prompt).lower()
if value in accepted:
return value
else :
print("That is not a recognised answer,must be one of",accepted)
def handle_room(location) :
global hp
if location== "start":
print("You are stading on a path at the edge of a jungle.There is a cave to your left and a beach to your right.")
object_.append(random.choice(tools))
print("Lucky,you have gained",object_[-1])
use_tools(object_)
direction = get_input("Do you want to go left or right?",["left","right"])
if direction == "left":
return "cave"
elif direction == "right":
return "beach"
elif location == "cave":
print("On the entrance of cave,you find a torch!!!")
object_.append("Torch")
print("You walk to the cave and notice there is an opening.")
print("A small snake bites you,and you lose 20 health points.")
hp-=20
answer = get_input("Do you want to go deeper?(y/n)",["y","n"])
if answer == "y":
return "deep_cave"
elif answer == "n":
return "start"
elif location == "beach":
print("You walk to the beach but remember you do not have any swimwming equipment.")
print("The cool water revitalizes you.You have never felt more alive,gain 70 health points.")
hp =70
answer = get_input("Do you want to go swimming?(y/n)",["y","n"])
if answer == "y":
return "sea"
elif answer == "n":
return "start"
elif location == "sea":
print("Suddenly there was a tsunami,you can't escape.")
hp=0
return "end"
else :
【树莓派如何安装程序】print("Programmer error,room",location,"is unknown")
return "end"
#define the function to use the tools of HP
def use_tools(tool):
global hp
length = len(tool)
for i in range(0,length):
if tool[i]=="50HP":
hp =50
tool.pop(i)
print("You have use the tool of 50HP")
j =1
elif tool[i]=="10HP":
hp =10
tool.pop(i)
print("You have use the tool of 10HP")
j =1
#The begin of the program.
location = "start"
#Loop until we reach the special "end" location
while location!="end":
location = handle_room(location)
#Check we are not dead each return
print("You now have",hp,"health points.")
if hp<=0:
print("You are dead.nGame Over!!!")
break
print("Your adventure has ended,bye~")
推荐阅读
- 如何破解qq空间密码 qq空间密码怎么解破
- 从长沙如何岳麓山
- 日本买表如何过海关
- 小米后如何刷机教程视频
- 小米防水性能如何
- G37 Coupe 的音响系统效果如何?
- 腾讯视频如何下载到电脑上 腾讯视频咋下载到电脑
- 如何防溺水安全知识 防溺水安全知识顺口溜
- 手机如何群发短信 手机如何群发短信?
- 新手应该如何正确换挡?