Browse Source

init tank project

zhangxiaoyu 3 years ago
parent
commit
150eb01fe9

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
1
+# Default ignored files
2
+/shelf/
3
+/workspace.xml
4
+# Datasource local storage ignored files
5
+/dataSources/
6
+/dataSources.local.xml
7
+# Editor-based HTTP Client requests
8
+/httpRequests/

+ 1 - 0
.idea/description.html

@@ -0,0 +1 @@
1
+<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="Encoding">
4
+    <file url="PROJECT" charset="UTF-8" />
5
+  </component>
6
+</project>

+ 12 - 0
.idea/misc.xml

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="EntryPointsManager">
4
+    <entry_points version="2.0" />
5
+  </component>
6
+  <component name="ProjectKey">
7
+    <option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
8
+  </component>
9
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
10
+    <output url="file://$PROJECT_DIR$/out" />
11
+  </component>
12
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/tank.iml" filepath="$PROJECT_DIR$/tank.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 3 - 0
.idea/project-template.xml

@@ -0,0 +1,3 @@
1
+<template>
2
+  <input-field default="com.company">IJ_BASE_PACKAGE</input-field>
3
+</template>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="" vcs="Git" />
5
+  </component>
6
+</project>

BIN
out/production/tank/com/company/Main.class


BIN
out/production/tank/draw/DrawCircle.class


BIN
out/production/tank/draw/Graphic_.class


BIN
out/production/tank/draw/GraphicsMethods.class


BIN
out/production/tank/draw/MyPanel.class


BIN
out/production/tank/event_/BallMove.class


BIN
out/production/tank/event_/MyPanel.class


BIN
out/production/tank/tankGame01/MyPanel.class


BIN
out/production/tank/tankGame01/Tank.class


BIN
out/production/tank/tankGame01/TankGame01.class


+ 9 - 0
src/com/company/Main.java

@@ -0,0 +1,9 @@
1
+package com.company;
2
+
3
+public class Main {
4
+
5
+    public static void main(String[] args) {
6
+	// write your code here
7
+
8
+    }
9
+}

+ 38 - 0
src/draw/DrawCircle.java

@@ -0,0 +1,38 @@
1
+package draw;
2
+
3
+
4
+import javax.swing.*;
5
+import java.awt.*;
6
+
7
+/**
8
+ * 演示在java画板中画一个圆
9
+ *
10
+ */
11
+public class DrawCircle extends JFrame{
12
+    private MyPanel myPanel;
13
+    public static void main(String[] args) {
14
+        new DrawCircle();
15
+    }
16
+    public DrawCircle() {
17
+        myPanel = new MyPanel();
18
+        this.add(myPanel);
19
+        this.setSize(400,300);
20
+        // 点击X时关闭程序
21
+        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22
+        this.setVisible(true);
23
+    }
24
+
25
+}
26
+class MyPanel extends JPanel {
27
+    /**
28
+     * 初始化一個畫板
29
+     * Graphics 理解成画笔
30
+     * @param graphics
31
+     */
32
+    @Override
33
+    public void paint(Graphics graphics) {
34
+        super.paint(graphics);
35
+        graphics.drawOval(0,0,50,50);
36
+    }
37
+
38
+}

+ 35 - 0
src/draw/GraphicsMethods.java

@@ -0,0 +1,35 @@
1
+package draw;
2
+
3
+import javax.swing.*;
4
+import java.awt.*;
5
+
6
+/**
7
+ * Graphics类使用方法 (画直线 椭圆等)
8
+ */
9
+public class GraphicsMethods extends JFrame {
10
+    public static void main(String[] args) {
11
+        GraphicsMethods graphicsMethods = new GraphicsMethods();
12
+    }
13
+    public GraphicsMethods() {
14
+        Graphic_ graphic_ = new Graphic_();
15
+        this.add(graphic_);
16
+        this.setSize(750,500);
17
+        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18
+        this.setVisible(true);
19
+    }
20
+}
21
+class Graphic_ extends JPanel {
22
+    @Override
23
+    public void paint(Graphics g) {
24
+        super.paint(g);
25
+        g.setColor(Color.ORANGE);
26
+        // 写中文 坐标(100,100)是字符串的左下角
27
+        g.drawString("我是张先生",100,100);
28
+
29
+        // 画直线
30
+        //  g.drawLine(0,0,300,300);
31
+        // 填充图片
32
+//        Image image = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/yu.jpg"));
33
+//        g.drawImage(image,0,0,720,480,this);
34
+    }
35
+}

+ 44 - 0
src/event_/BallMove.java

