1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import print_function
  4. from __future__ import unicode_literals
  5. from __future__ import division
  6. from __future__ import absolute_import
  7. try:
  8. str = unicode
  9. except NameError:
  10. pass
  11.  
  12. import random, sys, sip
  13. try:
  14. sip.setapi("QString" ,2)
  15. except ValueError:
  16. pass
  17.  
  18. from PyQt4 import QtCore, QtGui
  19.  
  20. NoShape, ZShape, SShape, LineShape, TShape, SquareShape, LShape, MirroredLShape = range(8)
  21.  
  22. random.seed(None)
  23.  
  24. class TetrixWindow(QtGui.QWidget):
  25. def __init__(self, parent = None):
  26. QtGui.QWidget.__init__(self, parent, QtCore.Qt.Window)
  27.  
  28. self.board = TetrixBoard()
  29. self.indictor = TetrixIndictor()
  30.  
  31. nextPieceLabel = QtGui.QLabel(self)
  32. nextPieceLabel.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Raised)
  33. nextPieceLabel.setAlignment(QtCore.Qt.AlignCenter)
  34. self.board.setNextPieceLabel(nextPieceLabel)
  35.  
  36. scoreLcd = QtGui.QLCDNumber(6)
  37. scoreLcd.setSegmentStyle(QtGui.QLCDNumber.Filled)
  38. levelLcd = QtGui.QLCDNumber(2)
  39. levelLcd.setSegmentStyle(QtGui.QLCDNumber.Filled)
  40. linesLcd = QtGui.QLCDNumber(6)
  41. linesLcd.setSegmentStyle(QtGui.QLCDNumber.Filled)
  42.  
  43. startButton = QtGui.QPushButton(self.trUtf8("开始(&S)"))
  44. startButton.setFocusPolicy(QtCore.Qt.NoFocus)
  45. quitButton = QtGui.QPushButton(self.trUtf8("退出(&X)"))
  46. quitButton.setFocusPolicy(QtCore.Qt.NoFocus)
  47. pauseButton = QtGui.QPushButton(self.trUtf8("暂停(&P)"))
  48. pauseButton.setFocusPolicy(QtCore.Qt.NoFocus)
  49.  
  50. startButton.clicked.connect(self.board.start)
  51. pauseButton.clicked.connect(self.board.pause)
  52. quitButton.clicked.connect(self.close)
  53. self.board.scoreChanged.connect(scoreLcd.display)
  54. self.board.levelChanged.connect(levelLcd.display)
  55. self.board.linesRemovedChanged.connect(linesLcd.display)
  56. self.board.act.connect(self.indictor.showIndictor)
  57.  
  58. layout1 = QtGui.QHBoxLayout()
  59. layout3 = QtGui.QVBoxLayout()
  60. layout3.addWidget(self.board)
  61. layout3.addWidget(self.indictor)
  62. layout3.setSpacing(0)
  63. layout1.addLayout(layout3)
  64. layout2 = QtGui.QVBoxLayout()
  65. layout2.addWidget(self.createLabel(self.trUtf8("下一个方块")))
  66. layout2.addWidget(nextPieceLabel)
  67. layout2.addWidget(self.createLabel(self.trUtf8("级别")))
  68. layout2.addWidget(levelLcd)
  69. layout2.addWidget(self.createLabel(self.trUtf8("成绩")),)
  70. layout2.addWidget(scoreLcd)
  71. layout2.addWidget(self.createLabel(self.trUtf8("总共消去行数")))
  72. layout2.addWidget(linesLcd)
  73. layout2.addWidget(startButton)
  74. layout2.addWidget(quitButton)
  75. layout2.addWidget(pauseButton)
  76. layout1.addLayout(layout2)
  77. layout1.setStretch(0, 75)
  78. layout1.setStretch(1, 25)
  79. self.setLayout(layout1)
  80.  
  81. self.setWindowTitle(self.trUtf8("俄罗斯方块(Tetrix)"))
  82. self.resize(self.logicalDpiX() / 96 * 275, self.logicalDpiY() / 96 * 380)
  83.  
  84. r = self.geometry()
  85. r.moveCenter(QtGui.qApp.desktop().screenGeometry().center())
  86. self.setGeometry(r)
  87.  
  88. def createLabel(self, text):
  89. lbl = QtGui.QLabel(text)
  90. lbl.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom)
  91. return lbl
  92.  
  93. class TetrixIndictor(QtGui.QWidget):
  94. """位于主游戏区下方的一个扁小的控件,用于显示当前位置落下时的位置。
  95. 现在主要的问题是游戏区的大小超出了人类的眼睛的焦点区。
  96. 或许可以让整个游戏界面更小一些。"""
  97.  
  98. def __init__(self, parent = None):
  99. QtGui.QWidget.__init__(self, parent)
  100. self.begin = self.end = None
  101. self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
  102.  
  103. def showIndictor(self, curX, piece):
  104. self.begin = curX + piece.minX()
  105. self.end = curX + piece.maxX()
  106. self.update()
  107.  
  108. def paintEvent(self, event):
  109. QtGui.QWidget.paintEvent(self, event)
  110. if self.begin is None:
  111. return
  112. board = self.parent().board
  113. pieceWidth = board.contentsRect().width() // TetrixBoard.BoardWidth
  114. brush = QtGui.QBrush(QtCore.Qt.yellow)
  115. painter = QtGui.QPainter(self)
  116. painter.setBrush(brush)
  117. painter.drawRect(board.contentsRect().left() + self.begin * pieceWidth, 0, \
  118. (self.end - self.begin + 1) * pieceWidth, self.height() - 1 )
  119.  
  120. def sizeHint(self):
  121. return QtCore.QSize(self.parent().board.width(), 8)
  122.  
  123. class TetrixBoard(QtGui.QFrame):
  124. BoardWidth = 11
  125. BoardHeight = 22
  126.  
  127. scoreChanged = QtCore.pyqtSignal(int)
  128. levelChanged = QtCore.pyqtSignal(int)
  129. linesRemovedChanged = QtCore.pyqtSignal(int)
  130. act = QtCore.pyqtSignal(int, "PyQt_PyObject")
  131.  
  132. def __init__(self, parent = None):
  133. super(TetrixBoard, self).__init__(parent)
  134. self.setStyleSheet("background-color:black;border:2px solid darkGreen;")
  135.  
  136. self.timer = QtCore.QBasicTimer()
  137. self.nextPieceLabel = None
  138. self.isWaitingAfterLine = False
  139. self.curPiece = TetrixPiece()
  140. self.nextPiece = TetrixPiece()
  141. self.curX = 0
  142. self.curY = 0
  143. self.numLinesRemoved = 0
  144. self.numPiecesDropped = 0
  145. self.score = 0
  146. self.level = 0
  147. self.board = None
  148.  
  149. #self.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
  150. self.setFrameStyle(QtGui.QFrame.Box)
  151. self.setFocusPolicy(QtCore.Qt.StrongFocus)
  152. self.isStarted = False
  153. self.isPaused = False
  154. self.clearBoard()
  155.  
  156. self.nextPiece.setRandomShape()
  157.  
  158. def focusOutEvent(self, event):
  159. if self.isStarted and not self.isPaused:
  160. self.pause()
  161. QtGui.QFrame.focusOutEvent(self, event)
  162.  
  163. def shapeAt(self, x, y):
  164. return self.board[(y * TetrixBoard.BoardWidth) + x]
  165.  
  166. def setShapeAt(self, x, y, shape):
  167. self.board[(y * TetrixBoard.BoardWidth) + x] = shape
  168.  
  169. def timeoutTime(self):
  170. return 1000 // (1 + self.level)
  171.  
  172. def squareWidth(self):
  173. return self.contentsRect().width() // TetrixBoard.BoardWidth
  174.  
  175. def squareHeight(self):
  176. return self.contentsRect().height() // TetrixBoard.BoardHeight
  177.  
  178. def setNextPieceLabel(self, label):
  179. self.nextPieceLabel = label
  180. #label.setScaledContents(True)
  181. label.setMinimumSize(label.width(), label.width())
  182.  
  183. def sizeHint(self):
  184. return QtCore.QSize(TetrixBoard.BoardWidth * 15 + self.frameWidth() * 2,
  185. TetrixBoard.BoardHeight * 15 + self.frameWidth() * 2)
  186.  
  187. def minimumSizeHint(self):
  188. return QtCore.QSize(TetrixBoard.BoardWidth * 15 + self.frameWidth() * 2,
  189. TetrixBoard.BoardHeight * 15 + self.frameWidth() * 2)
  190.  
  191. def start(self):
  192. if self.isPaused:
  193. return
  194.  
  195. self.isStarted = True
  196. self.isWaitingAfterLine = False
  197. self.numLinesRemoved = 0
  198. self.numPiecesDropped = 0
  199. self.score = 0
  200. self.level = 1
  201. self.clearBoard()
  202.  
  203. self.linesRemovedChanged.emit(self.numLinesRemoved)
  204. self.scoreChanged.emit(self.score)
  205. self.levelChanged.emit(self.level)
  206.  
  207. self.newPiece()
  208. self.timer.start(self.timeoutTime(), self)
  209.  
  210. def pause(self):
  211. if not self.isStarted:
  212. return
  213.  
  214. self.isPaused = not self.isPaused
  215. if self.isPaused:
  216. self.timer.stop()
  217. else:
  218. self.timer.start(self.timeoutTime(), self)
  219.  
  220. self.update()
  221.  
  222. def paintEvent(self, event):
  223. super(TetrixBoard, self).paintEvent(event)
  224.  
  225. painter = QtGui.QPainter(self)
  226. rect = self.contentsRect()
  227.  
  228. if self.isPaused:
  229. painter.drawText(rect, QtCore.Qt.AlignCenter, self.trUtf8("暂停"))
  230. return
  231.  
  232. boardTop = rect.bottom() - TetrixBoard.BoardHeight * self.squareHeight()
  233.  
  234. for i in range(TetrixBoard.BoardHeight):
  235. for j in range(TetrixBoard.BoardWidth):
  236. shape = self.shapeAt(j, TetrixBoard.BoardHeight - i - 1)
  237. if shape != NoShape:
  238. self.drawSquare(painter,
  239. rect.left() + j * self.squareWidth(),
  240. boardTop + i * self.squareHeight(), shape)
  241.  
  242. if self.curPiece.shape() != NoShape:
  243. for i in range(4):
  244. x = self.curX + self.curPiece.x(i)
  245. y = self.curY - self.curPiece.y(i)
  246. self.drawSquare(painter, rect.left() + x * self.squareWidth(),
  247. boardTop + (TetrixBoard.BoardHeight - y - 1) * self.squareHeight(),
  248. self.curPiece.shape())
  249.  
  250. def keyPressEvent(self, event):
  251. if not self.isStarted or self.isPaused or self.curPiece.shape() == NoShape:
  252. super(TetrixBoard, self).keyPressEvent(event)
  253. return
  254.  
  255. key = event.key()
  256. if key == QtCore.Qt.Key_Left:
  257. self.tryMove(self.curPiece, self.curX - 1, self.curY)
  258. elif key == QtCore.Qt.Key_Right:
  259. self.tryMove(self.curPiece, self.curX + 1, self.curY)
  260. elif key == QtCore.Qt.Key_Down:
  261. self.tryMove(self.curPiece.rotatedRight(), self.curX, self.curY)
  262. elif key == QtCore.Qt.Key_Up:
  263. self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)
  264. elif key == QtCore.Qt.Key_Space:
  265. self.dropDown()
  266. elif key == QtCore.Qt.Key_D:
  267. self.oneLineDown()
  268. else:
  269. super(TetrixBoard, self).keyPressEvent(event)
  270.  
  271. def timerEvent(self, event):
  272. if event.timerId() == self.timer.timerId():
  273. if self.isWaitingAfterLine:
  274. self.isWaitingAfterLine = False
  275. self.newPiece()
  276. self.timer.start(self.timeoutTime(), self)
  277. else:
  278. self.oneLineDown()
  279. else:
  280. super(TetrixBoard, self).timerEvent(event)
  281.  
  282. def clearBoard(self):
  283. self.board = [NoShape for i in range(TetrixBoard.BoardHeight * TetrixBoard.BoardWidth)]
  284.  
  285. def dropDown(self):
  286. dropHeight = 0
  287. newY = self.curY
  288. while newY > 0:
  289. if not self.tryMove(self.curPiece, self.curX, newY - 1):
  290. break
  291. newY -= 1
  292. dropHeight += 1
  293.  
  294. self.pieceDropped(dropHeight)
  295.  
  296. def oneLineDown(self):
  297. if not self.tryMove(self.curPiece, self.curX, self.curY - 1):
  298. self.pieceDropped(0)
  299.  
  300. def pieceDropped(self, dropHeight):
  301. for i in range(4):
  302. x = self.curX + self.curPiece.x(i)
  303. y = self.curY - self.curPiece.y(i)
  304. self.setShapeAt(x, y, self.curPiece.shape())
  305.  
  306. self.numPiecesDropped += 1
  307. if self.numPiecesDropped % 25 == 0:
  308. self.level += 1
  309. self.timer.start(self.timeoutTime(), self)
  310. self.levelChanged.emit(self.level)
  311.  
  312. self.score += dropHeight + 7
  313. self.scoreChanged.emit(self.score)
  314. self.removeFullLines()
  315.  
  316. if not self.isWaitingAfterLine:
  317. self.newPiece()
  318.  
  319. def removeFullLines(self):
  320. numFullLines = 0
  321.  
  322. for i in range(TetrixBoard.BoardHeight - 1, -1, -1):
  323. lineIsFull = True
  324.  
  325. for j in range(TetrixBoard.BoardWidth):
  326. if self.shapeAt(j, i) == NoShape:
  327. lineIsFull = False
  328. break
  329.  
  330. if lineIsFull:
  331. numFullLines += 1
  332. for k in range(i, TetrixBoard.BoardHeight - 1):
  333. for j in range(TetrixBoard.BoardWidth):
  334. self.setShapeAt(j, k, self.shapeAt(j, k + 1))
  335.  
  336. for j in range(TetrixBoard.BoardWidth):
  337. self.setShapeAt(j, TetrixBoard.BoardHeight - 1, NoShape)
  338.  
  339. if numFullLines > 0:
  340. self.numLinesRemoved += numFullLines
  341. self.score += 10 * numFullLines
  342. self.linesRemovedChanged.emit(self.numLinesRemoved)
  343. self.scoreChanged.emit(self.score)
  344.  
  345. self.timer.start(200, self)
  346. self.isWaitingAfterLine = True
  347. self.curPiece.setShape(NoShape)
  348. self.update()
  349.  
  350. def newPiece(self):
  351. self.curPiece = self.nextPiece
  352. self.nextPiece = TetrixPiece()
  353. self.nextPiece.setRandomShape()
  354. self.showNextPiece()
  355. self.curX = TetrixBoard.BoardWidth // 2
  356. self.curY = TetrixBoard.BoardHeight - 1 + self.curPiece.minY()
  357. self.act.emit(self.curX, self.curPiece)
  358.  
  359. if not self.tryMove(self.curPiece, self.curX, self.curY):
  360. self.curPiece.setShape(NoShape)
  361. self.timer.stop()
  362. self.isStarted = False
  363.  
  364. def showNextPiece(self):
  365. if self.nextPieceLabel is None:
  366. return
  367.  
  368. dx = self.nextPiece.maxX() - self.nextPiece.minX() + 1
  369. dy = self.nextPiece.maxY() - self.nextPiece.minY() + 1
  370.  
  371. self.pixmapNextPiece = QtGui.QPixmap(dx * self.squareWidth(), dy * self.squareHeight())
  372. painter = QtGui.QPainter(self.pixmapNextPiece)
  373. painter.fillRect(self.pixmapNextPiece.rect(), self.nextPieceLabel.palette().background())
  374.  
  375. for i in range(4):
  376. x = self.nextPiece.x(i) - self.nextPiece.minX()
  377. y = self.nextPiece.y(i) - self.nextPiece.minY()
  378. self.drawSquare(painter, x * self.squareWidth(),
  379. y * self.squareHeight(), self.nextPiece.shape())
  380.  
  381. self.nextPieceLabel.setPixmap(self.pixmapNextPiece)
  382.  
  383. def tryMove(self, newPiece, newX, newY):
  384. for i in range(4):
  385. x = newX + newPiece.x(i)
  386. y = newY - newPiece.y(i)
  387. if x < 0 or x >= TetrixBoard.BoardWidth or y < 0 or y >= TetrixBoard.BoardHeight:
  388. return False
  389. if self.shapeAt(x, y) != NoShape:
  390. return False
  391.  
  392. self.curPiece = newPiece
  393. self.curX = newX
  394. self.curY = newY
  395. self.update()
  396. self.act.emit(self.curX, self.curPiece)
  397. return True
  398.  
  399. def drawSquare(self, painter, x, y, shape):
  400. colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
  401. 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]
  402.  
  403. color = QtGui.QColor(colorTable[shape])
  404. painter.fillRect(x + 1, y + 1, self.squareWidth() - 2,
  405. self.squareHeight() - 2, color)
  406.  
  407. painter.setPen(color.light())
  408. painter.drawLine(x, y + self.squareHeight() - 1, x, y)
  409. painter.drawLine(x, y, x + self.squareWidth() - 1, y)
  410.  
  411. painter.setPen(color.dark())
  412. painter.drawLine(x + 1, y + self.squareHeight() - 1,
  413. x + self.squareWidth() - 1, y + self.squareHeight() - 1)
  414. painter.drawLine(x + self.squareWidth() - 1,
  415. y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)
  416.  
  417. class TetrixPiece(object):
  418. coordsTable = (
  419. ((0, 0), (0, 0), (0, 0), (0, 0)),
  420. ((0, -1), (0, 0), ( - 1, 0), ( - 1, 1)),
  421. ((0, -1), (0, 0), (1, 0), (1, 1)),
  422. ((0, -1), (0, 0), (0, 1), (0, 2)),
  423. (( - 1, 0), (0, 0), (1, 0), (0, 1)),
  424. ((0, 0), (1, 0), (0, 1), (1, 1)),
  425. (( - 1, -1), (0, -1), (0, 0), (0, 1)),
  426. ((1, -1), (0, -1), (0, 0), (0, 1))
  427. )
  428.  
  429. def __init__(self):
  430. self.coords = [[0,0] for _ in range(4)]
  431. self.pieceShape = NoShape
  432.  
  433. self.setShape(NoShape)
  434.  
  435. def shape(self):
  436. return self.pieceShape
  437.  
  438. def setShape(self, shape):
  439. table = TetrixPiece.coordsTable[shape]
  440. for i in range(4):
  441. for j in range(2):
  442. self.coords[i][j] = table[i][j]
  443.  
  444. self.pieceShape = shape
  445.  
  446. def setRandomShape(self):
  447. self.setShape(random.randint(1, 7))
  448.  
  449. def x(self, index):
  450. return self.coords[index][0]
  451.  
  452. def y(self, index):
  453. return self.coords[index][1]
  454.  
  455. def setX(self, index, x):
  456. self.coords[index][0] = x
  457.  
  458. def setY(self, index, y):
  459. self.coords[index][1] = y
  460.  
  461. def minX(self):
  462. m = self.coords[0][0]
  463. for i in range(4):
  464. m = min(m, self.coords[i][0])
  465.  
  466. return m
  467.  
  468. def maxX(self):
  469. m = self.coords[0][0]
  470. for i in range(4):
  471. m = max(m, self.coords[i][0])
  472.  
  473. return m
  474.  
  475. def minY(self):
  476. m = self.coords[0][1]
  477. for i in range(4):
  478. m = min(m, self.coords[i][1])
  479.  
  480. return m
  481.  
  482. def maxY(self):
  483. m = self.coords[0][1]
  484. for i in range(4):
  485. m = max(m, self.coords[i][1])
  486.  
  487. return m
  488.  
  489. def rotatedLeft(self):
  490. if self.pieceShape == SquareShape:
  491. return self
  492.  
  493. result = TetrixPiece()
  494. result.pieceShape = self.pieceShape
  495. for i in range(4):
  496. result.setX(i, self.y(i))
  497. result.setY(i, -self.x(i))
  498.  
  499. return result
  500.  
  501. def rotatedRight(self):
  502. if self.pieceShape == SquareShape:
  503. return self
  504.  
  505. result = TetrixPiece()
  506. result.pieceShape = self.pieceShape
  507. for i in range(4):
  508. result.setX(i, -self.y(i))
  509. result.setY(i, self.x(i))
  510.  
  511. return result
  512.  
  513. if __name__ == '__main__':
  514. app = QtGui.QApplication(sys.argv)
  515. window = TetrixWindow()
  516. window.show()
  517. if hasattr(app, "exec"):
  518. result = getattr(app, "exec")()
  519. else:
  520. result = getattr(app, "exec_")()
  521. sys.exit(result)

