Python之freegames 零代码的22个小游戏集合

简介

  • 简介:零代码的22个小游戏集合
  • 作者:Grant Jenks
  • 版本:2.4.0
  • 安装:
D:\>pip install freegames -i https://pypi.tuna.tsinghua.edu.cn/simple/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting freegames
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/62/f5/643ebe95085f1fea2
d8e4597259d8c56a920df1ed10dcfb65d7b80caff4f/freegames-2.4.0-py3-none-any.whl (10
8 kB)
     ------------------------------------ 109.0/109.0 kB 528.1 kB/s eta 0:00:00
Installing collected packages: freegames
Successfully installed freegames-2.4.0
  • 简要说明:

DESCRIPTION
    Free Python Games is an Apache2 licensed collection of free Python games
    intended for education and fun. The games are written in simple Python code and
    designed for experimentation and changes. Simplified versions of several
    classic arcade games are included.
    
    Python is one of the top-five most popular programming languages in the world
    and available for free from www.python.org. Python includes an extensive
    Standard Library distributed with your installation. The Standard Library has a
    module called Turtle which is a popular way to introduce programming to
    kids. Turtle was part of the original Logo programming language developed by
    Wally Feurzig and Seymour Papert in 1966. All of the games in Free Python Games
    are implemented using Python and its Turtle module.
    
    Starting in 2012, Free Python Games began as an after school program to teach
    programming to inner-city youth. The goal was to have fun as much as it was to
    learn. Since then the games have been improved and used in a variety of
    settings ranging from classrooms to summer day-camps.
    
    The games run anywhere Python can be installed which includes desktop computers
    running Windows, Mac OS, or Linux and older or low-power hardware such as the
    Raspberry Pi. Kids across the United States in grades 6th-12th have enjoyed
    learning about topics such as encryption and projectile motion through games.
    
    Each game is entirely independent from the others and includes comments along
    with a list of exercises to work through with students. Creativity and
    flexibility is important. There is no right or wrong way to implement a new
    feature or behavior! You never know which games students will engage with best.
    
    Free Python Games supports a command-line interface (CLI). Help for the CLI is
    available using::
    
      $ python3 -m freegames --help
    
    The CLI supports three commands: list, copy, and show. For a list of all games
    run::
    
      $ python3 -m freegames list
    
    Any of the listed games may be played by executing the Python module from the
    command-line. To reference the Python module, combine "freegames" with the name
    of the game. For example, to play the "snake" game run::
    
      $ python3 -m freegames.snake
    
    Games can be modified by copying their source code. The copy command will
    create a Python file in your local directory which you can edit. For example,
    to copy and play the "snake" game run::
    
      $ python3 -m freegames copy snake
      $ python3 snake.py
    
    Python includes a built-in text editor named IDLE which can also execute Python
    code. To launch the editor and make changes to the "snake" game run::
    
      $ python3 -m idlelib.idle snake.py

  • 游戏列表:
D:\>python -m freegames list
ant
bagels
bounce
cannon
connect
crypto
fidget
flappy
guess
life
madlibs
maze
memory
minesweeper
pacman
paint
pong
simonsays
snake
tictactoe
tiles
tron

游戏

执行方法 freegames.游戏名

python -m freegames.life

python -m freegames.pacman

python -m freegames.cannon

python -m freegames.pong

python -m freegames.tiles

python -m freegames.maze

代码学习

所谓“零代码”实际上只是作者帮你写好来,拿来就用或者参考学习而已。

执行: python -m freegames copy maze,就能拷贝出源码来

(Windows系统)执行后,在当前用户的文件夹下保存有源文件: maze.py

源代码:很明显游戏是基于turtle库的代码

"""Maze, move from one side to another.
Excercises
1. Keep score by counting taps.
2. Make the maze harder.
3. Generate the same maze twice.
"""

from random import random
from turtle import *

from freegames import line

def draw():
    """Draw maze."""
    color('black')
    width(5)

    for x in range(-200, 200, 40):
        for y in range(-200, 200, 40):
            if random() > 0.5:
                line(x, y, x + 40, y + 40)
            else:
                line(x, y + 40, x + 40, y)

    update()

def tap(x, y):
    """Draw line and dot for screen tap."""
    if abs(x) > 198 or abs(y) > 198:
        up()
    else:
        down()

    width(2)
    color('red')
    goto(x, y)
    dot(4)

