Beginner python and OpenGL, practiced hand's first small program life.py, this small program will continue to adjust in the future, add class, optimize judgment and operation
Execution effect:
Rules according to normal life game:
1, the surrounding life is equal to 3 to produce life
2, the surrounding life is equal to 2 o'clock remains unchanged
3, red and green two kinds of mutual erosion (new)
4. Death i
Given an array of non-negative integers, you is initially positioned at the first index of the array.Each element of the array represents your maximum jump length is at that position.Determine if you is able to reach the last index.for example:a =[2,3,1,1,4" , Returntrue . A = [3,2,1,0,4] , return false .This is a greedy problem with each step we need to check fastest reach step. If There is a step cannot help we step further that means we cannot reach the end.Code is as follow:Jump
10
30
-5 (P)
This problem is two-dimensional dynamic programming, the key is the tectonic transfer equation. The first requirement for each step of the move process Knight HP is greater than 0, followed by the minimum requirements.
So we can construct a matrix DP of MXN to record the moving process. Its transfer equation is Dp[row][col]=max (1,min (dp[row+1][col],dp[row][col+1])-dungeon[row][col]) space complexity and time complexity are O (MN)
This was
In the previous section, the ball is moved freely. In this section, the arrow keys are used to control the ball movement and background images are added to the game.
I. Implementation:
[Python]#-*-Coding: UTF-8 -*-Import OSImport sysImport pygameFrom pygame. locals import *Def load_image (pic_name ):'''''Function: Image Loading FunctionInput: NONEOutput: NONEAuthor: socratesBlog: http://blog.csdn.net/dyx102
Start letting the ball bounce back and forth in the vertical direction of the canvas.fromtkinterimport*importrandomimporttime# Create Ball class classball: def__init__ (Self,canvas,color): #初始化函数, including canvas and color parameters self.canvas=canvas #把参数canvas赋值给对象变量canvas self.id=canvas.create_oval (10,10,25,25,fill=color) #创建椭圆, Upper-left and lower-right XY coordinates, returning id representing the graphic Self.canvas.move (self.id,245,100) #把画好的椭圆形移动的画布中心, graphical ID represe
Python game engine development: TextField text
TextField
Anyone who has used flash knows that this class is not only used to display text, but also used to display input boxes. I will only implement some basic and practical functions here, and it will take some time to expand. Like the previous chapter,TextFieldIs a display object inherited fromDisplayObject. The following code is used:
class TextField(Disp
Python game engine development (7): drawing vector Graphs
Today, we will draw a vector image.Graphics class
First, createGraphicsClass is used to create vector graphics:
Class Graphics (DisplayObject): def _ init _ (self): super (Graphics, self ). _ init _ () # self. _ drawingList = [] # used to store the current graphic data self. _ currentGraphics = None
Since our window interface is constantly being clea
= ='Yes' orPlayagain = ='y': the + Displayintro () - $Cavenumber =Choosecave () $ - Checkcave (Cavenumber) - the Print('do you want to play it again? (yes or on)') -Playagain = input ()Coin toss Game1 ImportRandom2 Print('I toss 1000 coins and guess how many times it is facing up. Press ENTER to start ~')3 input ()4Flips =05Heads =06 whileFlips :7 ifRandom.randint (0,1) = = 1:8Heads = Heads + 19Flips = flips + 1Ten ifFlips = = 10: One Print('10 times inside, there'+ STR
Pygame1.pygame recognition: Pygame is a set of SDL-based templates for developing games that can be python to create fully-interface games and multimedia programs, and it can basically run on any system. Free2. Ready to install: Look at the system, if the Linux or OSX need PIP installation, if for Windows download Pygame directly, (if the EXE run directly. If WHL is run with PIP (must be in the directory)) {pip Install XXXXXXXX.WHL}3. Alien Invasion (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.