介绍

这个例子主要利用turtle库实现根据输入动态展示不同机器人的图像和属性信息。

代码部分非原创只是做了些许修改和整理使得更易阅读。

图片和文件资源请访问git仓库获取:

https://gitee.com/indexman/python-core

涉及以下知识点:

  1. 文件读取
  2. 字典
  3. turtle库的使用
  4. 控制语句

实现的效果

代码

#!/bin/python3

from turtle import *
from random import choice screen = Screen()
screen.setup(400, 400)
screen.bgcolor('white')
penup()
hideturtle()
robots = {} file = open('resource/cards.txt', 'r') # 将文件中机器人信息装载到字典中
for line in file.read().splitlines():
name, battery, intelligence, usefulness, speed, image, colour = line.split(', ')
robots[name] = [battery, intelligence, usefulness, speed, image, colour]
screen.register_shape('img/' + image)
file.close() print('Robots: ', ', '.join(robots.keys()), ' (or random)') while True:
robot = input("Choose a robot: ")
if robot == "random":
robot = choice(list(robots.keys()))
print(robot) if robot in robots:
stats = robots[robot]
style = ('Courier', 14, 'bold')
clear()
color(stats[5])
goto(0, 100)
shape('img/' + stats[4])
setheading(90)
# 将当前位置上的形状复制到画布上
stamp()
setheading(-90)
forward(70)
write('Name: ' + robot, font=style, align='center')
forward(25)
write('Battery: ' + stats[0], font=style, align='center')
forward(25)
write('Intelligence: ' + stats[1], font=style, align='center')
forward(25)
write('Usefulness: ' + stats[2], font=style, align='center')
forward(25)
write('Speed: ' + stats[3], font=style, align='center')
else:
print("Robot doesn't exist!")

Python之机器人卡牌的更多相关文章

  1. [Firefly引擎][学习笔记二][已完结]卡牌游戏开发模型的设计

    源地址:http://bbs.9miao.com/thread-44603-1-1.html 在此补充一下Socket的验证机制:socket登陆验证.会采用session会话超时的机制做心跳接口验证 ...

  2. BZOJ 4205: 卡牌配对

    4205: 卡牌配对 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 173  Solved: 76[Submit][Status][Discuss] ...

  3. 使用UIKit制作卡牌游戏(三)ios游戏篇

    译者: Lao Jiang | 原文作者: Matthijs Hollemans写于2012/07/13 转自朋友Tommy 的翻译,自己只翻译了这第三篇教程. 原文地址: http://www.ra ...

  4. CCOrbitCamera卡牌翻转效果

    static CCOrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngl ...

  5. JLOI 2013 卡牌游戏

    问题描述: N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X,则庄家首先 ...

  6. cocos2d-x 卡牌翻牌效果的实现

    转自:http://blog.csdn.net/yanghuiliu/article/details/9115833 这个能实现翻牌的action就是CCOrbitCamera. static CCO ...

  7. [JLOI2013]卡牌游戏

    [题目描述 Description] N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡 ...

  8. [bzoj3191] [JLOI2013]卡牌游戏

    概率DP. 首先由题解可得>_<,胜出概率只与剩余人数.与庄家的相对位置有关. 所以设f[i][j]表示剩下i个人,从庄家开始第j个人的胜利概率... 根据卡牌一通乱搞即可... #inc ...

  9. bzoj 3191: [JLOI2013]卡牌游戏

    Description N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X ...

  10. BZOJ_3191_[JLOI2013]卡牌游戏_概率DP

    BZOJ_3191_[JLOI2013]卡牌游戏_概率DP Description   N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随 ...

随机推荐

  1. [转帖]TiDB系统调参实战经验

    https://tidb.net/blog/c9466c40#TiDB%E7%B3%BB%E7%BB%9F%E8%B0%83%E5%8F%82%E5%AE%9E%E6%88%98%E7%BB%8F%E ...

  2. [转帖]tidb Modify Configuration Dynamically

    https://docs.pingcap.com/tidb/v6.5/dynamic-config This document describes how to dynamically modify ...

  3. [转帖]TiDB 5.1 Write Stalls 应急文档

    https://tidb.net/blog/ac7174dd#4.%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E5%87%BA%E7%8E%B0%E4%BA%86%20w ...

  4. [转帖]MioIO读/写性能测试

    https://www.jianshu.com/p/a0a84f91b16f   image.png COSBench是Intel团队基于java开发,是一个测试云对象存储系统的分布式基准测试工具,全 ...

  5. [转帖]gcc与makefile常用操作(绝对常用,也绝对够用)

    makefile与gcc常用操作 一.温故知新 1.可执行程序的生成过程 2.gcc的常用操作 二.make操作 三.编写Makefile文件时常用操作 注意:在Makefile文件中 空格和缩进是完 ...

  6. [转帖]02-rsync备份方式

    https://developer.aliyun.com/article/885789?spm=a2c6h.24874632.expert-profile.283.7c46cfe9h5DxWK 简介: ...

  7. [知乎]2019-nCov的致死率问题

    https://www.zhihu.com/question/369630554/answer/998649507 知乎 dr.李的文章 跟自己一开始的理解很相似.. 个人也认为死亡率会高于2% 武汉 ...

  8. 飞腾2000+上面银河麒麟v10 安装virt-manager创建虚拟机的操作过程

    操作系统安装完之后自带了repos 就可以执行大部分操作, 不需要修改包源 ###Kylin Linux Advanced Server 10 - os repo### [ks10-adv-os] n ...

  9. diff算法是如何比较的,保证让你看的明明白白的!

    更新dom节点,最小力度去跟新 index.html <body> <h1>你好啊!</h1> <button id="btn">该 ...

  10. 利用pearcmd.php本地文件包含(LFI)

    本文主要是为了学习如何用pearcmd进行本地文件包含 0x00  环境准备 首先先在docker中安装一个php环境. docker exec -it [container id] /bin/bas ...