【闲来无事,py写game】一个问答游戏Trivia -来自《Python游戏编程入门》

正文之前

嗯,没错,我只是为了规范化,就写这么多了!要洗澡了,明早有事!

正文

Trivia是一款书籍阅读类软件,支持Android 2.3.3。具体的内容是:

1.从网是络上收集比较人们比较容易忽视的冷知识
2.每周服务器端会自动更新冷知识
3.在阅读页面长按会弹出收藏和分享的list进行收藏和分享。


而我,做了个简化版的,好吧,这就是个问答游戏!没了~人家是卖内容,我啥都没得卖!!人家的高端版本的都是这么玩的!!


import pygame,sys
import time
import math
from pygame.locals import *
white=255,255,255
blue = 1,1,200
def print_text(font,x,y,text,color=white,shadow=True):
    if shadow:
        imgText = font.render(text,True,(0,0,0))
        screen.blit(imgText,(x-2,y-2))
    imgText=font.render(text,True,color)
    screen.blit(imgText,(x,y))

class Trivia(object):
    def __init__(self,filename):
        self.data = []
        self.current = 0 
        self.total = 0 
        self.correct = 0
        self.score = 0 
        self.scored = False
        self.failed = False
        self.wronganswer = 0
        self.colors = [white,white,white,white]

        f=open(filename,"r")
        trivia_data = f.readlines()
        f.close()

        for text_line in trivia_data:
            self.data.append(text_line.strip())
            self.total+=1

    def show_question(self):
        print_text(font1,210,5,"TRIVIA GAME")
        print_text(font2,190,500-20,"Press Keys (1-4) To Answer",purple)
        print_text(font2,530,5,"SCORE",purple)

        self.correct = int(self.data[self.current+5])

        question=self.current
        print_text(font1,5,80,"Question"+str(question))
        print_text(font2,20,120,self.data[self.current],yellow)

        if self.scored:
            self.colors = [white,white,white,white]
            self.colors[self.current-1] = green
            print_text(font1,230,380,"CORRECT!",green)
            print_text(font2,170,420,"Press Enter for Next One",green)
        elif self.failed:
            self.colors = [white,white,white,white]
            self.colors[self.current-1] = red
            print_text(font1,230,380,"INCORRECT!",red)
            print_text(font2,170,420,"Press Enter for Next One",red)
        print_text(font1,5,170,"Answer")
        print_text(font2,20,210,"1- "+self.data[self.current+1],self.colors[0])
        print_text(font2,20,240,"2- "+self.data[self.current+2],self.colors[1])
        print_text(font2,20,270,"3- "+self.data[self.current+3],self.colors[2])
        print_text(font2,20,300,"4- "+self.data[self.current+4],self.colors[3])

    def handle_input(self,number):
        if not self.scored and not self.failed:
            if number == self.correct:
                self.scored=True
                self.score+=1
            else:
                self.failed = True
                self.wronganswer = number
    def next_question(self):
        if self.scored or self.failed:
            self.failed = False
            self.scored = False
            self.correct = 0
            self.colors = [white,white,white,white]
            self.current += 6
            if self.current >= self.total:
                self.current = 0 

pygame.init()
screen = pygame.display.set_mode((600,600))
pygame.display.set_caption("The Trivia Game")
font1=pygame.font.Font(None,40)
font2=pygame.font.Font(None,24)
cyan=0,255,255
yellow=255,255,0
purple=255,0,255
green=0,255,0
red=255,0,0

trivia=Trivia("/Users/zhangzhaobo/test.txt")

while(True):
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        elif event.type == KEYUP:
            if event.type == pygame.K_ESCAPE:
                sys.exit()
            elif event.type == pygame.K_LEFT:
                trivia.handle_input(1)
            elif event.type == pygame.K_RIGHT:
                trivia.handle_input(2)
            elif event.type == pygame.K_UP:
                trivia.handle_input(3)
            elif event.type == pygame.K_DOWN:
                trivia.handle_input(4)
            elif event.type == pygame.K_RETURN:
                trivia.next_question()
    screen.fill((0,0,200))
    trivia.show_question()
    pygame.display.update()

不知道为啥,我没法进入下一个问题。感觉自己是错了。但是没找到跟书上的有差别的地方,有兴趣的可以玩下,我是没法了。要洗澡了,明早要去南一楼找教学主任签字。我要去计算机学院做毕设真是前路漫漫!!

英文版本的简介:

The trivia (singular trivium) are three lower Artes Liberales, i.e. grammar, logic, and rhetoric. These were the topics of basic education, foundational to the quadrivia of higher education, and hence the material of basic education and an important building block for all undergraduates.

The ancient Romans used the word triviae to describe where one road split or forked into two roads. Triviae was formed from tri (three) and viae (roads) – literally meaning "three roads", and in transferred use "a public place" and hence the meaning "commonplace."[2]

The pertaining adjective is triviālis. The adjective trivial was adopted in Early Modern English, while the noun trivium only appears in learned usage from the 19th century, in reference to the Artes Liberales and the plural trivia in the sense of "trivialities, trifles" only in the 20th century.[citation needed]

The Latin adjective triviālis in Classical Latin besides its literal meaning could have the meaning "appropriate to the street corner, commonplace, vulgar." In late Latin, it could also simply mean "triple." In medieval Latin, it came to refer to the lower division of the Artes Liberales, namely grammar, rhetoric, and logic. (The other four Liberal Arts were the quadrivium, namely arithmetic, geometry, music, and astronomy, which were more challenging.) Hence, trivial in this sense would have meant "of interest only to an undergraduate."[citation needed]


正文之后

表情包,真的可以!!拯救世界! 对了,推荐一本小书《重燃》真的写得好,我今天看了一天,这是多久以来这么浪了???忘了。反正以我的长久经验来说,这本书,真的好!!看完的话,还有一本我一直追的《从学霸开始》也是不可多得的优秀重生校园类文章!!真的很好!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,490评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,581评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,830评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,957评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,974评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,754评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,464评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,357评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,847评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,995评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,137评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,819评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,482评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,023评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,149评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,409评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,086评论 2 355

推荐阅读更多精彩内容