} /* init_complete() */ /*********************************************************** * * Method: * new_game * * Description: * Starts a new game. * ***********************************************************/ private void new_game ( int width, int height, int mine_count ) { /*---------------------------------------------------------- * Reset and start a new game * ----------------------------------------------------------*/ dims.reset(width, height); ms_ctlr.new_game(width, height, mine_count); /*---------------------------------------------------------- * Initialize image status variables * ----------------------------------------------------------*/ face_status = ms_face_status.ACTIVE; field_status = new ms_mine_status[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { field_status[i, j] = new ms_mine_status(); field_status[i, j] = ms_model.mine_field[i, j].mine_status; } } /*---------------------------------------------------------- * Reset window size * ----------------------------------------------------------*/ graphics.PreferredBackBufferWidth = dims.view.Width; graphics.PreferredBackBufferHeight = dims.view.Height; graphics.ApplyChanges(); toolbar.configure(dims.toolbar, Color.White, menu_font); GraphicsDevice.Clear(Color.White); } /* new_game() */
} /* UnloadContent() */ /*********************************************************** * * Method: * Update * * Description: * Passes input events to game controller. * ***********************************************************/ protected override void Update ( GameTime gameTime ) { /*---------------------------------------------------------- * Check if game should be exited * ----------------------------------------------------------*/ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } /*---------------------------------------------------------- * Check if the toolbar handled the input * ----------------------------------------------------------*/ if (toolbar.input_handled()) { return; } /*---------------------------------------------------------- * Update mouse status * ----------------------------------------------------------*/ mouse.update(dims); /*---------------------------------------------------------- * Update time * ----------------------------------------------------------*/ if (ms_model.status == ms_game_status.ACTIVE) { ms_model.current_time = (int)((DateTime.Now.Ticks - ms_model.start_time) / 10000000); } else if (ms_model.status == ms_game_status.INACTIVE) { ms_model.current_time = 0; } /*---------------------------------------------------------- * Release double click * ----------------------------------------------------------*/ if ((button_state_type.UNHELD == mouse.left) && (button_state_type.UNHELD == mouse.right)) { double_click = false; } /*---------------------------------------------------------- * Check for double click * ----------------------------------------------------------*/ if ((ms_mouse_location.FIELD == mouse.capture_left) && (ms_mouse_location.FIELD == mouse.capture_right)) { int x = mouse.mine_loc.X; int y = mouse.mine_loc.Y; int flag_count = 0; ms_field field = ms_model.mine_field[x, y]; double_click = true; for (int i = Math.Max(0, x - 1); i <= Math.Min(ms_model.field_width - 1, x + 1); i++) { for (int j = Math.Max(0, y - 1); j <= Math.Min(ms_model.field_height - 1, y + 1); j++) { if (ms_model.mine_field[i, j].mine_status == ms_mine_status.FLAGGED) { flag_count++; } } } set_field_image(); /*---------------------------------------------------------- * Double click indenting * ----------------------------------------------------------*/ if ((button_state_type.HELD == mouse.left) && (button_state_type.HELD == mouse.right)) { for (int i = Math.Max(0, x - 1); i <= Math.Min(ms_model.field_width - 1, x + 1); i++) { for (int j = Math.Max(0, y - 1); j <= Math.Min(ms_model.field_height - 1, y + 1); j++) { if (ms_model.mine_field[i, j].mine_status == ms_mine_status.UNCHECKED) { field_status[i, j] = ms_mine_status.CHECKED_0; } } } } if ((ms_mine_status.CHECKED_0 < field.mine_status) && (field.mine_status <= ms_mine_status.CHECKED_8) && (field.mine_count == flag_count)) { /*---------------------------------------------------------- * Double click searching * ----------------------------------------------------------*/ if ((button_state_type.UNCLICKED == mouse.left) || (button_state_type.UNCLICKED == mouse.right)) { for (int i = Math.Max(0, x - 1); i <= Math.Min(ms_model.field_width - 1, x + 1); i++) { for (int j = Math.Max(0, y - 1); j <= Math.Min(ms_model.field_height - 1, y + 1); j++) { if (ms_model.mine_field[i, j].mine_status == ms_mine_status.UNCHECKED) { ms_ctlr.search_field(i, j); } } } set_field_image(); } } } /*---------------------------------------------------------- * Check for searching a field * ----------------------------------------------------------*/ else if ((ms_mouse_location.FIELD == mouse.capture_left) && (button_state_type.UNCLICKED == mouse.left) && (false == double_click)) { ms_ctlr.search_field(mouse.mine_loc.X, mouse.mine_loc.Y); set_field_image(); } /*---------------------------------------------------------- * Check for indenting a field * ----------------------------------------------------------*/ else if ((button_state_type.HELD == mouse.left) && ((ms_game_status.ACTIVE == ms_model.status) || (ms_game_status.INACTIVE == ms_model.status)) && (false == double_click)) { set_field_image(); if ((ms_mouse_location.FIELD == mouse.capture_left) && ((ms_mine_status.UNCHECKED == ms_model.mine_field[mouse.mine_loc.X, mouse.mine_loc.Y].mine_status) || (ms_mine_status.QUESTION == ms_model.mine_field[mouse.mine_loc.X, mouse.mine_loc.Y].mine_status))) { field_status[mouse.mine_loc.X, mouse.mine_loc.Y] = ms_mine_status.CHECKED_0; } } /*---------------------------------------------------------- * Check for flagging a field * ----------------------------------------------------------*/ else if ((ms_mouse_location.FIELD == mouse.capture_right) && (button_state_type.CLICKED == mouse.right) && (false == double_click)) { ms_ctlr.flag_field(mouse.mine_loc.X, mouse.mine_loc.Y); set_field_image(); } /*---------------------------------------------------------- * Check for face clicked * ----------------------------------------------------------*/ if ((ms_mouse_location.FACE == mouse.capture_left) && (ms_mouse_location.FACE == mouse.cursor_location) && (button_state_type.UNCLICKED == mouse.left)) { new_game_same(); } /*---------------------------------------------------------- * Set the face status * ----------------------------------------------------------*/ if ((ms_mouse_location.FACE == mouse.capture_left) && (ms_mouse_location.FACE == mouse.cursor_location) && (button_state_type.HELD == mouse.left)) { face_status = ms_face_status.PRESSED; } else if ((ms_mouse_location.FIELD == mouse.capture_left) && ((ms_game_status.ACTIVE == ms_model.status) || (ms_game_status.INACTIVE == ms_model.status)) && ((!double_click) || (double_click && ms_mouse_location.FIELD == mouse.capture_right))) { face_status = ms_face_status.MOUSE_DOWN; } else { switch (ms_model.status) { case ms_game_status.WON: face_status = ms_face_status.WON; break; case ms_game_status.LOST: face_status = ms_face_status.LOST; break; case ms_game_status.INACTIVE: case ms_game_status.ACTIVE: face_status = ms_face_status.ACTIVE; break; } } base.Update(gameTime); } /* Update() */