【转载】Pyqt 编写的俄罗斯方块的更多相关文章

  1. 【Python】[技术博客] 如何对使用PYQT编写的GUI文件进行单元测试

    如何对使用PYQT编写的GUI文件进行单元测试 想要对PYQT编写的GUI文件进行单元测试,我们主要用到QTest QTest里面包含了一些对窗体的各种控件进行模拟操作的函数,通过QTest对窗体进行 ...

  2. 用Shell编写的俄罗斯方块代码

    用Shell编写的俄罗斯方块代码 不得不承认任何一门语言玩6了,啥都能搞出来啊,竟然用Shell编写出来了一个俄罗斯方块游戏的代码,很有意思,这个代码不是我写出来的,不过大家可以下载一下在window ...

  3. 一个VB编写的俄罗斯方块

    'VB语言版俄罗斯方块'Totoo.Aoo34智造(一个人的两个名字),一些方块,很多计算 Const WN As Integer = 10, HN As Integer = 20Const Boxl ...

  4. 转载:pyqt线程间通过 信号/槽 通信

    转自:http://blog.sina.com.cn/s/blog_613d5bb701016qzv.html 信号(singal)与槽(slot)用于对象相互通信,信号:当某个对象的某个事件发生时, ...

  5. 使用PyQT编写界面程序

    使用PyQT比QT好在,可以随时监测函数正确性,省去编译时间 ! 这是个不小的节省. 1. PyQt: 打开对话框 msgbox = QtGui.QMessageBox(self)# 我的语句是 ms ...

  6. [转载]自己编写 php 在线问卷调查程序

        <html> <head> <title>问卷调查</title> <meta http-equiv="Content-Type ...

  7. javascript 60行编写的俄罗斯方块游戏

    转自 http://***/share/1759652641295360.htm <!doctype html><html><head></head>& ...

  8. pyqt 实现的俄罗斯方块

    from PyQt5.QtWidgets import QMainWindow, QFrame, QDesktopWidget, QApplication from PyQt5.QtCore impo ...

  9. PyQt编写Python GUI程序,简易示例

    https://blog.csdn.net/qq_41841569/article/details/81014207