setup(420, 420, 370, 0)
hideturtle()
tracer(False)
draw()
onscreenclick(tap)
done()

再来看一个稍微复杂点的“贪吃蛇”代码:

"""Snake, classic arcade game.
Exercises
1. How do you make the snake faster or slower?
2. How can you make the snake go around the edges?
3. How would you move the food?
4. Change the snake to respond to mouse clicks.
"""

from random import randrange
from turtle import *

from freegames import square, vector

food = vector(0, 0)
snake = [vector(10, 0)]
aim = vector(0, -10)

def change(x, y):
    """Change snake direction."""
    aim.x = x
    aim.y = y

def inside(head):
    """Return True if head inside boundaries."""
    return -200 < head.x < 190 and -200 < head.y < 190

def move():
    """Move snake forward one segment."""
    head = snake[-1].copy()
    head.move(aim)

    if not inside(head) or head in snake:
        square(head.x, head.y, 9, 'red')
        update()
        return

    snake.append(head)

    if head == food:
        print('Snake:', len(snake))
        food.x = randrange(-15, 15) * 10
        food.y = randrange(-15, 15) * 10
    else:
        snake.pop(0)

    clear()

    for body in snake:
        square(body.x, body.y, 9, 'black')

    square(food.x, food.y, 9, 'green')
    update()
    ontimer(move, 100)

setup(420, 420, 370, 0)
hideturtle()
tracer(False)
listen()
onkey(lambda: change(10, 0), 'Right')
onkey(lambda: change(-10, 0), 'Left')
onkey(lambda: change(0, 10), 'Up')
onkey(lambda: change(0, -10), 'Down')
move()
done()

内置类和函数

snake游戏中使用了内置的类vector及函数square

>>> from freegames import square, vector

除了这2个库里还有其它3个:

>>> import freegames
>>> freegames.__all__
['floor', 'line', 'path', 'square', 'vector']

使用简介