@@ -0,0 +1,44 @@
1
+package event_;
2
+
3
+import javax.swing.*;
4
+import java.awt.*;
5
+import java.awt.event.KeyEvent;
6
+import java.awt.event.KeyListener;
7
+
8
+/**
9
+ * 小球移动
10
+ */
11
+public class BallMove  extends JFrame{
12
+    public static void main(String[] args) {
13
+        new BallMove();
14
+    }
15
+    public BallMove() {
16
+        MyPanel myPanel = new MyPanel();
17
+        this.add(myPanel);
18
+        this.setSize(400,300);
19
+        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20
+        this.setVisible(true);
21
+    }
22
+}
23
+class MyPanel extends JPanel implements KeyListener {
24
+    @Override
25
+    public void keyTyped(KeyEvent e) {
26
+        
27
+    }
28
+
29
+    @Override
30
+    public void keyPressed(KeyEvent e) {
31
+
32
+    }
33
+
34
+    @Override
35
+    public void keyReleased(KeyEvent e) {
36
+
37
+    }
38
+
39
+    @Override
40
+    public void paint(Graphics g) {
41
+        super.paint(g);
42
+        g.fillOval(10,10,20,20);
43
+    }
44
+}

+ 21 - 0
src/tankGame01/MyPanel.java

@@ -0,0 +1,21 @@
1
+package tankGame01;
2
+
3
+import javax.swing.*;
4
+import java.awt.*;
5
+
6
+public class MyPanel extends JPanel {
7
+    public MyPanel() {
8
+
9
+    }
10
+
11
+    @Override
12
+    public void paint(Graphics g) {
13
+        super.paint(g);
14
+        // 填充矩形
15
+        g.fillRect(0,0,1000,750);
16
+        Tank tank = new Tank(100, 100);
17
+        tank.initTank(g,1,1);
18
+        Tank tank2 = new Tank(200, 100);
19
+        tank2.initTank(g,1,2);
20
+    }
21
+}

+ 38 - 0
src/tankGame01/Tank.java

@@ -0,0 +1,38 @@
1
+package tankGame01;
2
+
3
+import java.awt.*;
4
+
5
+public class Tank {
6
+    // 横纵坐标
7
+    private Integer x;
8
+    private Integer y;
9
+
10
+    public Tank(Integer x, Integer y) {
11
+        this.x = x;
12
+        this.y = y;
13
+    }
14
+
15
+    /**
16
+     * 初始化坦克
17
+     * @param g 画笔
18
+     * @param direct 方向 上下左右 1234
19
+     * @param type 类型 1 我方 2 敌方
20
+     */
21
+    public void initTank(Graphics g, int direct,int type) {
22
+        Color color = type == 1? Color.CYAN:Color.ORANGE;
23
+        // 画坦克
24
+        g.setColor(color);
25
+        switch (direct) {
26
+            // 向上
27
+            case 1:
28
+                g.fill3DRect(x,y,10,60,false);// 坦克左侧履带
29
+                g.fill3DRect(x+30,y,10,60,false);// 坦克右侧履带
30
+                g.fill3DRect(x+10,y+10,20,40,false); // 中间控制台
31
+                g.fillOval(x+10,y+20,20,20);  // 画坦克的盖子
32
+                g.drawLine(x+20,y+30,x+20,y);// 画机关枪(中间的线)
33
+                break;
34
+        }
35
+
36
+    }
37
+
38
+}

+ 18 - 0
src/tankGame01/TankGame01.java

@@ -0,0 +1,18 @@
1
+package tankGame01;
2
+
3
+import javax.swing.*;
4
+
5
+public class TankGame01 extends JFrame {
6
+    public static void main(String[] args) {
7
+        new TankGame01();
8
+    }
9
+
10
+    public TankGame01() {
11
+        MyPanel myPanel = new MyPanel();
12
+        this.add(myPanel);
13
+        this.setSize(1000,750);
14
+        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15
+        this.setVisible(true);
16
+//        this.getDefaultCloseOperation()
17
+    }
18
+}

+ 27 - 0
tank.iml

@@ -0,0 +1,27 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$">
6
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+    </content>
8
+    <orderEntry type="inheritedJdk" />
9
+    <orderEntry type="sourceFolder" forTests="false" />
10
+    <orderEntry type="module-library">
11
+      <library name="JUnit5.7.0">
12
+        <CLASSES>
13
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.0/junit-jupiter-5.7.0.jar!/" />
14
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar!/" />
15
+          <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
16
+          <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
17
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.0/junit-platform-commons-1.7.0.jar!/" />
18
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.0/junit-jupiter-params-5.7.0.jar!/" />
19
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.0/junit-jupiter-engine-5.7.0.jar!/" />
20
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.0/junit-platform-engine-1.7.0.jar!/" />
21
+        </CLASSES>
22
+        <JAVADOC />
23
+        <SOURCES />
24
+      </library>
25
+    </orderEntry>
26
+  </component>
27
+</module>