#### dashboard.py for BASIC-RoBots#### Copyright (C) 2012 Pierre Surply## <pierre.surply@gmail.com>#### This file is part of BASIC-RoBots.#### BASIC-RoBots 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 3 of the License, or## (at your option) any later version.#### BASIC-RoBots 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 BASIC-RoBots. If not, see <http://www.gnu.org/licenses/>. ## ## Started on Thu Jun 28 21:12:48 2012 Pierre Surply## Last update Mon Sep 3 18:11:22 2012 Pierre Surply##importpygamefrompygame.localsimport*importworldmapimportterminalclassDashboard:commands=[("ENTER","land at the selected place"),\
(chr(24)+chr(25)+chr(26)+chr(27),"move cursor"),\
("ESC","cancel")]def__init__(self,worldmap,events):self.worldmap=worldmapself.terminal=terminal.Terminal(events)self.terminal.set_title("Worldmap")self.select_x=16self.select_y=16self.nbr_mothership=1self.update_term()defupdate(self,display,events):self.handle_events(events)w=display.window.get_width()h=display.window.get_height()self.terminal.display(display,(0,0,w/16-1,h/12-1))display.render_terminal()self.worldmap.render((w,h),(self.select_x,self.select_y))display.flip()returnevents.get_key_once(K_RETURN)defhandle_events(self,events):ifevents.get_key_once(K_UP)andself.select_y>0:self.select_y-=1self.update_term()if(events.get_key_once(K_DOWN))andself.select_y<self.worldmap.size-1:self.select_y+=1self.update_term()ifevents.get_key_once(K_LEFT)andself.select_x>0:self.select_x-=1self.update_term()if(events.get_key_once(K_RIGHT))andself.select_x<self.worldmap.size-1:self.select_x+=1self.update_term()defupdate_term(self):self.terminal.clear()self.terminal.write("Please select a landing site for the mothership\n\n")self.info_biomes(self.worldmap.tile[(self.select_y*self.worldmap.size)+self.select_x])self.terminal.write("\n\n")self.info_commands()definfo_biomes(self,n):self.terminal.write("World\n",1)self.terminal.write(" ")self.terminal.write("Name",1)self.terminal.write_line(": "+self.worldmap.path)self.terminal.write(" ")self.terminal.write("Mothership",1)self.terminal.write(": "+str(self.nbr_mothership))self.terminal.write("\n\nSelected place\n",1)foriinself.worldmap.biomes:ifi[1]==n:self.terminal.write(" ")self.terminal.write("X",1)self.terminal.write(": "+str(self.select_x))self.terminal.write(" ")self.terminal.write("Y",1)self.terminal.write(": "+str(self.select_y))self.terminal.write("\n ")self.terminal.write("Biome",1)self.terminal.write(": "+i[2])self.terminal.write("\n ")self.terminal.write("Difficulty",1)ifi[3]==0:dif=("Very easy",2)elifi[3]==1:dif=("Easy",3)elifi[3]==2:dif=("Normal",4)elifi[3]==3:dif=("Hard",5)elifi[3]==4:dif=("Very hard",6)self.terminal.write(": ")self.terminal.write(dif[0],dif[1])definfo_commands(self):self.terminal.write("Commands\n",1)foriinself.commands:self.terminal.write(" ")self.terminal.write(i[0],1)self.terminal.write(": "+i[1]+"\n")