void game::on_event(const SDL_Event& event) { if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) { if (in_board()) { if (m_active_special) { const int digit = m_board.get_digit(m_selx, m_sely); // Attempt a special move if (m_active_special->m_type == special_move::nuke && digit == -1) { clear_3x3(m_selx, m_sely); m_active_special->m_type = special_move::none; } if (m_active_special->m_type == special_move::clear_digit && digit != -1) { for (int y = 0; y != 9; ++y) for (int x = 0; x != 9; ++x) if (m_board.get_digit(x, y) == digit) m_board.set_digit(x, y, -1); m_active_special->m_type = special_move::none; } m_active_special = 0; } else { do_digit(); } if (m_queue.digits_left() == 0 || m_board.get_filled() == 0) end_game(); } for (int i = 0; i != 3; ++i) if (m_specials[i].m_button.click(event.button) && m_specials[i].m_type != special_move::none) do_special(m_specials[i]); if (m_quit.click(event.button)) m_sm.set_next_state("title"); } if (event.type == SDL_MOUSEMOTION) { // Check if the cursor is inside the board int mx = event.motion.x; int my = event.motion.y; if (mx >= board_xpos && mx < (board_xpos + 32 * 9) && my >= board_ypos && my < (board_ypos + 32 * 9)) { m_selx = (mx - board_xpos) / 32; m_sely = (my - board_ypos) / 32; } else { m_selx = -1; m_sely = -1; } m_quit.motion(event.motion); for (int i = 0; i != 3; ++i) if (m_specials[i].m_type != special_move::none) m_specials[i].m_button.motion(event.motion); } }
static const char *dnet_ntop1(const struct dn_naddr *dna, char *str, size_t len) { u_int16_t addr, area; size_t pos = 0; int started = 0; memcpy(&addr, dna->a_addr, sizeof(addr)); addr = dn_ntohs(addr); area = addr >> 10; if (dna->a_len != 2) return NULL; addr &= 0x03ff; if (len == 0) return str; if (do_digit(str + pos, &area, 10, &pos, len, &started)) return str; if (do_digit(str + pos, &area, 1, &pos, len, &started)) return str; if (pos == len) return str; *(str + pos) = '.'; pos++; started = 0; if (do_digit(str + pos, &addr, 1000, &pos, len, &started)) return str; if (do_digit(str + pos, &addr, 100, &pos, len, &started)) return str; if (do_digit(str + pos, &addr, 10, &pos, len, &started)) return str; if (do_digit(str + pos, &addr, 1, &pos, len, &started)) return str; if (pos == len) return str; *(str + pos) = 0; return str; }