2014-02-09 24 views
0

我很難試圖找出如何做到這一點。 好吧,我想通過我正在開發的Android遊戲賺錢,所以我認爲我可以在其中放入廣告,但根據廣泛的研究(pgs4a沒有很好地記錄),這需要一個體面的Java知識,我沒有。所以我想我可以創建一個adf.ly鏈接到我的網站,並使用python的webbrowser模塊在android的瀏覽器中打開它。但是當我打電話給webbrowser.open(「example.com」)時,什麼也沒有發生,然後遊戲崩潰。pgs4a:使用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

哇,我很快地解決了這個問題一個。

作爲最後的希望,我嘗試輸入一個完整的網址:open('http://google.com'),它的工作就像一個魅力。

因此,對於任何人想知道,完整的網址是必需的!