Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 58 additions & 58 deletions code/shorturl/app.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
from flask import Flask, render_template, request, redirect
import pymysql
from bases import Bases


bases = Bases()
host = 'http://127.0.0.1:5000/'


try:
connection = pymysql.connect(host='localhost',
port=3306,
user='root',
password='root',
db='test',
charset='utf8'
)
except pymysql.Error:
raise

cursor = connection.cursor()


app = Flask('__name__')

@app.route('/')
def index():
return render_template('index.html')


@app.route('/gen_short_url', methods=['POST'])
def gen_short_url():
long_url = request.form.get('long_url')
# 将长链接存入数据库
try:
cursor.execute('insert into urls (url) values ("{}")'.format(long_url))
connection.commit()
except pymysql.Error:
raise
# 获取id
last_id = cursor.lastrowid
# 将 id 转化为 62 进制
encode = bases.toBase62(last_id)
short_url = host + encode
return render_template('index.html', short_url=short_url)


@app.route('/<encode_id>')
def redirect_url(encode_id):
id = bases.fromBase62(encode_id)
try:
cursor.execute('select url from urls where id = {}'.format(id))
connection.commit()
url = cursor.fetchone()
return redirect(url[0])
except pymysql.Error:
raise

from flask import Flask, render_template, request, redirect
import pymysql
from bases import base62
bases = Bases()
host = 'http://127.0.0.1:5000/'
try:
connection = pymysql.connect(host='localhost',
port=3306,
user='root',
password='root',
db='test',
charset='utf8'
)
except pymysql.Error:
raise
cursor = connection.cursor()
app = Flask('__name__')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/gen_short_url', methods=['POST'])
def gen_short_url():
long_url = request.form.get('long_url')
# 将长链接存入数据库
try:
cursor.execute('insert into urls (url) values ("{}")'.format(long_url))
connection.commit()
except pymysql.Error:
raise
# 获取id
last_id = cursor.lastrowid
# 将 id 转化为 62 进制
encode = bases.toBase62(last_id)
short_url = host + encode
return render_template('index.html', short_url=short_url)
@app.route('/<encode_id>')
def redirect_url(encode_id):
id = bases.fromBase62(encode_id)
try:
cursor.execute('select url from urls where id = {}'.format(id))
connection.commit()
url = cursor.fetchone()
return redirect(url[0])
except pymysql.Error:
raise
1 change: 1 addition & 0 deletions python_meme_game
Submodule python_meme_game added at 1407d0
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions vip/kelvinweng/Kelvin_meme_game/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Config:
def __init__(self):
self.game_title = "吃shi啦你"
self.screen_width = 900
self.screen_height = 600
self.screen_bg_color = (255,255,255)

# meme
self.meme_head_size = (60,60)
self.meme_head_image = 'images/head.png'
self.meme_body_block_size = 30
self.meme_body_color = (0,0,0)
22 changes: 22 additions & 0 deletions vip/kelvinweng/Kelvin_meme_game/food.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pygame
import random

class Food:
def __init__(self,meme_game):
self.config = meme_game.config
self.screen = meme_game.screen
self.game = meme_game

self.food = pygame.image.load(self.config.food_image)
self.food = pygame.transform.scale(self.food,self.config.food_size)
self.food_rect = self.food.get_rect()
self.food_rect.x = 585
self.food_rect.y = 30

del blit_food(self):
screen_rect = self.screen.get_rect()
x_num = screen_rect.width
y_num = screen_rect.height
self.food_rect.x = random.randint(0,x_num-1)*30
self.food_rect.y = random.randint(0,y_num-1)*30
self.game.play_sound('chishi')
Binary file added vip/kelvinweng/Kelvin_meme_game/images/food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vip/kelvinweng/Kelvin_meme_game/images/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions vip/kelvinweng/Kelvin_meme_game/meme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pygame

class Meme():
def __init__(self,meme_game):
self.screen = meme_game.screen
self.config = meme_game.config

self.head = pygame.image.load(self.config.meme_head_image)
self.head = pygame.transform.scale(self.head,self.config.meme_head_size)
self.head_rect = self.head.get_rect()
self.head_rect.center = self.screen.get_rect().center

self.body_rect = pygame.Rect(
0,
0,
self.config.meme_body_block_size,
self.config.meme_body_block_size
)

self.len = 3
self.body = [(0,0),(130,200),(160,200)]

self.head_rect.x = 160
self.head_rect.y = 0

self.direction = 'k' #jkhl ----> 下上左右

def blit_meme(self):
for item in self.body:
self.body_rect.x = item[0]
self.body_rect.y = item[1]
pygame.draw.rect(self.screen,self.config.meme_body_color,self.body_rect)
self.screen.blit(self.head,self.head_rect)

