#play class for the title screen

import pygame
from pygame.locals import *

import gfx, snd, data, sheep, ticker

#images = ['title']
images = ['winner', 'loser']


class ShowImage:
    def __init__(self, winorlose):
    	self.nextmode = None
	self.Update = self.FirstUpdate
	if winorlose:
	    self.image = images.winner
	else:
	    self.image = images.loser
	self.ticker = ticker.Ticker(2000)
	

    def HandleEvent(self, e):   #handle an event
	if e.type in (KEYDOWN,QUIT,MOUSEBUTTONDOWN):
    	    self.nextmode = -1
	    

    def GetNextMode(self): #next mode, None=nochange, -1=quit
    	return self.nextmode


    def FirstUpdate(self, screen, time): #only called first draw
    	screen.blit(self.image, (0,0))



    def RealUpdate(self, screen, time):
    	if not self.ticker:
	    self.ticker = ticker.Ticker(1000)
	    sheep.sound()
	else:
	    self.ticker.tick(time)


class Play:
    def __init__(self):
    	self.nextmode = None
	self.Update = self.FirstUpdate

    def HandleEvent(self, e):   #handle an event
	if e.type == KEYDOWN:
	    if e.key == K_ESCAPE:
	    	self.nextmode = -1

    def GetNextMode(self): #next mode, None=nochange, -1=quit
    	return self.nextmode


    def FirstUpdate(self, screen, time): #only called first draw
        #r = gfx.position(images.title, center=gfx.res.center)
    	#r = screen.blit(images.title, r)
    	r = screen.fill((100,100,100))
	self.Update = self.RealUpdate
	return [gfx.res]


    def RealUpdate(self, screen, time):
    	return []
