Skip to content

Commit

Permalink
python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bison-- committed Sep 24, 2021
1 parent 32dd54b commit 9d0c281
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion popUp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
try:
import pygame_sdl2 as pygame
except ImportError:
print "pygame_sdl2 not found; falling back to pygame."
print("pygame_sdl2 not found; falling back to pygame.")
import pygame
import time

Expand Down
9 changes: 5 additions & 4 deletions snake.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python


from __future__ import print_function
import os
#from screen import screen
import sys
import random

try:
import pygame_sdl2 as pygame
except ImportError:
print "pygame_sdl2 not found; falling back to pygame."
print("pygame_sdl2 not found; falling back to pygame.")
import pygame
import conf
from ui import ui
Expand Down Expand Up @@ -292,7 +293,7 @@ def run_game(self):
elif event.key == pygame.K_q:
self.exit_game()
else:
print "event.key:", event.key
print("event.key:", event.key)
#if event.key == pygame.K_UP:
# self.move(1)
else:
Expand All @@ -301,7 +302,7 @@ def run_game(self):

if conf.TOUCH_SCREEN:
mouseAction = self.touchScreen.getEventBoxes()
if mouseAction > 0:
if mouseAction and mouseAction > 0:
if gameOver:
self.resetGame()
gameOver = False
Expand Down
4 changes: 3 additions & 1 deletion touchScreen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import print_function

try:
import pygame_sdl2 as pygame
except ImportError:
print "pygame_sdl2 not found; falling back to pygame."
print("pygame_sdl2 not found; falling back to pygame.")
import pygame

class touchScreen(object):
Expand Down
10 changes: 5 additions & 5 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# notes:
# The Ten Commandments Of Video Game Menus http://kotaku.com/5955855/the-ten-commandments-of-video-game-menus

from __future__ import print_function
try:
import pygame_sdl2 as pygame
except ImportError:
print "pygame_sdl2 not found; falling back to pygame."
print("pygame_sdl2 not found; falling back to pygame.")
import pygame
import sys

Expand Down Expand Up @@ -183,11 +183,11 @@ def draw(self, menuKey=''):

elif event.type == pygame.KEYDOWN:
if iUi.interaction(event.key):
print "UI catched this key:", event.key
print("UI catched this key:", event.key)
else:
print "no UI catch, key pressed:", event.key
print("no UI catch, key pressed:", event.key)
if pygame.K_RETURN == event.key:
print "selected item:", iUi.getSelectedItem()
print("selected item:", iUi.getSelectedItem())

if event.key == pygame.K_q:
sys.exit(0)
Expand Down

0 comments on commit 9d0c281

Please sign in to comment.