随机推荐

  1. 关于man和help的区别

    help 是内部命令的帮助,比如cdman 是外部命令的帮助,比如ls

  2. Caffe学习系列(9):solver优化方法

    介绍了各种优化算法 参考:http://www.cnblogs.com/denny402/p/5074212.html

  3. Linux下端口被占用解决

      有时候关闭软件后,后台进程死掉,导致端口被占用.下面以JBoss端口8083被占用为例,列出详细解决过程. 解决方法: 1.查找被占用的端口 netstat -tln netstat -tln | ...

  4. mysql 表关联查询报错 ERROR 1267 (HY000)

    解决翻案:http://stackoverflow.com/questions/1008287/illegal-mix-of-collations-mysql-error 即: SET collati ...

  5. centos 6.5 下用apache部署web 应用

    1. 修改/etc/httpd/conf/httpd.conf文件,添加一个virtualhost段,具体略.注意在段内配置NaveServer. 此文件全局也要配置一个NameServer(原因有待 ...

  6. angulaijs中的ng-upload-file与阿里云oss服务的结合,实现在浏览器端上传文件到阿里云(速度可以达到1.5M)

    2015-10-26 angularjs结合aliyun浏览器端oos文件上传加临时身份验证例子 在服务端获取sts 源码: public class StsServiceSample { // 目前 ...

  7. 嵌套div中margin-top转移问题的解决办法

    在这两个浏览器中,有两个嵌套关系的div,如果外层div的父元素padding值为0,那么内层div的margin-top或者margin-bottom的值会“转移”给外层div. <!DOCT ...

  8. java servlet的工作原理

    servlet本质上就是java类嘛.不过是有特殊规范的java类而已.下面就说一说为什么servlet要有特殊规范. 首先,考虑一下什么地方用servlet,WEB应用,而且是需要servlet容器 ...

  9. 设计算法,求AB两个整数集合的交集

    [本文链接] http://www.cnblogs.com/hellogiser/p/ab-set-intersection.html [分析] 思路1:排序法 对集合A和集合B进行排序(升序,用快排 ...

  10. bind+dlz+mysql实现区域记录动态更新

    BIND-DLZ实验:http://bind-dlz.sourceforge.net/ 实验环境:RHEL4,BIND-9.5.0-P2.tar.gz(9.4.0以上版本都已含DLZ补丁),Mysql ...