CLASSES
    collections.abc.Sequence(collections.abc.Reversible, collections.abc.Collection)
        freegames.utils.vector

    class vector(collections.abc.Sequence)
     |  vector(x, y)
     |
     |  Two-dimensional vector.
     |
     |  Vectors can be modified in-place.
     |
     |  >>> v = vector(0, 1)
     |  >>> v.move(1)
     |  >>> v
     |  vector(1, 2)
     |  >>> v.rotate(90)
     |  >>> v
     |  vector(-2.0, 1.0)
     |
     |  Method resolution order:
     |      vector
     |      collections.abc.Sequence
     |      collections.abc.Reversible
     |      collections.abc.Collection
     |      collections.abc.Sized
     |      collections.abc.Iterable
     |      collections.abc.Container
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __abs__(self)
     |      v.__abs__() -> abs(v)
     |
     |      >>> v = vector(3, 4)
     |      >>> abs(v)
     |      5.0
     |
     |  __add__(self, other)
     |      v.__add__(w) -> v + w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v + w
     |      vector(4, 6)
     |      >>> v + 1
     |      vector(2, 3)
     |      >>> 2.0 + v
     |      vector(3.0, 4.0)
     |
     |  __eq__(self, other)
     |      v.__eq__(w) -> v == w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(1, 2)
     |      >>> v == w
     |      True
     |
     |  __getitem__(self, index)
     |      v.__getitem__(v, i) -> v[i]
     |
     |      >>> v = vector(3, 4)
     |      >>> v[0]
     |      3
     |      >>> v[1]
     |      4
     |      >>> v[2]
     |      Traceback (most recent call last):
     |          ...
     |      IndexError
     |
     |  __hash__(self)
     |      v.__hash__() -> hash(v)
     |
     |      >>> v = vector(1, 2)
     |      >>> h = hash(v)
     |      >>> v.x = 2
     |      Traceback (most recent call last):
     |          ...
     |      ValueError: cannot set x after hashing
     |
     |  __iadd__(self, other)
     |      v.__iadd__(w) -> v += w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v += w
     |      >>> v
     |      vector(4, 6)
     |      >>> v += 1
     |      >>> v
     |      vector(5, 7)
     |
     |  __imul__(self, other)
     |      v.__imul__(w) -> v *= w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v *= w
     |      >>> v
     |      vector(3, 8)
     |      >>> v *= 2
     |      >>> v
     |      vector(6, 16)
     |
     |  __init__(self, x, y)
     |      Initialize vector with coordinates: x, y.
     |
     |      >>> v = vector(1, 2)
     |      >>> v.x
     |      1
     |      >>> v.y
     |      2
     |
     |  __isub__(self, other)
     |      v.__isub__(w) -> v -= w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v -= w
     |      >>> v
     |      vector(-2, -2)
     |      >>> v -= 1
     |      >>> v
     |      vector(-3, -3)
     |
     |  __itruediv__(self, other)
     |      v.__itruediv__(w) -> v /= w
     |
     |      >>> v = vector(2, 4)
     |      >>> w = vector(4, 8)
     |      >>> v /= w
     |      >>> v
     |      vector(0.5, 0.5)
     |      >>> v /= 2
     |      >>> v
     |      vector(0.25, 0.25)
     |
     |  __len__(self)
     |      v.__len__() -> len(v)
     |
     |      >>> v = vector(1, 2)
     |      >>> len(v)
     |      2
     |
     |  __mul__(self, other)
     |      v.__mul__(w) -> v * w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v * w
     |      vector(3, 8)
     |      >>> v * 2
     |      vector(2, 4)
     |      >>> 3.0 * v
     |      vector(3.0, 6.0)
     |
     |  __ne__(self, other)
     |      v.__ne__(w) -> v != w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v != w
     |      True
     |
     |  __neg__(self)
     |      v.__neg__() -> -v
     |
     |      >>> v = vector(1, 2)
     |      >>> -v
     |      vector(-1, -2)
     |
     |  __radd__ = __add__(self, other)
     |
     |  __repr__(self)
     |      v.__repr__() -> repr(v)
     |
     |      >>> v = vector(1, 2)
     |      >>> repr(v)
     |      'vector(1, 2)'
     |
     |  __rmul__ = __mul__(self, other)
     |
     |  __sub__(self, other)
     |      v.__sub__(w) -> v - w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v - w
     |      vector(-2, -2)
     |      >>> v - 1
     |      vector(0, 1)
     |
     |  __truediv__(self, other)
     |      v.__truediv__(w) -> v / w
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> w / v
     |      vector(3.0, 2.0)
     |      >>> v / 2
     |      vector(0.5, 1.0)
     |
     |  copy(self)
     |      Return copy of vector.
     |
     |      >>> v = vector(1, 2)
     |      >>> w = v.copy()
     |      >>> v is w
     |      False
     |
     |  move(self, other)
     |      Move vector by other (in-place).
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v.move(w)
     |      >>> v
     |      vector(4, 6)
     |      >>> v.move(3)
     |      >>> v
     |      vector(7, 9)
     |
     |  rotate(self, angle)
     |      Rotate vector counter-clockwise by angle (in-place).
     |
     |      >>> v = vector(1, 2)
     |      >>> v.rotate(90)
     |      >>> v == vector(-2, 1)
     |      True
     |
     |  scale(self, other)
     |      Scale vector by other (in-place).
     |
     |      >>> v = vector(1, 2)
     |      >>> w = vector(3, 4)
     |      >>> v.scale(w)
     |      >>> v
     |      vector(3, 8)
     |      >>> v.scale(0.5)
     |      >>> v
     |      vector(1.5, 4.0)
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  x
     |      X-axis component of vector.
     |
     |      >>> v = vector(1, 2)
     |      >>> v.x
     |      1
     |      >>> v.x = 3
     |      >>> v.x
     |      3
     |
     |  y
     |      Y-axis component of vector.
     |
     |      >>> v = vector(1, 2)
     |      >>> v.y
     |      2
     |      >>> v.y = 5
     |      >>> v.y
     |      5
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |
     |  PRECISION = 6
     |
     |  __abstractmethods__ = frozenset()
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from collections.abc.Sequence:
     |
     |  __contains__(self, value)
     |
     |  __iter__(self)
     |
     |  __reversed__(self)
     |
     |  count(self, value)
     |      S.count(value) -> integer -- return number of occurrences of value
     |
     |  index(self, value, start=0, stop=None)
     |      S.index(value, [start, [stop]]) -> integer -- return first index of value.
     |      Raises ValueError if the value is not present.
     |
     |      Supporting start and stop arguments is optional, but
     |      recommended.
     |
     |  ----------------------------------------------------------------------
     |  Class methods inherited from collections.abc.Reversible:
     |
     |  __subclasshook__(C) from abc.ABCMeta
     |      Abstract classes can override this to customize issubclass().
     |
     |      This is invoked early on by abc.ABCMeta.__subclasscheck__().
     |      It should return True, False or NotImplemented.  If it returns
     |      NotImplemented, the normal algorithm is used.  Otherwise, it
     |      overrides the normal algorithm (and the outcome is cached).

