https://www.myziyuan.com/
- 飞创科技
- import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import javax.swing.JFrame;@SuppressWarnings("serial")public class MainClass extends JFrame {ControlSnake control;Toolkit kit;Dimension dimen;public static void main(String[] args) { new MainClass("my snake");}public MainClass(String s) { super(s); control = new ControlSnake(); control.setFocusable(true); kit = Toolkit.getDefaultToolkit(); dimen = kit.getScreenSize();add(control); setLayout(new BorderLayout()); setLocation(dimen.width / 3, dimen.height / 3);// dimen.width/3,dimen.height/3 setSize(FWIDTH, FHEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setVisible(true);}public static final int FWIDTH = 315;public static final int FHEIGHT = 380;}import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.util.ArrayList;import java.util.Random;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.Timer;@SuppressWarnings("serial")public class ControlSnake extends JPanel implements ActionListener { Random rand; ArrayList list, listBody; String str, str1; static boolean key; int x, y, dx, dy, fx, fy, flag; int snakeBody; int speed; public ControlSnake() { snakeBody = 1; str = "上下左右方向键控制 P键暂停..."; str1 = "现在的长度为:" + snakeBody; key = true; flag = 1; speed = 700; rand = new Random(); list = new ArrayList(); listBody = new ArrayList(); x = 5; y = 5; list.add(new Point(x, y)); listBody.add(list.get(0)); dx = 10; dy = 0; fx = rand.nextInt(30) * 10 + 5;// 2 fy = rand.nextInt(30) * 10 + 5;// 2 setBackground(Color.BLACK); setSize(new Dimension(318, 380)); final Timer time = new Timer(speed, this); time.start(); addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 37) { dx = -10; dy = 0; } else if (e.getKeyCode() == 38) { dx = 0; dy = -10; } else if (e.getKeyCode() == 39) { dx = 10; dy = 0; } else if (e.getKeyCode() == 40) { dx = 0; dy = 10; } else if (e.getKeyCode() == 80) { if (flag % 2 == 1) { time.stop(); } if (flag % 2 == 0) { time.start(); } flag++; } } }); } public void paint(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0, 0, 400, 400); g.setColor(Color.DARK_GRAY); g.drawLine(3, 3, 305, 3); g.drawLine(3, 3, 3, 305); g.drawLine(305, 3, 305, 305); g.drawLine(3, 305, 305, 305); g.setColor(Color.PINK); for (int i = 0; i 0; i--) { listBody.add(list.get(i)); } } else { for (int i = list.size() - 1; listBody.size() 305 || y > 305)) { return false; } for (int i = 0; i < listBody.size() - 1; i++) { for (int j = i + 1; j < listBody.size(); j++) { if (listBody.get(i).equals(listBody.get(j))) { return false; } } } return true; }}/*贪吃蛇代码*/
- 2021-02-15 02:30:04
- 111
- 网页游戏哪要什么客户端。。有个浏览器就好了啊。。你点开那游戏的主页面就算开启了啊
- 2021-02-11 13:35:53
- 至深科技
- 网页游戏开发源码是什么,Java
- 2021-02-11 13:35:53