<s> import pygame <EOL> from pygame . locals import * <EOL> import gamelib <EOL> from elements import Arrow <EOL> from elements import Text <EOL> class MainGame ( gamelib . SimpleGame ) : <EOL> BLACK = pygame . Color ( '<STR_LIT>' ) <EOL> WHITE = pygame . Color ( '<STR_LIT>' ) <EOL> SECOND = <NUM_LIT:1000> <EOL> def __init__ ( self ) : <EOL> super ( MainGame , self ) . __init__ ( '<STR_LIT>' , MainGame . BLACK ) <EOL> self . instruction = [ ] <EOL> self . arrow = Arrow ( pos = ( self . window_size [ <NUM_LIT:0> ] / <NUM_LIT:2> , self . window_size [ <NUM_LIT:1> ] / <NUM_LIT:2> ) ) <EOL> x = self . window_size [ <NUM_LIT:0> ] / <NUM_LIT:20> <EOL> y = self . window_size [ <NUM_LIT:1> ] <EOL> self . create_instruction ( "<STR_LIT>" , ( x , y - <NUM_LIT> ) , MainGame . WHITE , self . font ) <EOL> self . init_game ( ) <EOL> def create_instruction ( self , text , pos , color , font ) : <EOL> self . instruction . append ( Text ( text , pos , color , font ) ) <EOL> def init ( self ) : <EOL> super ( MainGame , self ) . init ( ) <EOL> def init_game ( self ) : <EOL> self . score = <NUM_LIT:0> <EOL> self . arrow . change ( ) <EOL> self . time_limit = <NUM_LIT:2> * MainGame . SECOND <EOL> self . time_decrease = <NUM_LIT> <EOL> self . is_started = False <EOL> self . is_game_over = False <EOL> def update ( self ) : <EOL> if self . is_started and not self . is_game_over : <EOL> if self . is_over_time ( ) : <EOL> self . game_over ( ) <EOL> self . check_key ( ) <EOL> def is_over_time ( self ) : <EOL> if self . get_time ( ) - self . time > self . time_limit : <EOL> return True <EOL> return False <EOL> def get_time ( self ) : <EOL> return pygame . time . get_ticks ( ) <EOL> def check_key ( self ) : <EOL> for event in pygame . event . get ( ) : <EOL> if event . type == KEYUP : <EOL> self . check_key_exit ( event ) <EOL> if not self . is_game_over : <EOL> self . check_key_direction ( event ) <EOL> else : <EOL> self . check_key_reset ( event ) <EOL> def check_key_exit ( self , event ) : <EOL> if event . key == pygame . K_ESCAPE : <EOL> self . terminate ( ) <EOL> def check_key_direction ( self , event ) : <EOL> if event . key == pygame . K_h : <EOL> self . check_direction ( '<STR_LIT:left>' ) <EOL> elif event . key == pygame . K_j : <EOL> self . check_direction ( '<STR_LIT>' ) <EOL> elif event . key == pygame . K_k : <EOL> self . check_direction ( '<STR_LIT>' ) <EOL> elif event . key == pygame . K_l : <EOL> self . check_direction ( '<STR_LIT:right>' ) <EOL> def check_direction ( self , direction ) : <EOL> if not self . is_started : <EOL> self . is_started = True <EOL> if self . arrow . get_direction ( ) is direction : <EOL> self . correct_key ( ) <EOL> else : <EOL> self . game_over ( ) <EOL> def check_key_reset ( self , event ) : <EOL> if event . key == pygame . K_SPACE : <EOL> self . reset_game ( ) <EOL> def correct_key ( self ) : <EOL> self . time_limit -= self . time_decrease <EOL> self . set_time ( ) <EOL> self . arrow . change ( ) <EOL> self . score += <NUM_LIT:1> <EOL> def set_time ( self ) : <EOL> self . time = pygame . time . get_ticks ( ) <EOL> def game_over ( self ) : <EOL> self . is_game_over = True <EOL> def reset_game ( self ) : <EOL> self . init_game ( ) <EOL> def render_instruction ( self ) : <EOL> self . instruction1 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . instruction2 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . instruction3 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . instruction4 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . instruction5 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . instruction6 = self . font . render ( "<STR_LIT>" , <NUM_LIT:0> , MainGame . WHITE ) <EOL> def render_score ( self ) : <EOL> self . score_image = self . font . render ( "<STR_LIT>" % self . score , <NUM_LIT:0> , MainGame . WHITE ) <EOL> self . set_score_position ( ) <EOL> def set_score_position ( self ) : <EOL> self . score_pos_x = ( self . window_size [ <NUM_LIT:0> ] / <NUM_LIT:2> ) - ( self . score_image . get_width ( ) / <NUM_LIT:2> ) <EOL> if not self . is_game_over : <EOL> self . score_pos_y = ( self . window_size [ <NUM_LIT:1> ] / <NUM_LIT:10> ) - ( self . score_image . get_height ( ) / <NUM_LIT:2> ) <EOL> else : <EOL> self . score_pos_y = ( self . window_size [ <NUM_LIT:1> ] / <NUM_LIT:2> ) - ( self . score_image . get_height ( ) / <NUM_LIT:2> ) <EOL> def render ( self , surface ) : <EOL> self . render_score ( ) <EOL> self . render_instruction ( ) <EOL> surface . blit ( self . score_image , ( self . score_pos_x , self . score_pos_y ) ) <EOL> surface . blit ( self . instruction1 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT> ) ) <EOL> surface . blit ( self . instruction2 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT:100> ) ) <EOL> surface . blit ( self . instruction3 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT> ) ) <EOL> surface . blit ( self . instruction4 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT> ) ) <EOL> surface . blit ( self . instruction5 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT> ) ) <EOL> surface . blit ( self . instruction6 , ( <NUM_LIT:20> , self . window_size [ <NUM_LIT:1> ] - <NUM_LIT:20> ) ) <EOL> if not self . is_game_over : <EOL> self . arrow . render ( surface ) <EOL> def main ( ) : <EOL> game = MainGame ( ) <EOL> game . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
