Module tutorial
[hide private]
[frames] | no frames]

Source Code for Module tutorial

  1  from game_layers import MessageInstruction 
  2  from cocos.sprite import * 
  3  from cocos import euclid 
  4  from constants import CELL_SIZE 
  5  from models import Ping, Installer, AlgorithmFactory, DOS 
  6  import os 
  7   
  8   
9 -class Tutorial(object):
10
11 - def __init__(self, lvlNum, controller):
12 super(Tutorial, self).__init__() 13 self.curPrompt = 0 14 self.lvlNum = lvlNum 15 16 if lvlNum == 1: 17 self.t = L1Tutorial() 18 if lvlNum == 2: 19 self.t = L2Tutorial() 20 21 self.prompt_stats = self.t.prompt_stats 22 self.prompts = self.t.prompts 23 self.prompt_visual_aids = self.t.prompt_visual_aids 24 self.prompt_visual_aid_stats = self.t.prompt_visual_aid_stats 25 self.game_states = self.t.game_states 26 self.controller = controller 27 self.message = None 28 self.visual_aids = None 29 self.cur_vertex_highlight = None
30
31 - def next_prompt(self):
32 # self.message.removeMessage() 33 for visual in self.visual_aids: 34 visual.remove_visual_aid() 35 36 if self.curPrompt == 4: 37 self.cur_vertex_highlight = self.highlight_vertex(4) 38 39 if self.curPrompt == 6: 40 self.cur_vertex_highlight = self.highlight_vertex(5) 41 42 if self.curPrompt == 5: 43 self.cur_vertex_highlight.remove_highlighted_vertex() 44 45 if self.curPrompt == 7: 46 self.cur_vertex_highlight.remove_highlighted_vertex() 47 48 if self.curPrompt < len(self.prompts): 49 # self.message = self.get_message() 50 self.visual_aids = self.get_visual_aids() 51 self.curPrompt += 1 52 53 print "calling next prompt"
54
55 - def first_prompt(self, state):
56 # should only be called in on_enter 57 if self.get_cur_state()[0] == state: 58 # self.message = self.get_message() 59 self.visual_aids = self.get_visual_aids() 60 self.curPrompt += 1
61
62 - def get_message(self):
63 return MessageInstruction(self.controller, self.prompts[self.curPrompt], False, *self.prompt_stats[self.curPrompt])
64
65 - def get_visual_aids(self):
66 67 visual_aids = [] 68 i = 0 69 for image in self.prompt_visual_aids[self.curPrompt]: 70 visual_aids.append( 71 TutorialVisualAid(self.controller, image, self.prompt_visual_aid_stats[ 72 self.curPrompt][i][0], self.prompt_visual_aid_stats[self.curPrompt][i][1]) 73 ) 74 i += 1 75 76 return visual_aids
77
78 - def player_unit_attack(self, troop_type):
79 # DEBUG 80 # print "player_unit_attack" 81 if troop_type == self.get_cur_state()[1] and self.get_cur_state()[0] == "player_unit_attack": 82 self.next_prompt()
83
84 - def click_on_move(self, troop_type, destID):
85 # DEBUG 86 # print "click_on_move" 87 curState = self.get_cur_state() 88 if troop_type == curState[1] and curState[0] == "click_on_move": 89 if (curState[2] == -1) or (int(curState[2]) == int(destID)): 90 self.next_prompt()
91
92 - def click_on_action(self, actionName):
93 # DEBUG 94 # print "click_on_action" 95 print actionName, self.get_cur_state()[1] 96 if actionName == self.get_cur_state()[1] and self.get_cur_state()[0] == "click_on_action": 97 self.next_prompt()
98 # print "hello its me" 99
100 - def player_add_unit(self, troop_type):
101 # print "player_add_unit" 102 if self.get_cur_state()[1] == troop_type and self.get_cur_state()[0] == "player_add_unit": 103 self.next_prompt()
104 # print "indicator sade in player add_unit" 105 106
107 - def get_cur_state(self):
108 if self.curPrompt < len(self.game_states): 109 return self.game_states[self.curPrompt] 110 return [None]
111
112 - def player_add_building(self, building_type):
113 if building_type == self.get_cur_state()[1] and self.get_cur_state()[0] == "player_add_building": 114 self.next_prompt()
115
116 - def highlight_vertex(self, vertex_id):
117 return HighlightedVertex(vertex_id, self.controller)
118
119 -class TutorialVisualAid(Sprite):
120 - def __init__(self, layer, image, x, y):
121 super(TutorialVisualAid, self).__init__(image) 122 self.sprite = Sprite(image) 123 self.sprite.position = x, y 124 self.layer = layer 125 self.layer.add(self.sprite)
126
127 - def remove_visual_aid(self):
128 self.sprite.kill()
129
130 -class HighlightedVertex(Sprite):
131 - def __init__(self, vertex_id, controller, is_active=True):
132 super(HighlightedVertex, self).__init__("images/tutorial/vertex_highlighted.png") 133 self.vertex_id = vertex_id 134 self.controller = controller 135 self.is_active = is_active 136 vertex_position = self.controller.map.vertexPositions[ 137 str(vertex_id)] 138 col = vertex_position[0] 139 row = vertex_position[1] 140 self.position = euclid.Vector2(col * CELL_SIZE, row * CELL_SIZE) 141 self.controller.map.add(self)
142
144 self.kill()
145 146
147 -class L1Tutorial():
148
149 - def __init__(self):
150 #self.prompts is deprecated 151 self.prompts = [ 152 '''To get started, first build Ping troops. Ping lets you to locate the enemy. You can't see them now but they're there!\n1. Click the server \n2. Click Ping''' 153 , '''Servers can create troops called Installers that create buildings.\n1. Click the server \n2. Click the Installer''' 154 , '''Build the building by moving the Installer to a new location.\n1. Left click your Installer \n2. Right click the location you want to build on.''' 155 , '''Let's build an algorithm factory, it will allow you to build attack.\n1. Click the Installer\n2. Click the Algorithm Factory''' 156 , '''Now you need troops that allows you to attack an enemy once you see it. Build 2 DOS troops.\n1. Click the Algorithm Factory\n2. Click the DOS troop''' 157 , '''Now you need troops that allows you to attack an enemy once you see it. Build 2 DOS troops.\n1. Click the Algorithm Factory\n2. Click the DOS troop''' # I'm duplicating this because we need to build 2 DOS 158 , '''Remember Ping, now we will use it to find the enemy. Move a ping unit to the highlighted vertex.\n1. Left click Ping \n2. Right click the highlighted location''' 159 , '''Let's actually use the Ping troop to see the enemy. \n1. Click Ping \n2. Click the attack button.''' 160 , '''Now move your DOS troop to the location of the enemy and prepare for attack''' 161 , '''You can see the enemy now, lets attack em!\n1. Click DOS and then the attack button\n2.Click on an enemy troop''' 162 163 ] 164 165 self.prompt_visual_aids = [ 166 [os.path.join("images", "tutorial", "instruction1.png")], 167 [os.path.join("images", "tutorial", "instruction2.png")], 168 [os.path.join("images", "tutorial", "instruction3.png")], 169 [os.path.join("images", "tutorial", "instruction4.png")], 170 [os.path.join("images", "tutorial", "instruction5.png")], 171 [os.path.join("images", "tutorial", "instruction6.png")], 172 [os.path.join("images", "tutorial", "instruction7.png")], 173 [os.path.join("images", "tutorial", "instruction8.png")] 174 ] 175 176 self.game_states = [["on_enter", None], 177 ["player_add_unit", "Installer"], 178 ["click_on_move", "Installer", -1], 179 ["player_add_unit", "AlgorithmFactory"], 180 ["player_add_unit", "DOS"], 181 ["click_on_move", "Ping", 4], 182 ["click_on_action", "Ping"], 183 ["click_on_move", "DOS", 5], 184 ["player_unit_attack", "DOS"]] 185 186 self.prompt_stats = [(400, 450, 700, 300, 22), 187 (350, 450, 600, 300, 22), 188 (350, 450, 600, 300, 22), 189 (400, 450, 700, 300, 22), 190 (350, 450, 600, 300, 22), 191 (350, 450, 600, 300, 22), 192 (300, 450, 500, 300, 22), 193 (300, 450, 500, 300, 22), 194 (300, 450, 500, 300, 22), 195 (300, 450, 500, 300, 22), 196 (300, 450, 500, 300, 22), 197 (300, 450, 500, 300, 22)] 198 199 self.prompt_visual_aid_stats = [[(180, 570)], 200 [(180, 140)], 201 [(700, 560)], 202 [(180, 570)], 203 [(180, 570)], 204 [(180, 570)], 205 [(180, 140)], 206 [(600, 560)], 207 [(180, 600)]]
208
209 -class L2Tutorial():
210
211 - def __init__(self):
212 self.prompts = []
213