1.java ç¨åºè®¾è®¡
2.串å£è°è¯å·¥å
·åªä¸ªå¥½
java ç¨åºè®¾è®¡
ä¹åæ人é®è¿åæ ·çé®é¢ï¼æåççï¼ä½ 们æ¯ä¸æ¯åä¸ä¸ªç³»çï¼è¦å课ç¨è®¾è®¡ï¼æç´æ¥ç²è´´è¿æ¥ï¼
æèªå·±åäºä¸ä¸ªç®åçç¨åºï¼å¯éæ©è½åçå å顺åºï¼éæ°å¼å§ï¼æåå¤ææä¸æ¹æ¯å¦ä¸ºäºåè¿ç ãéæ©è½åçå å顺åºï¼åªéå®ä¹ä¸ä¸ªbooleanåéï¼æ¯æ¬¡åæ¢åå ¶åå¼ï¼éå¶æ£çæéæ°å¼å§å°±ææ£çéæ°ç»å¶ä¸éï¼å¤ææä¸æ¹æ¯å¦ä¸ºäºåè¿ç ï¼å°±å¤æææ¹çæ¯ä¸ªæ£åï¼ä»¥å®ä¸ºä¸å¿ä¸ä¹ç´§é»çæ°´å¹³ï¼åç´ï¼å·¦æï¼å³æå个æ¹åæ¯å¦æäºåè¿ç ãç¨ä¸ä¸ªäºç»´æ°ç»positionåå¨æ£çä¸çæ£åæ åµï¼position[x][y]=1,cc源码如何加密0,-1åå«è¡¨ç¤ºæ£çç第xè¡ç¬¬yåä¸æé»åï¼æ åï¼ç½åãæºä»£ç å¦ä¸ï¼
package com.test;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFiveChess {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
f.setSize(screenWidth / 2, screenHeight / 2);
f.setLocation(screenWidth / 4, screenHeight / 4);
f.setTitle("FiveChess");
MyPanel panel = new MyPanel();
f.add(panel);
f.setVisible(true);
}
}
class MyPanel extends JPanel {
private static final int SIDELENGTH = ;
private ArrayList<Ellipse2D> squares = new ArrayList<Ellipse2D>();;
private Ellipse2D current = null;
JButton jb = new JButton("éæ°å¼å§");
JButton jb2 = new JButton("åæ¢å æ");
boolean isBlack;
boolean first = true;
boolean isOver;
int l = ;
int n = ;
int bx = ;
int by = ;
int[][] position = new int[n + 1][n + 1];
public MyPanel(){
jb.addActionListener(new MyActionHandler());
jb2.addActionListener(new MyActionHandler());
addMouseListener(new MouseHandler());
addMouseMotionListener(new MouseMotionHandler());
add(jb);
add(jb2);
}
public void initMyPenal(){
squares = new ArrayList<Ellipse2D>();
current = null;
isBlack = first;
isOver = false;
position = new int[n + 1][n + 1];
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
position[i][j] = 0;
repaint();
}
public void paint(Graphics g) {
super.paint(g);
jb.setLocation(,);
jb2.setLocation(,);
g.setColor(Color.RED);
g.setFont(new Font(null, Font.BOLD, ));
g.drawString((first ? "é»" : "ç½")+"æ¹ä¸å", , );
g.setColor(new Color(, , ));
g.fillRect(bx - l, by - l, l * (n + 2), l * (n + 2));
g.setColor(Color.BLACK);
for (int i = 0; i <= n; i++){
g.drawLine(bx, by + i * l, bx + l * n, by + i * l);
g.drawLine(bx + i * l, by, bx + i * l, by + l * n);
}
Graphics2D g2 = (Graphics2D)g;
isBlack = first;
for(Ellipse2D r : squares){
g2.setColor(isBlack ? Color.BLACK : Color.WHITE);
g2.fill(r);
isBlack = !isBlack;
}
if(isOver) {
g.setColor(Color.RED);
g.setFont(new Font("TimesRoman", Font.BOLD, ));
g.drawString((isBlack ? "ç½" : "é»") + "æ¹è·è", , );
}
}
public Ellipse2D find(Point2D p){
for(Ellipse2D r : squares)
if(r.contains(p))
return r;
return null;
}
public void add(Point2D p) {
if(p.getX() > bx - l / 2 && p.getX() < bx + l * n + l / 2 &&
p.getY() > by - l / 2 && p.getY() < by + l * n + l / 2){
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if(position[i][j] == 1 || position[i][j] == -1) continue;
current = new Ellipse2D.Double(bx + j * l - l / 2,
by + i * l - l / 2, l, l);
if (current.contains(p)) {
position[i][j] = isBlack ? 1 : -1;
isOver = isWin(position, isBlack, i , j) ? true : false;
current.setFrame(bx + j * l - l / 2 + 1,
by + i * l - l / 2 + 1, l - 2, l - 2);
squares.add(current);
repaint();
return;
}
}
}
}
}
private class MouseHandler extends MouseAdapter{
public void mousePressed(MouseEvent event){
if(isOver) return;
current = find(event.getPoint());
if(current == null)
add(event.getPoint());
}
}
private class MyActionHandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
String cmd=e.getActionCommand();
if("éæ°å¼å§".equals(cmd)){
initMyPenal();
}else if("åæ¢å æ".equals(cmd)){
initMyPenal();
first=!first;
}
}
}
private class MouseMotionHandler implements MouseMotionListener{
public void mouseMoved(MouseEvent event){
Rectangle r = new Rectangle(bx - l, by - l, l * (n + 2), l * (n + 2));
if(r.contains(event.getPoint())){
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}else setCursor(Cursor.getDefaultCursor());
}
public void mouseDragged(MouseEvent event){ }
}
public boolean isWin(int[][] state, boolean isBlack, int x, int y) { //å个æ¹åä¸æ¯å¦æäºåè¿ç
return isCzWin(state, isBlack, x, y)
|| isSpWin(state, isBlack, x, y)
|| isYxWin(state, isBlack, x, y)
|| isZxWin(state, isBlack, x, y);
}
public boolean isCzWin(int[][] state, boolean isBlack, int x, int y) { //å¤æåç´æ¹åæ¯å¦æäºåè¿ç
int n = 0;
int a = (x >= 4 ? x - 4 : 0);
int b = (x <= state.length - 5 ? x + 4 : state.length - 1);
for (int i = a; i <= b; i++)
if (state[i][y] == (isBlack ? 1: -1)) {
if (++n == 5) return true;
} else n = 0;
return false;
}
public boolean isSpWin(int[][] state, boolean isBlack, int x, int y) { //å¤ææ°´å¹³æ¹åæ¯å¦æäºåè¿ç
int n = 0;
int a = (y >= 4 ? y - 4 : 0);
int b = (y <= state[0].length - 5 ? y + 4 : state[0].length - 1);
for (int i = a; i <= b; i++)
if (state[x][i] == (isBlack ? 1: -1)) {
if (++n == 5) return true;
} else n = 0;
return false;
}
public boolean isZxWin(int[][] state, boolean isBlack, int x, int y) { //å¤æå·¦ææ¹åæ¯å¦æäºåè¿ç
int n = 1, a = x, b = y;
for (int i = 1; i <= 4 && a > 0 && b > 0; i++)
if (state[a - 1][b - 1] == (isBlack ? 1: -1)) {
n++; a--; b--;
} else break;
for (int i = 1; i <= 4 && x < state.length - 1 && y < state[0].length - 1; i++)
if (state[x + 1][y + 1] == (isBlack ? 1: -1)) {
n++; x++; y++;
} else break;
if (n >= 5) return true;
return false;
}
public boolean isYxWin(int[][] state, boolean isBlack, int x, int y) { //å¤æå³ææ¹åæ¯å¦æäºåè¿ç
int n = 1, a = x, b = y;
for (int i = 1; i <= 4 && a > 0 && b < state[0].length - 1; i++)
if (state[a - 1][b + 1] == (isBlack ? 1: -1)) {
n++; a--; b++;
} else break;
for (int i = 1; i <= 4 && x < state.length - 1 && y > 0; i++)
if (state[x + 1][y - 1] == (isBlack ? 1: -1)) {
n++; x++; y--;
} else break;
if (n >= 5) return true;
return false;
}
}
æ¯è¾ç®ç¥ï¼èªå·±å¯ä»¥æ ¹æ®æ åµä¿®æ¹ï¼æ¹è¿æ¹è¿ï¼
串å£è°è¯å·¥å ·åªä¸ªå¥½
æ¨èwin ååºç 串å£è°è¯å©æ -âSerial Debug Assistantâ1. æ¥æ¶ä»ä¸²å£è¿æ¥çæ°æ®å¹¶å¨çªå£æ¾ç¤ºã
2. æ¥æ¶å°çæ°æ®æ¾ç¤ºæ¹å¼å¯ä»¥éæ©ä¸º"å符串"æ"HEX"ã
3. ä¸ææ¾ç¤ºæ ä¹±ç ãå¯ä»¥å¨è®¾ç½®ä¸æ´æ¹å符串ç¼ç ç±»åãæ¯æå¤ç§å符ç¼ç "ASCII","GB","UNICODE","UTF-8","BIG5","shift_jis"
4. 串å£æ³¢ç¹çå¯ä»¥éæ©ä¸ºbps-bps. (æ³¢ç¹ç>æ¶éè¦ç¡¬ä»¶æ¯æ)ã
5. æ¯æèªå®ä¹ä¸²å£æ³¢ç¹çã
6. å¯ä»¥å¨åéæ¡è¾å ¥æ¨æ³åéçå符串ï¼å¹¶åéï¼åéæ¯æ "å符串"æ"HEX"ã
7. æ¯ææ©å±å½ä»¤ï¼æ大ç»èªå®ä¹å½ä»¤ã
8. èªå®ä¹å½ä»¤å表ï¼å°å¤æ¡è¦åéçå½ä»¤ç»åæä¸ä¸ªå表ãåªéç¹å»ä¸æ¬¡åéï¼èªå¨æ§è¡å表ä¸çåæ¡å½ä»¤
9. èªå¨æ帧åè½ï¼å¦ææ¥æ¶å°ä¸¤ä¸ªæ°æ®å ä¹é´ææ¶é´é´éï¼ä¼å¨ä¸å æ°æ®åé¢æå ¥æ¢è¡ï¼ä¸ä¸å æ°æ®å¦èµ·æ°è¡ï¼ä»¥æ¹ä¾¿è§æµã
. åéæ ¡éªåè½,éç¨ JavaScript èæ¬,å¯æ ¹æ®éè¦èªè¡ç¼åæ ¡éªæ¹å¼.
. 波形æ¾ç¤ºåè½ãå¯å°æåè®®åéçæ°æ®æ¾ç¤ºæ波形ã并æ¯æ波形åçåè½åæªå¾åè½ã
. 带æ "Limited support" æ å¿çCOMå£é«éæ¥æ¶æ¶ä¼æå¡é¡¿ç°è±¡.