def move(self):
head = self.body[0]
if self.direction == 'k':
now_head = (head[0],head[1]+30)
self.body.insert(0,now_head)
self.head_rect.x = now_head[0] - 15
self.head_rect.y = now_head[1] + 15
35 changes: 35 additions & 0 deletions vip/kelvinweng/Kelvin_meme_game/meme_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
import pygame
from config import Config
from meme import Meme

class MemeGame:
def __init__(self):
pygame.init()
self.config = Config()

pygame.display.set_caption(self.config.game_title)

self.screen = pygame.display.set_mode((self.config.screen_width,self.config.screen_height))

self.meme = Meme(self)

def _listen_event(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()

def _update_screen(self):
self.screen.fill(self.config.screen_bg_color)


def run_game(self):
while True:
self._listen_event()
self._update_screen()
self.meme.blit_meme()
pygame.display.flip()

if __name__ == '__main__':
meme_game = MemeGame()
meme_game.run_game()
Binary file added vip/kelvinweng/Kelvin_meme_game/sound/chishi.mp3
Binary file not shown.
Binary file not shown.
Binary file added vip/kelvinweng/Niubility/auido.mp3
Binary file not shown.
Binary file added vip/kelvinweng/Niubility/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vip/kelvinweng/Niubility/cucumber.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions vip/kelvinweng/Niubility/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"err_detail":"16: Open api characters limit reached","err_msg":"16: Open api characters limit reached","err_no":502,"err_subcode":16,"tts_logid":3204479260}
Binary file added vip/kelvinweng/Niubility/floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions vip/kelvinweng/Niubility/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import pygame
from pygame.locals import *
import random



caption_width = 300
caption_height = 600
game_title = '牛逼的黄瓜'

hero_width = 50
hero_height = 50

cucumber_width = 80
cucumber_height = 380

floor_width = caption_width
floor_height = 100

speed = 10
space = 140

score = 0

class Hero(pygame.sprite.Sprite):


def __init__(self,top=0):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('hero.png').convert_alpha()
self.image = pygame.transform.scale(self.image,(hero_width,hero_height))
self.rect = self.image.get_rect()
self.rect.left = caption_width/2 - hero_width
self.rect.top = caption_height/2 - hero_height - top
self.speed = speed

def update(self):
self.speed += 1
self.rect.top += self.speed

def fly(self):
self.speed = -speed


class Cucumber(pygame.sprite.Sprite):

def __init__(self,change,left,top):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('cucumber.png').convert_alpha()
self.image = pygame.transform.scale(self.image,(cucumber_width,cucumber_height))
self.rect = self.image.get_rect()
self.rect.left = left
if change:
self.image = pygame.transform.flip(self.image,False,True)
self.rect.top = - (self.rect.bottom - top)
else:
self.rect.top = caption_height - top

def update(self):
self.rect.left -= speed



class Floor(pygame.sprite.Sprite):

def __init__(self,left):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('floor.png').convert_alpha()
self.image = pygame.transform.scale(self.image,(floor_width,floor_height))
self.rect = self.image.get_rect()
self.rect.left = left
self.rect.top = caption_height - floor_height

def generate_Cucumber(left):
top = random.randint(100,300)
cucumber = Cucumber(False,left,top)
cucumber_changed = Cucumber(True,left,caption_height - top - space)
return cucumber,cucumber_changed

if __name__ == '__main__':
pygame.init()
game_font = pygame.font.SysFont('arial',16)
caption = pygame.display.set_mode((caption_width,caption_height))
pygame.display.set_caption(game_title)

background = pygame.image.load('bg.png')
background = pygame.transform.scale(background,(caption_width,caption_height))

hero_group = pygame.sprite.Group()
hero = Hero()
hero_group.add(hero)

floor_group = pygame.sprite.Group()
floor = Floor(0)
floor_group.add(floor)


cucumber_group = pygame.sprite.Group()
cucumbers1 = generate_Cucumber(300)
cucumber_group.add(cucumbers1[0])
cucumber_group.add(cucumbers1[1])

clock = pygame.time.Clock()

while True:
clock.tick(25)
caption.blit(background,(0,0))
caption.blit(game_font.render('score:%d'%score,True,[0,0,0]),[20,20])

for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_SPACE:
hero.fly()

if cucumber_group.sprites()[0].rect.left < -(caption_width):
cucumber_group.remove(cucumber_group.sprites())
cucumbers = generate_Cucumber(caption_width)
cucumber_group.add(cucumbers[0])
cucumber_group.add(cucumbers[1])
score += 1

hero_group.update()
hero_group.draw(caption)
cucumber_group.update()
cucumber_group.draw(caption)
floor_group.draw(caption)
pygame.display.update()

#if pygame.sprite.groupcollide(hero_group,floor_group,False,False)\
# or pygame.sprite.groupcollide(hero_group,cucumber_group,False,False):
# pygame.quit()
# quit()

Loading