Mercurial > atc
view atc_message.py @ 35:c0c52fb4a7fd
Moved most of single player game code into new class Game()
This will simplify code management between single/multi-player game
modes
author | Josef "Jeff" Sipek <jeffpc@optonline.net> |
---|---|
date | Thu, 18 Aug 2005 00:14:13 -0500 |
parents | f346ce878117 |
children | c93c3c910c85 |
line wrap: on
line source
#/* # * ATC - Air Traffic Controller simulation game # * # * Copyright (C) 2004 Josef "Jeff" Sipek <jeffpc@optonline.net> # * # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by # * the Free Software Foundation; either version 2 of the License, or # * (at your option) any later version. # * # * This program is distributed in the hope that it will be useful, # * but WITHOUT ANY WARRANTY; without even the implied warranty of # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # * GNU General Public License for more details. # * # * You should have received a copy of the GNU General Public License # * along with this program; if not, write to the Free Software # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # * # * @(#) %M% %I% %E% %U% # */ import pygame import threading class Message: """ Interface to display a message and beep it off in morse code """ def __init__(self): """ Set up everything """ self.snd = {} self.snd["."] = pygame.mixer.Sound('data/sound/sbeep.wav') self.snd["."].set_volume(0.4) self.snd["-"] = pygame.mixer.Sound('data/sound/lbeep.wav') self.snd["-"].set_volume(0.4) self.snd[" "] = pygame.mixer.Sound('data/sound/nosnd.wav') self.snd[" "].set_volume(0.4) self.delay = {} self.delay["."] = 250 self.delay["-"] = 400 self.delay[" "] = 330 self.morse = {} self.morse["A"] = ".-" self.morse["B"] = "-..." self.morse["C"] = "-.-." self.morse["D"] = "-.." self.morse["E"] = "." self.morse["F"] = "..-." self.morse["G"] = "--." self.morse["H"] = "...." self.morse["I"] = ".." self.morse["J"] = ".---" self.morse["K"] = "-.-" self.morse["L"] = ".-.." self.morse["M"] = "--" self.morse["N"] = "-." self.morse["O"] = "---" self.morse["P"] = ".--." self.morse["Q"] = "--.-" self.morse["R"] = ".-." self.morse["S"] = "..." self.morse["T"] = "-" self.morse["U"] = "..-" self.morse["V"] = "...-" self.morse["W"] = ".--" self.morse["X"] = "-..-" self.morse["Y"] = "-.--" self.morse["Z"] = "--.." self.morse["1"] = ".----" self.morse["2"] = "..---" self.morse["3"] = "...--" self.morse["4"] = "....-" self.morse["5"] = "....." self.morse["6"] = "-...." self.morse["7"] = "--..." self.morse["8"] = "---.." self.morse["9"] = "----." self.morse["0"] = "-----" self.morse[" "] = " " self.morse[":"] = "" self.statusmess = "" self.messages = [] self.pickup_kill = 0 self.pickup_thread = threading.Timer(0, self.__pickup) self.pickup_thread.start() def write(self,screen,mess): """ Add message to the queue """ code = "" for letter in mess: code += self.morse[letter] + " " self.messages.append(code) def __beep(self,char): """ Beep one . or - """ self.snd[char].play() def __beeper(self,mess): """ Beep out all . and - in a message """ for char in mess: self.__beep(char) pygame.time.delay(self.delay[char]) if (self.pickup_kill): return def __pickup(self): """ The message pickup thread code, it picks up new messages and calls the appropreate functions to beep them out """ while(not self.pickup_kill): try: message = self.messages.pop() self.statusmess = message self.__beeper(message) pygame.time.delay(1400) self.statusmess = "" except IndexError: pass pygame.time.delay(100)