diff --git a/源代码/client/bin/Actor.class b/源代码/client/bin/Actor.class new file mode 100644 index 0000000..33cd367 Binary files /dev/null and b/源代码/client/bin/Actor.class differ diff --git a/源代码/client/bin/ClientControler$1.class b/源代码/client/bin/ClientControler$1.class new file mode 100644 index 0000000..cc427e8 Binary files /dev/null and b/源代码/client/bin/ClientControler$1.class differ diff --git a/源代码/client/bin/ClientControler$2.class b/源代码/client/bin/ClientControler$2.class new file mode 100644 index 0000000..9c37dc4 Binary files /dev/null and b/源代码/client/bin/ClientControler$2.class differ diff --git a/源代码/client/bin/ClientControler$3.class b/源代码/client/bin/ClientControler$3.class new file mode 100644 index 0000000..e46a960 Binary files /dev/null and b/源代码/client/bin/ClientControler$3.class differ diff --git a/源代码/client/bin/ClientControler$4.class b/源代码/client/bin/ClientControler$4.class new file mode 100644 index 0000000..d37b611 Binary files /dev/null and b/源代码/client/bin/ClientControler$4.class differ diff --git a/源代码/client/bin/ClientControler$5.class b/源代码/client/bin/ClientControler$5.class new file mode 100644 index 0000000..66b9a89 Binary files /dev/null and b/源代码/client/bin/ClientControler$5.class differ diff --git a/源代码/client/bin/ClientControler$6.class b/源代码/client/bin/ClientControler$6.class new file mode 100644 index 0000000..322aec4 Binary files /dev/null and b/源代码/client/bin/ClientControler$6.class differ diff --git a/源代码/client/bin/ClientControler$7.class b/源代码/client/bin/ClientControler$7.class new file mode 100644 index 0000000..af41dad Binary files /dev/null and b/源代码/client/bin/ClientControler$7.class differ diff --git a/源代码/client/bin/ClientControler.class b/源代码/client/bin/ClientControler.class new file mode 100644 index 0000000..e2d650c Binary files /dev/null and b/源代码/client/bin/ClientControler.class differ diff --git a/源代码/client/bin/ClientModel.class b/源代码/client/bin/ClientModel.class new file mode 100644 index 0000000..fdc1b13 Binary files /dev/null and b/源代码/client/bin/ClientModel.class differ diff --git a/源代码/client/bin/ClientView.class b/源代码/client/bin/ClientView.class new file mode 100644 index 0000000..8812a85 Binary files /dev/null and b/源代码/client/bin/ClientView.class differ diff --git a/源代码/client/bin/Steelwall.class b/源代码/client/bin/Steelwall.class new file mode 100644 index 0000000..f7b394f Binary files /dev/null and b/源代码/client/bin/Steelwall.class differ diff --git a/源代码/client/bin/Ticker.class b/源代码/client/bin/Ticker.class new file mode 100644 index 0000000..4f8464a Binary files /dev/null and b/源代码/client/bin/Ticker.class differ diff --git a/源代码/client/bin/bomb.class b/源代码/client/bin/bomb.class new file mode 100644 index 0000000..cb17fd7 Binary files /dev/null and b/源代码/client/bin/bomb.class differ diff --git a/源代码/client/bin/bullet.class b/源代码/client/bin/bullet.class new file mode 100644 index 0000000..03e92d7 Binary files /dev/null and b/源代码/client/bin/bullet.class differ diff --git a/源代码/client/bin/drawingPanel.class b/源代码/client/bin/drawingPanel.class new file mode 100644 index 0000000..70fc3ad Binary files /dev/null and b/源代码/client/bin/drawingPanel.class differ diff --git a/源代码/client/bin/instructionHandler.class b/源代码/client/bin/instructionHandler.class new file mode 100644 index 0000000..fc3e378 Binary files /dev/null and b/源代码/client/bin/instructionHandler.class differ diff --git a/源代码/client/bin/level.class b/源代码/client/bin/level.class new file mode 100644 index 0000000..48d483f Binary files /dev/null and b/源代码/client/bin/level.class differ diff --git a/源代码/client/bin/normalObject.class b/源代码/client/bin/normalObject.class new file mode 100644 index 0000000..2563a7f Binary files /dev/null and b/源代码/client/bin/normalObject.class differ diff --git a/源代码/client/bin/shield.class b/源代码/client/bin/shield.class new file mode 100644 index 0000000..5a7d67d Binary files /dev/null and b/源代码/client/bin/shield.class differ diff --git a/源代码/client/bin/wall.class b/源代码/client/bin/wall.class new file mode 100644 index 0000000..d2420d8 Binary files /dev/null and b/源代码/client/bin/wall.class differ diff --git a/源代码/client/image/1.jpg b/源代码/client/image/1.jpg new file mode 100644 index 0000000..bb1823d Binary files /dev/null and b/源代码/client/image/1.jpg differ diff --git a/源代码/client/image/10.jpg b/源代码/client/image/10.jpg new file mode 100644 index 0000000..d446085 Binary files /dev/null and b/源代码/client/image/10.jpg differ diff --git a/源代码/client/image/11.jpg b/源代码/client/image/11.jpg new file mode 100644 index 0000000..4a7a633 Binary files /dev/null and b/源代码/client/image/11.jpg differ diff --git a/源代码/client/image/12.jpg b/源代码/client/image/12.jpg new file mode 100644 index 0000000..8dd249b Binary files /dev/null and b/源代码/client/image/12.jpg differ diff --git a/源代码/client/image/13.jpg b/源代码/client/image/13.jpg new file mode 100644 index 0000000..c083a29 Binary files /dev/null and b/源代码/client/image/13.jpg differ diff --git a/源代码/client/image/14.jpg b/源代码/client/image/14.jpg new file mode 100644 index 0000000..cf49905 Binary files /dev/null and b/源代码/client/image/14.jpg differ diff --git a/源代码/client/image/15.jpg b/源代码/client/image/15.jpg new file mode 100644 index 0000000..3ced3c9 Binary files /dev/null and b/源代码/client/image/15.jpg differ diff --git a/源代码/client/image/16.jpg b/源代码/client/image/16.jpg new file mode 100644 index 0000000..3823579 Binary files /dev/null and b/源代码/client/image/16.jpg differ diff --git a/源代码/client/image/17.jpg b/源代码/client/image/17.jpg new file mode 100644 index 0000000..0197944 Binary files /dev/null and b/源代码/client/image/17.jpg differ diff --git a/源代码/client/image/18.jpg b/源代码/client/image/18.jpg new file mode 100644 index 0000000..8dc02d1 Binary files /dev/null and b/源代码/client/image/18.jpg differ diff --git a/源代码/client/image/19.jpg b/源代码/client/image/19.jpg new file mode 100644 index 0000000..7b903ad Binary files /dev/null and b/源代码/client/image/19.jpg differ diff --git a/源代码/client/image/2.jpg b/源代码/client/image/2.jpg new file mode 100644 index 0000000..a837dea Binary files /dev/null and b/源代码/client/image/2.jpg differ diff --git a/源代码/client/image/20.jpg b/源代码/client/image/20.jpg new file mode 100644 index 0000000..d156fae Binary files /dev/null and b/源代码/client/image/20.jpg differ diff --git a/源代码/client/image/21.jpg b/源代码/client/image/21.jpg new file mode 100644 index 0000000..00557b3 Binary files /dev/null and b/源代码/client/image/21.jpg differ diff --git a/源代码/client/image/22.jpg b/源代码/client/image/22.jpg new file mode 100644 index 0000000..2ff4934 Binary files /dev/null and b/源代码/client/image/22.jpg differ diff --git a/源代码/client/image/23.jpg b/源代码/client/image/23.jpg new file mode 100644 index 0000000..4219feb Binary files /dev/null and b/源代码/client/image/23.jpg differ diff --git a/源代码/client/image/24.jpg b/源代码/client/image/24.jpg new file mode 100644 index 0000000..9e22490 Binary files /dev/null and b/源代码/client/image/24.jpg differ diff --git a/源代码/client/image/25.jpg b/源代码/client/image/25.jpg new file mode 100644 index 0000000..90a4f3d Binary files /dev/null and b/源代码/client/image/25.jpg differ diff --git a/源代码/client/image/26.jpg b/源代码/client/image/26.jpg new file mode 100644 index 0000000..36b5b23 Binary files /dev/null and b/源代码/client/image/26.jpg differ diff --git a/源代码/client/image/27.jpg b/源代码/client/image/27.jpg new file mode 100644 index 0000000..9d8aff5 Binary files /dev/null and b/源代码/client/image/27.jpg differ diff --git a/源代码/client/image/28.jpg b/源代码/client/image/28.jpg new file mode 100644 index 0000000..37f234a Binary files /dev/null and b/源代码/client/image/28.jpg differ diff --git a/源代码/client/image/29.jpg b/源代码/client/image/29.jpg new file mode 100644 index 0000000..c98a9bb Binary files /dev/null and b/源代码/client/image/29.jpg differ diff --git a/源代码/client/image/3.jpg b/源代码/client/image/3.jpg new file mode 100644 index 0000000..7155db4 Binary files /dev/null and b/源代码/client/image/3.jpg differ diff --git a/源代码/client/image/30.jpg b/源代码/client/image/30.jpg new file mode 100644 index 0000000..d34e9bb Binary files /dev/null and b/源代码/client/image/30.jpg differ diff --git a/源代码/client/image/31.jpg b/源代码/client/image/31.jpg new file mode 100644 index 0000000..091234d Binary files /dev/null and b/源代码/client/image/31.jpg differ diff --git a/源代码/client/image/32.jpg b/源代码/client/image/32.jpg new file mode 100644 index 0000000..f1c859a Binary files /dev/null and b/源代码/client/image/32.jpg differ diff --git a/源代码/client/image/33.jpg b/源代码/client/image/33.jpg new file mode 100644 index 0000000..72f7a8a Binary files /dev/null and b/源代码/client/image/33.jpg differ diff --git a/源代码/client/image/34.jpg b/源代码/client/image/34.jpg new file mode 100644 index 0000000..c99035d Binary files /dev/null and b/源代码/client/image/34.jpg differ diff --git a/源代码/client/image/35.jpg b/源代码/client/image/35.jpg new file mode 100644 index 0000000..60ca424 Binary files /dev/null and b/源代码/client/image/35.jpg differ diff --git a/源代码/client/image/36.jpg b/源代码/client/image/36.jpg new file mode 100644 index 0000000..1951f74 Binary files /dev/null and b/源代码/client/image/36.jpg differ diff --git a/源代码/client/image/37.jpg b/源代码/client/image/37.jpg new file mode 100644 index 0000000..9761115 Binary files /dev/null and b/源代码/client/image/37.jpg differ diff --git a/源代码/client/image/38.jpg b/源代码/client/image/38.jpg new file mode 100644 index 0000000..91f26d8 Binary files /dev/null and b/源代码/client/image/38.jpg differ diff --git a/源代码/client/image/39.jpg b/源代码/client/image/39.jpg new file mode 100644 index 0000000..0e3655f Binary files /dev/null and b/源代码/client/image/39.jpg differ diff --git a/源代码/client/image/4.jpg b/源代码/client/image/4.jpg new file mode 100644 index 0000000..efcf8d5 Binary files /dev/null and b/源代码/client/image/4.jpg differ diff --git a/源代码/client/image/40.jpg b/源代码/client/image/40.jpg new file mode 100644 index 0000000..1d8280d Binary files /dev/null and b/源代码/client/image/40.jpg differ diff --git a/源代码/client/image/41.jpg b/源代码/client/image/41.jpg new file mode 100644 index 0000000..9123956 Binary files /dev/null and b/源代码/client/image/41.jpg differ diff --git a/源代码/client/image/42.jpg b/源代码/client/image/42.jpg new file mode 100644 index 0000000..c17ea64 Binary files /dev/null and b/源代码/client/image/42.jpg differ diff --git a/源代码/client/image/43.jpg b/源代码/client/image/43.jpg new file mode 100644 index 0000000..2270b56 Binary files /dev/null and b/源代码/client/image/43.jpg differ diff --git a/源代码/client/image/44.jpg b/源代码/client/image/44.jpg new file mode 100644 index 0000000..cca4208 Binary files /dev/null and b/源代码/client/image/44.jpg differ diff --git a/源代码/client/image/45.jpg b/源代码/client/image/45.jpg new file mode 100644 index 0000000..318c507 Binary files /dev/null and b/源代码/client/image/45.jpg differ diff --git a/源代码/client/image/46.jpg b/源代码/client/image/46.jpg new file mode 100644 index 0000000..7696ac5 Binary files /dev/null and b/源代码/client/image/46.jpg differ diff --git a/源代码/client/image/47.jpg b/源代码/client/image/47.jpg new file mode 100644 index 0000000..54d9bd1 Binary files /dev/null and b/源代码/client/image/47.jpg differ diff --git a/源代码/client/image/48.jpg b/源代码/client/image/48.jpg new file mode 100644 index 0000000..c9b335d Binary files /dev/null and b/源代码/client/image/48.jpg differ diff --git a/源代码/client/image/49.jpg b/源代码/client/image/49.jpg new file mode 100644 index 0000000..a234e4f Binary files /dev/null and b/源代码/client/image/49.jpg differ diff --git a/源代码/client/image/5.jpg b/源代码/client/image/5.jpg new file mode 100644 index 0000000..cf31c44 Binary files /dev/null and b/源代码/client/image/5.jpg differ diff --git a/源代码/client/image/50.jpg b/源代码/client/image/50.jpg new file mode 100644 index 0000000..6efa721 Binary files /dev/null and b/源代码/client/image/50.jpg differ diff --git a/源代码/client/image/51.jpg b/源代码/client/image/51.jpg new file mode 100644 index 0000000..009feb9 Binary files /dev/null and b/源代码/client/image/51.jpg differ diff --git a/源代码/client/image/52.jpg b/源代码/client/image/52.jpg new file mode 100644 index 0000000..5b65e21 Binary files /dev/null and b/源代码/client/image/52.jpg differ diff --git a/源代码/client/image/53.jpg b/源代码/client/image/53.jpg new file mode 100644 index 0000000..084a2a5 Binary files /dev/null and b/源代码/client/image/53.jpg differ diff --git a/源代码/client/image/54.jpg b/源代码/client/image/54.jpg new file mode 100644 index 0000000..3acee9f Binary files /dev/null and b/源代码/client/image/54.jpg differ diff --git a/源代码/client/image/55.jpg b/源代码/client/image/55.jpg new file mode 100644 index 0000000..67e2259 Binary files /dev/null and b/源代码/client/image/55.jpg differ diff --git a/源代码/client/image/56.jpg b/源代码/client/image/56.jpg new file mode 100644 index 0000000..6f4b02c Binary files /dev/null and b/源代码/client/image/56.jpg differ diff --git a/源代码/client/image/57.jpg b/源代码/client/image/57.jpg new file mode 100644 index 0000000..a336d53 Binary files /dev/null and b/源代码/client/image/57.jpg differ diff --git a/源代码/client/image/58.jpg b/源代码/client/image/58.jpg new file mode 100644 index 0000000..d2916f4 Binary files /dev/null and b/源代码/client/image/58.jpg differ diff --git a/源代码/client/image/59.jpg b/源代码/client/image/59.jpg new file mode 100644 index 0000000..ba972df Binary files /dev/null and b/源代码/client/image/59.jpg differ diff --git a/源代码/client/image/6.jpg b/源代码/client/image/6.jpg new file mode 100644 index 0000000..34ec3cd Binary files /dev/null and b/源代码/client/image/6.jpg differ diff --git a/源代码/client/image/60.jpg b/源代码/client/image/60.jpg new file mode 100644 index 0000000..6f6ffb6 Binary files /dev/null and b/源代码/client/image/60.jpg differ diff --git a/源代码/client/image/61.jpg b/源代码/client/image/61.jpg new file mode 100644 index 0000000..ef20698 Binary files /dev/null and b/源代码/client/image/61.jpg differ diff --git a/源代码/client/image/62.jpg b/源代码/client/image/62.jpg new file mode 100644 index 0000000..46908fc Binary files /dev/null and b/源代码/client/image/62.jpg differ diff --git a/源代码/client/image/63.jpg b/源代码/client/image/63.jpg new file mode 100644 index 0000000..7264d23 Binary files /dev/null and b/源代码/client/image/63.jpg differ diff --git a/源代码/client/image/64.jpg b/源代码/client/image/64.jpg new file mode 100644 index 0000000..09ca67b Binary files /dev/null and b/源代码/client/image/64.jpg differ diff --git a/源代码/client/image/65.jpg b/源代码/client/image/65.jpg new file mode 100644 index 0000000..3abeb62 Binary files /dev/null and b/源代码/client/image/65.jpg differ diff --git a/源代码/client/image/66.jpg b/源代码/client/image/66.jpg new file mode 100644 index 0000000..ea9d8c9 Binary files /dev/null and b/源代码/client/image/66.jpg differ diff --git a/源代码/client/image/67.jpg b/源代码/client/image/67.jpg new file mode 100644 index 0000000..0c63b54 Binary files /dev/null and b/源代码/client/image/67.jpg differ diff --git a/源代码/client/image/68.jpg b/源代码/client/image/68.jpg new file mode 100644 index 0000000..d3de2a4 Binary files /dev/null and b/源代码/client/image/68.jpg differ diff --git a/源代码/client/image/69.jpg b/源代码/client/image/69.jpg new file mode 100644 index 0000000..25d19f7 Binary files /dev/null and b/源代码/client/image/69.jpg differ diff --git a/源代码/client/image/7.jpg b/源代码/client/image/7.jpg new file mode 100644 index 0000000..d107ff1 Binary files /dev/null and b/源代码/client/image/7.jpg differ diff --git a/源代码/client/image/70.jpg b/源代码/client/image/70.jpg new file mode 100644 index 0000000..7d6190c Binary files /dev/null and b/源代码/client/image/70.jpg differ diff --git a/源代码/client/image/71.jpg b/源代码/client/image/71.jpg new file mode 100644 index 0000000..641240c Binary files /dev/null and b/源代码/client/image/71.jpg differ diff --git a/源代码/client/image/72.jpg b/源代码/client/image/72.jpg new file mode 100644 index 0000000..96edb91 Binary files /dev/null and b/源代码/client/image/72.jpg differ diff --git a/源代码/client/image/73.JPG b/源代码/client/image/73.JPG new file mode 100644 index 0000000..63ccfcb Binary files /dev/null and b/源代码/client/image/73.JPG differ diff --git a/源代码/client/image/74.JPG b/源代码/client/image/74.JPG new file mode 100644 index 0000000..159afe3 Binary files /dev/null and b/源代码/client/image/74.JPG differ diff --git a/源代码/client/image/75.JPG b/源代码/client/image/75.JPG new file mode 100644 index 0000000..25f2f57 Binary files /dev/null and b/源代码/client/image/75.JPG differ diff --git a/源代码/client/image/76.JPG b/源代码/client/image/76.JPG new file mode 100644 index 0000000..876b883 Binary files /dev/null and b/源代码/client/image/76.JPG differ diff --git a/源代码/client/image/77.JPG b/源代码/client/image/77.JPG new file mode 100644 index 0000000..9904e4c Binary files /dev/null and b/源代码/client/image/77.JPG differ diff --git a/源代码/client/image/78.JPG b/源代码/client/image/78.JPG new file mode 100644 index 0000000..8eb3102 Binary files /dev/null and b/源代码/client/image/78.JPG differ diff --git a/源代码/client/image/79.JPG b/源代码/client/image/79.JPG new file mode 100644 index 0000000..8c7b06d Binary files /dev/null and b/源代码/client/image/79.JPG differ diff --git a/源代码/client/image/8.jpg b/源代码/client/image/8.jpg new file mode 100644 index 0000000..e9be67b Binary files /dev/null and b/源代码/client/image/8.jpg differ diff --git a/源代码/client/image/80.JPG b/源代码/client/image/80.JPG new file mode 100644 index 0000000..5f0655e Binary files /dev/null and b/源代码/client/image/80.JPG differ diff --git a/源代码/client/image/81.JPG b/源代码/client/image/81.JPG new file mode 100644 index 0000000..fc4d646 Binary files /dev/null and b/源代码/client/image/81.JPG differ diff --git a/源代码/client/image/82.JPG b/源代码/client/image/82.JPG new file mode 100644 index 0000000..f03255c Binary files /dev/null and b/源代码/client/image/82.JPG differ diff --git a/源代码/client/image/83.JPG b/源代码/client/image/83.JPG new file mode 100644 index 0000000..ffbee39 Binary files /dev/null and b/源代码/client/image/83.JPG differ diff --git a/源代码/client/image/84.JPG b/源代码/client/image/84.JPG new file mode 100644 index 0000000..8a9860b Binary files /dev/null and b/源代码/client/image/84.JPG differ diff --git a/源代码/client/image/85.JPG b/源代码/client/image/85.JPG new file mode 100644 index 0000000..1f23308 Binary files /dev/null and b/源代码/client/image/85.JPG differ diff --git a/源代码/client/image/86.JPG b/源代码/client/image/86.JPG new file mode 100644 index 0000000..f6c472e Binary files /dev/null and b/源代码/client/image/86.JPG differ diff --git a/源代码/client/image/87.JPG b/源代码/client/image/87.JPG new file mode 100644 index 0000000..f13e29f Binary files /dev/null and b/源代码/client/image/87.JPG differ diff --git a/源代码/client/image/88.JPG b/源代码/client/image/88.JPG new file mode 100644 index 0000000..2780490 Binary files /dev/null and b/源代码/client/image/88.JPG differ diff --git a/源代码/client/image/9.jpg b/源代码/client/image/9.jpg new file mode 100644 index 0000000..6d79128 Binary files /dev/null and b/源代码/client/image/9.jpg differ diff --git a/源代码/client/image/Thumbs.db b/源代码/client/image/Thumbs.db new file mode 100644 index 0000000..b1b2db9 Binary files /dev/null and b/源代码/client/image/Thumbs.db differ diff --git a/源代码/client/src/Actor.java b/源代码/client/src/Actor.java new file mode 100644 index 0000000..04d5839 --- /dev/null +++ b/源代码/client/src/Actor.java @@ -0,0 +1,7 @@ +import java.awt.*; +//创建接口 +public interface Actor { + public void draw(Graphics g); + public int getxPos(); + public int getyPos(); +} diff --git a/源代码/client/src/ClientControler.java b/源代码/client/src/ClientControler.java new file mode 100644 index 0000000..a821101 --- /dev/null +++ b/源代码/client/src/ClientControler.java @@ -0,0 +1,172 @@ +import javax.swing.*; +import java.awt.event.*; +//Download:http://www.codefans.net +//这个类处理来自客户端视图框架的输入 +public class ClientControler{ + public boolean serverConnected;; + public boolean gameStarted; + public boolean gamePaused; + public ClientView view; + public ClientModel model; + public int helpMessageCount = 1; + + + public ClientControler(ClientView thisview, ClientModel thismodel){ + view = thisview; + model = thismodel; + + //发送消息按钮操作 + view.sendMessage.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + if(!model.gameStarted){ + model.addMessage("还没有和主机端玩家联上, 无法发送对话"); + return; + } + + if(!view.messageField.getText().equals("")){ + model.addMessage("用户端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "e" + view.messageField.getText() + ";"; + view.messageField.setText(""); + }else{ + model.addMessage("对话内容不能为空"); + } + } + } + ); + + //handel connectServer按钮操作 + view.connectServer.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + if(!model.serverConnected){ + model.serverIP = view.IPfield.getText(); + model.t.start(); + } + } + } + ); + + //handel pauseAndResume 按钮操作 + view.pauseAndResume.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + if(!model.gameOver && model.gameStarted){ + model.pausePressed = true; + if(!model.gamePaused){ + model.gamePaused = true; + model.addMessage("用户端玩家暂停了游戏"); + }else{ + model.gamePaused = false; + model.addMessage("用户端玩家取消了暂停"); + } + } + } + } + ); + + //handel help 按钮操作 + view.help.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + model.addMessage("******************************坦克大战 ******************************"); + model.addMessage("帮助: 按s键发射子弹,按键盘的方向键来控制坦克的移动"); + model.addMessage("如果按键没有反应请 1. 关闭大写功能; 2. 用 tab键切换 "); + model.addMessage("如果您在使用对话界面请移动到控制界面."); + model.addMessage("********************************************************************************"); + } + } + ); + + //handel exit 按钮操作 + view.exit.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + } + ); + + + //处理从键盘输入 + view.messageField.addKeyListener( new KeyAdapter(){ + public void keyPressed(KeyEvent e){ + if(helpMessageCount > 0){ + model.addMessage("提示:用\"tab\"键可以自由切换于控制界面和对话界面"); + model.addMessage("提示:按回车键可以直接发送您的对话"); + helpMessageCount--; + } + + if(e.getKeyCode()==e.VK_ENTER){ + if(!view.messageField.getText().equals("")){ + model.addMessage("用户端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "e" + view.messageField.getText() + ";"; + view.messageField.setText(""); + }else{ + model.addMessage("对话内容不能为空"); + } + } + } + }); + + JPanel temp = view.mainPanel; + temp.addKeyListener( new KeyAdapter(){ + public void keyPressed(KeyEvent e){ + if(e.getKeyCode() == KeyEvent.VK_UP){ + model.moveUp = true; + model.moveDown = false; + model.moveLeft = false; + model.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_DOWN ){ + model.moveDown = true; + model.moveUp = false; + model.moveLeft = false; + model.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_LEFT ){ + model.moveLeft = true; + model.moveUp = false; + model.moveDown = false; + model.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_RIGHT ){ + model.moveLeft = false; + model.moveUp = false; + model.moveDown = false; + model.moveRight = true; + } + + if(e.getKeyChar() == 's') + model.fire = true; + + if(e.getKeyCode()==e.VK_ENTER){ + if(!view.messageField.getText().equals("")){ + model.addMessage("用户端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "e" + view.messageField.getText() + ";"; + view.messageField.setText(""); + } + } + + if(e.getKeyChar() == 'y' && model.gameOver && !model.clientVoteYes){ + model.clientVoteYes = true; + model.addMessage("等待主机端玩家回应..."); + } + + if(e.getKeyChar() == 'n' && model.gameOver) + model.clientVoteNo = true; + } + + public void keyReleased(KeyEvent e){ + if(e.getKeyCode() == KeyEvent.VK_UP) + model.moveUp = false; + if(e.getKeyCode() == KeyEvent.VK_DOWN ) + model.moveDown = false; + if(e.getKeyCode() == KeyEvent.VK_LEFT ) + model.moveLeft = false; + if(e.getKeyCode() == KeyEvent.VK_RIGHT ) + model.moveRight = false; + if(e.getKeyChar() == 's') + model.fire = false; + } + } + ); + + } +} + diff --git a/源代码/client/src/ClientModel.java b/源代码/client/src/ClientModel.java new file mode 100644 index 0000000..e2b8de3 --- /dev/null +++ b/源代码/client/src/ClientModel.java @@ -0,0 +1,256 @@ +import java.net.*; +import java.io.*; +import java.awt.event.*; +import java.awt.*; + +public class ClientModel implements ActionListener{ + public ClientView view; + + //连接变量 + public Socket clientSocket; + public PrintWriter out; + public BufferedReader in; + public String fromServer, fromUser; + public String serverIP; + + //客户端状态 + public boolean serverConnected; + public boolean gameStarted; + public boolean gamePaused; + public boolean gameOver; + public boolean serverVoteYes, serverVoteNo; + public boolean clientVoteYes, clientVoteNo; + public boolean pausePressed; + + //图像信息 + public String[] messageQueue; + public int messageIndex; + public String playerTypedMessage = ""; + + + //textures + public Image[] textures; + + //实际的游戏运行在这个线程,而主线程听用户的输入 + public Ticker t; + + //游戏变量 + public static int gameFlow; + public Actor[] drawingList; + public boolean moveUp; + public boolean moveDown; + public boolean moveLeft; + public boolean moveRight; + public boolean fire; + + + public ClientModel(ClientView thisview){ + view = thisview; + messageQueue = new String[8]; + view.mainPanel.messageQueue = messageQueue; + addMessage("欢迎来到坦克大战用户端!请输入主机IP地址然后点击\"连接主机\"按钮开始游戏"); + + t = new Ticker(1000); + t.addActionListener(this); + + } + + public void connectServer(){ + addMessage("正在连接主机"); + + try{ + serverIP = view.IPfield.getText(); + InetAddress addr = InetAddress.getByName(serverIP); + clientSocket = new Socket(addr, 9999); + + out = new PrintWriter(clientSocket.getOutputStream(), true); + in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + + }catch(Exception e){ + t.stop(); + System.out.println(e); + addMessage("连接中出现错误, 请确认 1. 输入的IP是否正确, 2. 主机端已存在"); + return; + } + + serverConnected = true; + addMessage("已成功连接到主机,开始载入游戏"); + view.IPfield.setFocusable(false); + view.IPfield.setEnabled(false); + + //加载游戏 texture + textures = new Image[88]; + for(int i = 1; i < textures.length+1; i++) + textures[i-1] = Toolkit.getDefaultToolkit().getImage("image\\" + i + ".jpg"); + + + drawingList = new Actor[400]; + + gameStarted = true; + view.mainPanel.gameStarted = gameStarted;; + view.mainPanel.drawingList = drawingList; + view.messageField.setEnabled(true); + addMessage("载入完毕,游戏开始了!"); + } + + public void actionPerformed(ActionEvent e){ + connectServer(); + + //如果程序不能连接到服务器然后什么都不做 + if(!serverConnected) + return; + + //游戏逻辑循环,客户端程序实际不执行任何逻辑计算,它只接受drawing-instructions + try{ + while ((fromServer = in.readLine()) != null) { + fromUser = ""; + + gameFlow++; + + if(pausePressed){ + fromUser+= "x;"; + pausePressed = false; + } + + if(gameOver){ + if(clientVoteNo) + System.exit(0); + + if(clientVoteYes){ + fromUser+="j;"; + if(serverVoteYes){ + addMessage("主机端玩家决定再玩一次,游戏重新开始了..."); + gameOver = false; + clientVoteYes = false; + serverVoteYes = false; + } + } + } + + //指令字符串做出反馈,告诉服务器客户端在做什么 + fromUser +="m"; + if(moveUp) + fromUser+= "1"; + else + fromUser+= "0"; + if(moveDown) + fromUser+="1"; + else + fromUser+= "0"; + if(moveLeft) + fromUser+="1"; + else + fromUser+= "0"; + if(moveRight) + fromUser+="1"; + else + fromUser+= "0"; + if(fire) + fromUser+="1"; + else + fromUser+= "0"; + fromUser+=";"; + + //来自服务器的进程指令 + instructionHandler.handleInstruction(this, fromServer); + + //从消息队列中删除一个消息每10秒,(如果有) + if(gameFlow%300 == 0) + removeMessage(); + + //输出玩家坦克信息 + if(!playerTypedMessage.equals("")){ + fromUser+=playerTypedMessage; + playerTypedMessage = ""; + } + + //发送反馈指令 + out.println(fromUser); + + //调用视图重新绘制它自己 + view.mainPanel.repaint(); + + //如果切换到对话模式的玩家,那么停止所有坦克行动 + if(!view.mainPanel.hasFocus()){ + moveLeft = false; + moveUp = false; + moveDown = false; + moveRight = false; + fire = false; + } + } + }catch(Exception ex){ + ex.printStackTrace(); + t.stop(); + view.messageField.setEnabled(false); + serverConnected = false; + gameStarted = false; + view.mainPanel.gameStarted = false; + gameOver = false; + addMessage("主机端退出了"); + view.IPfield.setFocusable(true); + view.IPfield.setEnabled(true); + + //当有错误发生时,关闭创建的任何事情 + try{ + out.close(); + in.close(); + clientSocket.close(); + }catch(Exception exc){ + System.out.println(exc); + } + } + } + + //在屏幕上显示一条消息 + public void addMessage(String message){ + if(messageIndex < 8){ + messageQueue[messageIndex] = message; + messageIndex++; + } + else{ + for(int i = 0; i < 7; i++) + messageQueue[i] = messageQueue[i+1]; + messageQueue[7] = message; + } + + //调用视图来重新绘制屏幕,如果没有开始游戏 + if(!gameStarted) + view.mainPanel.repaint(); + } + + //删除最早的消息在屏幕上 + public void removeMessage(){ + if(messageIndex == 0) + return; + + messageIndex--; + for(int i = 0; i < messageIndex; i++) + messageQueue[i] = messageQueue[i+1]; + messageQueue[messageIndex] = null; + + //调用视图来重新绘制屏幕如果没有开始游戏 + if(!gameStarted) + view.mainPanel.repaint(); + } + + //添加一个游戏对象(如坦克、子弹等)图纸清单 + public void addActor(Actor actor){ + for(int i = 0; i < drawingList.length; i ++ ) + if(drawingList[i] == null){ + drawingList[i] = actor; + break; + } + } + + //删除一个游戏对象从图纸清单 + public void removeActor(Actor actor){ + for(int i = 0; i < drawingList.length; i ++ ) + if(drawingList[i] == actor){ + drawingList[i] = null; + break; + } + } + + +} diff --git a/源代码/client/src/ClientView.java b/源代码/client/src/ClientView.java new file mode 100644 index 0000000..da14016 --- /dev/null +++ b/源代码/client/src/ClientView.java @@ -0,0 +1,89 @@ +// 坦克大战连线版用户端 +import javax.swing.*; +import java.awt.*; + +//这个类代表服务器的图形界面 +public class ClientView extends JFrame{ + public drawingPanel mainPanel; + public JButton sendMessage, connectServer, exit, pauseAndResume, help; + public JTextField messageField, IPfield; + public JLabel enterIP; + public Image offScreenImage; + + public ClientControler controler; + public ClientModel model; + + + public ClientView(){ + super("坦克大战"); + + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { } + + getContentPane().setLayout(null); + + //设置动画绘制主面板 + mainPanel = new drawingPanel(); + mainPanel.setLayout(null); + mainPanel.setBounds(0, 22, 679, 605); + mainPanel.setBackground(new Color(128, 64, 0)); + + messageField = new JTextField(); + messageField.setBounds(0,519, 560,22); + messageField.setEnabled(false); + sendMessage = new JButton("发送"); + sendMessage.setBounds(570,518, 62,24); + sendMessage.setFocusable(false); + mainPanel.add(messageField); + mainPanel.add(sendMessage); + getContentPane().add(mainPanel); + mainPanel.setFocusable(true); + + //设置选项按钮和IP文本字段 + enterIP = new JLabel("输入主机IP"); + enterIP.setBounds(10, 0,60,22); + getContentPane().add(enterIP); + + IPfield = new JTextField(); + IPfield.setBounds(65, 0,90,22); + getContentPane().add(IPfield); + + connectServer = new JButton("连接主机"); + connectServer.setBounds(160, 0,100,22); + getContentPane().add(connectServer); + connectServer.setFocusable(false); + + pauseAndResume = new JButton("暂停/继续"); + pauseAndResume.setBounds(260, 0,100,22); + getContentPane().add(pauseAndResume); + pauseAndResume.setFocusable(false); + + help = new JButton("帮助"); + help.setBounds(360, 0,100,22); + getContentPane().add(help); + help.setFocusable(false); + + exit = new JButton("退出"); + exit.setBounds(460, 0,100,22); + getContentPane().add(exit); + exit.setFocusable(false); + + //设置面框架 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(150, 130, 640, 590); + setVisible(true); + setResizable( false ); + + //设置客户端模型 + model = new ClientModel(this); + + //设置客户端控制器 + controler = new ClientControler(this, model); + } + + public static void main(String[] args){ + new ClientView(); + } + +} \ No newline at end of file diff --git a/源代码/client/src/Steelwall.java b/源代码/client/src/Steelwall.java new file mode 100644 index 0000000..2d877d3 --- /dev/null +++ b/源代码/client/src/Steelwall.java @@ -0,0 +1,70 @@ +import java.awt.*; + +public class Steelwall implements Actor{ + public final String Type = "Steelwall"; + public Image Steelwall; + public int xPos; + public int yPos; + public boolean[] shape; + public ClientModel gameModel; + + public Steelwall(int xPos, int yPos, int orientation, ClientModel gameModel){ + this.xPos = xPos; + this.yPos = yPos; + this.gameModel = gameModel; + shape = new boolean[4]; + Steelwall = gameModel.textures[53]; + + if(orientation == 0){ + shape[2] = true; + shape[3] = true; + } + if(orientation == 1){ + shape[0] = true; + shape[1] = true; + } + if(orientation == 2){ + shape[1] = true; + shape[3] = true; + } + if(orientation == 3){ + shape[0] = true; + shape[2] = true; + } + } + + public void draw(Graphics g){ + boolean walldestoried = true; + for(int i = 0; i < shape.length; i++) + if(!shape[i]){ + walldestoried = false; + break; + } + if(walldestoried) + return; + + g.drawImage(Steelwall, xPos - 12, yPos - 12, null); + g.setColor(new Color(128, 64, 0)); + if(shape[0]) + g.fillRect(xPos - 12, yPos - 12, 13, 13); + if(shape[1]) + g.fillRect(xPos, yPos - 12, 13, 13); + if(shape[2]) + g.fillRect(xPos - 12, yPos, 13, 13); + if(shape[3]) + g.fillRect(xPos, yPos, 13, 13); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return Type; + } + +} \ No newline at end of file diff --git a/源代码/client/src/Ticker.java b/源代码/client/src/Ticker.java new file mode 100644 index 0000000..ec0c82f --- /dev/null +++ b/源代码/client/src/Ticker.java @@ -0,0 +1,75 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.PrintStream; + +public class Ticker implements Runnable{ + ActionListener al; + private boolean isTicking; + Thread t; + int delay; + public Ticker(int i, ActionListener actionlistener){ + al = actionlistener; + delay = i; + t = new Thread(this); + t.start(); + isTicking = false; + } + + public Ticker(int i){ + delay = i; + t = new Thread(this); + t.start(); + isTicking = false; + } + + public void addActionListener(ActionListener actionlistener){ + if(al == null) + al = actionlistener; + else + System.out.println("WARNING: ActionListener already added to Ticker."); + } + + public boolean isRunning(){ + return isTicking; + } + + public void start(){ + isTicking = true; + } + + public void stop(){ + isTicking = false; + } + + public void setDelay(int i){ + delay = i; + } + + public int getDelay(){ + return delay; + } + + private void fireActionPerformed(){ + if(al == null || !isTicking) + { + return; + } else{ + ActionEvent actionevent = new ActionEvent(this, 0, null); + al.actionPerformed(actionevent); + return; + } + } + + public void run(){ + do{ + fireActionPerformed(); + try{ + Thread.sleep(delay); + } + catch(InterruptedException interruptedexception){ + System.out.println("WARNING: Ticker thread interrupted."); + } + } while(true); + } +} + diff --git a/源代码/client/src/bomb.java b/源代码/client/src/bomb.java new file mode 100644 index 0000000..d628e33 --- /dev/null +++ b/源代码/client/src/bomb.java @@ -0,0 +1,40 @@ +import java.awt.*; + +public class bomb implements Actor{ + public int xPos, yPos; + public ClientModel gameModel; + public int size; + public int inner, middle, outer; + + public bomb(int a, int b, int size, ClientModel gameModel){ + this.size = size; + this.gameModel = gameModel; + xPos = a; + yPos = b; + + if(size == 0 ){ + inner = 6; middle = 9; outer = 14; + }else if(size == 1){ + inner = 2; middle = 4; outer = 7; + } + } + + public void draw(Graphics g){ + g.setColor(Color.red); + g.fillOval(xPos-outer, yPos-outer, 2*outer, 2*outer); + g.setColor(Color.orange); + g.fillOval(xPos-middle, yPos-middle, 2*middle, 2*middle); + g.setColor(Color.yellow); + g.fillOval(xPos-inner, yPos-inner, 2*inner, 2*inner); + + gameModel.removeActor(this); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } +} \ No newline at end of file diff --git a/源代码/client/src/bullet.java b/源代码/client/src/bullet.java new file mode 100644 index 0000000..c60047e --- /dev/null +++ b/源代码/client/src/bullet.java @@ -0,0 +1,38 @@ +import java.awt.*; + +public class bullet implements Actor{ + public int xPos; + public int yPos; + public ClientModel gameModel; + public int direction; + public String Type = "bullet"; + + public bullet(int xPos, int yPos, ClientModel gameModel, int direction){ + this.xPos = xPos; + this.yPos = yPos; + this.gameModel = gameModel; + this.direction = direction; + } + + public void draw(Graphics g){ + g.setColor(Color.lightGray); + if(direction == 0 || direction == 1) + g.fillRect(xPos - 1,yPos - 4, 3, 9); + if(direction == 2 || direction == 3) + g.fillRect(xPos - 4, yPos - 1, 9, 3); + gameModel.removeActor(this); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return Type; + } +} + diff --git a/源代码/client/src/drawingPanel.java b/源代码/client/src/drawingPanel.java new file mode 100644 index 0000000..8085e26 --- /dev/null +++ b/源代码/client/src/drawingPanel.java @@ -0,0 +1,105 @@ +import java.awt.*; +import javax.swing.*; + +//绘图面板类属于客户端程序 +public class drawingPanel extends JPanel{ + public Image offScreenImage; + + public String[] messageQueue; + public Actor[] drawingList; + public boolean gameStarted; + public int green, red, blue; + public int P1Life, P2Life, P1Score, P2Score, EnemyLeft, LevelIndex; + public Image P1Image, P2Image; + + public drawingPanel() { + P1Image = Toolkit.getDefaultToolkit().getImage("image\\" + 55 + ".jpg"); + P2Image = Toolkit.getDefaultToolkit().getImage("image\\" + 73 + ".jpg"); + } + + + + public void paintComponent(Graphics g) { + Graphics offScreenGraphics; + if (offScreenImage == null) { + offScreenImage = createImage(640, 550); + } + offScreenGraphics = offScreenImage.getGraphics(); + myPaint(offScreenGraphics); + g.drawImage(offScreenImage, 0, 0, this); + } + + public void myPaint(Graphics g) { + super.paintComponent(g); + + if(gameStarted){ + //画游戏信息 + g.setColor(new Color(81,111, 230)); + g.drawString("第 " + LevelIndex + " 关", 527, 39); + g.drawString("敌人数 = " + EnemyLeft, 527, 79); + + g.setColor(Color.yellow); + g.drawImage(P1Image, 520, 380, null ); + g.drawString("x", 555, 395); + g.drawString(P1Life + "", 565, 396); + String SCORE = "000000000" + P1Score; + g.drawString("P1" +" 得分:" + "", 515, 370); + g.drawString(SCORE.substring(SCORE.length() - 7, SCORE.length()) + "", 566, 370); + + g.setColor(Color.green); + g.drawImage(P2Image, 520, 460, null ); + g.drawString("x", 555, 475); + g.drawString(P2Life + "", 565, 476); + SCORE = "000000000" + P2Score; + g.drawString("P2" +" 得分:" + "", 515, 450); + g.drawString(SCORE.substring(SCORE.length() - 7, SCORE.length()) + "", 566, 450); + + + + //绘制背景 + g.setColor(Color.blue); + g.drawRect(10, 10, 501, 501); + + //绘制坦克等等 + if(drawingList != null) + for(int i = 0; i < drawingList.length; i++) + if(drawingList[i] != null) + drawingList[i].draw(g); + + //绘制获胜场景 + if(level.winningCount > 150){ + int temp = level.winningCount - 150; + if(temp*10 > 300) + temp = 30; + if(level.winningCount > 470) + temp = 500 - level.winningCount; + g.setColor(Color.gray); + g.fillRect(11,11, 500, temp*10); + g.fillRect(11, 500 - temp*10, 500, (1+temp)*10 + 2); + + if(level.winningCount > 190 &&level.winningCount < 470){ + if(level.winningCount > 400 ){ + red+=(int)((128-red)*0.2); + green+=(int)((128-green)*0.2); + } + g.setColor(new Color(red, green, blue)); + g.drawString("过 关 了 !", 240, 250); + } + }else{ + green = 23; red = 34; blue = 128; + } + } + + //消息 + g.setColor(new Color(255, 255, 255)); + if(messageQueue != null){ + for(int i = 0 ; i < 8; i++){ + if(messageQueue[i] != null) + g.drawString(messageQueue[i] , 5, 12 +i*16); + else + break; + } + } + + } +} \ No newline at end of file diff --git a/源代码/client/src/instructionHandler.java b/源代码/client/src/instructionHandler.java new file mode 100644 index 0000000..4332702 --- /dev/null +++ b/源代码/client/src/instructionHandler.java @@ -0,0 +1,352 @@ +//该类从服务器程序解码指令字符串,然后将字符串转换为真正的指令 + +//由客户端程序可读 +public class instructionHandler{ + public static void handleInstruction(ClientModel gameModel, String instruction){ + if(instruction.length() == 0) + return; + + int i = 0; + while(i < instruction.length()){ + String perInstruction = ""; + + //指令由”;“开头在instruction-string分离 + while(!instruction.substring(i, i+1).equals(";")){ + perInstruction+=instruction.substring(i, i+1); + i++; + } + + //指令“L”开头是负载水平,其次是“L”数量水平指数 + if(perInstruction.substring(0,1).equals("L")){ + level.loadLevel(gameModel, Integer.parseInt(perInstruction.substring(1,2))); + return; + } + + //指令“w”开头意味着一些事情改变了在墙上的对象 + if(perInstruction.substring(0,1).equals("w")){ + int xPos = 0; int yPos = 0; boolean[] shape = new boolean[16]; + String temp = ""; + int j = 1; + //得到x的位置 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y的位置 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + yPos = Integer.parseInt(temp); + + //墙的详细的边界 + for(int k = 0; k < 16; k++){ + if(perInstruction. substring(j, j+1).equals("1")) + shape[k] = true; + else + shape[k] = false; + j++; + } + + //执行指令 + for(int k = 0; k < gameModel.drawingList.length; k++){ + if(gameModel.drawingList[k] != null){ + if(gameModel.drawingList[k].getxPos() == xPos && gameModel.drawingList[k].getyPos() == yPos){ + wall tempWall = new wall(xPos, yPos, 4, gameModel); + tempWall.shape = shape; + gameModel.drawingList[k] = tempWall; + } + } + } + } + + //指令“s”开头意味着一些事情改变了一个铁墙对象 + if(perInstruction.substring(0,1).equals("s")){ + int xPos = 0; int yPos = 0; boolean[] shape = new boolean[4]; + String temp = ""; + int j = 1; + //得到x的位置 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y的位置 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + yPos = Integer.parseInt(temp); + + //详细的钢墙边境 + for(int k = 0; k < 4; k++){ + if(perInstruction. substring(j, j+1).equals("1")) + shape[k] = true; + else + shape[k] = false; + j++; + } + + //执行指令 + for(int k = 0; k < gameModel.drawingList.length; k++){ + if(gameModel.drawingList[k] != null){ + if(gameModel.drawingList[k].getxPos() == xPos && gameModel.drawingList[k].getyPos() == yPos){ + Steelwall tempWall = new Steelwall(xPos, yPos, 4, gameModel); + tempWall.shape = shape; + gameModel.drawingList[k] = tempWall; + } + } + } + } + + //指令“b”开头意味着基地已被摧毁 + if(perInstruction.substring(0,1).equals("b")){ + gameModel.drawingList[4] = new normalObject(260, 498, gameModel, "base", 1); + } + + //指令“n”开头显示正常的对象,如坦克、启动符号 + if(perInstruction.substring(0,1).equals("n")){ + int xPos = 0; int yPos = 0; int textureIndex = -1; + String temp = ""; + int j = 1; + //得到x对象的位置 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y对象的位置 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + yPos = Integer.parseInt(temp); + + //获得对象的纹理指数 + temp = ""; + while(j < perInstruction.length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + textureIndex = Integer.parseInt(temp); + + //执行指令 + gameModel.addActor(new normalObject(xPos, yPos, gameModel, "normal", textureIndex)); + } + + + //指令“t”开头表明子弹 + if(perInstruction.substring(0,1).equals("t")){ + int xPos = 0; int yPos = 0; int direction = -1; + String temp = ""; + int j = 1; + //得到x子弹的位置 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y子弹的位置 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + yPos = Integer.parseInt(temp); + + //子弹的方向 + temp = ""; + while(j < perInstruction.length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + direction = Integer.parseInt(temp); + + //执行指令 + gameModel.addActor(new bullet(xPos, yPos, gameModel, direction)); + } + + //指令“o”开头表示一个炸弹 + if(perInstruction.substring(0,1).equals("o")){ + int xPos = 0; int yPos = 0; int size = -1; + String temp = ""; + int j = 1; + //得到x炸弹的位置 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y炸弹的位置 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + yPos = Integer.parseInt(temp); + + //炸弹的大小 + temp = ""; + while(j < perInstruction.length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + if(temp.equals("small")) + size = 1; + else + size = 0; + //执行指令 + gameModel.addActor(new bomb(xPos, yPos, size, gameModel)); + } + + //指令“i”开头表明坦克盾牌 + if(perInstruction.substring(0,1).equals("i")){ + int xPos = 0; int yPos = 0; + String temp = ""; + int j = 1; + //得到x位置的盾牌 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + xPos = Integer.parseInt(temp); + + //得到y位置的盾牌 + temp = ""; + while(j < perInstruction. length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + yPos = Integer.parseInt(temp); + + //执行指令 + gameModel.addActor(new shield(xPos, yPos, gameModel)); + } + + //指令“p”开头表示水平和玩家信息 + if(perInstruction.substring(0,1).equals("p")){ + String temp = ""; + int j = 1; + //得到敌人离开的数量 + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.EnemyLeft = Integer.parseInt(temp); + + //得到水平指数 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.LevelIndex = Integer.parseInt(temp); + + //玩家1的生命量 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.P1Life = Integer.parseInt(temp); + + //玩家1的分数 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.P1Score = Integer.parseInt(temp); + + //玩家2的生命量 + temp = ""; + while(!perInstruction. substring(j, j+1).equals(",")){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.P2Life = Integer.parseInt(temp); + + //玩家2的分数 + temp = ""; + while(j < perInstruction.length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + j++; + gameModel.view.mainPanel.P2Score = Integer.parseInt(temp); + } + + //指令“g”开头表明获取胜利的统计数量 + if(perInstruction.substring(0,1).equals("g")){ + String temp = ""; + int j = 1; + //得到敌人离开的数量 + while(j < perInstruction.length()){ + temp+=perInstruction. substring(j, j+1); + j++; + } + level.winningCount = Integer.parseInt(temp); + } + + //指令“m”开头表示服务器玩家的信息 + if(perInstruction.substring(0,1).equals("m")){ + gameModel.addMessage("主机端玩家说:" + perInstruction.substring(1,perInstruction.length())); + } + + //指令“a”开头表示游戏结束 + if(perInstruction.substring(0,1).equals("a")){ + if(!gameModel.gameOver){ + gameModel.addMessage("GAME OVER !  想再玩一次吗 ( y / n ) ?"); + gameModel.gameOver = true; + } + } + //指令“j”开头表示服务器玩家想在玩一次 + if(perInstruction.substring(0,1).equals("j")){ + if(gameModel.gameOver) + gameModel.serverVoteYes = true; + } + + //指令“x”开头表示服务器玩家暂停游戏 + if(perInstruction.substring(0,1).equals("x")){ + int temp = Integer.parseInt(perInstruction.substring(1,2)); + if(temp == 0){ + if(gameModel.gamePaused){ + gameModel.addMessage("主机端玩家取消了暂停"); + gameModel.gamePaused = false; + } + }else{ + if(!gameModel.gamePaused){ + gameModel.addMessage("主机端玩家暂停了游戏"); + gameModel.gamePaused = true; + } + } + } + i++; + } + } +} \ No newline at end of file diff --git a/源代码/client/src/level.java b/源代码/client/src/level.java new file mode 100644 index 0000000..429a0c1 --- /dev/null +++ b/源代码/client/src/level.java @@ -0,0 +1,266 @@ +import java.awt.*; + +//服务器端的level类 +//因为只有一层对象,所以在这个类是一个静态变量 + +public class level{ + public static int winningCount; + + public static void loadLevel(ClientModel gameModel, int levelIndex){ + //清除所有的东西 + for(int i = 0; i < 400; i ++) + gameModel.drawingList[i] = null; + + //加载基地 + gameModel.drawingList[0] = new wall(248, 498, 2, gameModel); + gameModel.drawingList[1] = new wall(273, 498, 3, gameModel); + gameModel.drawingList[2] = new wall(248, 473, 1, gameModel); + gameModel.drawingList[3] = new wall(273, 473, 1, gameModel); + gameModel.drawingList[4] = new normalObject(260, 498, gameModel, "base", 0); + + //加载一个级别 + if(1+ (levelIndex-1)%8 == 1){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "ss", "ss", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "s0", "##", "##", "__", "__", "__", "__", "__", "##", "s0", "s0", "##", "__", "__", "__", "__", "__", "##", "##", "s0", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 2){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "$$", "==", "==", "==", "==", "==", "==", "==", "$$", "$$", "==", "==", "==", "==", "==", "==", "==", "==", "==", "$$", + "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "ss", "##", "##", "##", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "ss", "##", "##", "##", "__", "__", "ss", "ss", "##", "##", "##", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 3){ + String[] level = new String[]{ + "__", "__", "__", "ss", "__", "__", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "s3", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "##", "##", "##", "__", "##", "##", "##", "##", "__", "s3", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "s3", "__", "__", "__", + "__", "__", "ss", "ss", "__", "##", "##", "##", "##", "__", "__", "##", "##", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "ss", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "__", "##", "s1", + "__", "__", "__", "ss", "__", "##", "__", "ss", "##", "ss", "##", "ss", "##", "##", "##", "##", "##", "__", "__", "##", + "__", "__", "__", "ss", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "__", "__", "__", "ss", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "__", "__", "__", "##", "ss", "ss", "ss", "ss", "##", "##", "##", "##", "##", "$$", "$$", "$$", "$$", "##", "##", "##", + "##", "__", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "##", "##", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "##", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", "##", "##", "##", "##", "__", "__", "__", + "##", "##", "##", "##", "##", "##", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", + "##", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", + "#0", "s0", "s0", "s0", "$$", "ss", "ss", "ss", "ss", "##", "ss", "ss", "$$", "ss", "ss", "##", "##", "##", "ss", "##", + "__", "__", "__", "##", "__", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", + "__", "__", "__", "##", "__", "__", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 4){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "ss", "##", "##", "##", "##", "__", "__", "__", + "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "ss", "ss", "s2", "__", "__", + "__", "__", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$","$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "__", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "##", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "##", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "$$", "$$", "$$", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$", "##", "s2", "__", "__", + "__", "__", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "##", "__", "__", + "__", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "s3", "s2", "$$", "$$", "$$", "$$", "##", "##", "s0", "s0", "s0", + "__", "__", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", "##", "__", "__", "__", "__", + "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 5){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "==", "==", "==", "__", "__", "==", "==", "==", "==", "==", "==", "__", "==", "==", "==", "==", "==", "==", "__", + "__", "==", "ss", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "==", "__", "==", "==", "__", "ss", "==", "==", "==", "==", "__", "==", "__", + "__", "==", "__", "==", "==", "==", "==", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", + "__", "==", "__", "==", "__", "__", "__", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", + "__", "==", "__", "==", "__", "__", "==", "==", "==", "==", "__", "__", "==", "__", "__", "==", "__", "==", "==", "__", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "__", "__", "__", "==", "ss", "__", "__", "__", "==", "__", "__", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "==", "__", "==", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "==", "__", "__", + "__", "==", "__", "==", "__", "==", "==", "__", "__", "==", "__", "__", "==", "__", "==", "==", "__", "==", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "__", "__", "==", "__", "__", "==", "__", "==", "__", "__", "__", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", "==", "==", "==", "__", "__", "__", + "__", "==", "==", "==", "__", "==", "==", "==", "__", "ss", "ss", "==", "==", "__", "__", "__", "==", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "==", "__", "ss", "__", "==", "__", "==", "__", + "==", "==", "==", "==", "==", "__", "==", "__", "__", "__", "__", "__", "==", "__", "__", "__", "==", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "==", "==", "==", "__", "==", "==", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 6){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "$$", "__", "__", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "__", "$$", "__", + "__", "__", "$$", "ss", "$$", "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", "$$", "ss", "$$", + "__", "$$", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "ss", "$$", + "__", "$$", "ss", "ss", "ss", "$$", "ss", "ss", "ss", "$$", "$$", "$$", "$$", "__", "__", "__", "$$", "ss", "ss", "$$", + "__", "$$", "ss", "ss", "ss", "$$", "$$", "ss", "$$", "$$", "ss", "ss", "ss", "$$", "__", "__", "$$", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "$$", "$$", "ss", "ss", "ss", "$$", "__", "__", "$$", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "__", "$$", "$$", "ss", "$$", "$$", "__", "__", "$$", "ss", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "$$", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "__", "__", "ss", "ss", "$$", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "$$", "ss", "ss", "ss", "$$", "$$", "ss", "$$", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "$$", "ss", "ss", "ss", "$$", "__", "$$", "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", "$$", "$$", "$$", "$$", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "$$", "__", + "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "ss", "$$", "$$", "__", "__", + "__", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "$$", "$$", "$$", "$$", "__", "__", "__", "__" + + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 7){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (levelIndex-1)%8 == 8){ + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "##", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "##", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "##", "##", "##", "__", "##", "__", "__", "__", "##", "__", "__", "##", "##", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "##", "__", "__", "__", "##", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "##", "__", "##", "__", "##", "__", "__", "##", "__", "__", "__", "##", "__", "__", "__", "##", "__", "__", "##", "__", + "__", "##", "__", "__", "__", "##", "##", "__", "##", "__", "__", "##", "__", "__", "__", "__", "##", "##", "__", "##", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + } + public static void loadLevel(ClientModel gameModel, String[] level){ + for(int i = 0; i < level.length; i++){ + if(level[i].equals("##")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 4,gameModel)); + if(level[i].equals("#0")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 0, gameModel)); + if(level[i].equals("#1")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 1, gameModel)); + if(level[i].equals("#2")) + gameModel.addActor(new wall(23 + (i%19)*25, 23 + (i/20)*25, 2, gameModel)); + if(level[i].equals("#3")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 3, gameModel)); + if(level[i].equals("ss")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 4, gameModel)); + if(level[i].equals("s0")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 0, gameModel)); + if(level[i].equals("s1")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 1, gameModel)); + if(level[i].equals("s2")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 2, gameModel)); + if(level[i].equals("s3")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 3, gameModel)); + + if(level[i].equals("$$")){ + for(int j = 399; j >=0; j--){ + if(gameModel.drawingList[j] == null){ + gameModel.drawingList[j] = new normalObject(23 + (i%20)*25, 23 + (i/20)*25, gameModel, "grass", -1); + break; + } + } + } + if(level[i].equals("==")) + gameModel.addActor(new normalObject(23 + (i%20)*25, 23 + (i/20)*25, gameModel, "river", 71)); + } + } +} \ No newline at end of file diff --git a/源代码/client/src/normalObject.java b/源代码/client/src/normalObject.java new file mode 100644 index 0000000..a0ab1e8 --- /dev/null +++ b/源代码/client/src/normalObject.java @@ -0,0 +1,50 @@ +import java.awt.*; +//这个类代表除了墙和钢墙外所有其他对象 +public class normalObject implements Actor{ + public String Type; + public Image image; + public int xPos; + public int yPos; + public ClientModel gameModel; + + public normalObject(int xPos, int yPos, ClientModel gameModel, String Type, int imageIndex){ + this.xPos = xPos; + this.yPos = yPos; + this.gameModel = gameModel; + this.Type = Type; + if(imageIndex != -1) + image = gameModel.textures[imageIndex]; + } + + public void draw(Graphics g){ + if(image != null) + g.drawImage(image, xPos - 12, yPos - 12, null); + else{ + g.setColor(new Color(0, 225, 0)); + for(int i = yPos - 11; i <= yPos + 12; i+=5) + g.drawLine(xPos - 12, i, xPos + 12, i); + for(int i = xPos - 11; i <= xPos + 12; i+=5) + g.drawLine(i, yPos - 12, i, yPos + 12); + g.setColor(new Color(0, 128, 0)); + for(int i = yPos - 10; i <= yPos + 12; i+=5) + g.drawLine(xPos - 12, i, xPos + 12, i); + for(int i = xPos - 10; i <= xPos + 12; i+=5) + g.drawLine( i, yPos - 12, i, yPos + 12); + } + + if(!Type.equals("river") && !Type.equals("grass") && !Type.equals("base")) + gameModel.removeActor(this); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return Type; + } +} \ No newline at end of file diff --git a/源代码/client/src/shield.java b/源代码/client/src/shield.java new file mode 100644 index 0000000..171b333 --- /dev/null +++ b/源代码/client/src/shield.java @@ -0,0 +1,32 @@ +import java.awt.*; +public class shield implements Actor{ + public int xPos; + public int yPos; + public ClientModel gameModel; + public String Type = "shield"; + + public shield(int xPos, int yPos, ClientModel gameModel){ + this.xPos = xPos; + this.yPos = yPos; + this.gameModel = gameModel; + } + + public void draw(Graphics g){ + g.setColor(Color.red); + g.drawRect(xPos - 12, yPos - 12, 25,25); + g.drawRect(xPos - 11, yPos - 11, 23,23); + gameModel.removeActor(this); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return Type; + } +} \ No newline at end of file diff --git a/源代码/client/src/wall.java b/源代码/client/src/wall.java new file mode 100644 index 0000000..97076ec --- /dev/null +++ b/源代码/client/src/wall.java @@ -0,0 +1,100 @@ +import java.awt.*; + +public class wall implements Actor{ + public final String Type = "wall"; + public Image wall; + public int xPos; + public int yPos; + public boolean[] shape; + public ClientModel gameModel; + + public wall(int xPos, int yPos, int orientation, ClientModel gameModel){ + this.xPos = xPos; + this.yPos = yPos; + this.gameModel = gameModel; + shape = new boolean[16]; + wall = gameModel.textures[70]; + + if(orientation == 0){ + for(int i = 8; i < 12; i ++) + shape[i] = true; + for(int i = 12; i < 16; i ++) + shape[i] = true; + } + if(orientation == 1){ + for(int i = 0; i < 4; i ++) + shape[i] = true; + for(int i = 4; i < 8; i ++) + shape[i] = true; + } + if(orientation == 2){ + for(int i = 3; i <= 15; i+=4) + shape[i] = true; + for(int i = 2; i <= 14; i+=4) + shape[i] = true; + } + if(orientation == 3){ + for(int i = 1; i <= 13; i+=4) + shape[i] = true; + for(int i = 0; i <= 12; i+=4) + shape[i] = true; + } + } + + public void draw(Graphics g){ + boolean walldestoried = true; + for(int i = 0; i < shape.length; i++) + if(!shape[i]){ + walldestoried = false; + break; + } + if(walldestoried) + return; + g.drawImage(wall, xPos - 12, yPos - 12, null); + g.setColor(new Color(128, 64, 0)); + if(shape[0]) + g.fillRect(xPos - 12, yPos - 12, 7, 7); + if(shape[1]) + g.fillRect(xPos - 6, yPos - 12, 7, 7); + if(shape[2]) + g.fillRect(xPos, yPos - 12, 7, 7); + if(shape[3]) + g.fillRect(xPos + 6, yPos - 12, 7, 7); + if(shape[4]) + g.fillRect(xPos - 12, yPos - 6, 7, 7); + if(shape[5]) + g.fillRect(xPos - 6, yPos - 6, 7, 7); + if(shape[6]) + g.fillRect(xPos, yPos - 6, 7, 7); + if(shape[7]) + g.fillRect(xPos + 6, yPos - 6, 7, 7); + if(shape[8]) + g.fillRect(xPos - 12, yPos, 7, 7); + if(shape[9]) + g.fillRect(xPos - 6, yPos, 7, 7); + if(shape[10]) + g.fillRect(xPos, yPos, 7, 7); + if(shape[11]) + g.fillRect(xPos + 6, yPos, 7, 7); + if(shape[12]) + g.fillRect(xPos - 12, yPos + 6, 7, 7); + if(shape[13]) + g.fillRect(xPos - 6, yPos + 6, 7, 7); + if(shape[14]) + g.fillRect(xPos, yPos + 6, 7, 7); + if(shape[15]) + g.fillRect(xPos + 6, yPos + 6, 7, 7); + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return Type; + } +} \ No newline at end of file diff --git a/源代码/server/.settings/org.eclipse.jdt.core.prefs b/源代码/server/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/源代码/server/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/源代码/server/bin/Actor.class b/源代码/server/bin/Actor.class new file mode 100644 index 0000000..740d713 Binary files /dev/null and b/源代码/server/bin/Actor.class differ diff --git a/源代码/server/bin/ServerControler$1.class b/源代码/server/bin/ServerControler$1.class new file mode 100644 index 0000000..81b064e Binary files /dev/null and b/源代码/server/bin/ServerControler$1.class differ diff --git a/源代码/server/bin/ServerControler$2.class b/源代码/server/bin/ServerControler$2.class new file mode 100644 index 0000000..35ea345 Binary files /dev/null and b/源代码/server/bin/ServerControler$2.class differ diff --git a/源代码/server/bin/ServerControler$3.class b/源代码/server/bin/ServerControler$3.class new file mode 100644 index 0000000..9255b0c Binary files /dev/null and b/源代码/server/bin/ServerControler$3.class differ diff --git a/源代码/server/bin/ServerControler$4.class b/源代码/server/bin/ServerControler$4.class new file mode 100644 index 0000000..18b6e9f Binary files /dev/null and b/源代码/server/bin/ServerControler$4.class differ diff --git a/源代码/server/bin/ServerControler$5.class b/源代码/server/bin/ServerControler$5.class new file mode 100644 index 0000000..e4accd0 Binary files /dev/null and b/源代码/server/bin/ServerControler$5.class differ diff --git a/源代码/server/bin/ServerControler$6.class b/源代码/server/bin/ServerControler$6.class new file mode 100644 index 0000000..fa52e12 Binary files /dev/null and b/源代码/server/bin/ServerControler$6.class differ diff --git a/源代码/server/bin/ServerControler$7.class b/源代码/server/bin/ServerControler$7.class new file mode 100644 index 0000000..f4a7915 Binary files /dev/null and b/源代码/server/bin/ServerControler$7.class differ diff --git a/源代码/server/bin/ServerControler.class b/源代码/server/bin/ServerControler.class new file mode 100644 index 0000000..f7ecf68 Binary files /dev/null and b/源代码/server/bin/ServerControler.class differ diff --git a/源代码/server/bin/ServerModel.class b/源代码/server/bin/ServerModel.class new file mode 100644 index 0000000..8c578e1 Binary files /dev/null and b/源代码/server/bin/ServerModel.class differ diff --git a/源代码/server/bin/ServerView.class b/源代码/server/bin/ServerView.class new file mode 100644 index 0000000..7c1cd4a Binary files /dev/null and b/源代码/server/bin/ServerView.class differ diff --git a/源代码/server/bin/Steelwall.class b/源代码/server/bin/Steelwall.class new file mode 100644 index 0000000..f2c57eb Binary files /dev/null and b/源代码/server/bin/Steelwall.class differ diff --git a/源代码/server/bin/Ticker.class b/源代码/server/bin/Ticker.class new file mode 100644 index 0000000..2199f2c Binary files /dev/null and b/源代码/server/bin/Ticker.class differ diff --git a/源代码/server/bin/base.class b/源代码/server/bin/base.class new file mode 100644 index 0000000..158156b Binary files /dev/null and b/源代码/server/bin/base.class differ diff --git a/源代码/server/bin/bomb.class b/源代码/server/bin/bomb.class new file mode 100644 index 0000000..88b426a Binary files /dev/null and b/源代码/server/bin/bomb.class differ diff --git a/源代码/server/bin/bullet.class b/源代码/server/bin/bullet.class new file mode 100644 index 0000000..bc59203 Binary files /dev/null and b/源代码/server/bin/bullet.class differ diff --git a/源代码/server/bin/drawingPanel.class b/源代码/server/bin/drawingPanel.class new file mode 100644 index 0000000..5085edb Binary files /dev/null and b/源代码/server/bin/drawingPanel.class differ diff --git a/源代码/server/bin/enemy.class b/源代码/server/bin/enemy.class new file mode 100644 index 0000000..9b817db Binary files /dev/null and b/源代码/server/bin/enemy.class differ diff --git a/源代码/server/bin/feedbackHandler.class b/源代码/server/bin/feedbackHandler.class new file mode 100644 index 0000000..71361c0 Binary files /dev/null and b/源代码/server/bin/feedbackHandler.class differ diff --git a/源代码/server/bin/grass.class b/源代码/server/bin/grass.class new file mode 100644 index 0000000..0e43cde Binary files /dev/null and b/源代码/server/bin/grass.class differ diff --git a/源代码/server/bin/level.class b/源代码/server/bin/level.class new file mode 100644 index 0000000..1be723b Binary files /dev/null and b/源代码/server/bin/level.class differ diff --git a/源代码/server/bin/player.class b/源代码/server/bin/player.class new file mode 100644 index 0000000..e714439 Binary files /dev/null and b/源代码/server/bin/player.class differ diff --git a/源代码/server/bin/powerUp.class b/源代码/server/bin/powerUp.class new file mode 100644 index 0000000..d2d417c Binary files /dev/null and b/源代码/server/bin/powerUp.class differ diff --git a/源代码/server/bin/river.class b/源代码/server/bin/river.class new file mode 100644 index 0000000..4cfd3d6 Binary files /dev/null and b/源代码/server/bin/river.class differ diff --git a/源代码/server/bin/wall.class b/源代码/server/bin/wall.class new file mode 100644 index 0000000..4631d79 Binary files /dev/null and b/源代码/server/bin/wall.class differ diff --git a/源代码/server/image/1(1).jpg b/源代码/server/image/1(1).jpg new file mode 100644 index 0000000..bb1823d Binary files /dev/null and b/源代码/server/image/1(1).jpg differ diff --git a/源代码/server/image/1.jpg b/源代码/server/image/1.jpg new file mode 100644 index 0000000..bb1823d Binary files /dev/null and b/源代码/server/image/1.jpg differ diff --git a/源代码/server/image/10.jpg b/源代码/server/image/10.jpg new file mode 100644 index 0000000..d446085 Binary files /dev/null and b/源代码/server/image/10.jpg differ diff --git a/源代码/server/image/11.jpg b/源代码/server/image/11.jpg new file mode 100644 index 0000000..4a7a633 Binary files /dev/null and b/源代码/server/image/11.jpg differ diff --git a/源代码/server/image/12.jpg b/源代码/server/image/12.jpg new file mode 100644 index 0000000..8dd249b Binary files /dev/null and b/源代码/server/image/12.jpg differ diff --git a/源代码/server/image/13.jpg b/源代码/server/image/13.jpg new file mode 100644 index 0000000..c083a29 Binary files /dev/null and b/源代码/server/image/13.jpg differ diff --git a/源代码/server/image/14.jpg b/源代码/server/image/14.jpg new file mode 100644 index 0000000..cf49905 Binary files /dev/null and b/源代码/server/image/14.jpg differ diff --git a/源代码/server/image/15.jpg b/源代码/server/image/15.jpg new file mode 100644 index 0000000..3ced3c9 Binary files /dev/null and b/源代码/server/image/15.jpg differ diff --git a/源代码/server/image/16.jpg b/源代码/server/image/16.jpg new file mode 100644 index 0000000..3823579 Binary files /dev/null and b/源代码/server/image/16.jpg differ diff --git a/源代码/server/image/17.jpg b/源代码/server/image/17.jpg new file mode 100644 index 0000000..0197944 Binary files /dev/null and b/源代码/server/image/17.jpg differ diff --git a/源代码/server/image/18.jpg b/源代码/server/image/18.jpg new file mode 100644 index 0000000..8dc02d1 Binary files /dev/null and b/源代码/server/image/18.jpg differ diff --git a/源代码/server/image/19.jpg b/源代码/server/image/19.jpg new file mode 100644 index 0000000..7b903ad Binary files /dev/null and b/源代码/server/image/19.jpg differ diff --git a/源代码/server/image/2.jpg b/源代码/server/image/2.jpg new file mode 100644 index 0000000..a837dea Binary files /dev/null and b/源代码/server/image/2.jpg differ diff --git a/源代码/server/image/20.jpg b/源代码/server/image/20.jpg new file mode 100644 index 0000000..d156fae Binary files /dev/null and b/源代码/server/image/20.jpg differ diff --git a/源代码/server/image/21.jpg b/源代码/server/image/21.jpg new file mode 100644 index 0000000..00557b3 Binary files /dev/null and b/源代码/server/image/21.jpg differ diff --git a/源代码/server/image/22.jpg b/源代码/server/image/22.jpg new file mode 100644 index 0000000..2ff4934 Binary files /dev/null and b/源代码/server/image/22.jpg differ diff --git a/源代码/server/image/23.jpg b/源代码/server/image/23.jpg new file mode 100644 index 0000000..4219feb Binary files /dev/null and b/源代码/server/image/23.jpg differ diff --git a/源代码/server/image/24.jpg b/源代码/server/image/24.jpg new file mode 100644 index 0000000..9e22490 Binary files /dev/null and b/源代码/server/image/24.jpg differ diff --git a/源代码/server/image/25.jpg b/源代码/server/image/25.jpg new file mode 100644 index 0000000..90a4f3d Binary files /dev/null and b/源代码/server/image/25.jpg differ diff --git a/源代码/server/image/26.jpg b/源代码/server/image/26.jpg new file mode 100644 index 0000000..36b5b23 Binary files /dev/null and b/源代码/server/image/26.jpg differ diff --git a/源代码/server/image/27.jpg b/源代码/server/image/27.jpg new file mode 100644 index 0000000..9d8aff5 Binary files /dev/null and b/源代码/server/image/27.jpg differ diff --git a/源代码/server/image/28.jpg b/源代码/server/image/28.jpg new file mode 100644 index 0000000..37f234a Binary files /dev/null and b/源代码/server/image/28.jpg differ diff --git a/源代码/server/image/29.jpg b/源代码/server/image/29.jpg new file mode 100644 index 0000000..c98a9bb Binary files /dev/null and b/源代码/server/image/29.jpg differ diff --git a/源代码/server/image/3.jpg b/源代码/server/image/3.jpg new file mode 100644 index 0000000..7155db4 Binary files /dev/null and b/源代码/server/image/3.jpg differ diff --git a/源代码/server/image/30.jpg b/源代码/server/image/30.jpg new file mode 100644 index 0000000..d34e9bb Binary files /dev/null and b/源代码/server/image/30.jpg differ diff --git a/源代码/server/image/31.jpg b/源代码/server/image/31.jpg new file mode 100644 index 0000000..091234d Binary files /dev/null and b/源代码/server/image/31.jpg differ diff --git a/源代码/server/image/32.jpg b/源代码/server/image/32.jpg new file mode 100644 index 0000000..f1c859a Binary files /dev/null and b/源代码/server/image/32.jpg differ diff --git a/源代码/server/image/33.jpg b/源代码/server/image/33.jpg new file mode 100644 index 0000000..72f7a8a Binary files /dev/null and b/源代码/server/image/33.jpg differ diff --git a/源代码/server/image/34.jpg b/源代码/server/image/34.jpg new file mode 100644 index 0000000..c99035d Binary files /dev/null and b/源代码/server/image/34.jpg differ diff --git a/源代码/server/image/35.jpg b/源代码/server/image/35.jpg new file mode 100644 index 0000000..60ca424 Binary files /dev/null and b/源代码/server/image/35.jpg differ diff --git a/源代码/server/image/36.jpg b/源代码/server/image/36.jpg new file mode 100644 index 0000000..1951f74 Binary files /dev/null and b/源代码/server/image/36.jpg differ diff --git a/源代码/server/image/37.jpg b/源代码/server/image/37.jpg new file mode 100644 index 0000000..9761115 Binary files /dev/null and b/源代码/server/image/37.jpg differ diff --git a/源代码/server/image/38.jpg b/源代码/server/image/38.jpg new file mode 100644 index 0000000..91f26d8 Binary files /dev/null and b/源代码/server/image/38.jpg differ diff --git a/源代码/server/image/39.jpg b/源代码/server/image/39.jpg new file mode 100644 index 0000000..0e3655f Binary files /dev/null and b/源代码/server/image/39.jpg differ diff --git a/源代码/server/image/4.jpg b/源代码/server/image/4.jpg new file mode 100644 index 0000000..efcf8d5 Binary files /dev/null and b/源代码/server/image/4.jpg differ diff --git a/源代码/server/image/40.jpg b/源代码/server/image/40.jpg new file mode 100644 index 0000000..1d8280d Binary files /dev/null and b/源代码/server/image/40.jpg differ diff --git a/源代码/server/image/41.jpg b/源代码/server/image/41.jpg new file mode 100644 index 0000000..9123956 Binary files /dev/null and b/源代码/server/image/41.jpg differ diff --git a/源代码/server/image/42.jpg b/源代码/server/image/42.jpg new file mode 100644 index 0000000..c17ea64 Binary files /dev/null and b/源代码/server/image/42.jpg differ diff --git a/源代码/server/image/43.jpg b/源代码/server/image/43.jpg new file mode 100644 index 0000000..2270b56 Binary files /dev/null and b/源代码/server/image/43.jpg differ diff --git a/源代码/server/image/44.jpg b/源代码/server/image/44.jpg new file mode 100644 index 0000000..cca4208 Binary files /dev/null and b/源代码/server/image/44.jpg differ diff --git a/源代码/server/image/45.jpg b/源代码/server/image/45.jpg new file mode 100644 index 0000000..318c507 Binary files /dev/null and b/源代码/server/image/45.jpg differ diff --git a/源代码/server/image/46.jpg b/源代码/server/image/46.jpg new file mode 100644 index 0000000..7696ac5 Binary files /dev/null and b/源代码/server/image/46.jpg differ diff --git a/源代码/server/image/47.jpg b/源代码/server/image/47.jpg new file mode 100644 index 0000000..54d9bd1 Binary files /dev/null and b/源代码/server/image/47.jpg differ diff --git a/源代码/server/image/48.jpg b/源代码/server/image/48.jpg new file mode 100644 index 0000000..c9b335d Binary files /dev/null and b/源代码/server/image/48.jpg differ diff --git a/源代码/server/image/49.jpg b/源代码/server/image/49.jpg new file mode 100644 index 0000000..a234e4f Binary files /dev/null and b/源代码/server/image/49.jpg differ diff --git a/源代码/server/image/5.jpg b/源代码/server/image/5.jpg new file mode 100644 index 0000000..cf31c44 Binary files /dev/null and b/源代码/server/image/5.jpg differ diff --git a/源代码/server/image/50.jpg b/源代码/server/image/50.jpg new file mode 100644 index 0000000..6efa721 Binary files /dev/null and b/源代码/server/image/50.jpg differ diff --git a/源代码/server/image/51.jpg b/源代码/server/image/51.jpg new file mode 100644 index 0000000..009feb9 Binary files /dev/null and b/源代码/server/image/51.jpg differ diff --git a/源代码/server/image/52.jpg b/源代码/server/image/52.jpg new file mode 100644 index 0000000..5b65e21 Binary files /dev/null and b/源代码/server/image/52.jpg differ diff --git a/源代码/server/image/53.jpg b/源代码/server/image/53.jpg new file mode 100644 index 0000000..084a2a5 Binary files /dev/null and b/源代码/server/image/53.jpg differ diff --git a/源代码/server/image/54.jpg b/源代码/server/image/54.jpg new file mode 100644 index 0000000..3acee9f Binary files /dev/null and b/源代码/server/image/54.jpg differ diff --git a/源代码/server/image/55.jpg b/源代码/server/image/55.jpg new file mode 100644 index 0000000..67e2259 Binary files /dev/null and b/源代码/server/image/55.jpg differ diff --git a/源代码/server/image/56.jpg b/源代码/server/image/56.jpg new file mode 100644 index 0000000..6f4b02c Binary files /dev/null and b/源代码/server/image/56.jpg differ diff --git a/源代码/server/image/57.jpg b/源代码/server/image/57.jpg new file mode 100644 index 0000000..a336d53 Binary files /dev/null and b/源代码/server/image/57.jpg differ diff --git a/源代码/server/image/58.jpg b/源代码/server/image/58.jpg new file mode 100644 index 0000000..d2916f4 Binary files /dev/null and b/源代码/server/image/58.jpg differ diff --git a/源代码/server/image/59.jpg b/源代码/server/image/59.jpg new file mode 100644 index 0000000..ba972df Binary files /dev/null and b/源代码/server/image/59.jpg differ diff --git a/源代码/server/image/6.jpg b/源代码/server/image/6.jpg new file mode 100644 index 0000000..34ec3cd Binary files /dev/null and b/源代码/server/image/6.jpg differ diff --git a/源代码/server/image/60.jpg b/源代码/server/image/60.jpg new file mode 100644 index 0000000..6f6ffb6 Binary files /dev/null and b/源代码/server/image/60.jpg differ diff --git a/源代码/server/image/61.jpg b/源代码/server/image/61.jpg new file mode 100644 index 0000000..ef20698 Binary files /dev/null and b/源代码/server/image/61.jpg differ diff --git a/源代码/server/image/62.jpg b/源代码/server/image/62.jpg new file mode 100644 index 0000000..46908fc Binary files /dev/null and b/源代码/server/image/62.jpg differ diff --git a/源代码/server/image/63.jpg b/源代码/server/image/63.jpg new file mode 100644 index 0000000..7264d23 Binary files /dev/null and b/源代码/server/image/63.jpg differ diff --git a/源代码/server/image/64.jpg b/源代码/server/image/64.jpg new file mode 100644 index 0000000..09ca67b Binary files /dev/null and b/源代码/server/image/64.jpg differ diff --git a/源代码/server/image/65.jpg b/源代码/server/image/65.jpg new file mode 100644 index 0000000..3abeb62 Binary files /dev/null and b/源代码/server/image/65.jpg differ diff --git a/源代码/server/image/66.jpg b/源代码/server/image/66.jpg new file mode 100644 index 0000000..ea9d8c9 Binary files /dev/null and b/源代码/server/image/66.jpg differ diff --git a/源代码/server/image/67.jpg b/源代码/server/image/67.jpg new file mode 100644 index 0000000..0c63b54 Binary files /dev/null and b/源代码/server/image/67.jpg differ diff --git a/源代码/server/image/68.jpg b/源代码/server/image/68.jpg new file mode 100644 index 0000000..d3de2a4 Binary files /dev/null and b/源代码/server/image/68.jpg differ diff --git a/源代码/server/image/69.jpg b/源代码/server/image/69.jpg new file mode 100644 index 0000000..25d19f7 Binary files /dev/null and b/源代码/server/image/69.jpg differ diff --git a/源代码/server/image/7.jpg b/源代码/server/image/7.jpg new file mode 100644 index 0000000..d107ff1 Binary files /dev/null and b/源代码/server/image/7.jpg differ diff --git a/源代码/server/image/70.jpg b/源代码/server/image/70.jpg new file mode 100644 index 0000000..7d6190c Binary files /dev/null and b/源代码/server/image/70.jpg differ diff --git a/源代码/server/image/71.jpg b/源代码/server/image/71.jpg new file mode 100644 index 0000000..641240c Binary files /dev/null and b/源代码/server/image/71.jpg differ diff --git a/源代码/server/image/72.jpg b/源代码/server/image/72.jpg new file mode 100644 index 0000000..96edb91 Binary files /dev/null and b/源代码/server/image/72.jpg differ diff --git a/源代码/server/image/73.JPG b/源代码/server/image/73.JPG new file mode 100644 index 0000000..63ccfcb Binary files /dev/null and b/源代码/server/image/73.JPG differ diff --git a/源代码/server/image/74.JPG b/源代码/server/image/74.JPG new file mode 100644 index 0000000..159afe3 Binary files /dev/null and b/源代码/server/image/74.JPG differ diff --git a/源代码/server/image/75.JPG b/源代码/server/image/75.JPG new file mode 100644 index 0000000..25f2f57 Binary files /dev/null and b/源代码/server/image/75.JPG differ diff --git a/源代码/server/image/76.JPG b/源代码/server/image/76.JPG new file mode 100644 index 0000000..876b883 Binary files /dev/null and b/源代码/server/image/76.JPG differ diff --git a/源代码/server/image/77.JPG b/源代码/server/image/77.JPG new file mode 100644 index 0000000..9904e4c Binary files /dev/null and b/源代码/server/image/77.JPG differ diff --git a/源代码/server/image/78.JPG b/源代码/server/image/78.JPG new file mode 100644 index 0000000..8eb3102 Binary files /dev/null and b/源代码/server/image/78.JPG differ diff --git a/源代码/server/image/79.JPG b/源代码/server/image/79.JPG new file mode 100644 index 0000000..8c7b06d Binary files /dev/null and b/源代码/server/image/79.JPG differ diff --git a/源代码/server/image/8.jpg b/源代码/server/image/8.jpg new file mode 100644 index 0000000..e9be67b Binary files /dev/null and b/源代码/server/image/8.jpg differ diff --git a/源代码/server/image/80.JPG b/源代码/server/image/80.JPG new file mode 100644 index 0000000..5f0655e Binary files /dev/null and b/源代码/server/image/80.JPG differ diff --git a/源代码/server/image/81.JPG b/源代码/server/image/81.JPG new file mode 100644 index 0000000..fc4d646 Binary files /dev/null and b/源代码/server/image/81.JPG differ diff --git a/源代码/server/image/82.JPG b/源代码/server/image/82.JPG new file mode 100644 index 0000000..f03255c Binary files /dev/null and b/源代码/server/image/82.JPG differ diff --git a/源代码/server/image/83.JPG b/源代码/server/image/83.JPG new file mode 100644 index 0000000..ffbee39 Binary files /dev/null and b/源代码/server/image/83.JPG differ diff --git a/源代码/server/image/84.JPG b/源代码/server/image/84.JPG new file mode 100644 index 0000000..8a9860b Binary files /dev/null and b/源代码/server/image/84.JPG differ diff --git a/源代码/server/image/85.JPG b/源代码/server/image/85.JPG new file mode 100644 index 0000000..1f23308 Binary files /dev/null and b/源代码/server/image/85.JPG differ diff --git a/源代码/server/image/86.JPG b/源代码/server/image/86.JPG new file mode 100644 index 0000000..f6c472e Binary files /dev/null and b/源代码/server/image/86.JPG differ diff --git a/源代码/server/image/87.JPG b/源代码/server/image/87.JPG new file mode 100644 index 0000000..f13e29f Binary files /dev/null and b/源代码/server/image/87.JPG differ diff --git a/源代码/server/image/88.JPG b/源代码/server/image/88.JPG new file mode 100644 index 0000000..2780490 Binary files /dev/null and b/源代码/server/image/88.JPG differ diff --git a/源代码/server/image/9.jpg b/源代码/server/image/9.jpg new file mode 100644 index 0000000..6d79128 Binary files /dev/null and b/源代码/server/image/9.jpg differ diff --git a/源代码/server/image/Thumbs.db b/源代码/server/image/Thumbs.db new file mode 100644 index 0000000..b1b2db9 Binary files /dev/null and b/源代码/server/image/Thumbs.db differ diff --git a/源代码/server/src/Actor.java b/源代码/server/src/Actor.java new file mode 100644 index 0000000..9b47c54 --- /dev/null +++ b/源代码/server/src/Actor.java @@ -0,0 +1,11 @@ +//创建接口 +import java.awt.*; + +public interface Actor{ + public void draw(Graphics g); + public void move(); + public String getType(); + public Rectangle getBorder(); + public Rectangle[] getDetailedBorder(); + public boolean walldestoried(); +} \ No newline at end of file diff --git a/源代码/server/src/ServerControler.java b/源代码/server/src/ServerControler.java new file mode 100644 index 0000000..84b05f8 --- /dev/null +++ b/源代码/server/src/ServerControler.java @@ -0,0 +1,169 @@ +import javax.swing.*; +import java.awt.event.*; + +//这个类处理来自服务器视图的输入 +public class ServerControler{ + public ServerView view; + public ServerModel model; + public int helpMessageCount = 1; + + //一个玩家坦克的参考 + + public ServerControler(ServerView thisview, ServerModel thismodel){ + view = thisview; + model = thismodel; + + //操作发送消息按钮的动作 + view.sendMessage.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + if(!model.gameStarted){ + model.addMessage("还没有和别的玩家联上, 无法发送对话"); + return; + } + + if(!view.messageField.getText().equals("")){ + model.addMessage("主机端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "m" + view.messageField.getText() + ";"; + view.messageField.setText(""); + }else{ + model.addMessage("对话内容不能为空"); + } + } + } + ); + + //操作建立主机按钮的动作 + view.createServer.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + if(!model.serverCreated) + model.t.start(); + } + } + ); + + //操作暂停/继续按钮的动作 + view.pauseAndResume.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + model.pausePressed = true;; + if(!model.gameOver && model.gameStarted){ + if(!model.gamePaused){ + model.gamePaused = true; + model.addMessage("主机端玩家暂停了游戏"); + }else{ + model.gamePaused = false; + model.addMessage("主机端玩家取消了暂停"); + } + } + } + } + ); + + //操作帮助按钮的动作 + view.help.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + model.addMessage("-------------------------------坦克大战 1.0-----------------------------------"); + model.addMessage("帮助: 按 s 键开火, 按键盘的方向键来控制坦克的移动"); + model.addMessage("如果按键没有反应请 1. 关闭大写功能; 2. 用 tab键切换 "); + model.addMessage("到控制界面如果您在使用对话界面."); + model.addMessage("--------------------------------------------------------------------------------------"); + } + } + ); + + //操作退出按钮的动作 + view.exit.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + } + ); + + //操作输入按钮的动作 + view.messageField.addKeyListener( new KeyAdapter(){ + public void keyPressed(KeyEvent e){ + if(helpMessageCount > 0){ + model.addMessage("提示:用\"tab\"键可以自由切换于控制界面和对话界面"); + model.addMessage("提示:按回车键可以直接发送您的对话"); + helpMessageCount--; + } + + if(e.getKeyCode()==e.VK_ENTER){ + if(!view.messageField.getText().equals("")){ + model.addMessage("主机端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "m" + view.messageField.getText() + ";"; + view.messageField.setText(""); + }else{ + model.addMessage("对话内容不能为空"); + } + } + } + }); + + JPanel temp = view.mainPanel; + temp.addKeyListener( new KeyAdapter(){ + public void keyPressed(KeyEvent e){ + if(model.P1 != null){ + if(e.getKeyCode() == KeyEvent.VK_UP){ + model.P1.moveUp = true; + model.P1.moveDown = false; + model.P1.moveLeft = false; + model.P1.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_DOWN ){ + model.P1.moveDown = true; + model.P1.moveUp = false; + model.P1.moveLeft = false; + model.P1.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_LEFT ){ + model.P1.moveLeft = true; + model.P1.moveUp = false; + model.P1.moveDown = false; + model.P1.moveRight = false; + } + if(e.getKeyCode() == KeyEvent.VK_RIGHT ){ + model.P1.moveLeft = false; + model.P1.moveUp = false; + model.P1.moveDown = false; + model.P1.moveRight = true; + } + if(e.getKeyChar() == 's') + model.P1.fire = true; + + if(e.getKeyCode()==e.VK_ENTER){ + if(!view.messageField.getText().equals("")){ + model.addMessage("主机端玩家说:" + view.messageField.getText()); + model.playerTypedMessage += "m" + view.messageField.getText() + ";"; + view.messageField.setText(""); + } + } + + if(e.getKeyChar() == 'y' && model.gameOver && !model.serverVoteYes){ + model.serverVoteYes = true; + model.addMessage("等待用户端玩家的回应..."); + } + + if(e.getKeyChar() == 'n' && model.gameOver) + model.serverVoteNo = true; + } + } + + public void keyReleased(KeyEvent e){ + if(model.P1 != null){ + if(e.getKeyCode() == KeyEvent.VK_UP) + model.P1.moveUp = false; + if(e.getKeyCode() == KeyEvent.VK_DOWN ) + model.P1.moveDown = false; + if(e.getKeyCode() == KeyEvent.VK_LEFT ) + model.P1.moveLeft = false; + if(e.getKeyCode() == KeyEvent.VK_RIGHT ) + model.P1.moveRight = false; + if(e.getKeyChar() == 's') + model.P1.fire = false; + } + } + } + ); + + } +} \ No newline at end of file diff --git a/源代码/server/src/ServerModel.java b/源代码/server/src/ServerModel.java new file mode 100644 index 0000000..e8a9f9f --- /dev/null +++ b/源代码/server/src/ServerModel.java @@ -0,0 +1,343 @@ +import java.net.*; +import java.io.*; +import java.awt.event.*; +import java.awt.*; + +public class ServerModel implements ActionListener{ + //视图参考 + public ServerView view; + + //连接变量 + public ServerSocket serverSocket; + public Socket clientSocket; + public PrintWriter out; + public BufferedReader in; + public String inputLine, outputLine; + + //服务器状态 + public boolean serverCreated; + public boolean clientConnected; + public boolean gameStarted; + public boolean gamePaused; + public boolean gameOver; + public boolean serverVoteYes, serverVoteNo; + public boolean clientVoteYes, clientVoteNo; + public boolean pausePressed; + + //游戏消息 + public String[] messageQueue; + public int messageIndex; + public String playerTypedMessage = ""; + + //实际的游戏在这个线程上运行,而主线程监听用户的输入 + public Ticker t; + + public Image[] textures; + + //游戏变量 + public static int gameFlow; + public Actor[] actors; + public player P1; //由服务器玩家控制的坦克 + public player P2; //有客户端玩家控制的坦克 + + public ServerModel(ServerView thisview){ + + view = thisview; + messageQueue = new String[8]; + view.mainPanel.messageQueue = messageQueue; + + addMessage("欢迎来到坦克大战主机端! 请点击\"建立主机\"按钮开始游戏" ); + + t = new Ticker(1000); + t.addActionListener(this); + + } + + + public void createServer(){ + + addMessage("正在建立主机(端口9999)"); + + try { + serverSocket = new ServerSocket(9999); + serverCreated = true; + } catch (Exception e) { + addMessage("无法建立主机,请确认端口9999没有被别的程序使用"); + System.out.println(e); + t.stop(); + return; + } + + addMessage("建立完成,等待玩家连接"); + + try { + clientSocket = serverSocket.accept(); + clientConnected = true; + + out = new PrintWriter(clientSocket.getOutputStream(), true); + in = new BufferedReader(new InputStreamReader( + clientSocket.getInputStream())); + + } catch (Exception e) { + addMessage("连接中出现错误,请重新建立主机"); + serverCreated = false; + clientConnected = false; + t.stop(); + + //当发生错误,摧毁一切已创建的 + try{ + serverSocket.close(); + clientSocket.close(); + out.close(); + in.close(); + }catch(Exception ex){} + + return; + } + + view.messageField.setEnabled(true); + addMessage("玩家已连接上,开始载入游戏"); + + //一旦客户端连接,然后告诉客户端开始加载游戏 + out.println("L1;"); + + //加载游戏 + textures = new Image[88]; + for(int i = 1; i < textures.length+1; i++) + textures[i-1] = Toolkit.getDefaultToolkit().getImage("image\\" + i + ".jpg"); + + + //设置第一关 + actors = new Actor[400]; + level.loadLevel(this); + + P1 = new player("1P", this); + addActor(P1); + P2 = new player("2P", this); + addActor(P2); + + + + gameStarted = true; + view.mainPanel.actors = actors; + view.mainPanel.gameStarted = true; + + addMessage("载入完毕,游戏开始了!"); + } + + public void actionPerformed(ActionEvent e){ + createServer(); + + //如果程序未能创建服务器,则什么也不做 + if(!serverCreated) + return; + + //游戏逻辑回路, + try{ + while((inputLine = in.readLine()) != null){ + //处理客户反馈消息 + feedbackHandler.handleInstruction(this, inputLine); + + outputLine = ""; + + if(!gamePaused) + gameFlow++; + + if(pausePressed){ + if(!gamePaused){ + outputLine+= "x0;"; + }else{ + outputLine+= "x1;"; + } + pausePressed = false; + } + + if(gameOver || (P1.life == 0 && P2.life == 0)){ + if(P1.freezed != 1) + outputLine+="a;"; + + + if((P1.freezed != 1 || messageIndex == 1) && serverVoteYes){ + addMessage("等待用户端玩家的回应..."); + } + if(P1.freezed != 1 || messageIndex == 0){ + addMessage("GAME OVER !  想再玩一次吗 ( y / n ) ?"); + } + gameOver = true; + P1.freezed = 1; + P2.freezed = 1; + + if(serverVoteNo && !serverVoteYes) + System.exit(0); + + if(serverVoteYes){ + outputLine+="j;"; + if(clientVoteYes){ + addMessage("用户端玩家决定再玩一次,游戏重新开始了..."); + + //重新启动游戏 + P1 = new player("1P", this); + P2 = new player("2P", this); + level.reset(); + level.loadLevel(this); + gameOver = false; + serverVoteYes = false; + clientVoteYes = false; + serverVoteNo = false; + enemy.freezedMoment = 0; + enemy.freezedTime = 0; + gameFlow = 0; + + //告诉客户端程序重新启动游戏 + outputLine+="L1;"; + } + } + } + + if(level.deathCount == 20 && !gameOver){ + level.winningCount++; + if(level.winningCount == 120){ + P1.freezed = 1; + P2.freezed = 1; + } + if(level.winningCount == 470){ + if(P1.life > 0) + P1.reset(); + if(P2.life > 0) + P2.reset(); + level.loadLevel(this); + //告诉客户端程序加载下一关 + outputLine+="L" +(1 + (level.currentLevel-1)%8) + ";"; + } + if(level.winningCount == 500){ + P1.freezed = 0; + P2.freezed = 0; + level.deathCount = 0; + level.winningCount = 0; + } + + } + + //大量生产敌人坦克 + if(!gamePaused) + level.spawnEnemy(this); + + for(int i = 0; i < actors.length; i++){ + if(actors[i] != null) + actors[i].move(); + } + + //从消息队列中删除一个消息每10秒,(如果有的话) + if(gameFlow%300 == 0) + removeMessage(); + + //将玩家、关卡的信息写入输出行 + outputLine+="p" + level.enemyLeft + "," + level.currentLevel + "," + P1.life + "," + P1.scores + "," + P2.life + "," + P2.scores +";"; + outputLine+="g" + level.winningCount + ";"; + + //将玩家类型信息写入输出行 + if(!playerTypedMessage.equals("")){ + outputLine+=playerTypedMessage; + playerTypedMessage = ""; + } + + //将最后的指令字符串发送到客户端程序 + out.println(outputLine); + + //调用视图重绘本身 + view.mainPanel.repaint(); + + //如果玩家切换到对话框模式,则停止所有坦克动作 + if(!view.mainPanel.hasFocus()){ + P1.moveLeft = false; + P1.moveUp = false; + P1.moveDown = false; + P1.moveRight = false; + P1.fire = false; + } + + Thread.sleep(30); + } + }catch(Exception ex){ + ex.printStackTrace(); + view.messageField.setEnabled(false); + serverVoteYes= false; + serverVoteNo = false; + clientVoteYes = false; + serverCreated = false; + gameStarted = false; + gameOver = false; + gameFlow = 0; + enemy.freezedTime = 0; + enemy.freezedMoment = 0; + view.mainPanel.gameStarted = false; + t.stop(); + addMessage("玩家退出了,请重新建立主机"); + + //当发生错误在游戏中,摧毁任何东西,包括游戏的变量 + try{ + out.close(); + in.close(); + clientSocket.close(); + serverSocket.close(); + }catch(Exception exc){} + + //破坏游戏数据 + P1 = null; + P2 = null; + level.reset(); + } + } + + //添加游戏对象(如坦克,子弹等..)到游戏系统 + public void addActor(Actor actor){ + for(int i = 0; i < actors.length; i ++ ) + if(actors[i] == null){ + actors[i] = actor; + break; + } + } + + //从游戏系统中移除游戏对象 + public void removeActor(Actor actor){ + for(int i = 0; i < actors.length; i ++ ) + if(actors[i] == actor){ + actors[i] = null; + break; + } + } + + + //在屏幕上显示一行消息 + public void addMessage(String message){ + if(messageIndex < 8){ + messageQueue[messageIndex] = message; + messageIndex++; + } + else{ + for(int i = 0; i < 7; i++) + messageQueue[i] = messageQueue[i+1]; + messageQueue[7] = message; + } + + //调用视图重绘屏幕如果游戏有没有开始 + if(!gameStarted) + view.mainPanel.repaint(); + } + + //删除屏幕上最早的信息 + public void removeMessage(){ + if(messageIndex == 0) + return; + + messageIndex--; + for(int i = 0; i < messageIndex; i++) + messageQueue[i] = messageQueue[i+1]; + messageQueue[messageIndex] = null; + + //调用视图重绘屏幕如果比赛还没开始 + if(!gameStarted) + view.mainPanel.repaint(); + } + +} \ No newline at end of file diff --git a/源代码/server/src/ServerView.java b/源代码/server/src/ServerView.java new file mode 100644 index 0000000..08a3a99 --- /dev/null +++ b/源代码/server/src/ServerView.java @@ -0,0 +1,87 @@ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + + +//这个类表示服务器的图形界面 +public class ServerView extends JFrame{ + public drawingPanel mainPanel; + public JButton createServer, exit, pauseAndResume, help, hiddenButton; + public JTextField messageField; + public JButton sendMessage; + + public ServerControler controler; + public ServerModel model; + + public ServerView(){ + + super("坦克大战"); + + + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { } + + getContentPane().setLayout(null); + + //制作动画绘制的主面板 + mainPanel = new drawingPanel(); + mainPanel.setLayout(null); + mainPanel.setBounds(0, 22, 679, 605); + mainPanel.setBackground(new Color(128, 64, 0)); + messageField = new JTextField(); + messageField.setBounds(0,519, 560,22); + messageField.setEnabled(false); + sendMessage = new JButton("发送"); + sendMessage.setBounds(570,518, 62,24); + sendMessage.setFocusable(false); + mainPanel.add(messageField); + mainPanel.add(sendMessage); + getContentPane().add(mainPanel); + mainPanel.setFocusable(true); + + //制作选项按钮 + createServer = new JButton("建立主机"); + createServer.setBounds(0, 0,120,22); + getContentPane().add(createServer); + createServer.setFocusable(false); + + pauseAndResume = new JButton("暂停/继续"); + pauseAndResume.setBounds(120, 0,120,22); + getContentPane().add(pauseAndResume); + pauseAndResume.setFocusable(false); + + help = new JButton("帮助"); + help.setBounds(240, 0,120,22); + getContentPane().add(help); + help.setFocusable(false); + + exit = new JButton("退出"); + exit.setBounds(360, 0,120,22); + getContentPane().add(exit); + exit.setFocusable(false); + + //设置主框架 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(150, 130, 640, 590); + setVisible(true); + setResizable( false ); + + //设置服务器模式 + model = new ServerModel(this); + + //设置服务器控制器 + controler = new ServerControler(this, model); + + + } + + + public static void main(String[] args){ + new ServerView(); + } + + + +} \ No newline at end of file diff --git a/源代码/server/src/Steelwall.java b/源代码/server/src/Steelwall.java new file mode 100644 index 0000000..98c35bb --- /dev/null +++ b/源代码/server/src/Steelwall.java @@ -0,0 +1,133 @@ +import java.awt.*; + +public class Steelwall implements Actor{ + private int xPos; + private int yPos; + private Rectangle[] border = new Rectangle[4]; + public boolean[] shape = new boolean[4]; + public boolean walldestoried; + public boolean bulletdestoried; + public ServerModel gameModel; + public Image steelWall; + public Rectangle generalBorder; + + public Steelwall(int a, int b, ServerModel gameModel){ + this.gameModel = gameModel; + steelWall = gameModel.textures[53]; + xPos = a; + yPos = b; + generalBorder = new Rectangle(xPos - 12, yPos - 12, 25, 25); + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + } + + public Steelwall(int a, int b, int orientation, ServerModel gameModel){ + xPos = a; + yPos = b; + this.gameModel = gameModel; + steelWall = gameModel.textures[53]; + generalBorder = new Rectangle(xPos - 12, yPos - 12, 25, 25); + if(orientation == 0){ + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + shape[2] = true; + shape[3] = true; + } + if(orientation == 1){ + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + shape[0] = true; + shape[1] = true; + } + if(orientation == 2){ + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + shape[1] = true; + shape[3] = true; + } + if(orientation == 3){ + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + shape[0] = true; + shape[2] = true; + } + } + + + public void damageWall(Rectangle bullet, int bulletpower, int bulletdirection){ + bulletdestoried = false; + if(bulletpower == 2){ + for(int i = 0; i < 4; i++){ + if(border[i] != null){ + if(bullet.intersects(border[i])){ + bulletdestoried = true; + border[i] = null; + shape[i] = true; + } + } + } + } + if(bulletpower == 1){ + for(int i = 0; i < 4; i++){ + if(border[i] != null){ + if(bullet.intersects(border[i])) + bulletdestoried = true; + } + } + } + + //将变化写入输出行 + gameModel.outputLine+="s" + xPos + ","+ yPos+","; + for(int i = 0; i < shape.length; i++){ + if(shape[i]) + gameModel.outputLine+="1"; + else + gameModel.outputLine+="0"; + } + gameModel.outputLine+=";"; + + } + + public boolean walldestoried(){ + if(walldestoried) + return true; + boolean walldestory = false; + if(border[0] == null && border[1] == null && border[2] == null && border[3] == null) + walldestory = true; + return walldestory; + } + + public Rectangle getBorder(){ + return generalBorder; + } + + public Rectangle[] getDetailedBorder(){ + return border; + } + + public void draw(Graphics g) { + if(walldestoried) + return; + + g.drawImage(steelWall, xPos - 12, yPos - 12, null); + g.setColor(new Color(128, 64, 0)); + if(shape[0]) + g.fillRect(xPos - 12, yPos - 12, 13, 13); + if(shape[1]) + g.fillRect(xPos, yPos - 12, 13, 13); + if(shape[2]) + g.fillRect(xPos - 12, yPos, 13, 13); + if(shape[3]) + g.fillRect(xPos, yPos, 13, 13); + } + + public String getType(){ + return "steelWall"; + } + + + //未使用的方法 + public void move(){} +} \ No newline at end of file diff --git a/源代码/server/src/Ticker.java b/源代码/server/src/Ticker.java new file mode 100644 index 0000000..9ef0a2a --- /dev/null +++ b/源代码/server/src/Ticker.java @@ -0,0 +1,78 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.PrintStream; + +public class Ticker implements Runnable{ + + + + ActionListener al; + private boolean isTicking; + Thread t; + int delay; + + public Ticker(int i, ActionListener actionlistener){ + al = actionlistener; + delay = i; + t = new Thread(this); + t.start(); + isTicking = false; + } + + public Ticker(int i){ + delay = i; + t = new Thread(this); + t.start(); + isTicking = false; + } + + public void addActionListener(ActionListener actionlistener){ + if(al == null) + al = actionlistener; + else + System.out.println("WARNING: ActionListener already added to Ticker."); + } + + public boolean isRunning(){ + return isTicking; + } + + public void start(){ + isTicking = true; + } + + public void stop(){ + isTicking = false; + } + + public void setDelay(int i){ + delay = i; + } + + public int getDelay(){ + return delay; + } + + private void fireActionPerformed(){ + if(al == null || !isTicking){ + return; + } else{ + ActionEvent actionevent = new ActionEvent(this, 0, null); + al.actionPerformed(actionevent); + return; + } + } + + public void run(){ + do{ + fireActionPerformed(); + try{ + Thread.sleep(delay); + }catch(InterruptedException interruptedexception){ + System.out.println("WARNING: Ticker thread interrupted."); + } + } while(true); + } +} + + diff --git a/源代码/server/src/base.java b/源代码/server/src/base.java new file mode 100644 index 0000000..5c17cf9 --- /dev/null +++ b/源代码/server/src/base.java @@ -0,0 +1,99 @@ +import java.awt.*; + +public class base implements Actor{ + private Rectangle border; + public Image base; + public int xPos, yPos; + public ServerModel gameModel; + public int steelWallTime; + public boolean baseKilled; + + public base(ServerModel gameModel){ + this.gameModel = gameModel; + xPos = 260; + yPos = 498; + base = gameModel.textures[0]; + border = new Rectangle(xPos - 11, yPos - 11, 23, 23); + + } + + public Rectangle getBorder(){ + return border; + } + + public void doom(){ + base = gameModel.textures[1]; + if(!baseKilled) + gameModel.addActor(new bomb(xPos, yPos, "big", gameModel)); + baseKilled = true; + + //记录变化到输出行 + gameModel.outputLine+="b"+ xPos + "," + yPos + "," + "1;"; + + } + + public void move(){ + if(steelWallTime == 600){ + Steelwall temp = new Steelwall(248, 498, 2, gameModel); + gameModel.actors[0] = temp; + writeToOutputLine("s", temp.shape, 248, 498); + + temp = new Steelwall(273, 498, 3, gameModel); + gameModel.actors[1] = temp; + writeToOutputLine("s", temp.shape, 273, 498); + + temp = new Steelwall(248, 473, 1, gameModel); + gameModel.actors[2] = temp; + writeToOutputLine("s", temp.shape, 248, 473); + + temp = new Steelwall(273, 473, 1, gameModel); + gameModel.actors[3] = temp; + writeToOutputLine("s", temp.shape, 273, 473); + } + if(steelWallTime> 0) + steelWallTime--; + if(steelWallTime == 1){ + wall temp = new wall(248, 498, 2, gameModel); + gameModel.actors[0] = temp; + writeToOutputLine("w", temp.shape, 248, 498); + + temp = new wall(273, 498, 3, gameModel); + gameModel.actors[1] = temp; + writeToOutputLine("w", temp.shape, 273, 498); + + temp = new wall(248, 473, 1, gameModel); + gameModel.actors[2] = temp; + writeToOutputLine("w", temp.shape, 248, 473); + + temp = new wall(273, 473, 1, gameModel); + gameModel.actors[3] = temp; + writeToOutputLine("w", temp.shape, 273, 473); + } + + } + + public void writeToOutputLine(String type, boolean[] shape, int xPos, int yPos){ + //记录变化到输出行 + gameModel.outputLine+=type + xPos + ","+ yPos+","; + for(int i = 0; i < shape.length; i++){ + if(shape[i]) + gameModel.outputLine+="1"; + else + gameModel.outputLine+="0"; + } + gameModel.outputLine+=";"; + } + + public String getType(){ + return "base"; + } + + public void draw(Graphics g){ + g.drawImage(base, xPos - 12, yPos - 12, null ); + } + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + +} \ No newline at end of file diff --git a/源代码/server/src/bomb.java b/源代码/server/src/bomb.java new file mode 100644 index 0000000..e6b234e --- /dev/null +++ b/源代码/server/src/bomb.java @@ -0,0 +1,69 @@ +import java.awt.*; + +public class bomb implements Actor{ + private int xPos, yPos; + private int animationTime; + public final Rectangle border = new Rectangle(0,0,0,0); + public String size; + public int inner, middle, outer, jumpDistance; + public ServerModel gameModel; + + + public bomb(int a, int b, String size, ServerModel gameModel){ + this.size = size; + this.gameModel = gameModel; + if(size.equals("big") ){ + inner = 6; middle = 9; outer = 14; + jumpDistance = 8; + animationTime = 6; + }else if(size.equals("small")){ + inner = 2; middle = 4; outer = 7; + jumpDistance = 4; + animationTime = 4; + } + + xPos = a; + yPos = b; + } + + public void draw(Graphics g){ + g.setColor(Color.red); + g.fillOval(xPos-outer, yPos-outer, 2*outer, 2*outer); + g.setColor(Color.orange); + g.fillOval(xPos-middle, yPos-middle, 2*middle, 2*middle); + g.setColor(Color.yellow); + g.fillOval(xPos-inner, yPos-inner, 2*inner, 2*inner); + } + + public void move(){ + if(gameModel.gamePaused){ + gameModel.outputLine+="o"+ xPos + "," + yPos + "," + size + ";" ; + return; + } + + animationTime--; + if(animationTime < 0){ + gameModel.removeActor(this); + return; + } + xPos = xPos + (int)(Math.random()*jumpDistance) - (int)(Math.random()*jumpDistance); + yPos = yPos + (int)(Math.random()*jumpDistance) - (int)(Math.random()*jumpDistance); + + //将变化写入输出行 + gameModel.outputLine+="o"+ xPos + "," + yPos + "," + size + ";" ; + } + + public Rectangle getBorder(){ + return border; + } + + public String getType(){ + return "bomb"; + } + + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + +} diff --git a/源代码/server/src/bullet.java b/源代码/server/src/bullet.java new file mode 100644 index 0000000..f34b7d8 --- /dev/null +++ b/源代码/server/src/bullet.java @@ -0,0 +1,166 @@ +import java.awt.*; + +public class bullet implements Actor{ + public final Rectangle map = new Rectangle(18, 18, 486, 486); + private Rectangle border; + private int direction; + private int Speed; + private int bulletpower; + public int xPos, yPos; + public Actor owner; + public ServerModel gameModel; + public boolean hitTarget; + + public bullet(int a, int b, int c, int d, int e, Actor owner, ServerModel gameModel){ + this.owner = owner; + this.gameModel = gameModel; + xPos = a; yPos = b; + direction = c; + if(direction == 0 || direction == 1) + border = new Rectangle(a - 2, b - 5, 5, 13); + else + border = new Rectangle(a - 5, b - 2, 13, 5); + + Speed = d; + bulletpower = e; + } + + public void draw(Graphics g) { + g.setColor(Color.lightGray); + if(direction == 0 || direction == 1) + g.fillRect(border.x + 1, border.y +1, 3, 9); + if(direction == 2 || direction == 3) + g.fillRect(border.x +1, border.y + 1, 9, 3); + } + + public void move(){ + if(gameModel.gamePaused){ + writeToOutputLine(); + return; + } + + + //检查这子弹是否撞击地图边界 + if(!border.intersects(map)){ + gameModel.removeActor(this); + notifiyOwner(); + makeBomb(); + writeToOutputLine(); + return; + } + //检查这颗子弹是否击中其他对象 + for(int i = 0; i < gameModel.actors.length; i++){ + if(gameModel.actors[i] != null){ + if(gameModel.actors[i] != this && gameModel.actors[i] != owner){ + if(border.intersects(gameModel.actors[i].getBorder())){ + + if(gameModel.actors[i].getType().equals("steelWall")){ + Steelwall temp = (Steelwall)gameModel.actors[i]; + if(!temp.walldestoried){ + temp.damageWall(border, bulletpower, direction); + if(temp.bulletdestoried) + hitTarget = true; + } + }else if(gameModel.actors[i].getType().equals("wall")){ + wall temp = (wall)gameModel.actors[i]; + if(!temp.walldestoried){ + temp.damageWall(border, bulletpower, direction); + if(temp.bulletdestoried) + hitTarget = true; + } + }else if(gameModel.actors[i].getType().equals("bullet")){ + bullet temp = (bullet)gameModel.actors[i]; + if(temp.owner.getType().equals("Player")){ + hitTarget = true; + gameModel.removeActor(gameModel.actors[i]); + temp.notifiyOwner(); + } + }else if(gameModel.actors[i].getType().equals("Player")){ + if(owner.getType().equals("enemy")){ + player temp = (player)gameModel.actors[i]; + temp.hurt(); + }else{ + } + hitTarget = true; + }else if(gameModel.actors[i].getType().equals("enemy") && owner.getType().equals("Player")){ + enemy temp = (enemy)gameModel.actors[i]; + player tempe = (player)owner; + if(temp.health == 0) + tempe.scores+=temp.type*100; + temp.hurt(); + hitTarget = true; + }else if(gameModel.actors[i].getType().equals("base")){ + base temp = (base)gameModel.actors[i]; + temp.doom(); + hitTarget = true; + gameModel.gameOver = true; + } + } + } + } + } + + //如果子弹打到其他对象,从游戏系统中删除这个子弹对象 + if(hitTarget){ + gameModel.removeActor(this); + notifiyOwner(); + makeBomb(); + writeToOutputLine(); + return; + } + + if(direction == 0){ + border.y -= Speed; + yPos -= Speed; + } + if(direction == 1){ + border.y += Speed; + yPos += Speed; + } + if(direction == 2){ + border.x -= Speed; + xPos -= Speed; + } + if(direction == 3){ + border.x += Speed; + xPos += Speed; + } + writeToOutputLine(); + } + + public void writeToOutputLine(){ + gameModel.outputLine+="t"+ xPos + "," + yPos + "," + direction + ";"; + } + + public Rectangle getBorder(){ + return border; + } + + public String getType(){ + return "bullet"; + } + + public void notifiyOwner(){ + if(owner != null){ + if(owner.getType().equals("Player")){ + player temp = (player)owner; + temp.numberOfBullet++; + }else if(owner.getType().equals("enemy")){ + enemy temp = (enemy)owner; + temp.numberOfBullet++; + } + } + } + + public void makeBomb(){ + gameModel.addActor(new bomb(xPos, yPos, "small", gameModel)); + } + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + + + + +} diff --git a/源代码/server/src/drawingPanel.java b/源代码/server/src/drawingPanel.java new file mode 100644 index 0000000..4c69479 --- /dev/null +++ b/源代码/server/src/drawingPanel.java @@ -0,0 +1,81 @@ +import java.awt.*; +import javax.swing.*; + +//drawingPanel类属于服务器程序 +public class drawingPanel extends JPanel{ + public Image offScreenImage; + + //这些是指出在serverModel都是真实的东西的参考 + public String[] messageQueue; + public Actor[] actors; + public boolean gameStarted; + public int green, red, blue; + + public drawingPanel() {} + + public void paintComponent(Graphics g) { + Graphics offScreenGraphics; + if (offScreenImage == null) { + offScreenImage = createImage(640, 550); + } + offScreenGraphics = offScreenImage.getGraphics(); + myPaint(offScreenGraphics); + g.drawImage(offScreenImage, 0, 0, this); + } + + public void myPaint(Graphics g) { + super.paintComponent(g); + + if(gameStarted){ + //制作背景 + g.setColor(Color.blue); + g.drawRect(10, 10, 501, 501); + + //制作坦克等等 + if(actors != null) + for(int i = 0; i < actors.length; i++) + if(actors[i] != null) + actors[i].draw(g); + + //制作级别关卡 + g.setColor(new Color(81,111, 230)); + g.drawString("第 " + level.currentLevel + " 关", 527, 39); + g.drawString("敌人数 = " + level.enemyLeft, 527, 79); + + //制作获胜场景 + if(level.winningCount > 150){ + int temp = level.winningCount - 150; + if(temp*10 > 300) + temp = 30; + if(level.winningCount > 470) + temp = 500 - level.winningCount; + g.setColor(Color.gray); + g.fillRect(11,11, 500, temp*10); + g.fillRect(11, 500 - temp*10, 500, (1+temp)*10 + 2); + + if(level.winningCount > 190 &&level.winningCount < 470){ + if(level.winningCount > 400 ){ + red+=(int)((128-red)*0.2); + green+=(int)((128-green)*0.2); + } + g.setColor(new Color(red, green, blue)); + g.drawString("过 关 了 !", 240, 250); + } + }else{ + green = 23; red = 34; blue = 128; + } + + } + + //消息 + g.setColor(new Color(255, 255, 255)); + if(messageQueue != null){ + for(int i = 0 ; i < 8; i++){ + if(messageQueue[i] != null) + g.drawString(messageQueue[i] , 5, 12 +i*16); + else + break; + } + } + } +} \ No newline at end of file diff --git a/源代码/server/src/enemy.java b/源代码/server/src/enemy.java new file mode 100644 index 0000000..d284f51 --- /dev/null +++ b/源代码/server/src/enemy.java @@ -0,0 +1,330 @@ +import java.awt.*; + +public class enemy implements Actor{ + public final int UP = 0; + public final int DOWN = 1; + public final int LEFT = 2; + public final int RIGHT = 3; + public final int size = 12; + public final Rectangle map = new Rectangle(35, 35, 452, 452); + public static int freezedTime; + public static int freezedMoment; + public int numberOfBullet; + public int coolDownTime; + public int type; + public int speed; + public int direction; + public int interval; + public int health;; + public int xPos, yPos, xVPos, yVPos; + public Rectangle border; + public boolean flashing; + public double firePosibility; + public Image[] textures; + public ServerModel gameModel; + + public enemy(int type, boolean flashing, int xPos, int yPos, ServerModel gameModel){ + this.type = type; + this. xPos = xPos; + this.yPos = yPos; + this.flashing = flashing; + this.gameModel = gameModel; + + //设置全部敌人的共同属性 + interval = (int)(Math.random()*200); + direction = (int)(Math.random()*4); + numberOfBullet = 1; + xVPos = xPos; + yVPos = yPos; + border = new Rectangle(xPos - size, yPos - size, 25, 25); + + + //根据不同类型的敌人设置独特的属性如:容貌,速度,等等 + if(type ==1 ){ + firePosibility = 0.95; + speed = 2; + textures = new Image[8]; + for(int i = 0; i < 8; i++) + textures[i] = gameModel.textures[38+i]; + }else if(type == 2){ + firePosibility = 0.95; + speed = 4; + textures = new Image[8]; + for(int i = 0; i < 8; i++) + textures[i] = gameModel.textures[2+i]; + }else if(type == 3){ + firePosibility = 0.9; + speed = 2; + textures = new Image[8]; + for(int i = 0; i < 8; i++) + textures[i] = gameModel.textures[10+i]; + }else{ + firePosibility = 0.95; + health = 3; + speed = 2; + textures = new Image[20]; + for(int i = 0; i < 20; i++) + textures[i] = gameModel.textures[18+i]; + + } + + } + + public void move(){ + if(gameModel.gamePaused){ + writeToOutputLine(); + return; + } + + if(freezedTime > ServerModel.gameFlow - freezedMoment){ + writeToOutputLine(); + return; + } + + + //敌方坦克在一个周期内将会朝着相同的方向继续移动(如果不与其他对象相互影响) + //在每个周期结束时,它将转向新的方向 + if(interval > 0) + interval--; + if(interval == 0){ + interval = (int)(Math.random()*200); + int newDirection = (int)(Math.random()*4); + if(direction != newDirection){ + if(direction/2 != newDirection/2){ + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + } + direction = newDirection; + } + + } + + + //完全随机的决定是否要发射一颗子弹,敌方坦克不能开火 + //如果第一个不是摧毁的子弹 + if(coolDownTime > 0) + coolDownTime--; + if(Math.random() > firePosibility && coolDownTime == 0 && numberOfBullet > 0){ + //获得子弹方向 + int c = direction; + //获得子弹位置 + int a, b; + if(direction == UP){ + a = xPos; b = yPos - size; + }else if(direction == DOWN){ + a = xPos; b = yPos + size; + }else if(direction == LEFT){ + a = xPos - size; b = yPos; + }else{ + a = xPos + size; b = yPos; + } + //获得子弹速度 + int d; + if(type == 3){ + d = 12; + }else{ + d = 7; + } + //添加子弹 + gameModel.addActor(new bullet(a,b,c,d,1, this, gameModel)); + coolDownTime = 7; + if(type == 3) + coolDownTime = 5; + numberOfBullet--; + } + + //保存当前位置信息,如果确定了新举措无效后,然后改变 + + int xPosTemp = xPos; + int yPosTemp = yPos; + Rectangle borderTemp = new Rectangle(xPosTemp - size, yPosTemp - size, 25,25); + + //定义地方坦克的下一个边界,假设它有效的根据方向来进行移动 + if(direction == UP){ + yPos-=speed; + }else if(direction == DOWN){ + yPos+=speed; + }else if(direction == LEFT){ + xPos-=speed; + }else{ + xPos+=speed; + } + + + //更新边界 + border.y = yPos - size; + border.x = xPos - size; + + //检查下一个边界是否会与地图边界相交,如果不相交则随机生成边界 + if(!border.intersects(map)){ + direction = (int)(Math.random()*4); + interval = (int)(Math.random()*250); + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + + //检查下一个边界是否与其他对象相交,例如玩家控制的坦克,墙等等 + for(int i = 0; i < gameModel.actors.length; i++){ + if(gameModel.actors[i] != null){ + if(this != gameModel.actors[i] ){ + if(border.intersects(gameModel.actors[i].getBorder())){ + //静态对象,例如河流,墙等等 + if(gameModel.actors[i].getType().equals("steelWall") || gameModel.actors[i].getType().equals("wall")){ + if(!gameModel.actors[i].walldestoried()){ + for(int j = 0;j < gameModel.actors[i].getDetailedBorder().length; j++){ + if( gameModel.actors[i].getDetailedBorder()[j] != null){ + if(gameModel.actors[i].getDetailedBorder()[j].intersects(border)){ + if(Math.random() > 0.90) + direction = (int)(Math.random()*4); + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + } + } + } + }else if(gameModel.actors[i].getType().equals("river") || gameModel.actors[i].getType().equals("base")){ + if(Math.random() > 0.90) + direction = (int)(Math.random()*4); + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + //其他对象,其他的坦克 + if(gameModel.actors[i].getType().equals("Player") || gameModel.actors[i].getType().equals("enemy")){ + if(!borderTemp.intersects(gameModel.actors[i].getBorder())){ + xPos = xPosTemp; + yPos = yPosTemp; + border.x = xPos - size; border.y = yPos - size; + int newDirection = (int)(Math.random()*4); + if(direction != newDirection){ + if(direction/2 != newDirection/2){ + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + } + direction = newDirection; + } + writeToOutputLine(); + return; + } + } + } + } + } + } + + + ///当坦克是90度倾斜时,找到坦克的虚拟位置,使用虚拟位置调整坦克的真实位置 + int a = (xPos - 10)/25; + int b = (xPos - 10)%25; + if(b < 7) + b = 0; + if(b > 18) + b = 25; + if((b < 19 && b > 6) || xPos < 17 || xPos > 492) + b = 13; + xVPos = a*25 + b + 10; + int c = (yPos - 10)/25; + int d = (yPos - 10)%25; + if(d < 7) + d = 0; + if(d > 18) + d = 25; + if((d < 19 && d > 6) || yPos < 17 || yPos > 492) + d = 13; + yVPos = c*25 + d + 10; + writeToOutputLine(); + } + + public void writeToOutputLine(){ + //将变化写入输出行 + gameModel.outputLine+="n"+ xPos + "," + yPos + ","; + int textureIndex = 0; + if(flashing && gameModel.gameFlow%10 > 4){ + if(type == 1) + textureIndex = 42+ direction; + else if(type == 2) + textureIndex = 6 + direction; + else if(type == 3) + textureIndex = 14 + direction; + else + textureIndex = 34 + direction; + }else{ + if(type == 1) + textureIndex = 38 + direction; + else if(type == 2) + textureIndex = 2 + direction; + else if(type == 3) + textureIndex = 10 + direction; + else{ + if(health == 3) + textureIndex = 18 + direction; + else if(health == 2) + textureIndex = 22 + direction; + else if(health == 1) + textureIndex = 26 + direction; + else + textureIndex = 30 + direction; + } + } + gameModel.outputLine+= "" + textureIndex + ";"; + + } + + //如果敌方坦克打出一颗子弹,判断会发生什么 + public void hurt(){ + if(flashing) + gameModel.addActor(new powerUp(gameModel)); + flashing = false; + boolean death = false; + if(type != 4 ) + death = true; + else{ + if(health == 0) + death = true; + else{ + if(health == 3){ + for(int i = 0; i < 4; i++) + textures[i] = textures[4+i]; + }else if(health == 2){ + for(int i = 0; i < 4; i++) + textures[i] = textures[8+i]; + }else if(health == 1){ + for(int i = 0; i < 4; i++) + textures[i] = textures[12+i]; + } + health--; + } + } + + if(death){ + level.NoOfEnemy--; + level.deathCount++; + gameModel.removeActor(this); + gameModel.addActor(new bomb(xPos, yPos, "big", gameModel)); + } + } + + public String getType(){ + return "enemy"; + } + + public void draw(Graphics g){ + if(flashing && gameModel.gameFlow%10 > 4) + g.drawImage(textures[textures.length-4+direction], xPos - size, yPos - size, null); + else + g.drawImage(textures[direction], xPos - size, yPos - size, null); + } + + public Rectangle getBorder(){ + return border; + } + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} +} \ No newline at end of file diff --git a/源代码/server/src/feedbackHandler.java b/源代码/server/src/feedbackHandler.java new file mode 100644 index 0000000..804acfe --- /dev/null +++ b/源代码/server/src/feedbackHandler.java @@ -0,0 +1,69 @@ +//这个类从客户端程序解码指令字符串,然后将字符串转换为真正的指令 +//服务器程序可读 + +public class feedbackHandler{ + public static void handleInstruction(ServerModel gameModel, String instruction){ + if(instruction.length() == 0) + return; + + int i = 0; + while(i < instruction.length()){ + String perInstruction = ""; + + //指令是“;”时 + while(!instruction.substring(i, i+1).equals(";")){ + perInstruction+=instruction.substring(i, i+1); + i++; + } + + //指令是“m”表明客户端运动信息 + if(perInstruction.substring(0,1).equals("m")){ + gameModel.P2.moveUp = false; + gameModel.P2.moveDown = false; + gameModel.P2.moveLeft = false; + gameModel.P2.moveRight = false; + gameModel.P2.fire = false; + + String temp = perInstruction.substring(1,2); + if(temp.equals("1")) + gameModel.P2.moveUp = true; + temp = perInstruction.substring(2,3); + if(temp.equals("1")) + gameModel.P2.moveDown = true; + temp = perInstruction.substring(3,4); + if(temp.equals("1")) + gameModel.P2.moveLeft = true; + temp = perInstruction.substring(4,5); + if(temp.equals("1")) + gameModel.P2.moveRight = true; + temp = perInstruction.substring(5,6); + if(temp.equals("1")) + gameModel.P2.fire = true; + } + + //指令是“m”表示服务器玩家信息 + if(perInstruction.substring(0,1).equals("e")){ + gameModel.addMessage("用户端玩家说:" + perInstruction.substring(1,perInstruction.length())); + } + + //指令是“j”表示客户端玩家想在玩一次 + if(perInstruction.substring(0,1).equals("j")){ + if(gameModel.gameOver) + gameModel.clientVoteYes = true; + } + + //指令是“x”表示服务器玩家暂停游戏 + if(perInstruction.substring(0,1).equals("x")){ + if(gameModel.gamePaused){ + gameModel.addMessage("用户端玩家取消了暂停"); + gameModel.gamePaused = false; + } else if(!gameModel.gamePaused){ + gameModel.addMessage("用户端玩家暂停了游戏"); + gameModel.gamePaused = true; + } + } + i++; + } + } + +} \ No newline at end of file diff --git a/源代码/server/src/grass.java b/源代码/server/src/grass.java new file mode 100644 index 0000000..3fe5c59 --- /dev/null +++ b/源代码/server/src/grass.java @@ -0,0 +1,40 @@ +import java.awt.*; + +public class grass implements Actor{ + private int xPos; + private int yPos; + public Rectangle border; + + public grass(int a, int b){ + xPos = a; + yPos = b; + border = new Rectangle(0,0,0,0); + } + + public void draw(Graphics g) { + g.setColor(new Color(0, 225, 0)); + for(int i = yPos - 11; i <= yPos + 12; i+=5) + g.drawLine(xPos - 12, i, xPos + 12, i); + for(int i = xPos - 11; i <= xPos + 12; i+=5) + g.drawLine(i, yPos - 12, i, yPos + 12); + g.setColor(new Color(0, 128, 0)); + for(int i = yPos - 10; i <= yPos + 12; i+=5) + g.drawLine(xPos - 12, i, xPos + 12, i); + for(int i = xPos - 10; i <= xPos + 12; i+=5) + g.drawLine( i, yPos - 12, i, yPos + 12); + } + + public String getType(){ + return "grass"; + } + + public Rectangle getBorder(){ + return border; + } + + public void move(){} + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + + +} \ No newline at end of file diff --git a/源代码/server/src/level.java b/源代码/server/src/level.java new file mode 100644 index 0000000..3b36d41 --- /dev/null +++ b/源代码/server/src/level.java @@ -0,0 +1,316 @@ +import java.awt.*; + +//服务器端的类 +//因为只有一层对象,所以在这个类是一个静态变量 +public class level{ + public static int currentLevel = 0; + public static int enemySpawnTime = 150; + public static int enemyLeft = 20; + public static int deathCount = 0; + public static int maxNoEnemy = 3; + public static int NoOfEnemy = 0; + public static int[] enemySequence; + + //制作获胜场景所需的变量 + public static int winningCount; + + public static void loadLevel(ServerModel gameModel){ + //增加关卡数量 + currentLevel++; + + //每次加载一个新的关卡将增加难度 + if(enemySpawnTime > 30) + enemySpawnTime-=10; + if(maxNoEnemy < 10 && (currentLevel%2 == 0)) + maxNoEnemy++; + + //从上个关卡清除所有东西 + for(int i = 0; i < 400; i ++) + gameModel.actors[i] = null; + + //启动时各关卡共享 + enemyLeft = 20; + + //加载基地,每个关卡都一样 + gameModel.actors[0] = new wall(248, 498, 2, gameModel); + gameModel.actors[1] = new wall(273, 498, 3, gameModel); + gameModel.actors[2] = new wall(248, 473, 1, gameModel); + gameModel.actors[3] = new wall(273, 473, 1, gameModel); + gameModel.actors[4] = new base(gameModel); + + //加载一个关卡 + if(1+ (currentLevel-1)%8 == 1){ + enemySequence = new int[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "ss", "ss", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "s0", "##", "##", "__", "__", "__", "__", "__", "##", "s0", "s0", "##", "__", "__", "__", "__", "__", "##", "##", "s0", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "##", "##", "__", "__", "__", "__", "__", "##", "__", "__", "##", "__", "__", "__", "__", "__", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 2){ + enemySequence = new int[]{1,1,2,2,1,1,1,1,2,2,2,2,1,1,1,1,3,3,3,3}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "$$", "==", "==", "==", "==", "==", "==", "==", "$$", "$$", "==", "==", "==", "==", "==", "==", "==", "==", "==", "$$", + "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "ss", "##", "##", "##", "##", "##", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "ss", "##", "##", "##", "__", "__", "ss", "ss", "##", "##", "##", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "##", "##", "##", "##", "##", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__", + "__", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", "__", "__", "##", "==", "==", "==", "==", "==", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 3){ + enemySequence = new int[]{1,1,1,2,2,2,4,4,2,2,2,2,1,1,1,1,2,2,4,4}; + String[] level = new String[]{ + "__", "__", "__", "ss", "__", "__", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "s3", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "##", "##", "##", "__", "##", "##", "##", "##", "__", "s3", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "s3", "__", "__", "__", + "__", "__", "ss", "ss", "__", "##", "##", "##", "##", "__", "__", "##", "##", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "ss", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "__", "##", "s1", + "__", "__", "__", "ss", "__", "##", "__", "ss", "##", "ss", "##", "ss", "##", "##", "##", "##", "##", "__", "__", "##", + "__", "__", "__", "ss", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "__", "__", "__", "ss", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "__", "__", "__", "##", "ss", "ss", "ss", "ss", "##", "##", "##", "##", "##", "$$", "$$", "$$", "$$", "##", "##", "##", + "##", "__", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "##", "##", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "__", "__", "__", + "##", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", "##", "##", "##", "##", "__", "__", "__", + "##", "##", "##", "##", "##", "##", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", + "##", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "__", "__", "__", "__", + "#0", "s0", "s0", "s0", "$$", "ss", "ss", "ss", "ss", "##", "ss", "ss", "$$", "ss", "ss", "##", "##", "##", "ss", "##", + "__", "__", "__", "##", "__", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", + "__", "__", "__", "##", "__", "__", "__", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 4){ + enemySequence = new int[]{3,3,3,3,2,2,2,3,3,1,1,1,3,3,3,1,1,4,4,4}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "__", "__", "__", "__", "__", + "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "ss", "##", "##", "##", "##", "__", "__", "__", + "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "ss", "ss", "s2", "__", "__", + "__", "__", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$","$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "__", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "##", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "##", "$$", "$$", "##", "$$", "$$", "$$", "##", "$$", "$$","$$", "$$", "s2", "__", "__", + "__", "##", "##", "##", "##", "$$", "$$", "$$", "$$", "##", "$$", "##", "$$", "$$", "$$", "$$","##", "s2", "__", "__", + "__", "__", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "##", "$$", "$$", "$$", "$$", "$$", "##", "##", "__", "__", + "__", "__", "##", "$$", "$$", "$$", "$$", "$$", "$$", "##", "##", "$$", "$$", "$$", "$$", "##", "##", "s0", "s0", "s0", + "__", "__", "##", "##", "##", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "$$", "##", "##", "__", "__", "__", "__", + "__", "__", "__", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "##", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 5){ + enemySequence = new int[]{2,2,2,3,3,3,2,2,2,4,4,4,3,3,3,3,3,2,2,2}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "==", "==", "==", "__", "__", "==", "==", "==", "==", "==", "==", "__", "==", "==", "==", "==", "==", "==", "__", + "__", "==", "ss", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "==", "__", "==", "==", "__", "ss", "==", "==", "==", "==", "__", "==", "__", + "__", "==", "__", "==", "==", "==", "==", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", + "__", "==", "__", "==", "__", "__", "__", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", + "__", "==", "__", "==", "__", "__", "==", "==", "==", "==", "__", "__", "==", "__", "__", "==", "__", "==", "==", "__", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "__", "__", "__", "==", "ss", "__", "__", "__", "==", "__", "__", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "==", "__", "==", + "__", "==", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "__", "==", "__", "==", "__", "__", + "__", "==", "__", "==", "__", "==", "==", "__", "__", "==", "__", "__", "==", "__", "==", "==", "__", "==", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "__", "__", "==", "__", "__", "==", "__", "==", "__", "__", "__", "==", "__", + "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", "==", "==", "==", "__", "__", "__", + "__", "==", "==", "==", "__", "==", "==", "==", "__", "ss", "ss", "==", "==", "__", "__", "__", "==", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "==", "__", "ss", "__", "==", "__", "==", "__", + "==", "==", "==", "==", "==", "__", "==", "__", "__", "__", "__", "__", "==", "__", "__", "__", "==", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "==", "==", "==", "__", "==", "==", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__", + "__", "__", "__", "__", "__", "__", "==", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "==", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 6){ + enemySequence = new int[]{4,4,4,4,2,2,2,4,4,1,1,1,3,3,3,1,1,4,4,4}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "$$", "__", "__", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "__", "$$", "__", + "__", "__", "$$", "ss", "$$", "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", "$$", "ss", "$$", + "__", "$$", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "ss", "$$", + "__", "$$", "ss", "ss", "ss", "$$", "ss", "ss", "ss", "$$", "$$", "$$", "$$", "__", "__", "__", "$$", "ss", "ss", "$$", + "__", "$$", "ss", "ss", "ss", "$$", "$$", "ss", "$$", "$$", "ss", "ss", "ss", "$$", "__", "__", "$$", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "$$", "$$", "ss", "ss", "ss", "$$", "__", "__", "$$", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "__", "$$", "$$", "ss", "$$", "$$", "__", "__", "$$", "ss", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", + "$$", "ss", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "ss", "$$", "__", "__", "__", "$$", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "__", "__", "ss", "ss", "$$", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", "__", + "$$", "ss", "ss", "ss", "$$", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "$$", "ss", "ss", "ss", "$$", "$$", "ss", "$$", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "$$", "ss", "ss", "ss", "$$", "__", "$$", "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "$$", "$$", "$$", "$$", "$$", "__", "__", + "__", "$$", "ss", "ss", "$$", "__", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "$$", "__", + "__", "__", "$$", "ss", "$$", "__", "__", "__", "__", "__", "__", "$$", "ss", "ss", "ss", "ss", "$$", "$$", "__", "__", + "__", "__", "__", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "$$", "$$", "$$", "$$", "__", "__", "__", "__" + + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 7){ + enemySequence = new int[]{3,3,3,3,3,3,3,3,3,3,2,4,2,4,2,4,2,4,2,4}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "##", "##", "##", "__", "__", "__", "__", "$$", "$$", "$$", "__", "__", + "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "==", "==", "==", "__", + "$$", "$$", "$$", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "ss", "ss", "ss", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__", + "__", "__", "__", "__", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "==", "==", "==", "__", "__" + }; + loadLevel(gameModel, level); + } + + if(1+ (currentLevel-1)%8 == 8){ + enemySequence = new int[]{3,4,4,2,3,4,4,2,3,4,4,2,3,4,4,2,3,4,4,2}; + String[] level = new String[]{ + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "##", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "##", "##", "##", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "##", "__", "__", "##", "##", "##", "__", "##", "__", "__", "__", "##", "__", "__", "##", "##", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "##", "__", "__", "__", "##", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", "##", "__", "__", "##", "__", "__", "##", "__", + "##", "__", "##", "__", "##", "__", "__", "##", "__", "__", "__", "##", "__", "__", "__", "##", "__", "__", "##", "__", + "__", "##", "__", "__", "__", "##", "##", "__", "##", "__", "__", "##", "__", "__", "__", "__", "##", "##", "__", "##", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", + "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__", "__" + }; + loadLevel(gameModel, level); + } + + gameModel.addActor(gameModel.P1); + gameModel.addActor(gameModel.P2); + } + + public static void loadLevel(ServerModel gameModel, String[] level){ + for(int i = 0; i < level.length; i++){ + if(level[i].equals("##")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, gameModel)); + if(level[i].equals("#0")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 0, gameModel)); + if(level[i].equals("#1")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 1, gameModel)); + if(level[i].equals("#2")) + gameModel.addActor(new wall(23 + (i%19)*25, 23 + (i/20)*25, 2, gameModel)); + if(level[i].equals("#3")) + gameModel.addActor(new wall(23 + (i%20)*25, 23 + (i/20)*25, 3, gameModel)); + if(level[i].equals("ss")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, gameModel)); + if(level[i].equals("s0")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 0, gameModel)); + if(level[i].equals("s1")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 1, gameModel)); + if(level[i].equals("s2")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 2, gameModel)); + if(level[i].equals("s3")) + gameModel.addActor(new Steelwall(23 + (i%20)*25, 23 + (i/20)*25, 3, gameModel)); + if(level[i].equals("$$")){ + for(int j = 399; j >=0; j--){ + if(gameModel.actors[j] == null){ + gameModel.actors[j] = new grass(23 + (i%20)*25, 23 + (i/20)*25); + break; + } + } + } + if(level[i].equals("==")) + gameModel.addActor(new river(23 + (i%20)*25, 23 + (i/20)*25, gameModel)); + } + } + + public static void spawnEnemy(ServerModel gameModel){ + if(NoOfEnemy < maxNoEnemy && enemyLeft > 0 && (gameModel.gameFlow % enemySpawnTime == 0)){ + int xPos = 23 + (20 -enemyLeft)%3*238; + boolean flashing = (enemyLeft%3 == 0); + gameModel.addActor(new enemy(enemySequence[20-enemyLeft], flashing, xPos, 23, gameModel)); + enemyLeft--; + NoOfEnemy++; + } + } + + public static void reset(){ + currentLevel = 0; + enemySpawnTime = 150; + enemyLeft = 20; + deathCount = 0; + maxNoEnemy = 3; + NoOfEnemy = 0; + } +} \ No newline at end of file diff --git a/源代码/server/src/player.java b/源代码/server/src/player.java new file mode 100644 index 0000000..7995053 --- /dev/null +++ b/源代码/server/src/player.java @@ -0,0 +1,460 @@ +import java.awt.*; + +public class player implements Actor{ + public final int UP = 0; + public final int DOWN = 1; + public final int LEFT = 2; + public final int RIGHT = 3; + public final int size = 12; + public final Rectangle map = new Rectangle(35, 35, 452, 452); + public int scores; + public String type; + public int life; + public int speed; + public int direction; + public int InvulnerableTime; + public int freezed; + public int freezedTime; + public boolean moveUp; + public boolean moveDown; + public boolean moveLeft; + public boolean moveRight; + public boolean fire; + public int numberOfBullet; + public int coolDownTime; + public int status; + public int health; + public int xPos, yPos, xVPos, yVPos; + public Rectangle border; + public Image standardImage; + public Image[] textures; + public ServerModel gameModel; + + public player(String type, ServerModel gameModel){ + this.type = type; + life = 3; + direction = UP; + status = 1; + health = 1; + numberOfBullet = 1; + InvulnerableTime = 150; + this.gameModel = gameModel; + + textures = new Image[4]; + if(type.equals( "1P")){ + //玩家1游戏开启时位置 + xPos = 198; + yPos = 498; + //玩家1的图像 + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[54+i]; + standardImage = textures[0]; + }else{ + //玩家2游戏开启时位置 + xPos = 323; + yPos = 498; + //玩家2的图像 + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[72+i]; + standardImage = textures[0]; + } + + xVPos = xPos; + yVPos = yPos; + border = new Rectangle(xPos - size, yPos - size, 25, 25); + + } + + public void move(){ + if(gameModel.gamePaused){ + writeToOutputLine(); + return; + } + + if(coolDownTime > 0) + coolDownTime--; + if(InvulnerableTime > 0) + InvulnerableTime--; + + if(freezed == 1){ + writeToOutputLine(); + return; + } + + //如果玩家点击“开火”键,并且满足条件,则创建一个子弹目标(即发射子弹) + if(fire && coolDownTime == 0 && numberOfBullet > 0){ + //子弹方向 + int c = direction; + //子弹位置 + int a, b; + if(direction == UP){ + a = xPos; b = yPos - size; + }else if(direction == DOWN){ + a = xPos; b = yPos + size; + }else if(direction == LEFT){ + a = xPos - size; b = yPos; + }else{ + a = xPos + size; b = yPos; + } + //子弹速度 + int d; + if(status == 1){ + numberOfBullet = 1; + d = 7; + }else{ + d = 12; + } + //子弹能力 + int e; + if(status == 4){ + e = 2; + }else{ + e = 1; + } + //添加子弹 + gameModel.addActor(new bullet(a,b,c,d,e, this, gameModel)); + //coolDownTime是你要等到你可以发射第二颗子弹时间(与魔兽争霸3相同) + if(status> 2) + coolDownTime = 5; + else + coolDownTime = 8; + //减少子弹的可用数,子弹发射时numberOfBullet会增加 + //由玩家的坦克击中目标(例如,墙壁,敌人坦克等); + numberOfBullet--; + } + + + //保存当前位置信息,如果新的移动确定后无效,则更改 + //以前的位置 + int xPosTemp = xPos; + int yPosTemp = yPos; + Rectangle borderTemp = new Rectangle(xPosTemp - size, yPosTemp - size, 25,25); + + //根据玩家坦克的移动定义玩家坦克的下一个边界,假设它的下一个移动是有效的; + boolean notMoving = false; + if(moveUp){ + if(direction != UP && direction != DOWN) + xPos = xVPos; + yPos-=speed; + direction = UP; + }else if(moveDown){ + if(direction != UP && direction != DOWN) + xPos = xVPos; + yPos+=speed; + direction = DOWN; + }else if(moveLeft){ + if(direction != LEFT && direction != RIGHT) + yPos = yVPos; + xPos-=speed; + direction = LEFT; + }else if(moveRight){ + if(direction != LEFT && direction != RIGHT) + yPos = yVPos; + xPos+=speed; + direction = RIGHT; + }else{ + notMoving = true; + } + if(notMoving){ + if(speed > 0) + speed--; + }else{ + if(speed < 3) + speed++; + } + + //更新边界 + border.y = yPos - size; + border.x = xPos - size; + + //检查下一个边界是否与地图边界相交,如果不移动到任何地方 + if(!border.intersects(map)){ + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + + + //检查下个边界是否与其他对象相交,如玩家控制的坦克,墙等等 + for(int i = 0; i < gameModel.actors.length; i++){ + if(gameModel.actors[i] != null){ + if(this != gameModel.actors[i] ){ + if(border.intersects(gameModel.actors[i].getBorder())){ + if(gameModel.actors[i].getType().equals("powerUp")){ + scores+=50; + powerUp temp = (powerUp)gameModel.actors[i]; + int function = temp.function; + if(function == 0){ //普通星星,增加速度 + upgrade(); + }else if(function == 1){ //钢墙保护基地 + base tempe = (base)gameModel.actors[4]; + tempe.steelWallTime = 600; + }else if(function == 2){ // 杀死所有的敌方坦克 + for(int j = 0; j < gameModel.actors.length; j++) + if(gameModel.actors[j] != null) + if(gameModel.actors[j].getType().equals("enemy")){ + enemy tempe = (enemy)gameModel.actors[j]; + gameModel.addActor(new bomb(tempe.xPos, tempe.yPos, "big", gameModel)); + gameModel.removeActor(gameModel.actors[j]); + } + level.NoOfEnemy = 0; + level.deathCount = 20 - level.enemyLeft; + }else if(function == 3){ //防护盾,刀枪不入 + InvulnerableTime = 300 + (int)Math.random()*400; + }else if(function == 4){ //冻结所有敌人 + enemy.freezedTime = 300 + (int)Math.random()*400; + enemy.freezedMoment = ServerModel.gameFlow; + }else if(function == 5){ //超级星星 + if(status < 3) + numberOfBullet++; + status =4; + health = 2; + if(type.equals("1P")) + for(int j = 0; j < 4; j ++) + textures[j] = gameModel.textures[66+j]; + else + for(int j = 0; j < 4; j ++) + textures[j] = gameModel.textures[84+j]; + }else if(function == 6){ // 增加生命 + life++; + } + + gameModel.removeActor(gameModel.actors[i]); + + } + //静态对象,如墙壁,河流 + else if(gameModel.actors[i].getType().equals("steelWall") || gameModel.actors[i].getType().equals("wall")){ + if(!gameModel.actors[i].walldestoried()){ + for(int j = 0;j < gameModel.actors[i].getDetailedBorder().length; j++){ + if( gameModel.actors[i].getDetailedBorder()[j] != null){ + if(gameModel.actors[i].getDetailedBorder()[j].intersects(border)){ + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + } + } + } + } + else if(gameModel.actors[i].getType().equals("river") || gameModel.actors[i].getType().equals("base")){ + xPos = xVPos; yPos = yVPos; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + //移动对象,例如敌人坦克 + else if(gameModel.actors[i].getType().equals("enemy") || gameModel.actors[i].getType().equals("Player") ){ + if(!borderTemp.intersects(gameModel.actors[i].getBorder()) || gameModel.actors[i].getType().equals("enemy")){ + xPos = xPosTemp; + yPos = yPosTemp; + border.x = xPos - size; border.y = yPos - size; + writeToOutputLine(); + return; + } + } + } + } + } + } + + //找到坦克的虚拟位置,当90度转弯时,虚拟位置用来调整坦克的真实位置。 + int a = (xPos - 10)/25; + int b = (xPos - 10)%25; + if(b < 7) + b = 0; + if(b > 18) + b = 25; + if((b < 19 && b > 6) || xPos < 17 || xPos > 492) + b = 13; + xVPos = a*25 + b + 10; + int c = (yPos - 10)/25; + int d = (yPos - 10)%25; + if(d < 7) + d = 0; + if(d > 18) + d = 25; + if((d < 19 && d > 6) || yPos < 17 || yPos > 492) + d = 13; + yVPos = c*25 + d + 10; + + writeToOutputLine(); + } + + public void writeToOutputLine(){ + //将变化写入输出行 + gameModel.outputLine+="n"+ xPos + "," + yPos + ","; + int textureIndex = 0; + if(type.equals("1P")){ + if(status == 1) + textureIndex = 54 + direction; + else if (status == 2) + textureIndex = 58 + direction; + else if(status == 3) + textureIndex = 62 + direction; + else + textureIndex = 66 + direction; + }else{ + if(status == 1) + textureIndex = 72 + direction; + else if (status == 2) + textureIndex = 76 + direction; + else if(status == 3) + textureIndex = 80 + direction; + else + textureIndex = 84 + direction; + } + + + gameModel.outputLine+= "" + textureIndex + ";"; + + if(InvulnerableTime > 0) + gameModel.outputLine+="i"+ xPos + "," + yPos + ";"; + } + + public void draw(Graphics g){ + //绘制玩家坦克 + g.drawImage(textures[direction], xPos - size, yPos - size, null); + if(InvulnerableTime > 0){ + g.setColor(Color.red); + g.drawRect(xPos - 12, yPos - 12, 25,25); + g.drawRect(xPos - 11, yPos - 11, 23,23); + } + + //关于玩家的信息,如分数,生命等 + if(type.equals("1P")){ + g.setColor(Color.yellow); + g.drawImage(standardImage, 520, 380, null ); + g.drawString("x", 555, 395); + g.drawString(life + "", 565, 396); + String SCORE = "000000000" + scores; + g.drawString(type +" 得分:" + "", 515, 370); + g.drawString(SCORE.substring(SCORE.length() - 7, SCORE.length()) + "", 566, 370); + } + if(type.equals("2P")){ + g.setColor(Color.green); + g.drawImage(standardImage, 520, 460, null ); + g.drawString("x", 555, 475); + g.drawString(life + "", 565, 476); + String SCORE = "000000000" + scores; + g.drawString(type +" 得分:" + "", 515, 450); + g.drawString(SCORE.substring(SCORE.length() - 7, SCORE.length()) + "", 566, 450); + } + + + } + + public Rectangle getBorder(){ + return border; + } + + public String getType(){ + return "Player"; + } + + public void hurt(){ + if(InvulnerableTime != 0) + return; + + //如果坦克只有1级的健康状态,被击中,那么玩家坦克失去一个生命,如果玩家坦克是最后一次生命,被击中,则game over + //只有吃掉超级星星时,玩家才会有2级的生命健康状态 + if(health == 1){ + gameModel.addActor(new bomb(xPos, yPos, "big", gameModel)); + life--; + if(life == 0){ + xPos = 100000; yPos = 100000; //this will make the player never come back to the main screen, thus looks like "dead" + border = new Rectangle(xPos - size, yPos - size, 25, 25); + xVPos = xPos; yVPos = yPos; + return; + }else{ + direction = UP; + status = 1; + health = 1; + numberOfBullet = 1; + InvulnerableTime = 150; + if(type.equals( "1P")){ + xPos = 198; + yPos = 498; + border = new Rectangle(xPos - size, yPos - size, 25, 25); + xVPos = xPos; yVPos = yPos; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[54+i]; + }else{ + xPos = 323; + yPos = 498; + border = new Rectangle(xPos - size, yPos - size, 25, 25); + xVPos = xPos; yVPos = yPos; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[72+i]; + } + } + }else{ + health--; + status = 3; + if(type.equals( "1P")){ + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[62+i]; + }else{ + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[80+i]; + } + } + } + + public void upgrade(){ + //当玩家坦克吃掉正常的星星时,他的子弹将会升级 + if(type.equals( "1P")){ + if(status == 1){ + status = 2; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[58+i]; + }else if(status == 2){ + status = 3; + numberOfBullet ++; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[62+i]; + }else if(status == 3){ + status = 4; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[66+i]; + } + }else{ + if(status == 1){ + status = 2; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[76+i]; + }else if(status == 2){ + status = 3; + numberOfBullet ++; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[80+i]; + }else if(status == 3){ + status = 4; + for(int i = 0; i < 4; i ++) + textures[i] = gameModel.textures[84+i]; + } + } + } + + public void reset(){ + direction = UP; + InvulnerableTime = 150; + if(type.equals( "1P")){ + xPos = 198; + yPos = 498; + }else{ + xPos = 323; + yPos = 498; + } + + xVPos = xPos; + yVPos = yPos; + border = new Rectangle(xPos - size, yPos - size, 25, 25); + } + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + +} diff --git a/源代码/server/src/powerUp.java b/源代码/server/src/powerUp.java new file mode 100644 index 0000000..c10bf57 --- /dev/null +++ b/源代码/server/src/powerUp.java @@ -0,0 +1,70 @@ +import java.awt.*; + +public class powerUp implements Actor{ + private int xPos; + private int yPos; + public int function; + public Rectangle border; + public int displaytime; + public Image[] textures; + public ServerModel gameModel; + + public powerUp(ServerModel gameModel){ + this.gameModel = gameModel; + //加载图像 + textures = new Image[7]; + for(int i = 0; i < 7; i ++) + textures[i] = gameModel.textures[46+i]; + + xPos = 24 + (int)(Math.random()*475); + yPos = 24 + (int)(Math.random()*475); + int a = (int)(Math.random()*17); + if(0 <= a && a< 3) + function = 0; + if(3 <= a && a < 6) + function = 1; + if(6 <= a && a < 9) + function = 2; + if(9 <= a && a< 12) + function = 3; + if(12 <= a && a < 15) + function = 4; + if(15 <= a && a < 16) + function = 5; + if(16 <= a && a < 17) + function = 6; + displaytime = 100 + (int)(Math.random()*630); + border= new Rectangle(xPos - 12, yPos -12, 25, 25); + } + + public Rectangle getBorder(){ + return border; + } + + public int getFunction(){ + return function; + } + + public String getType(){ + return "powerUp"; + } + + public void move(){ + displaytime--; + if(displaytime == 0) + gameModel.removeActor(this); + + //将变化写入输出行 + gameModel.outputLine+="n"+ xPos + "," + yPos + ","; + gameModel.outputLine+= "" + (46 + function) + ";"; + } + + public void draw(Graphics g){ + g.drawImage(textures[function], xPos - 12, yPos - 12, null); + } + + //未使用的方法 + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;}; + +} \ No newline at end of file diff --git a/源代码/server/src/river.java b/源代码/server/src/river.java new file mode 100644 index 0000000..26c69da --- /dev/null +++ b/源代码/server/src/river.java @@ -0,0 +1,46 @@ +import java.awt.*; + +public class river implements Actor{ + private int xPos; + private int yPos; + private Rectangle Border; + public Image river; + public ServerModel gameModel; + + public river(int a, int b, ServerModel gameModel){ + this.gameModel = gameModel; + river = gameModel.textures[71]; + xPos = a; + yPos = b; + Border = new Rectangle(xPos - 12, yPos - 12, 25, 25); + } + + public Rectangle getBorder(){ + return Border; + } + + public int getxPos(){ + return xPos; + } + + public int getyPos(){ + return yPos; + } + + public String getType(){ + return "river"; + } + + public void draw(Graphics g){ + g.drawImage(river, xPos - 12, yPos - 12, null); + } + + + + //未使用的方法 + public void move(){} + public Rectangle[] getDetailedBorder(){return null;} + public boolean walldestoried(){return false;} + +} + diff --git a/源代码/server/src/wall.java b/源代码/server/src/wall.java new file mode 100644 index 0000000..b08f42c --- /dev/null +++ b/源代码/server/src/wall.java @@ -0,0 +1,1095 @@ +import java.awt.*; + +public class wall implements Actor{ + private int xPos; + private int yPos; + private Rectangle[] border = new Rectangle[4]; + public boolean[] shape = new boolean[16]; + public boolean walldestoried; + public boolean bulletdestoried; + public ServerModel gameModel; + public Image wall; + public Rectangle generalBorder; + + + public wall(int a, int b, ServerModel gameModel){ + xPos = a; + yPos = b; + this.gameModel = gameModel; + wall = gameModel.textures[70]; + generalBorder = new Rectangle(xPos - 12, yPos - 12, 25, 25); + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + + } + + public wall(int a, int b, int orientation, ServerModel gameModel){ + xPos = a; + yPos = b; + this.gameModel = gameModel; + wall = gameModel.textures[70]; + generalBorder = new Rectangle(xPos - 12, yPos - 12, 25, 25); + if(orientation == 0){ + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + for(int i = 8; i < 12; i ++) + shape[i] = true; + for(int i = 12; i < 16; i ++) + shape[i] = true; + } + if(orientation == 1){ + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + for(int i = 0; i < 4; i ++) + shape[i] = true; + for(int i = 4; i < 8; i ++) + shape[i] = true; + } + if(orientation == 2){ + border[0] = new Rectangle(xPos - 11, yPos - 11, 11, 11); + border[2] = new Rectangle(xPos - 11, yPos + 1, 11, 11); + for(int i = 3; i <= 15; i+=4) + shape[i] = true; + for(int i = 2; i <= 14; i+=4) + shape[i] = true; + } + if(orientation == 3){ + border[1] = new Rectangle(xPos + 1, yPos - 11, 11, 11); + border[3] = new Rectangle(xPos + 1, yPos + 1, 11, 11); + for(int i = 1; i <= 13; i+=4) + shape[i] = true; + for(int i = 0; i <= 12; i+=4) + shape[i] = true; + } + + } + + + + public void damageWall(Rectangle bullet, int bulletpower, int bulletdirection){ + + + bulletdestoried = false; + + if(bulletpower == 1){ + if(border[0] != null && border[1] != null && bulletdirection == 1){ + if(bullet.intersects(border[0]) && bullet.intersects(border[1])){ + if(shape[1] && shape[2]){ + for(int i = 4; i < 8; i ++) + shape[i] = true; + border[0] = null; + border[1] = null; + } + if(!shape[1] || !shape[2]){ + for(int i = 0; i < 4; i ++) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[0] != null && border[1] != null && bulletdirection == 0){ + if(bullet.intersects(border[0]) && bullet.intersects(border[1])){ + if(shape[5] && shape[6]){ + for(int i = 0; i < 4; i ++) + shape[i] = true; + border[0] = null; + border[1] = null; + } + if(!shape[5] || !shape[6]){ + for(int i = 4; i < 8; i ++) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[2] != null && border[3] != null && bulletdirection == 1){ + if(bullet.intersects(border[2]) && bullet.intersects(border[3])){ + if(shape[9] && shape[10]){ + for(int i = 12; i < 16; i ++) + shape[i] = true; + border[2] = null; + border[3] = null; + } + if(!shape[9] || !shape[10]){ + for(int i = 8; i < 12; i ++) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[2] != null && border[3] != null && bulletdirection == 0){ + if(bullet.intersects(border[2]) && bullet.intersects(border[3])){ + if(shape[13] && shape[14]){ + for(int i = 8; i < 12; i ++) + shape[i] = true; + border[2] = null; + border[3] = null; + } + if(!shape[13] || !shape[14]){ + for(int i = 12; i < 16; i ++) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[0] != null && border[2] != null && bulletdirection == 3){ + if(bullet.intersects(border[0]) && bullet.intersects(border[2])){ + if(shape[4] && shape[8]){ + for(int i = 1; i <= 13; i+=4) + shape[i] = true; + border[0] = null; + border[2] = null; + } + if(!shape[4] || !shape[8]){ + for(int i = 0; i <= 12; i+=4) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[0] != null && border[2] != null && bulletdirection == 2){ + if(bullet.intersects(border[0]) && bullet.intersects(border[2])){ + if(shape[5] && shape[9]){ + for(int i = 0; i <= 12; i+=4) + shape[i] = true; + border[0] = null; + border[2] = null; + } + if(!shape[5] || !shape[9]){ + for(int i = 1; i <= 13; i+=4) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[1] != null && border[3] != null && bulletdirection == 3){ + if(bullet.intersects(border[1]) && bullet.intersects(border[3])){ + if(shape[6] && shape[10]){ + for(int i = 3; i <= 15; i+=4) + shape[i] = true; + border[1] = null; + border[3] = null; + } + if(!shape[6] || !shape[10]){ + for(int i = 2; i <= 14; i+=4) + shape[i] = true; + } + bulletdestoried = true; + } + } + if(border[1] != null && border[3] != null && bulletdirection == 2){ + if(bullet.intersects(border[1]) && bullet.intersects(border[3])){ + if(shape[7] && shape[11]){ + for(int i = 2; i <= 14; i+=4) + shape[i] = true; + border[1] = null; + border[3] = null; + } + if(!shape[7] || !shape[11]){ + for(int i = 3; i <= 15; i+=4) + shape[i] = true; + } + bulletdestoried = true; + } + } + } + + if(bulletpower == 2){ + if(border[0] != null && border[1] != null && (bulletdirection == 0 || bulletdirection == 1)){ + if(bullet.intersects(border[0]) && bullet.intersects(border[1])){ + for(int i = 0; i < 8; i++) + shape[i] = true; + border[0] = null; + border[1] = null; + bulletdestoried = true; + } + } + if(border[2] != null && border[3] != null && (bulletdirection == 0 || bulletdirection == 1)){ + if(bullet.intersects(border[2]) && bullet.intersects(border[3])){ + for(int i = 8; i < 16; i++) + shape[i] = true; + border[2] = null; + border[3] = null; + bulletdestoried = true; + } + } + if(border[0] != null && border[2] != null && (bulletdirection == 2 || bulletdirection == 3)){ + if(bullet.intersects(border[0]) && bullet.intersects(border[2])){ + for(int i = 0; i <= 12; i+=4) + shape[i] = true; + for(int i = 1; i <= 13; i+=4) + shape[i] = true; + border[0] = null; + border[2] = null; + bulletdestoried = true; + } + } + if(border[1] != null && border[3] != null && (bulletdirection == 2 || bulletdirection == 3)){ + if(bullet.intersects(border[1]) && bullet.intersects(border[3])){ + for(int i = 2; i <= 14; i+=4) + shape[i] = true; + for(int i = 3; i <= 15; i+=4) + shape[i] = true; + border[1] = null; + border[3] = null; + bulletdestoried = true; + } + } + } + + + +//******************************************************************************************* if(border[0] != null ){ + if(border[0] != null){ + Rectangle a = new Rectangle(border[0].x, border[0].y, 5, 5); + Rectangle b = new Rectangle(border[0].x + 7, border[0].y, 5, 5); + Rectangle c = new Rectangle(border[0].x, border[0].y + 7, 5, 5); + Rectangle d = new Rectangle(border[0].x + 7, border[0].y + 7, 5, 5); + if(border[0] != null){ + if(bullet.intersects(border[0]) && bulletdirection == 1 && !(bullet.intersects(b) && ((!shape[2] || !shape[6]) || (shape[1] && shape[2] && shape[5] && shape[6])))){ + if(bullet.intersects(a) && shape[0] && !shape[4]){ + shape[4] = true; + shape[5] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(b) && shape[1] && !shape[5]){ + shape[4] = true; + shape[5] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(a) && !shape[0]) { + if(bulletpower == 1){ + shape[0] = true; + shape[1] = true; + } + if(bulletpower == 2){ + shape[0] = true; + shape[1] = true; + shape[4] = true; + shape[5] = true; + } + bulletdestoried = true; + if(shape[4] && shape[5]) + border[0] = null; + } + if(bullet.intersects(b) && !shape[1]) { + if(bulletpower == 1){ + shape[0] = true; + shape[1] = true; + } + if(bulletpower == 2){ + shape[0] = true; + shape[1] = true; + shape[4] = true; + shape[5] = true; + } + bulletdestoried = true; + if(shape[4] && shape[5]) + border[0] = null; + } + } + } + if(border[0] != null){ + if(bullet.intersects(border[0]) && bulletdirection == 0 && !(bullet.intersects(d) && ((!shape[2] || !shape[6]) || (shape[1] && shape[2] && shape[5] && shape[6])))){ + if(bullet.intersects(c) && shape[4] && !shape[0]){ + shape[0] = true; + shape[1] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(d) && shape[5] && !shape[1]){ + shape[0] = true; + shape[1] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(c) && !shape[4]){ + if(bulletpower == 1){ + shape[4] = true; + shape[5] = true; + } + if(bulletpower == 2){ + shape[4] = true; + shape[5] = true; + shape[1] = true; + shape[0] = true; + } + bulletdestoried = true; + if(shape[0] && shape[1]) + border[0] = null; + } + if(bullet.intersects(d) && !shape[5]){ + if(bulletpower == 1){ + shape[4] = true; + shape[5] = true; + } + if(bulletpower == 2){ + shape[4] = true; + shape[5] = true; + shape[1] = true; + shape[0] = true; + } + bulletdestoried = true; + if(shape[0] && shape[1]) + border[0] = null; + } + } + } + if(border[0] != null){ + if(bullet.intersects(border[0]) && bulletdirection == 3 && !(bullet.intersects(c) && ((!shape[8] || !shape[9]) || (shape[4] && shape[5] && shape[8] && shape[9])))){ + if(bullet.intersects(a) && shape[0] && !shape[1]){ + shape[1] = true; + shape[5] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(c) && shape[4] && !shape[5]){ + shape[1] = true; + shape[5] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(a) && !shape[0]){ + if(bulletpower == 1){ + shape[0] = true; + shape[4] = true; + } + if(bulletpower == 2){ + shape[0] = true; + shape[4] = true; + shape[1] = true; + shape[5] = true; + } + bulletdestoried = true; + if(shape[1] && shape[5]) + border[0] = null; + } + if(bullet.intersects(c) && !shape[4]){ + if(bulletpower == 1){ + shape[0] = true; + shape[4] = true; + } + if(bulletpower == 2){ + shape[0] = true; + shape[4] = true; + shape[1] = true; + shape[5] = true; + } + bulletdestoried = true; + if(shape[1] && shape[5]) + border[0] = null; + } + } + } + if(border[0] != null){ + if(bullet.intersects(border[0]) && bulletdirection == 2 && !(bullet.intersects(d) && ((!shape[8] || !shape[9]) || (shape[4] && shape[5] && shape[8] && shape[9])))){ + if(bullet.intersects(b) && shape[1] && !shape[0]){ + shape[0] = true; + shape[4] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(d) && shape[5] && !shape[4]){ + shape[0] = true; + shape[4] = true; + bulletdestoried = true; + border[0] = null; + } + if(bullet.intersects(b) && !shape[1]){ + if(bulletpower == 1){ + shape[1] = true; + shape[5] = true; + } + if(bulletpower == 2){ + shape[1] = true; + shape[5] = true; + shape[0] = true; + shape[4] = true; + } + bulletdestoried = true; + if(shape[0] && shape[4]) + border[0] = null; + } + if(bullet.intersects(d) && !shape[5]){ + if(bulletpower == 1){ + shape[1] = true; + shape[5] = true; + } + if(bulletpower == 2){ + shape[1] = true; + shape[5] = true; + shape[0] = true; + shape[4] = true; + } + bulletdestoried = true; + if(shape[0] && shape[4]) + border[0] = null; + } + } + } + } + //******************************************************************************* + if(border[1] != null ){ + Rectangle a = new Rectangle(border[1].x, border[1].y, 5, 5); + Rectangle b = new Rectangle(border[1].x + 7, border[1].y, 5, 5); + Rectangle c = new Rectangle(border[1].x, border[1].y + 7, 5, 5); + Rectangle d = new Rectangle(border[1].x + 7, border[1].y + 7, 5, 5); + if(border[1] != null){ + if(bullet.intersects(border[1]) && bulletdirection == 1 && !(bullet.intersects(a) && ((!shape[1] || !shape[5]) || (shape[1] && shape[2] && shape[5] && shape[6])))){ + if(bullet.intersects(a) && shape[2] && !shape[6]){ + shape[6] = true; + shape[7] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(b) && shape[3] && !shape[7]){ + shape[6] = true; + shape[7] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(a) && !shape[2]) { + if(bulletpower == 1){ + shape[2] = true; + shape[3] = true; + } + if(bulletpower == 2){ + shape[2] = true; + shape[3] = true; + shape[6] = true; + shape[7] = true; + } + bulletdestoried = true; + if(shape[6] && shape[7]) + border[1] = null; + } + if(bullet.intersects(b) && !shape[3]) { + if(bulletpower == 1){ + shape[2] = true; + shape[3] = true; + } + if(bulletpower == 2){ + shape[2] = true; + shape[3] = true; + shape[6] = true; + shape[7] = true; + } + bulletdestoried = true; + if(shape[6] && shape[7]) + border[1] = null; + } + } + } + if(border[1] != null){ + if(bullet.intersects(border[1]) && bulletdirection == 0 && !(bullet.intersects(c) && ((!shape[1] || !shape[5]) || (shape[1] && shape[2] && shape[5] && shape[6])))){ + if(bullet.intersects(c) && shape[6] && !shape[2]){ + shape[2] = true; + shape[3] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(d) && shape[7] && !shape[3]){ + shape[2] = true; + shape[3] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(c) && !shape[6]){ + if(bulletpower == 1){ + shape[6] = true; + shape[7] = true; + } + if(bulletpower == 2){ + shape[6] = true; + shape[7] = true; + shape[2] = true; + shape[3] = true; + } + bulletdestoried = true; + if(shape[2] && shape[3]) + border[1] = null; + } + if(bullet.intersects(d) && !shape[7]){ + if(bulletpower == 1){ + shape[6] = true; + shape[7] = true; + } + if(bulletpower == 2){ + shape[6] = true; + shape[7] = true; + shape[2] = true; + shape[3] = true; + } + bulletdestoried = true; + if(shape[2] && shape[3]) + border[1] = null; + } + } + } + if(border[1] != null){ + if(bullet.intersects(border[1]) && bulletdirection == 3 && !(bullet.intersects(c) && ((!shape[10] || !shape[11]) || (shape[6] && shape[7] && shape[10] && shape[11])))){ + if(bullet.intersects(a) && shape[2] && !shape[3]){ + shape[3] = true; + shape[7] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(c) && shape[6] && !shape[7]){ + shape[3] = true; + shape[7] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(a) && !shape[2]){ + if(bulletpower == 1){ + shape[2] = true; + shape[6] = true; + } + if(bulletpower == 2){ + shape[2] = true; + shape[6] = true; + shape[3] = true; + shape[7] = true; + } + bulletdestoried = true; + if(shape[3] && shape[7]) + border[1] = null; + } + if(bullet.intersects(c) && !shape[6]){ + if(bulletpower == 1){ + shape[2] = true; + shape[6] = true; + } + if(bulletpower == 2){ + shape[2] = true; + shape[6] = true; + shape[3] = true; + shape[7] = true; + } + bulletdestoried = true; + if(shape[3] && shape[7]) + border[1] = null; + } + } + } + if(border[1] != null){ + if(bullet.intersects(border[1]) && bulletdirection == 2 && !(bullet.intersects(d) && ((!shape[10] || !shape[11]) || (shape[6] && shape[7] && shape[10] && shape[11])))){ + if(bullet.intersects(b) && shape[3] && !shape[2]){ + shape[2] = true; + shape[6] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(d) && shape[7] && !shape[6]){ + shape[2] = true; + shape[6] = true; + bulletdestoried = true; + border[1] = null; + } + if(bullet.intersects(b) && !shape[3]){ + if(bulletpower == 1){ + shape[3] = true; + shape[7] = true; + } + if(bulletpower == 2){ + shape[3] = true; + shape[7] = true; + shape[2] = true; + shape[6] = true; + } + bulletdestoried = true; + if(shape[2] && shape[6]) + border[1] = null; + } + if(bullet.intersects(d) && !shape[7]){ + if(bulletpower == 1){ + shape[3] = true; + shape[7] = true; + } + if(bulletpower == 2){ + shape[3] = true; + shape[7] = true; + shape[2] = true; + shape[6] = true; + } + bulletdestoried = true; + if(shape[2] && shape[6]) + border[1] = null; + } + } + } + } + + //*********************************************************************************** + if(border[2] != null ){ + Rectangle a = new Rectangle(border[2].x, border[2].y, 5, 5); + Rectangle b = new Rectangle(border[2].x + 7, border[2].y, 5, 5); + Rectangle c = new Rectangle(border[2].x, border[2].y + 7, 5, 5); + Rectangle d = new Rectangle(border[2].x + 7, border[2].y + 7, 5, 5); + if(border[2] != null ){ + if(bullet.intersects(border[2]) && bulletdirection == 1 && !(bullet.intersects(b) && ((!shape[10] || !shape[14]) || (shape[9] && shape[10] && shape[13] && shape[14])))){ + if(bullet.intersects(a) && shape[8] && !shape[12]){ + shape[12] = true; + shape[13] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(b) && shape[9] && !shape[13]){ + shape[12] = true; + shape[13] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(a) && !shape[8]) { + if(bulletpower == 1){ + shape[8] = true; + shape[9] = true; + } + if(bulletpower == 2){ + shape[8] = true; + shape[9] = true; + shape[12] = true; + shape[13] = true; + } + bulletdestoried = true; + if(shape[12] && shape[13]) + border[2] = null; + } + if(bullet.intersects(b) && !shape[9]) { + if(bulletpower == 1){ + shape[8] = true; + shape[9] = true; + } + if(bulletpower == 2){ + shape[8] = true; + shape[9] = true; + shape[12] = true; + shape[13] = true; + } + bulletdestoried = true; + if(shape[12] && shape[13]) + border[2] = null; + } + } + } + if(border[2] != null){ + if(bullet.intersects(border[2]) && bulletdirection == 0 && !(bullet.intersects(d) && ((!shape[10] || !shape[14]) || (shape[9] && shape[10] && shape[13] && shape[14])))){ + if(bullet.intersects(c) && shape[12] && !shape[8]){ + shape[8] = true; + shape[9] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(d) && shape[13] && !shape[9]){ + shape[8] = true; + shape[9] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(c) && !shape[12]){ + if(bulletpower == 1){ + shape[12] = true; + shape[13] = true; + } + if(bulletpower == 2){ + shape[12] = true; + shape[13] = true; + shape[8] = true; + shape[9] = true; + } + bulletdestoried = true; + if(shape[8] && shape[9]) + border[2] = null; + } + if(bullet.intersects(d) && !shape[13]){ + if(bulletpower == 1){ + shape[12] = true; + shape[13] = true; + } + if(bulletpower == 2){ + shape[12] = true; + shape[13] = true; + shape[8] = true; + shape[9] = true; + } + bulletdestoried = true; + if(shape[8] && shape[9]) + border[2] = null; + } + } + } + if(border[2] != null){ + if(bullet.intersects(border[2]) && bulletdirection == 3 && !(bullet.intersects(a) && ((!shape[4] || !shape[5]) || (shape[4] && shape[5] && shape[8] && shape[9])))){ + if(bullet.intersects(a) && shape[8] && !shape[9]){ + shape[9] = true; + shape[13] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(c) && shape[12] && !shape[13]){ + shape[9] = true; + shape[13] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(a) && !shape[8]){ + if(bulletpower == 1){ + shape[8] = true; + shape[12] = true; + } + if(bulletpower == 2){ + shape[8] = true; + shape[12] = true; + shape[9] = true; + shape[13] = true; + } + bulletdestoried = true; + if(shape[9] && shape[13]) + border[2] = null; + } + if(bullet.intersects(c) && !shape[12]){ + if(bulletpower == 1){ + shape[8] = true; + shape[12] = true; + } + if(bulletpower == 2){ + shape[8] = true; + shape[12] = true; + shape[9] = true; + shape[13] = true; + } + bulletdestoried = true; + if(shape[9] && shape[13]) + border[2] = null; + } + } + } + if(border[2] != null){ + if(bullet.intersects(border[2]) && bulletdirection == 2 && !(bullet.intersects(b) && ((!shape[4] || !shape[5]) || (shape[4] && shape[5] && shape[8] && shape[9])))){ + if(bullet.intersects(b) && shape[9] && !shape[8]){ + shape[8] = true; + shape[12] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(d) && shape[13] && !shape[12]){ + shape[8] = true; + shape[12] = true; + bulletdestoried = true; + border[2] = null; + } + if(bullet.intersects(b) && !shape[9]){ + if(bulletpower == 1){ + shape[9] = true; + shape[13] = true; + } + if(bulletpower == 2){ + shape[9] = true; + shape[13] = true; + shape[8] = true; + shape[12] = true; + } + bulletdestoried = true; + if(shape[8] && shape[12]) + border[2] = null; + } + if(bullet.intersects(d) && !shape[13]){ + if(bulletpower == 1){ + shape[9] = true; + shape[13] = true; + } + if(bulletpower == 2){ + shape[9] = true; + shape[13] = true; + shape[8] = true; + shape[12] = true; + } + bulletdestoried = true; + if(shape[8] && shape[12]) + border[2] = null; + } + } + } + + } + //************************************************************************************ + if(border[3] != null ){ + Rectangle a = new Rectangle(border[3].x, border[3].y, 5, 5); + Rectangle b = new Rectangle(border[3].x + 7, border[3].y, 5, 5); + Rectangle c = new Rectangle(border[3].x, border[3].y + 7, 5, 5); + Rectangle d = new Rectangle(border[3].x + 7, border[3].y + 7, 5, 5); + if(border[3] != null ){ + if(bullet.intersects(border[3]) && bulletdirection == 1 && !(bullet.intersects(a) && ((!shape[9] || !shape[13]) || (shape[9] && shape[10] && shape[13] && shape[14])))){ + if(bullet.intersects(a) && shape[10] && !shape[14]){ + shape[14] = true; + shape[15] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(b) && shape[11] && !shape[15]){ + shape[14] = true; + shape[15] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(a) && !shape[10]) { + if(bulletpower == 1){ + shape[10] = true; + shape[11] = true; + } + if(bulletpower == 2){ + shape[10] = true; + shape[11] = true; + shape[14] = true; + shape[15] = true; + } + bulletdestoried = true; + if(shape[14] && shape[15]) + border[3] = null; + } + if(bullet.intersects(b) && !shape[11]) { + if(bulletpower == 1){ + shape[10] = true; + shape[11] = true; + } + if(bulletpower == 2){ + shape[10] = true; + shape[11] = true; + shape[14] = true; + shape[15] = true; + } + bulletdestoried = true; + if(shape[14] && shape[15]) + border[3] = null; + } + } + } + if(border[3] != null){ + if(bullet.intersects(border[3]) && bulletdirection == 0 && !(bullet.intersects(c) && ((!shape[9] || !shape[13]) || (shape[9] && shape[10] && shape[13] && shape[14])))){ + if(bullet.intersects(c) && shape[14] && !shape[10]){ + shape[10] = true; + shape[11] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(d) && shape[15] && !shape[11]){ + shape[10] = true; + shape[11] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(c) && !shape[14]){ + if(bulletpower == 1){ + shape[14] = true; + shape[15] = true; + } + if(bulletpower == 2){ + shape[14] = true; + shape[15] = true; + shape[10] = true; + shape[11] = true; + } + bulletdestoried = true; + if(shape[10] && shape[11]) + border[3] = null; + } + if(bullet.intersects(d) && !shape[15]){ + if(bulletpower == 1){ + shape[14] = true; + shape[15] = true; + } + if(bulletpower == 2){ + shape[14] = true; + shape[15] = true; + shape[10] = true; + shape[11] = true; + } + bulletdestoried = true; + if(shape[10] && shape[11]) + border[3] = null; + } + } + } + if(border[3] != null){ + if(bullet.intersects(border[3]) && bulletdirection == 3 && !(bullet.intersects(a) && ((!shape[6] || !shape[7]) || (shape[6] && shape[7] && shape[10] && shape[11])))){ + if(bullet.intersects(a) && shape[10] && !shape[11]){ + shape[11] = true; + shape[15] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(c) && shape[14] && !shape[15]){ + shape[11] = true; + shape[15] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(a) && !shape[10]){ + if(bulletpower == 1){ + shape[10] = true; + shape[14] = true; + } + if(bulletpower == 2){ + shape[10] = true; + shape[14] = true; + shape[11] = true; + shape[15] = true; + } + bulletdestoried = true; + if(shape[11] && shape[15]) + border[3] = null; + } + if(bullet.intersects(c) && !shape[14]){ + if(bulletpower == 1){ + shape[10] = true; + shape[14] = true; + } + if(bulletpower == 2){ + shape[10] = true; + shape[14] = true; + shape[11] = true; + shape[15] = true; + } + bulletdestoried = true; + if(shape[11] && shape[15]) + border[3] = null; + } + } + } + if(border[3] != null){ + if(bullet.intersects(border[3]) && bulletdirection == 2 && !(bullet.intersects(b) && ((!shape[6] || !shape[7]) || (shape[6] && shape[7] && shape[10] && shape[11])))){ + if(bullet.intersects(b) && shape[11] && !shape[10]){ + shape[10] = true; + shape[14] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(d) && shape[15] && !shape[14]){ + shape[10] = true; + shape[14] = true; + bulletdestoried = true; + border[3] = null; + } + if(bullet.intersects(b) && !shape[11]){ + if(bulletpower == 1){ + shape[11] = true; + shape[15] = true; + } + if(bulletpower == 2){ + shape[11] = true; + shape[15] = true; + shape[10] = true; + shape[14] = true; + } + bulletdestoried = true; + if(shape[10] && shape[14]) + border[3] = null; + } + if(bullet.intersects(d) && !shape[15]){ + if(bulletpower == 1){ + shape[11] = true; + shape[15] = true; + } + if(bulletpower == 2){ + shape[11] = true; + shape[15] = true; + shape[10] = true; + shape[14] = true; + } + bulletdestoried = true; + if(shape[10] && shape[14]) + border[3] = null; + } + } + } + } + + //write changes to the outputline + gameModel.outputLine+="w" + xPos + ","+ yPos+","; + for(int i = 0; i < shape.length; i++){ + if(shape[i]) + gameModel.outputLine+="1"; + else + gameModel.outputLine+="0"; + } + gameModel.outputLine+=";"; + + } +//=========================================================================================== + + public boolean walldestoried(){ + if(walldestoried) + return true; + walldestoried = true; + for(int i = 0; i < shape.length; i++) + if(!shape[i]){ + walldestoried = false; + break; + } + return walldestoried; + } + + + public Rectangle getBorder(){ + return generalBorder; + } + + public Rectangle[] getDetailedBorder(){ + return border; + } + + + public void draw(Graphics g) { + if(walldestoried) + return; + g.drawImage(wall, xPos - 12, yPos - 12, null); + g.setColor(new Color(128, 64, 0)); + if(shape[0]) + g.fillRect(xPos - 12, yPos - 12, 7, 7); + if(shape[1]) + g.fillRect(xPos - 6, yPos - 12, 7, 7); + if(shape[2]) + g.fillRect(xPos, yPos - 12, 7, 7); + if(shape[3]) + g.fillRect(xPos + 6, yPos - 12, 7, 7); + if(shape[4]) + g.fillRect(xPos - 12, yPos - 6, 7, 7); + if(shape[5]) + g.fillRect(xPos - 6, yPos - 6, 7, 7); + if(shape[6]) + g.fillRect(xPos, yPos - 6, 7, 7); + if(shape[7]) + g.fillRect(xPos + 6, yPos - 6, 7, 7); + if(shape[8]) + g.fillRect(xPos - 12, yPos, 7, 7); + if(shape[9]) + g.fillRect(xPos - 6, yPos, 7, 7); + if(shape[10]) + g.fillRect(xPos, yPos, 7, 7); + if(shape[11]) + g.fillRect(xPos + 6, yPos, 7, 7); + if(shape[12]) + g.fillRect(xPos - 12, yPos + 6, 7, 7); + if(shape[13]) + g.fillRect(xPos - 6, yPos + 6, 7, 7); + if(shape[14]) + g.fillRect(xPos, yPos + 6, 7, 7); + if(shape[15]) + g.fillRect(xPos + 6, yPos + 6, 7, 7); + } + + public String getType(){ + return "wall"; + } + + + //未使用的方法 + public void move(){} +} + + +