Commit 24a8caf2 authored by 9731301's avatar 9731301

change wall structure

parent 05bedc2e
...@@ -2,40 +2,40 @@ ...@@ -2,40 +2,40 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment=""> <list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/UI/MyListener.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/Rendering.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameFrame.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maps/map1.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map1.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/maps/map2.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map2.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maps/map3.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map3.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState$KeyHandler2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState$KeyHandler2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$KeyHandler.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$KeyHandler1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$KeyHandler1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$MouseHandler.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$MouseHandler.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$MouseHandler.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState$MouseHandler.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$1.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState$WallData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState$WallData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$2.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$3.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Setting.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Setting.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pics/tank_blue.png" beforeDir="false" afterPath="$PROJECT_DIR$/pics/tank_blue.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pics/tank_dark.png" beforeDir="false" afterPath="$PROJECT_DIR$/pics/tank_dark.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pics/tank_green.png" beforeDir="false" afterPath="$PROJECT_DIR$/pics/tank_green.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pics/tank_sand.png" beforeDir="false" afterPath="$PROJECT_DIR$/pics/tank_sand.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/TankState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameState/TankState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameState/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="DatabaseView">
<option name="SHOW_INTERMEDIATE" value="true" />
<option name="GROUP_DATA_SOURCES" value="true" />
<option name="GROUP_SCHEMA" value="true" />
<option name="GROUP_CONTENTS" value="false" />
<option name="SORT_POSITIONED" value="false" />
<option name="SHOW_EMPTY_GROUPS" value="false" />
<option name="AUTO_SCROLL_FROM_SOURCE" value="false" />
<option name="HIDDEN_KINDS">
<set />
</option>
<expand />
<select />
</component>
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
...@@ -135,7 +135,8 @@ ...@@ -135,7 +135,8 @@
<workItem from="1596026842920" duration="4069000" /> <workItem from="1596026842920" duration="4069000" />
<workItem from="1596042670145" duration="24545000" /> <workItem from="1596042670145" duration="24545000" />
<workItem from="1596134290663" duration="37548000" /> <workItem from="1596134290663" duration="37548000" />
<workItem from="1596205210217" duration="611000" /> <workItem from="1596205210217" duration="16177000" />
<workItem from="1596226360961" duration="600000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -147,10 +148,10 @@ ...@@ -147,10 +148,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1595580808418" /> <state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1595580808418" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596157366636"> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596220903263">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596157366636" /> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596220903263" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596028833005"> <state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596028833005">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -163,30 +164,30 @@ ...@@ -163,30 +164,30 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" /> <state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" />
<state width="1493" height="225" key="GridCell.Tab.0.bottom" timestamp="1596174690095"> <state width="1493" height="104" key="GridCell.Tab.0.bottom" timestamp="1596222336558">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="225" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596174690095" /> <state width="1493" height="104" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596222336558" />
<state width="1493" height="225" key="GridCell.Tab.0.center" timestamp="1596174690095"> <state width="1493" height="104" key="GridCell.Tab.0.center" timestamp="1596222336558">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="225" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596174690095" /> <state width="1493" height="104" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596222336558" />
<state width="1493" height="225" key="GridCell.Tab.0.left" timestamp="1596174690094"> <state width="1493" height="104" key="GridCell.Tab.0.left" timestamp="1596222336557">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="225" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596174690094" /> <state width="1493" height="104" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596222336557" />
<state width="1493" height="225" key="GridCell.Tab.0.right" timestamp="1596174690095"> <state width="1493" height="104" key="GridCell.Tab.0.right" timestamp="1596222336558">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="225" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596174690095" /> <state width="1493" height="104" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596222336558" />
<state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731"> <state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" /> <state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596205227078"> <state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596226398477">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596205227078" /> <state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596226398477" />
<state x="209" y="33" key="new project wizard" timestamp="1593723788909"> <state x="209" y="33" key="new project wizard" timestamp="1593723788909">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -195,10 +196,10 @@ ...@@ -195,10 +196,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1595774253325" /> <state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1595774253325" />
<state x="426" y="187" key="run.anything.popup" timestamp="1595788998130"> <state x="426" y="187" key="run.anything.popup" timestamp="1596226569574">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1595788998130" /> <state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1596226569574" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595684580506"> <state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595684580506">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
100111000111011100001 100111000111011100001
101100000000000100111 101100000000000100111
100000111100111100001 100000111100111100001
100000010000010000001
111111111111111111111 111111111111111111111
\ No newline at end of file
1111111 11111
1000001 10101
1010001 10111
1111111 10101
\ No newline at end of file 11111
\ No newline at end of file
111111111 1111111111111
100100001 1001001000001
100100011 1001100010001
101100001 1011020011111
101000001 1000020010001
101101111 1011011110001
100100001 1001000000111
111111111 1111111111111
\ No newline at end of file \ No newline at end of file
...@@ -9,14 +9,14 @@ import java.awt.event.KeyEvent; ...@@ -9,14 +9,14 @@ import java.awt.event.KeyEvent;
public class BulletState { public class BulletState {
public int locX, locY, diam , angle; public int locX, locY, diam , angle;
private WallState wallState; private WallState walls;
private boolean keySpace; private boolean keySpace;
private KeyHandler2 keyHandler2 = new KeyHandler2(); private KeyHandler2 keyHandler2 = new KeyHandler2();
private long createTime; private long createTime;
public BulletState(WallState wallState , TankState tankState){ public BulletState(WallState wallState , TankState tankState){
this.wallState = wallState ; this.walls = wallState ;
// Initialize the game state and all elements ... // Initialize the game state and all elements ...
locX = tankState.locX; locX = tankState.locX;
locY = tankState.locY; locY = tankState.locY;
...@@ -30,6 +30,15 @@ public class BulletState { ...@@ -30,6 +30,15 @@ public class BulletState {
public void update(){ public void update(){
locY += 10*Math.sin(Math.toRadians(angle) ) ; locY += 10*Math.sin(Math.toRadians(angle) ) ;
locX += 10*Math.cos(Math.toRadians(angle) ) ; locX += 10*Math.cos(Math.toRadians(angle) ) ;
for (WallState.WallData wall : walls.getWalls()){
if (wall.isWall(locX , locY) && wall.isHorizontal()) {
locY -= 10 * Math.sin(Math.toRadians(angle));
}
if (wall.isWall(locX , locY)&& wall.isVertical()){
locX-= 10*Math.cos(Math.toRadians(angle) ) ;
}
}
} }
......
...@@ -71,7 +71,6 @@ public class TankState { ...@@ -71,7 +71,6 @@ public class TankState {
if (keyUP) { if (keyUP) {
if (rotate == 0) if (rotate == 0)
rotate = 360; rotate = 360;
System.out.println(rotate);
locY -= 8; locY -= 8;
if ((rotate > 180 && rotate < 270)|| rotate ==180 ) if ((rotate > 180 && rotate < 270)|| rotate ==180 )
rotate +=10; rotate +=10;
...@@ -115,7 +114,6 @@ public class TankState { ...@@ -115,7 +114,6 @@ public class TankState {
if (bullets.size() == 0 || System.currentTimeMillis() -bullets.get(bullets.size()-1).getCreateTime()>500 ) { if (bullets.size() == 0 || System.currentTimeMillis() -bullets.get(bullets.size()-1).getCreateTime()>500 ) {
BulletState newBullet = new BulletState(walls, this); BulletState newBullet = new BulletState(walls, this);
bullets.add(newBullet); bullets.add(newBullet);
System.out.println(newBullet.angle);
} }
} }
...@@ -206,9 +204,6 @@ public class TankState { ...@@ -206,9 +204,6 @@ public class TankState {
} }
public void setWalls(WallState walls) {
this.walls = walls;
}
/** /**
* The mouse handler. * The mouse handler.
......
package UI.GameState; package UI.GameState;
import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -16,6 +18,9 @@ public class WallState { ...@@ -16,6 +18,9 @@ public class WallState {
private int numRows, numColumns, w, h; private int numRows, numColumns, w, h;
private final int wallWidth = 5; private final int wallWidth = 5;
private ArrayList<WallData> walls = new ArrayList<>(); private ArrayList<WallData> walls = new ArrayList<>();
private Image wall1 ;
private Image wall2 ;
private Image blank ;
public WallState(int GAME_WIDTH, int GAME_HEIGHT) { public WallState(int GAME_WIDTH, int GAME_HEIGHT) {
...@@ -24,6 +29,9 @@ public class WallState { ...@@ -24,6 +29,9 @@ public class WallState {
try { try {
source = new String(Files.readAllBytes(Paths.get("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map3.txt")), StandardCharsets.UTF_8); source = new String(Files.readAllBytes(Paths.get("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map3.txt")), StandardCharsets.UTF_8);
wall1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall1.png"));
wall2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall2.png"));
blank = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\blank.png"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -34,18 +42,48 @@ public class WallState { ...@@ -34,18 +42,48 @@ public class WallState {
h = (frameY-30) / (numRows); //sideY h = (frameY-30) / (numRows); //sideY
w = (frameX-10) / (numColumns); //sideX w = (frameX-10) / (numColumns); //sideX
} }
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
Image wall1scaled = wall1.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
Image wall2scaled = wall2.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
Image blankScaled = blank.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
// Draw background // Draw background
walls.clear(); walls.clear();
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.fillRect(0, 0, frameX, frameY); g.fillRect(0, 0, frameX, frameY);
g.setColor(Color.black); //colour of the walls g.setColor(Color.black); //colour of the walls
int x = 0;
int y = 0;
for (int r = 0; r < numRows; r++) {
x = 0 ;
String rowChars = lines[r];
for (int c = 0; c < numColumns; c++) {
if (rowChars.charAt(c) == '0') {
drawBlanks(g, x, y ,blankScaled);
x += w;
}
else if (rowChars.charAt(c) == '1') {
drawAndSaveWalls(g, x, y, r , c, wall1scaled);
x += w;
}
else if (rowChars.charAt(c) == '2') {
drawAndSaveWalls(g, x, y, r , c, wall2scaled);
x += w;
}
}
y += h;
}
int start = 10; /* int start = 10;
int startTop = 30; int startTop = 30;
for (int r = 0; r < numRows; r++) { for (int r = 0; r < numRows; r++) {
String rowChars = lines[r]; String rowChars = lines[r];
...@@ -98,12 +136,25 @@ public class WallState { ...@@ -98,12 +136,25 @@ public class WallState {
} }
} }
//draw frame */
g.setColor(Color.WHITE); }
g.fillRect(0,frameX,frameX,startTop);
g.fillRect(0,0,start,frameY);
g.fillRect(frameX-start,0,start,frameY);
g.fillRect(0,frameY-start,frameX,start); private void drawAndSaveWalls(Graphics g2d,int x,int y , int r , int c ,Image image){
WallData wall = new WallData(x , y , w, h);
if ((c<numColumns-1 && lines[r].charAt(c+1)=='1') || (c>0 && lines[r].charAt(c-1)=='1')){ //horizontal
wall.setHorizontal(true);
}
if ((r>0 && lines[r-1].charAt(c)=='1') || (r>0 && r<numRows-1 && lines[r+1].charAt(c)=='1')) { //vertical
wall.setVertical(true);
}
walls.add(wall);
g2d.drawImage(image , x , y , null);
}
private void drawBlanks(Graphics g2d,int x,int y,Image image){
g2d.drawImage(image , x , y , null);
} }
public boolean isWall(int x,int y){ public boolean isWall(int x,int y){
...@@ -113,15 +164,15 @@ public class WallState { ...@@ -113,15 +164,15 @@ public class WallState {
return false; return false;
} }
private void draw(Graphics g,int x,int y,int w,int h){
walls.add(new WallData(x,y,w,h));
g.fillRect(x,y,w,h);
}
public ArrayList<WallData> getWalls() {
return walls;
}
public class WallData { public class WallData {
int x,y,w,h; private int x,y,w,h;
private boolean horizontal = false;
private boolean vertical = false;
public WallData(int x,int y,int w,int h){ public WallData(int x,int y,int w,int h){
this.x = x; this.x = x;
...@@ -134,5 +185,21 @@ public class WallState { ...@@ -134,5 +185,21 @@ public class WallState {
//BUG //BUG
return (x>this.x && x<this.x+w && y>this.y && y<this.y+h); return (x>this.x && x<this.x+w && y>this.y && y<this.y+h);
} }
public boolean isHorizontal() {
return horizontal;
}
public void setHorizontal(boolean horizontal) {
this.horizontal = horizontal;
}
public boolean isVertical() {
return vertical;
}
public void setVertical(boolean vertical) {
this.vertical = vertical;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment