diff --git a/sources/tech/20171214 Build a game framework with Python using the module Pygame.md b/sources/tech/20171214 Build a game framework with Python using the module Pygame.md deleted file mode 100644 index 1acdd12a7c..0000000000 --- a/sources/tech/20171214 Build a game framework with Python using the module Pygame.md +++ /dev/null @@ -1,283 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (robsean) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Build a game framework with Python using the module Pygame) -[#]: via: (https://opensource.com/article/17/12/game-framework-python) -[#]: author: (Seth Kenlon https://opensource.com/users/seth) - -Build a game framework with Python using the module Pygame -====== -The first part of this series explored Python by creating a simple dice game. Now it's time to make your own game from scratch. -![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python2-header.png?itok=tEvOVo4A) - -In my [first article in this series][1], I explained how to use Python to create a simple, text-based dice game. This time, I'll demonstrate how to use the Python module Pygame to create a graphical game. It will take several articles to get a game that actually does anything, but by the end of the series, you will have a better understanding of how to find and learn new Python modules and how to build an application from the ground up. - -Before you start, you must install [Pygame][2]. - -### Installing new Python modules - -There are several ways to install Python modules, but the two most common are: - - * From your distribution's software repository - * Using the Python package manager, pip - - - -Both methods work well, and each has its own set of advantages. If you're developing on Linux or BSD, leveraging your distribution's software repository ensures automated and timely updates. - -However, using Python's built-in package manager gives you control over when modules are updated. Also, it is not OS-specific, meaning you can use it even when you're not on your usual development machine. Another advantage of pip is that it allows local installs of modules, which is helpful if you don't have administrative rights to a computer you're using. - -### Using pip - -If you have both Python and Python3 installed on your system, the command you want to use is probably `pip3`, which differentiates it from Python 2.x's `pip` command. If you're unsure, try `pip3` first. - -The `pip` command works a lot like most Linux package managers. You can search for Python modules with `search`, then install them with `install`. If you don't have permission to install software on the computer you're using, you can use the `--user` option to just install the module into your home directory. - -``` -$ pip3 search pygame -[...] -Pygame (1.9.3)                 - Python Game Development -sge-pygame (1.5)               - A 2-D game engine for Python -pygame_camera (0.1.1)          - A Camera lib for PyGame -pygame_cffi (0.2.1)            - A cffi-based SDL wrapper that copies the pygame API. -[...] -$ pip3 install Pygame --user -``` - -Pygame is a Python module, which means that it's just a set of libraries that can be used in your Python programs. In other words, it's not a program that you launch, like [IDLE][3] or [Ninja-IDE][4] are. - -### Getting started with Pygame - -A video game needs a setting; a world in which it takes place. In Python, there are two different ways to create your setting: - - * Set a background color - * Set a background image - - - -Your background is only an image or a color. Your video game characters can't interact with things in the background, so don't put anything too important back there. It's just set dressing. - -### Setting up your Pygame script - -To start a new Pygame project, create a folder on your computer. All your game files go into this directory. It's vitally important that you keep all the files needed to run your game inside of your project folder. - -![](https://opensource.com/sites/default/files/u128651/project.jpg) - -A Python script starts with the file type, your name, and the license you want to use. Use an open source license so your friends can improve your game and share their changes with you: - -``` -#!/usr/bin/env python3 -# by Seth Kenlon - -## GPLv3 -# This program is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program.  If not, see . -``` - -Then you tell Python what modules you want to use. Some of the modules are common Python libraries, and of course, you want to include the one you just installed, Pygame. - -``` -import pygame  # load pygame keywords -import sys     # let  python use your file system -import os      # help python identify your OS -``` - -Since you'll be working a lot with this script file, it helps to make sections within the file so you know where to put stuff. You do this with block comments, which are comments that are visible only when looking at your source code. Create three blocks in your code. - -``` -''' -Objects -''' - -# put Python classes and functions here - -''' -Setup -''' - -# put run-once code here - -''' -Main Loop -''' - -# put game loop here -``` - -Next, set the window size for your game. Keep in mind that not everyone has a big computer screen, so it's best to use a screen size that fits on most people's computers. - -There is a way to toggle full-screen mode, the way many modern video games do, but since you're just starting out, keep it simple and just set one size. - -``` -''' -Setup -''' -worldx = 960 -worldy = 720 -``` - -The Pygame engine requires some basic setup before you can use it in a script. You must set the frame rate, start its internal clock, and start (`init`) Pygame. - -``` -fps   = 40  # frame rate -ani   = 4   # animation cycles -clock = pygame.time.Clock() -pygame.init() -``` - -Now you can set your background. - -### Setting the background - -Before you continue, open a graphics application and create a background for your game world. Save it as `stage.png` inside a folder called `images` in your project directory. - -There are several free graphics applications you can use. - - * [Krita][5] is a professional-level paint materials emulator that can be used to create beautiful images. If you're very interested in creating art for video games, you can even purchase a series of online [game art tutorials][6]. - * [Pinta][7] is a basic, easy to learn paint application. - * [Inkscape][8] is a vector graphics application. Use it to draw with shapes, lines, splines, and Bézier curves. - - - -Your graphic doesn't have to be complex, and you can always go back and change it later. Once you have it, add this code in the setup section of your file: - -``` -world    = pygame.display.set_mode([worldx,worldy]) -backdrop = pygame.image.load(os.path.join('images','stage.png').convert()) -backdropbox = world.get_rect() -``` - -If you're just going to fill the background of your game world with a color, all you need is: - -``` -world = pygame.display.set_mode([worldx,worldy]) -``` - -You also must define a color to use. In your setup section, create some color definitions using values for red, green, and blue (RGB). - -``` -''' -Setup -''' - -BLUE  = (25,25,200) -BLACK = (23,23,23 ) -WHITE = (254,254,254) -``` - -At this point, you could theoretically start your game. The problem is, it would only last for a millisecond. - -To prove this, save your file as `your-name_game.py` (replace `your-name` with your actual name). Then launch your game. - -If you are using IDLE, run your game by selecting `Run Module` from the Run menu. - -If you are using Ninja, click the `Run file` button in the left button bar. - -![](https://opensource.com/sites/default/files/u128651/ninja_run_0.png) - -You can also run a Python script straight from a Unix terminal or a Windows command prompt. - -``` -$ python3 ./your-name_game.py -``` - -If you're using Windows, use this command: - -``` -py.exe your-name_game.py -``` - -However you launch it, don't expect much, because your game only lasts a few milliseconds right now. You can fix that in the next section. - -### Looping - -Unless told otherwise, a Python script runs once and only once. Computers are very fast these days, so your Python script runs in less than a second. - -To force your game to stay open and active long enough for someone to see it (let alone play it), use a `while` loop. To make your game remain open, you can set a variable to some value, then tell a `while` loop to keep looping for as long as the variable remains unchanged. - -This is often called a "main loop," and you can use the term `main` as your variable. Add this anywhere in your setup section: - -``` -main = True -``` - -During the main loop, use Pygame keywords to detect if keys on the keyboard have been pressed or released. Add this to your main loop section: - -``` -''' -Main loop -''' -while main == True: -    for event in pygame.event.get(): -        if event.type == pygame.QUIT: -            pygame.quit(); sys.exit() -            main = False - -        if event.type == pygame.KEYDOWN: -            if event.key == ord('q'): -                pygame.quit() -                sys.exit() -                main = False -``` - -Also in your main loop, refresh your world's background. - -If you are using an image for the background: - -``` -world.blit(backdrop, backdropbox) -``` - -If you are using a color for the background: - -``` -world.fill(BLUE) -``` - -Finally, tell Pygame to refresh everything on the screen and advance the game's internal clock. - -``` -    pygame.display.flip() -    clock.tick(fps) -``` - -Save your file, and run it again to see the most boring game ever created. - -To quit the game, press `q` on your keyboard. - -In the [next article][9] of this series, I'll show you how to add to your currently empty game world, so go ahead and start creating some graphics to use! - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/17/12/game-framework-python - -作者:[Seth Kenlon][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/seth -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/article/17/10/python-101 -[2]: http://www.pygame.org/wiki/about -[3]: https://en.wikipedia.org/wiki/IDLE -[4]: http://ninja-ide.org/ -[5]: http://krita.org -[6]: https://gumroad.com/l/krita-game-art-tutorial-1 -[7]: https://pinta-project.com/pintaproject/pinta/releases -[8]: http://inkscape.org -[9]: https://opensource.com/article/17/12/program-game-python-part-3-spawning-player diff --git a/sources/tech/20190205 Install Apache, MySQL, PHP (LAMP) Stack On Ubuntu 18.04 LTS.md b/sources/tech/20190205 Install Apache, MySQL, PHP (LAMP) Stack On Ubuntu 18.04 LTS.md index 13b441f85d..7ce1201c4f 100644 --- a/sources/tech/20190205 Install Apache, MySQL, PHP (LAMP) Stack On Ubuntu 18.04 LTS.md +++ b/sources/tech/20190205 Install Apache, MySQL, PHP (LAMP) Stack On Ubuntu 18.04 LTS.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: (ustblixin) +[#]: translator: ( ) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) diff --git a/sources/tech/20190410 Managing Partitions with sgdisk.md b/sources/tech/20190410 Managing Partitions with sgdisk.md deleted file mode 100644 index b42fef82af..0000000000 --- a/sources/tech/20190410 Managing Partitions with sgdisk.md +++ /dev/null @@ -1,94 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Managing Partitions with sgdisk) -[#]: via: (https://fedoramagazine.org/managing-partitions-with-sgdisk/) -[#]: author: (Gregory Bartholomew https://fedoramagazine.org/author/glb/) - -Managing Partitions with sgdisk -====== - -![][1] - -[Roderick W. Smith][2]‘s _sgdisk_ command can be used to manage the partitioning of your hard disk drive from the command line. The basics that you need to get started with it are demonstrated below. - -The following six parameters are all that you need to know to make use of sgdisk’s most basic features: - - 1. **-p** -_Print_ the partition table: -### sgdisk -p /dev/sda - 2. **-d x** -_Delete_ partition x: -### sgdisk -d 1 /dev/sda - 3. **-n x:y:z** -Create a _new_ partition numbered x, starting at y and ending at z: -### sgdisk -n 1:1MiB:2MiB /dev/sda - 4. **-c x:y** -_Change_ the name of partition x to y: -### sgdisk -c 1:grub /dev/sda - 5. **-t x:y** -Change the _type_ of partition x to y: -### sgdisk -t 1:ef02 /dev/sda - 6. **–list-types** -List the partition type codes: -### sgdisk --list-types - - - -![The SGDisk Command][3] - -As you can see in the above examples, most of the commands require that the [device file name][4] of the hard disk drive to operate on be specified as the last parameter. - -The parameters shown above can be combined so that you can completely define a partition with a single run of the sgdisk command: - -### sgdisk -n 1:1MiB:2MiB -t 1:ef02 -c 1:grub /dev/sda - -Relative values can be specified for some fields by prefixing the value with a **+** or **–** symbol. If you use a relative value, sgdisk will do the math for you. For example, the above example could be written as: - -### sgdisk -n 1:1MiB:+1MiB -t 1:ef02 -c 1:grub /dev/sda - -The value **0** has a special-case meaning for several of the fields: - - * In the _partition number_ field, 0 indicates that the next available number should be used (numbering starts at 1). - * In the _starting address_ field, 0 indicates that the start of the largest available block of free space should be used. Some space at the start of the hard drive is always reserved for the partition table itself. - * In the _ending address_ field, 0 indicates that the end of the largest available block of free space should be used. - - - -By using **0** and relative values in the appropriate fields, you can create a series of partitions without having to pre-calculate any absolute values. For example, the following sequence of sgdisk commands would create all the basic partitions that are needed for a typical Linux installation if in run sequence against a blank hard drive: - -### sgdisk -n 0:0:+1MiB -t 0:ef02 -c 0:grub /dev/sda -### sgdisk -n 0:0:+1GiB -t 0:ea00 -c 0:boot /dev/sda -### sgdisk -n 0:0:+4GiB -t 0:8200 -c 0:swap /dev/sda -### sgdisk -n 0:0:0 -t 0:8300 -c 0:root /dev/sda - -The above example shows how to partition a hard disk for a BIOS-based computer. The [grub partition][5] is not needed on a UEFI-based computer. Because sgdisk is calculating all the absolute values for you in the above example, you can just skip running the first command on a UEFI-based computer and the remaining commands can be run without modification. Likewise, you could skip creating the swap partition and the remaining commands would not need to be modified. - -There is also a short-cut for deleting all the partitions from a hard disk with a single command: - -### sgdisk --zap-all /dev/sda - -For the most up-to-date and detailed information, check the man page: - -$ man sgdisk - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/managing-partitions-with-sgdisk/ - -作者:[Gregory Bartholomew][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://fedoramagazine.org/author/glb/ -[b]: https://github.com/lujun9972 -[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/managing-partitions-816x345.png -[2]: https://www.rodsbooks.com/ -[3]: https://fedoramagazine.org/wp-content/uploads/2019/04/sgdisk.jpg -[4]: https://en.wikipedia.org/wiki/Device_file -[5]: https://en.wikipedia.org/wiki/BIOS_boot_partition diff --git a/sources/tech/20190415 Getting started with Mercurial for version control.md b/sources/tech/20190415 Getting started with Mercurial for version control.md index c2e451fd06..10812affed 100644 --- a/sources/tech/20190415 Getting started with Mercurial for version control.md +++ b/sources/tech/20190415 Getting started with Mercurial for version control.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: ( ) +[#]: translator: (geekpi) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) diff --git a/sources/tech/20190416 How to Install MySQL in Ubuntu Linux.md b/sources/tech/20190416 How to Install MySQL in Ubuntu Linux.md index ee3a82ca03..87d7c98172 100644 --- a/sources/tech/20190416 How to Install MySQL in Ubuntu Linux.md +++ b/sources/tech/20190416 How to Install MySQL in Ubuntu Linux.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: ( ) +[#]: translator: (arrowfeng) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) diff --git a/translated/tech/20171214 Build a game framework with Python using the module Pygame.md b/translated/tech/20171214 Build a game framework with Python using the module Pygame.md new file mode 100644 index 0000000000..7ce7402959 --- /dev/null +++ b/translated/tech/20171214 Build a game framework with Python using the module Pygame.md @@ -0,0 +1,279 @@ +[#]: collector: (lujun9972) +[#]: translator: (robsean) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Build a game framework with Python using the module Pygame) +[#]: via: (https://opensource.com/article/17/12/game-framework-python) +[#]: author: (Seth Kenlon https://opensource.com/users/seth) + +使用 Python 和 Pygame 模块构建一个游戏框架 +====== +这系列的第一篇通过创建一个简单的骰子游戏来探究 Python。现在是来从零制作你自己的游戏的时间。 +![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python2-header.png?itok=tEvOVo4A) + +在我的 [这系列的第一篇文章][1] 中, 我已经讲解如何使用 Python 创建一个简单的,基于文本的骰子游戏。这次,我将展示如何使用 Python 和 Pygame 模块来创建一个图形化游戏。它将占用一些文章来得到一个确实完成一些东西的游戏,但是在这系列的结尾,你将有一个更好的理解,如何查找和学习新的 Python 模块和如何从其基础上构建一个应用程序。 + +在开始前,你必须安装 [Pygame][2]。 + +### 安装新的 Python 模块 + +这里有一些方法来安装 Python 模块,但是最通用的两个是: + + * 从你的发行版的软件存储库 + * 使用 Python 的软件包管理器,pip + +两个方法都工作很好,并且每一个都有它自己的一套优势。如果你是在 Linux 或 BSD 上开发,促使你的发行版的软件存储库确保自动及时更新。 + +然而,使用 Python 的内置软件包管理器给予你控制更新模块时间的能力。而且,它不是明确指定操作系统的,意味着,即使当你不是在你常用的开发机器上时,你也可以使用它。pip 的其它的优势是允许模块局部安装,如果你没有一台正在使用的计算机的权限,它是有用的。 + +### 使用 pip + +如果 Python 和 Python3 都安装在你的系统上,你想使用的命令很可能是 `pip3`,它区分来自Python 2.x 的 `pip` 的命令。如果你不确定,先尝试 `pip3`。 + +`pip` 命令有些像大多数 Linux 软件包管理器的工作。你可以使用 `search` 搜索 Pythin 模块,然后使用 `install` 安装它们。如果你没有你正在使用的计算机的权限来安装软件,你可以使用 `--user` 选项来仅仅安装模块到你的 home 目录。 + +``` +$ pip3 search pygame +[...] +Pygame (1.9.3)                 - Python Game Development +sge-pygame (1.5)               - A 2-D game engine for Python +pygame_camera (0.1.1)          - A Camera lib for PyGame +pygame_cffi (0.2.1)            - A cffi-based SDL wrapper that copies the pygame API. +[...] +$ pip3 install Pygame --user +``` + +Pygame 是一个 Python 模块,这意味着它仅仅是一套可以被使用在你的 Python 程序中库。换句话说,它不是一个你启动的程序,像 [IDLE][3] 或 [Ninja-IDE][4] 一样。 + +### Pygame 新手入门 + +一个电子游戏需要一个故事背景;一个发生的地点。在 Python 中,有两种不同的方法来创建你的故事背景: + + * 设置一种背景颜色 + * 设置一张背景图片 + +你的背景仅是一张图片或一种颜色。你的电子游戏人物不能与在背景中的东西相互作用,因此,不要在后面放置一些太重要的东西。它仅仅是设置装饰。 + +### 设置你的 Pygame 脚本 + +为了开始一个新的 Pygame 脚本,在计算机上创建一个文件夹。游戏的全部文件被放在这个目录中。在工程文件夹内部保持所需要的所有的文件来运行游戏是极其重要的。 + +![](https://opensource.com/sites/default/files/u128651/project.jpg) + +一个 Python 脚本以文件类型,你的姓名,和你想使用的协议开始。使用一个开放源码协议,以便你的朋友可以改善你的游戏并与你一起分享他们的更改: + +``` +#!/usr/bin/env python3 +# Seth Kenlon 编写 + +## GPLv3 +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see . +``` + +然后,你告诉 Python 你想使用的模块。一些模块是常见的 Python 库,当然,你想包括一个你刚刚安装的,Pygame 。 + +``` +import pygame  # 加载 pygame 关键字 +import sys     # 让 python 使用你的文件系统 +import os      # 帮助 python 识别你的操作系统 +``` + +由于你将用这个脚本文件工作很多,在文件中制作成段落是有帮助的,以便你知道在哪里放原料。使用语句块注释来做这些,这些注释仅在看你的源文件代码时是可见的。在你的代码中创建三个语句块。 + +``` +''' +Objects +''' + +# 在这里放置 Python 类和函数 + +''' +Setup +''' + +# 在这里放置一次性的运行代码 + +''' +Main Loop +''' + +# 在这里放置游戏的循环代码指令 +``` + +接下来,为你的游戏设置窗口大小。注意,不是每一个人都有大计算机屏幕,所以,最好使用一个适合大多数人的计算机的屏幕大小。 + +这里有一个方法来切换全屏模式,很多现代电子游戏做的方法,但是,由于你刚刚开始,保存它简单和仅设置一个大小。 + +``` +''' +Setup +''' +worldx = 960 +worldy = 720 +``` + +在一个脚本中使用 Pygame 引擎前,你需要一些基本的设置。你必需设置帧频,启动它的内部时钟,然后开始 (`init`) Pygame 。 + +``` +fps   = 40  # 帧频 +ani   = 4   # 动画循环 +clock = pygame.time.Clock() +pygame.init() +``` + +现在你可以设置你的背景。 + +### 设置背景 + +在你继续前,打开一个图形应用程序,并为你的游戏世界创建一个背景。在你的工程目录中的 `images` 文件夹内部保存它为 `stage.png` 。 + +这里有一些你可以使用的自由图形应用程序。 + + * [Krita][5] 是一个专业级绘图原料模拟器,它可以被用于创建漂亮的图片。如果你对电子游戏创建艺术作品非常感兴趣,你甚至可以购买一系列的[游戏艺术作品教程][6]. + * [Pinta][7] 是一个基本的,易于学习的绘图应用程序。 + * [Inkscape][8] 是一个矢量图形应用程序。使用它来绘制形状,线,样条曲线,和 Bézier 曲线。 + + + +你的图像不必很复杂,你可以以后回去更改它。一旦你有它,在你文件的 setup 部分添加这些代码: + +``` +world    = pygame.display.set_mode([worldx,worldy]) +backdrop = pygame.image.load(os.path.join('images','stage.png').convert()) +backdropbox = world.get_rect() +``` + +如果你仅仅用一种颜色来填充你的游戏的背景,你需要做的全部是: + +``` +world = pygame.display.set_mode([worldx,worldy]) +``` + +你也必需定义一个来使用的颜色。在你的 setup 部分,使用红,绿,蓝 (RGB) 的值来创建一些颜色的定义。 + +``` +''' +Setup +''' + +BLUE  = (25,25,200) +BLACK = (23,23,23 ) +WHITE = (254,254,254) +``` + +在这点上,你能理论上启动你的游戏。问题是,它可能仅持续一毫秒。 + +为证明这一点,保存你的文件为 `your-name_game.py` (用你真实的名称替换 `your-name` )。然后启动你的游戏。 + +如果你正在使用 IDLE ,通过选择来自 Run 菜单的 `Run Module` 来运行你的游戏。 + +如果你正在使用 Ninja ,在左侧按钮条中单击 `Run file` 按钮。 + +![](https://opensource.com/sites/default/files/u128651/ninja_run_0.png) + +你也可以直接从一个 Unix 终端或一个 Windows 命令提示符中运行一个 Python 脚本。 + +``` +$ python3 ./your-name_game.py +``` + +如果你正在使用 Windows ,使用这命令: + +``` +py.exe your-name_game.py +``` + +你启动它,不过不要期望很多,因为你的游戏现在仅仅持续几毫秒。你可以在下一部分中修复它。 + +### 循环 + +除非另有说明,一个 Python 脚本运行一次并仅一次。近来计算机的运行速度是非常快的,所以你的 Python 脚本运行时间少于1秒钟。 + +为强制你的游戏来处于足够长的打开和活跃状态来让人看到它(更不要说玩它),使用一个 `while` 循环。为使你的游戏保存打开,你可以设置一个变量为一些值,然后告诉一个 `while` 循环只要变量保持未更改则一直保存循环。 + +这经常被称为一个"主循环",你可以使用术语 `main` 作为你的变量。在你的 setup 部分的任意位置添加这些代码: + +``` +main = True +``` + +在主循环期间,使用 Pygame 关键字来检查是否在键盘上的按键已经被按下或释放。添加这些代码到你的主循环部分: + +``` +''' +Main loop +''' +while main == True: +    for event in pygame.event.get(): +        if event.type == pygame.QUIT: +            pygame.quit(); sys.exit() +            main = False + +        if event.type == pygame.KEYDOWN: +            if event.key == ord('q'): +                pygame.quit() +                sys.exit() +                main = False +``` + +也在你的循环中,刷新你世界的背景。 + +如果你使用一个图片作为背景: + +``` +world.blit(backdrop, backdropbox) +``` + +如果你使用一种颜色作为背景: + +``` +world.fill(BLUE) +``` + +最后,告诉 Pygame 来刷新在屏幕上的所有内容并推进游戏的内部时钟。 + +``` +    pygame.display.flip() +    clock.tick(fps) +``` + +保存你的文件,再次运行它来查看曾经创建的最无趣的游戏。 + +退出游戏,在你的键盘上按 `q` 键。 + +在这系列的 [下一篇文章][9] 中,我将向你演示,如何加强你当前空的游戏世界,所以,继续学习并创建一些将要使用的图形! + +-------------------------------------------------------------------------------- + +通过: https://opensource.com/article/17/12/game-framework-python + +作者:[Seth Kenlon][a] +选题:[lujun9972][b] +译者:[robsean](https://github.com/robsean) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/seth +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/article/17/10/python-101 +[2]: http://www.pygame.org/wiki/about +[3]: https://en.wikipedia.org/wiki/IDLE +[4]: http://ninja-ide.org/ +[5]: http://krita.org +[6]: https://gumroad.com/l/krita-game-art-tutorial-1 +[7]: https://pinta-project.com/pintaproject/pinta/releases +[8]: http://inkscape.org +[9]: https://opensource.com/article/17/12/program-game-python-part-3-spawning-player diff --git a/translated/tech/20190410 Managing Partitions with sgdisk.md b/translated/tech/20190410 Managing Partitions with sgdisk.md new file mode 100644 index 0000000000..19f2752245 --- /dev/null +++ b/translated/tech/20190410 Managing Partitions with sgdisk.md @@ -0,0 +1,94 @@ +[#]: collector: (lujun9972) +[#]: translator: (geekpi) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Managing Partitions with sgdisk) +[#]: via: (https://fedoramagazine.org/managing-partitions-with-sgdisk/) +[#]: author: (Gregory Bartholomew https://fedoramagazine.org/author/glb/) + +使用 sgdisk 管理分区 +====== + +![][1] + +[Roderick W. Smith][2] 的 _sgdisk_ 命令可在命令行中管理硬盘的分区。下面将介绍使用它所需的基础知识。 + +以下六个参数是你使用 sgdisk 大多数基本功能所需了解的: + + 1. **-p** +_打印_ 分区表: +### sgdisk -p /dev/sda + 2. **-d x** +_删除_分区 x: +### sgdisk -d 1 /dev/sda + 3. **-n x:y:z** +创建一个编号 x 的_新_分区,从 y 开始,从 z 结束: +### sgdisk -n 1:1MiB:2MiB /dev/sda + 4. **-c x:y** +_更改_分区 x 的名称为 y: +### sgdisk -c 1:grub /dev/sda + 5. **-t x:y** +将分区 x 的_类型_更改为 y: +### sgdisk -t 1:ef02 /dev/sda + 6. **–list-types** +列出分区类型代码: +### sgdisk --list-types + + + +![The SGDisk Command][3] + +如你在上面的例子中所见,大多数命令都要求将要操作的硬盘的[设备文件名][4]指定为最后一个参数。 + +可以组合上面的参数,这样你可以一次定义所有分区: + +### sgdisk -n 1:1MiB:2MiB -t 1:ef02 -c 1:grub /dev/sda + +在值的前面加上 **+** 或 **–** 符号,可以为某些字段指定相对值。如果你使用相对值,sgdisk 会为你做数学运算。例如,上面的例子可以写成: + +### sgdisk -n 1:1MiB:+1MiB -t 1:ef02 -c 1:grub /dev/sda + +**0** 值对于以下几个字段是特殊情况: + + * 对于_分区号_字段,0 表示应使用下一个可用编号(编号从 1 开始)。 +  * 对于_起始地址_字段,0 表示使用最大可用空闲块的头。硬盘开头的一些空间始终保留给分区表本身。 +  * 对于_结束地址_字段,0 表示使用最大可用空闲块的末尾。 + + + +通过在适当的字段中使用 **0** 和相对值,你可以创建一系列分区,而无需预先计算任何绝对值。例如,如果在一块空白硬盘中,以下 sgdisk 命令序列将创建典型 Linux 安装所需的所有基本分区: + +### sgdisk -n 0:0:+1MiB -t 0:ef02 -c 0:grub /dev/sda +### sgdisk -n 0:0:+1GiB -t 0:ea00 -c 0:boot /dev/sda +### sgdisk -n 0:0:+4GiB -t 0:8200 -c 0:swap /dev/sda +### sgdisk -n 0:0:0 -t 0:8300 -c 0:root /dev/sda + +上面的例子展示了如何为基于 BIOS 的计算机分区硬盘。基于 UEFI 的计算机上不需要 [grub分区][5]。由于 sgdisk 在上面的示例中为你计算了所有绝对值,因此你可以在基于 UEFI 的计算机上跳过第一个命令,并且可以无需修改即可运行其余命令。同样,你可以跳过创建交换分区,并且不需要修改其余命令。 + +还有使用一个命令删除硬盘上所有分区的快捷方式: + +### sgdisk --zap-all /dev/sda + +关于最新和详细信息,请查看手册页: + +$ man sgdisk + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/managing-partitions-with-sgdisk/ + +作者:[Gregory Bartholomew][a] +选题:[lujun9972][b] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/glb/ +[b]: https://github.com/lujun9972 +[1]: https://fedoramagazine.org/wp-content/uploads/2019/04/managing-partitions-816x345.png +[2]: https://www.rodsbooks.com/ +[3]: https://fedoramagazine.org/wp-content/uploads/2019/04/sgdisk.jpg +[4]: https://en.wikipedia.org/wiki/Device_file +[5]: https://en.wikipedia.org/wiki/BIOS_boot_partition