FUNCTIONS
    floor(value, size, offset=200)
        Floor of `value` given `size` and `offset`.

        The floor function is best understood with a diagram of the number line::

             -200  -100    0    100   200
            <--|--x--|-----|--y--|--z--|-->

        The number line shown has offset 200 denoted by the left-hand tick mark at
        -200 and size 100 denoted by the tick marks at -100, 0, 100, and 200. The
        floor of a value is the left-hand tick mark of the range where it lies. So
        for the points show above: ``floor(x)`` is -200, ``floor(y)`` is 0, and
        ``floor(z)`` is 100.

        >>> floor(10, 100)
        0.0
        >>> floor(120, 100)
        100.0
        >>> floor(-10, 100)
        -100.0
        >>> floor(-150, 100)
        -200.0
        >>> floor(50, 167)
        -33.0

    line(a, b, x, y)
        Draw line from `(a, b)` to `(x, y)`.

    path(filename)
        Return full path to `filename` in freegames module.

    square(x, y, size, name)
        Draw square at `(x, y)` with side length `size` and fill color `name`.

        The square is oriented so the bottom left corner is at (x, y).

另外还有20段代码,你可以用命令自己copy出来一一学习。总体来说,代码难度不是很高,重要的是要自己动手模仿编出新的游戏来!

以上就是Python之freegames 零代码的22个小游戏集合的详细内容,更多关于Python之freegames库的资料请关注我们其它相关文章!

(0)

