我很难弄清楚如何做到这一点。 好的,所以我想通过我正在处理的安卓游戏货币化,所以我想我可以在其中放置广告,但是根据广泛的研究,(pgs4a的文档记录不是很好),这需要对java的正确认识,我没有。所以我想我可以创建一个adf.ly链接到我的网站,并在android的浏览器中使用python的webbrowser模块打开它。但是当我调用webbrowser.open(“example.com”)时没有任何反应,然后游戏崩溃了。
我做错了什么?它在文档中指出webbrowser应该可以工作,任何pgs4a专家都请帮帮我,这里是代码:
import pygame
from pygame.locals import *
from random import randrange,choice
from math import trunc
import webbrowser
try:
import android
except ImportError:
android = None
pygame.init()
if android:
android.init()
android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
import android.mixer as mixer
else:
import pygame.mixer as mixer
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=500)
passsnd=mixer.Sound('pass.wav')
splatsnd=mixer.Sound('splat.wav')
scor=0
font=pygame.font.Font(None,45)
def main():
scoredraw=font.render('Score: '+str(scor), 0, (255,255,255))
screen=pygame.display.set_mode((480,640))
px=64
py=240
yspeed=0
clock=pygame.time.Clock()
bird=pygame.image.load('bird.png').convert()
bird.set_colorkey((0,255,0))
bloodspr=pygame.image.load('blood.png').convert()
bloodspr.set_colorkey((0,0,0))
run=1
mode=1
endtime='alive'
class Obstacle(object):
def __init__(self,x):
top=randrange(50,300)
self.rect=pygame.Rect(x,0,64,top)
self.rectt=pygame.Rect(x,top+160,64,480)
self.dead=0
self.gameover=0
def update(self):
if self.gameover==0:
self.rect.right-=3
self.rectt.right-=3
if self.dead==0 and self.rect.centerx<px:
global scor
global scoredraw
passsnd.play()
scor+=1
scoredraw=font.render('Score: '+str(scor), 0, (255,255,255))
self.dead=1
if self.rect.right<0:
obs.remove(self)
obs.append(Obstacle(640))
pygame.draw.rect(screen, (0,255,0), self.rect, 0)
pygame.draw.rect(screen, (0,255,0), self.rectt, 0)
class BloodPart(object):
def __init__(self,x,y):
self.direction=choice([[0,0],[-randrange(5,30),randrange(5,30)],[randrange(5,30),randrange(5,30)],[randrange(5,30),-randrange(5,30)],[-randrange(5,30),-randrange(5,30)]])
self.x=x
self.y=trunc(y)
def update(self):
if self.y<592:
self.x+=self.direction[0]
self.y+=self.direction[1]
pygame.draw.circle(screen, (255,0,0), (self.x,self.y), 3)
self.direction[1]+=3
if self.y>590:
splatsnd.play()
else:
screen.blit(bloodspr,(self.x,605))
obs=[Obstacle(640)]
go=0
pdead=0
playerrect=pygame.Rect(px-16,py-16,32,32)
blood=[]
#+++++++++++++++HERE IS THE ERROR++++++++++++++++++++++++++++++++++++++++++++++++++
webbrowser.open('facebook.com')
while go==0:
screen.fill((0,0,0))
words=font.render('Tap to Begin',1,(255,255,255))
if android:
if android.check_pause():
android.wait_for_resume()
for e in pygame.event.get():
if e.type==KEYUP:
if e.key==K_ESCAPE:
run=0
go=1
if e.type==MOUSEBUTTONUP:
if e.button==1:
go=1
screen.blit(words, (165,250))
pygame.display.flip()
while run==1:
if android:
if android.check_pause():
android.wait_for_resume()
if mode==1:
screen.fill((0,15,185))
for o in obs:
o.update()
if o.rect.colliderect(playerrect) or o.rectt.colliderect(playerrect):
o.gameover=1
if pdead==0:
while len(blood)<15:
blood.append(BloodPart(px,py))
pdead=1
for e in pygame.event.get():
if e.type==MOUSEBUTTONDOWN:
if pdead==0:
yspeed=-12
if e.type==QUIT:
run=0
if e.type==KEYUP:
if e.key==K_ESCAPE:
run=0
if yspeed<18:
yspeed+=0.9
py+=yspeed
if py>592:
py=592
pdead=1
if len(blood)<15:
blood.append(BloodPart(px,py))
for o in obs:
o.gameover=1
if endtime=='alive':
endtime=82
if py<0:
py+=14
playerrect=pygame.Rect(px-16,py-16,32,32)
screen.blit(bird,(px-16,py-16))
pygame.draw.rect(screen, (94,64,0), (0,640,480,-32), 0)
for b in blood:
b.update()
screen.blit(scoredraw, (0,0))
clock.tick(70)
if endtime is not 'alive':
endtime-=1
if endtime==0:
mode=2
pygame.display.update()
else:
screen.fill((0,0,0))
words=font.render('Score: '+str(scor), 0, (255,0,0))
words2=font.render('Tap to Retry',0,(255,255,255))
screen.blit(words, (180,250))
screen.blit(words2,(150,320))
for e in pygame.event.get():
if e.type==QUIT:
run=0
if e.type==KEYUP:
if e.key==K_ESCAPE:
run=0
if e.type==MOUSEBUTTONUP:
mode=1
px=64
py=240
yspeed=0
go=0
bird=pygame.image.load('bird.png').convert()
bird.set_colorkey((0,255,0))
bloodspr=pygame.image.load('blood.png').convert()
bloodspr.set_colorkey((0,0,0))
run=1
mode=1
endtime='alive'
obs=[Obstacle(640)]
pdead=0
playerrect=pygame.Rect(px-16,py-16,32,32)
blood=[]
global scor
global scoredraw
scor=0
scoredraw=font.render('Score: '+str(scor), 0, (255,255,255))
pygame.display.update()
main()
我尝试过的事情:
using open_new()
enabling INTERNET in the config
using different urls
答案 0 :(得分:0)
作为最后的希望,我尝试输入一个完整的网址:open('http://google.com')
,它就像一个魅力。
所以对于其他想知道的人来说,需要一个完整的网址!