相关推荐

  • Python+numpy实现一个蜘蛛纸牌游戏

    目录 1.过程 2.思路 3.配置 4.代码 四.效果图 1.过程 蜘蛛纸牌大家玩过没有?之前的电脑上自带的游戏,用他来摸鱼过的举个手. 但是现在的电脑上已经没有蜘蛛纸牌了.所以…… 可不可以自己做一个呢? 想法有了,实践开始. 首先,应该怎么写?首选的方案就是pygame和numpy. 最后选了numpy.一是因为作者用电脑的时间比较短,没有时间力,而手机的在线编译器可以用numpy,不能用pygame.二是因为之前了解过numpy,但是pygame当时都没安装,是昨天才安装完毕的三是因为想挑

  • Python+Pygame编写一个Pong游戏

    目录 前言 代码教学 最终代码 前言 这次,我们要用Pygame写一个Pong游戏 先看看效果: 需要的模块:Pygame 在python文件同目录下新建resources文件夹,在文件夹中新建Pong文件夹,文件夹中放入两个音频文件 代码教学 导入需要的模块 import pygame from pygame.locals import * import random import sys 定义常量 COUNTDOWN=USEREVENT+1 path="resources/Pong/&quo

  • Python+Pygame实战之文字剧情游戏的实现

    目录 前言 一.<巨龙之洞> 1)小故事 2)环境配置 3)代码展示 4)效果展示 二.<太空矿工> 1)小故事 2)环境配置 3)代码展示 4)效果展示 前言 哈喽!我是你们的栗子同学——又到周一,新的一天也要元气满满啊~ 想了下是不是你们还是喜欢游戏代码(肯定是 嗯嗯.jpg)今天换个口味给大家写一些文字游戏 吧!送我上热门蛮~下次再写爬虫的吧!喜欢啥写啥哦~ 今日游戏更新——自己取的名字哦,不是在推荐别的游戏,不要限流呀~(代码版本)<巨龙之洞>.<太空矿工

  • Python Pygame实战之实现经营类游戏梦想小镇代码版

    目录 导语 一.注意事项 二.运行环境 三.代码展示 四.效果展示 导语 梦想还是要有的,万一实现了呢?!今天小编就来用代码实现自己专属的城市——特大都市:梦想小镇启航.顾名思义,梦想小镇是梦想花开之地. 我是一名模拟经营类游戏的发烧友,各种农场类.医院类.铁路类的游戏玩儿了很多年.以前在电脑上玩单机版,自从有了手游,就可以随时随地玩儿了(别被老板看到,哈哈哈). 经营类游戏有个特点就是变化少,时间长了难免觉得单调.so,朋友想看看我能不能写出这个类型的游戏,评论区问我给安排不?of cours

  • Python+Pygame实现接小弹珠游戏

    目录 游戏介绍 效果展示 游戏代码 项目资源 游戏介绍 小学生都不一定会晚的游戏,用挡板接住会反弹的小球,随着次数的增多,速度变快,分数增多. 效果展示 游戏代码 import pygame as pg import sys from random import randint import time pg.init() #对pygame内部各功能模块进行初始化创建及变量设置,默认调用 game_window = pg.display.set_mode((600, 500)) #初始化显示窗口,

  • Python+Pygame实战之俄罗斯方块游戏的实现

    目录 导语 一.运行环境 二.代码展示 三.效果展示 导语 俄罗斯方块,作为是一款家喻户晓的游戏,陪伴70.80甚至90后,度过无忧的儿时岁月 它上手简单能自由组合.拼接技巧也很多. 你知道么,最原始的俄罗斯方块,是长这样婶儿的~ 是不是很有童年的味道?今天小编还要给大家,介绍一个全新版本——程序员的版本,期待期待 自从俄罗斯猫被制裁以后,很多人不禁担心起俄罗斯方块的命运. 虽然名字的含俄量很高,但这款游戏圈抗衰老神话肯定不会遭殃,因为它的版权归美国人所有,跟俄罗斯没半毛钱关系.很多玩了半辈子俄

  • Python+Pygame实战之炫舞小游戏的实现

    目录 导语 一.环境安装 二.代码展示 三.效果展示 1)简洁版炫舞 ​2)随机截图 3)MISS节拍 导语 昨天去老姐家里蹭饭,进门的时候就看到佳佳妹(我姐的女儿)低头霹雳吧啦一顿操作猛如虎,饭好了都还在玩儿,什么东西这么好玩?一走进就看到这是一款酷似炫舞的小游戏.(死去的回忆突然在攻击我~没想到现在还有这款游戏就是不知道升级了多少次啦) 不知道你们还记不记得曾经有个风靡一时的舞蹈游戏炫舞. 我读小学的时候,大概是09年吧,这个游戏非常火爆,如果你去网吧,十个女生里,有十一个都是在玩炫舞,像我

  • Python利用3D引擎写一个Pong游戏

    目录 前言 实现方法 完整代码 前言 之前,我们用pygame做了一个2D的Pong游戏,今天我们做一个3D的,游戏画面如下: 用ad和←→操作,双人对战 实现该效果我们使用Python强大的3D引擎Ursina,基础的使用方法见这篇文章:详解Python 3D引擎Ursina如何绘制立体图形 接下来开始写代码吧! 实现方法 首先,导入ursina和随机库 from ursina import * import random as rd 定义两个玩家的分数 scorea=scoreb=0 然后,

  • 使用Python第三方库pygame写个贪吃蛇小游戏

    今天看到几个关于pygame模块的博客和视频,感觉非常有趣,这里照猫画虎写了一个贪吃蛇小游戏,目前还有待完善,但是基本游戏功能已经实现,下面是代码: # 导入模块 import pygame import random # 初始化 pygame.init() w = 720 #窗口宽度 h = 600 #窗口高度 ROW = 30 #行数 COL = 36 #列数 #将所有的坐标看作是一个个点,定义点类 class Point: row = 0 col = 0 def __init__(self

  • Python实现的摇骰子猜大小功能小游戏示例

    本文实例讲述了Python实现的摇骰子猜大小功能小游戏.分享给大家供大家参考,具体如下: 最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环境:python2.7 , 附上源代码如下: 摇骰子的函数,这个函数其实并不需要传任何参数,调用后会返回三个点数结果的列表. import random def roll_dice(numbers=3,points=None): print ('<<<<< ROLL THE DI

  • C语言代码实现三子棋小游戏

    本文实例为大家分享了C语言实现三子棋小游戏的具体代码,供大家参考,具体内容如下 设计思路 三子棋的C语言设计的思路: 1.设计一个界面:让玩家运行后即可以看到一个界面,而此时界面需要一个让玩家选择的语句,即可以选择玩游戏或者退出操作.界面设计需要swich语句的实现,退出游戏设计选项为0,即可以当选择退出游戏时直接退出while(循环),即结束游戏. 2.游戏实现:当玩家选择玩游戏时,调用启动游戏的函数,而在游戏中,应当有的内容有: (1)游戏内的棋盘设计:三子棋应当是三行三列的一个棋盘,通过函

  • C++代码实现贪吃蛇小游戏

    本文实例为大家分享了C++实现贪吃蛇小游戏的具体代码,供大家参考,具体内容如下 1.游戏描述 贪吃蛇可谓是从小玩到大的经典趣味小游戏,蛇每吃到一次食物,身体就会长一节,如果撞到墙或者撞到自身,游戏结束. 2.代码实现 1.首先需要思考的问题是如何指定位置输出字符?这时候就有一个非常强大的函数叫 gotoxy() ,现在库函数里边已经没有了,只能我们自己实现,代码中注释很完整,自行阅读即可. 2.实现了指哪画哪的目标之后,就可以开始游戏内容制作了.首先便是圈地,即画地图,一个简简单单的循环就能安排

  • JavaScript用200行代码制作打飞机小游戏实例

    我去,我的图片分数被这个录屏软件的水印盖上了,扎心. 这个程序的文件以及代码全部上传到了github 程序下载链接传送门 这是自己第一次通过js写的小游戏,那个时候对象的原理跟结构体的概念不是特别的清晰,所以没用对象来写,所以直接导致后期我对这个程序进行修改的时候出现问题,太过于复杂了,我终于了解什么叫做牵一发动全身了.所以这个程序教会我一定一定要用对象的思想处理以后的问题,尤其是这种带属性明显的东西. 当然你要问我图片怎么来的我只能说都是我自己画的所以这可是原创的原创. 代码部分我是通过一个大

  • C语言代码实现推箱子小游戏

    本文实例为大家分享了C语言实现推箱子小游戏的具体代码,供大家参考,具体内容如下 本次游戏是个推箱子第一关最简单的小游戏 有详细注释,下面是做出来的游戏界面 游戏操作说明和功能说明: 1.按wasd控制小人的上下左右移动. 2.按 r 重新开始游戏 3.游戏开始有操作介绍 4.游戏结束有胜利提示 游戏原理分析 1.游戏开始时的星星个数 = 箱子在星星上的个数时 , 游戏胜利. 2.按 r 键重新开始游戏, 我们需要定义一个量 map_1[8][8] 来保存游戏初始时的界面, 操作时我们将其赋值给

  • python实现带界面的井字棋小游戏

    目录 1.首先安装tkinter 2.初始化窗口 3.定义按钮 4.检查获胜的条件 今天我们用python+tkinter安装带界面的井字棋,效果如图所示. Tkinter 是 Python 的标准 GUI 库.Python 使用 Tkinter 可以快速的创建 GUI 应用程序.由于 Tkinter 是内置到 python 的安装包中.只要安装好 Python 之后就能 import Tkinter 库.而且 IDLE 也是用 Tkinter 编写而成.对于简单的图形界面 Tkinter 还是

  • C语言代码实现简单扫雷小游戏

    用C语言写一个简单的扫雷,供大家参考,具体内容如下 1.所需要的知识 c语言的基本语法,简单的二维数组,一点简单的递归知识. 2.总体思路 扫雷游戏主要由3个部分组成,埋雷子,扫雷,判断输赢. 扫雷游戏的主体是两个个字符类型的二维数组.一个是mine[][]它的构成是'0'和'1',其中'0'表示无雷,'1'表示有雷.一个是show[][]它的构成是'*'和'数字'.星号表示未开启的地方,数字表示周围的雷数.这里要注意的是:mine和show的实际大小是11x11,但是展示的效果是 9x9.这样

  • Python实现Pig Latin小游戏实例代码

    前言: 本文研究的主要是Python实现pig Latin小游戏的简单代码,具体介绍如下. Pig Latin是一个语言游戏. 步骤: 1.让用户输入一个英文单词 2.确保用户输入一个有效单词 3.将单词转换成Pig Latin 4.显示转换结果 一.Input 函数:raw_input()用于输出一个字符串并等待键盘输入某字符串,最后以Enter(或Return)结束输入 original = raw_input("Enter a word:") print original 上述中

  • python实现统计代码行数的小工具

    一个用python实现的统计代码行数的小工具,供大家参考,具体内容如下 实现功能 计算出某一目录以及子目录下代码文件的行数 在计算代码的过程中,只对标准命名的文件进行统计,如[文件名.文件类型] 排除了以"#"开头的包含文件,宏定义等,如#include, #define, #pragma等 排除了c,cpp文件中的"//", "/-/"等的注释 排除了python文件中import, from 等开头的导入 使用方法 新建countLines.

随机推荐