naval battle game

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
azwraith69 azwraith69 is offline Offline Oct 17th, 2009, 1:23 am |
0
Hello...

This is my naval battle game so far..
Just search i t if you're unfamiliar with the game
it is only player vs computer..

can you adjust/fix my code so that:

-the player is able to place his ships by means of dragging the JLabel ships at the left to the playing area...

-the computerAI can randomly place his ships on its play area

-the computerAI can wisely(with randomness) select my ships

thanks in advance
by the way, i don't frequent the net so please be direct in the post and avoid asking me things that just waste time..
i need to finish this project asap.
Quick reply to this message  
Java Syntax
  1. import java.awt.BorderLayout;
  2. import java.awt.FlowLayout;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.GridLayout;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.MouseAdapter;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14.  
  15. import javax.swing.Icon;
  16. import javax.swing.ImageIcon;
  17. import javax.swing.JButton;
  18. import javax.swing.JFrame;
  19. import javax.swing.JLabel;
  20. import javax.swing.JPanel;
  21. import javax.swing.JScrollPane;
  22. import javax.swing.JTextArea;
  23. import javax.swing.border.TitledBorder;
  24.  
  25. //import PlayArea.ButtonHandler;
  26.  
  27.  
  28. public class PlayArea extends JPanel {
  29. private static final long serialVersionUID = 69L;
  30. private static final int POINTLESS = 0;
  31. private static final int POINTFUL = 2;
  32.  
  33. protected int selectedShip = 0;
  34. protected int selectedShipSize = 0;
  35. private int mode = POINTLESS;
  36. //private Point curCursor;
  37.  
  38. static Image target, hit, missed;
  39. private JLabel carrierH, battleshipH, destroyerH, submarineH, patrolboatH;
  40. private JLabel carrierV, battleshipV, destroyerV, submarineV, patrolboatV;
  41. static Ship shipsH[] = new Ship[6];
  42. static Ship shipsV[] = new Ship[6];
  43.  
  44. private GridArea playerGrid, computerGrid;
  45. private JPanel fieldsP, shipsP, messageP;
  46. private JTextArea messageTA;
  47.  
  48. public PlayArea() {
  49. JPanel mainPanel = new JPanel(new BorderLayout(20, 5));
  50. this.setLayout(new BorderLayout());
  51.  
  52.  
  53. target = (new ImageIcon("images/shoot.gif")).getImage();
  54. hit = (new ImageIcon("images/firex.gif")).getImage();
  55. missed = (new ImageIcon("images/splash.gif")).getImage();
  56.  
  57. fieldsP = new JPanel();
  58. playerGrid = new PlayerGrid(this);
  59. computerGrid = new ComputerGrid(this);
  60. fieldsP.setLayout(new FlowLayout());
  61. fieldsP.add(playerGrid);
  62. fieldsP.add(computerGrid);
  63. //fieldsP.add(new LogoPanel());
  64.  
  65. fieldsP.setBorder(new TitledBorder("BattleShip"));
  66.  
  67. messageTA = new JTextArea("BattleShip Game\n", 4, 0);
  68. (messageP = new JPanel()).setLayout(new BorderLayout());
  69. messageP.setBorder(new TitledBorder("Status: "));
  70. messageP.add(new JScrollPane(messageTA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  71. JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
  72.  
  73. mainPanel.add(fieldsP, BorderLayout.CENTER);
  74. mainPanel.add(messageP, BorderLayout.SOUTH);
  75.  
  76. //ButtonHandler shipHandler = new ButtonHandler();
  77.  
  78.  
  79. shipsH[1] = new Ship(1, false);
  80. shipsH[2] = new Ship(2, false);
  81. shipsH[3] = new Ship(3, false);
  82. shipsH[4] = new Ship(4, false);
  83. shipsH[5] = new Ship(5, false);
  84. carrierH = new JLabel(new ImageIcon(shipsH[Ship.CARRIER].image));
  85. battleshipH = new JLabel(new ImageIcon(shipsH[Ship.BATTLESHIP].image));
  86. destroyerH = new JLabel(new ImageIcon(shipsH[Ship.DESTROYER].image));
  87. submarineH = new JLabel(new ImageIcon(shipsH[Ship.SUBMARINE].image));
  88. patrolboatH = new JLabel(new ImageIcon(shipsH[Ship.PATROLBOAT].image));
  89.  
  90. MouseHandler dragger = new MouseHandler();
  91. carrierH.addMouseMotionListener(dragger);
  92. battleshipH.addMouseMotionListener(dragger);
  93. destroyerH.addMouseMotionListener(dragger);
  94. submarineH.addMouseMotionListener(dragger);
  95. patrolboatH.addMouseMotionListener(dragger);
  96.  
  97.  
  98. shipsV[1] = new Ship(1, true);
  99. shipsV[2] = new Ship(2, true);
  100. shipsV[3] = new Ship(3, true);
  101. shipsV[4] = new Ship(4, true);
  102. shipsV[5] = new Ship(5, true);
  103. carrierV = new JLabel(new ImageIcon(shipsV[Ship.CARRIER].image));
  104. battleshipV = new JLabel(new ImageIcon(shipsV[Ship.BATTLESHIP].image));
  105. destroyerV = new JLabel(new ImageIcon(shipsV[Ship.DESTROYER].image));
  106. submarineV = new JLabel(new ImageIcon(shipsV[Ship.SUBMARINE].image));
  107. patrolboatV = new JLabel(new ImageIcon(shipsV[Ship.PATROLBOAT].image));
  108.  
  109. JPanel ships = new JPanel(new GridLayout(5,1));
  110. ships.add(carrierH);
  111. ships.add(battleshipH);
  112. ships.add(destroyerH);
  113. ships.add(submarineH);
  114. ships.add(patrolboatH);
  115.  
  116. shipsP = new JPanel();
  117. shipsP.setLayout(new BorderLayout());
  118. shipsP.setBorder(new TitledBorder("Drag ship to place."));
  119. shipsP.add(ships, BorderLayout.CENTER);
  120.  
  121. this.add(mainPanel, BorderLayout.CENTER);
  122. this.add(shipsP, BorderLayout.WEST);
  123. //this.add(messageP, BorderLayout.SOUTH);
  124. this.setSize(1000,800);
  125. this.setVisible(true);
  126. }
  127.  
  128.  
  129. public Point getPoint()
  130. {
  131. Point cursor = null;
  132.  
  133. mode = POINTFUL;
  134. do
  135. {
  136. cursor = computerGrid.getSelected();
  137. try
  138. {
  139. Thread.sleep(69);
  140. }
  141. catch(InterruptedException ie) {ie.printStackTrace();}
  142. }
  143. while (cursor == null);
  144.  
  145. mode = POINTLESS;
  146. return cursor;
  147. }
  148.  
  149. public int ifPlayerHit(Point cursor) {
  150. int coordinate = playerGrid.getArea(cursor);
  151. if((coordinate)%10 == 0) {
  152. coordinate = coordinate + 100;
  153. playerGrid.setArea(cursor, coordinate);
  154. playerGrid.repaint();
  155. }
  156. else
  157. coordinate = -coordinate;
  158.  
  159. return coordinate;
  160. }
  161.  
  162. public int ifComputerHit(Point cursor) {
  163. int coordinate = computerGrid.getArea(cursor);
  164. if((coordinate/100)%10 == 0) {
  165. coordinate = coordinate + 100;
  166. computerGrid.setArea(cursor, coordinate);
  167. computerGrid.repaint();
  168. }
  169. else
  170. coordinate = -coordinate;
  171.  
  172. return coordinate;
  173. }
  174.  
  175. public void setResult(Point coordinates, int result)
  176. {
  177. int temp = computerGrid.getArea(coordinates);
  178. computerGrid.setArea(coordinates, result + temp);
  179. computerGrid.repaint();
  180. }
  181. /*
  182. private class ButtonHandler implements ActionListener {
  183. public void actionPerformed(ActionEvent e) {
  184. ((JButton)e.getSource()).setEnabled(false);
  185. if (e.getSource()== carrier) {
  186.  
  187. //selectedShip = CARRIER;
  188. selectedShipSize = 5;
  189. }
  190. if (e.getSource()== battleship) {
  191. //selectedShip = BATTLESHIP;
  192. selectedShipSize = 4;
  193. }
  194. if (e.getSource()== destroyer) {
  195. //selectedShip = ;
  196. selectedShipSize = 3;
  197. }
  198. if (e.getSource()== submarine) {
  199. //selectedShip = SEAWOLF;
  200. selectedShipSize = 3;
  201. }
  202. if (e.getSource()==patrolboat) {
  203. //selectedShip = PATROL;
  204. selectedShipSize = 2;
  205. }
  206. }
  207. }
  208. */
  209. public static void main(String args[]) {
  210.  
  211. JFrame frame = new JFrame("BATTLESHIP");
  212. PlayArea sample = new PlayArea();
  213. frame.getContentPane().add(sample,BorderLayout.CENTER);
  214. frame.setVisible(true);
  215. frame.pack();
  216. Point curCursor;
  217. int result;
  218.  
  219. while (true)
  220. {
  221. curCursor = sample.getPoint();
  222. result = sample.ifComputerHit(curCursor); //In real game this is sent to & recieved from opponent
  223. if (result>0)
  224. sample.setResult(curCursor, result);
  225. try {
  226. Thread.sleep(10);
  227. }
  228. catch (InterruptedException ie) { ie.printStackTrace(); }
  229. }
  230.  
  231.  
  232. }
  233.  
  234. private class MouseHandler implements MouseMotionListener {
  235. public void mouseDragged(MouseEvent e) {
  236. if(e.getModifiers() == e.MOUSE_DRAGGED) {
  237. Point location = e.getLocationOnScreen();
  238. }
  239. }
  240.  
  241. public void mouseMoved(MouseEvent e) {
  242.  
  243. }
  244. }
  245. }
  246.  
  247.  
  248. class PlayerGrid extends GridArea
  249. {
  250. public PlayerGrid(PlayArea handle)
  251. {
  252. super("Human", handle);
  253. ships[0] = new Ship(1, false);
  254. ships[1] = new Ship(2, true);
  255. ships[2] = new Ship(3, false);
  256. ships[3] = new Ship(4, true);
  257. ships[4] = new Ship(5, true);
  258.  
  259. placeShip(ships[0], new Point(0,1));
  260. placeShip(ships[1], new Point(9,1));
  261. placeShip(ships[2], new Point(2,3));
  262. placeShip(ships[3], new Point(1,3));
  263. placeShip(ships[4], new Point(7,7));
  264.  
  265. }
  266.  
  267. public void paintComponent(Graphics g)
  268. {
  269. super.paintComponent(g);
  270. Graphics2D g2 = (Graphics2D)g;
  271. Ship temp;
  272. for(int i=0; i < 5; i++) {
  273. temp = ships[i];
  274. g2.drawImage(temp.image, 25*(int)temp.getStart().getX(),
  275. 25*(int)temp.getStart().getY(), this);
  276. }
  277.  
  278.  
  279. int current;
  280. for (int y=0; y<10; y++) for (int x=0; x<10; x++)
  281. {
  282. if (area[x][y]!=0)
  283. {
  284. current = area[x][y]/10;
  285.  
  286. if ((current/10)%10==1)
  287. {
  288. if (current%10!=0) g2.drawImage(PlayArea.hit, 25*x, 25*y, this);
  289. else g2.drawImage(PlayArea.missed, 25*x, 25*y, this);
  290. }
  291. }
  292. }
  293. if (mainHandle.selectedShipSize!=0 )
  294. {
  295. if (vertical) g2.fill3DRect(25*(int)cursorLocation.getX(),
  296. 25*(int)cursorLocation.getY(), 25, 25*mainHandle.selectedShipSize, false);
  297. else g2.fill3DRect(25*(int)cursorLocation.getX(),
  298. 25*(int)cursorLocation.getY(), 25*mainHandle.selectedShipSize, 25, false);
  299. }
  300.  
  301.  
  302. }
  303.  
  304. }
  305.  
  306.  
  307.  
  308.  
  309. import javax.swing.*;
  310. import java.awt.*;
  311. import java.awt.event.*;
  312.  
  313.  
  314.  
  315. class GridArea extends JPanel
  316. {
  317. protected int area [][] = new int[10][10];
  318.  
  319. protected boolean vertical = false;
  320. private String title;
  321. private Point selected;
  322. protected Point cursorLocation;
  323. private Rectangle gridRects[][] = new Rectangle[10][10];
  324. protected PlayArea mainHandle;
  325. Ship[] ships = new Ship[5];
  326.  
  327.  
  328. public GridArea(String title, PlayArea mainHandle)
  329. {
  330. this.title = title;
  331. this.mainHandle = mainHandle;
  332. for (int y=0; y<10; y++)
  333. for (int x=0; x<10; x++) {
  334. gridRects[x][y] = new Rectangle(x*25,y*25,25,25);
  335. area[x][y] = 0;;
  336. }
  337.  
  338. addMouseMotionListener(new MouseMovingHandler());
  339. addMouseListener(new MouseHandler());
  340.  
  341. setOpaque(false);
  342. }
  343.  
  344.  
  345. public Point getSelected()
  346. {
  347. Point temp = selected;
  348. selected = null;
  349. mainHandle.selectedShip = 0; //be sure to get the ship before getSelected
  350. return temp;
  351. }
  352.  
  353. public Dimension getPreferredSize() { return new Dimension(251,270); }
  354. public void setArea(Point where, int contents)
  355. {
  356. area[(int)where.getX()][(int)where.getY()] = contents;
  357. }
  358.  
  359. public int getArea(Point check)
  360. {
  361. return area[(int)check.getX()][(int)check.getY()];
  362. }
  363.  
  364. public void placeShip(Ship s, Point start) {
  365. int size = s.getSize();
  366. //int type = s.getType();
  367. vertical = s.getOrientation();
  368. s.setStart(start);
  369. if(isValid(s)) {
  370. if(vertical)
  371. for(int i=0; i < size; i++)
  372. area[(int)start.getX()][(int)start.getY() + i] = 10;
  373.  
  374. else
  375. for(int i=0; i < size; i++)
  376. area[(int)start.getX() + i][(int)start.getY()] = 10;
  377. }
  378. }
  379.  
  380. protected boolean isValid(Ship s)
  381. {
  382. int size = s.getSize();
  383. vertical = s.getOrientation();
  384. Point start = s.getStart();
  385.  
  386. if(vertical)
  387. for(int i=0; i < size; i++) {
  388. if(area[(int)start.getX()][(int)start.getY() + i] != 0)
  389. return false;
  390. }
  391. else
  392. for(int i=0; i < size; i++) {
  393. if(area[(int)start.getX() + i][(int)start.getY()] != 0)
  394. return false;
  395. }
  396. return true;
  397. }
  398.  
  399. public void paintComponent(Graphics g)
  400. {
  401. Graphics2D g2D = (Graphics2D)g; //convert to 2D for easier manipulations
  402. GradientPaint gp = new GradientPaint(0.0f, 0.0f,
  403. new Color(40,100,140), 250.0f, 250.0f, new Color(40,180,210));
  404.  
  405. g2D.setPaint(gp); //color of grid
  406. g2D.fillRect(0, 0, 250, 250);
  407. g2D.setColor(new Color(0,100,90));
  408.  
  409. for (int i=1; i<10; i++) { //grid lines
  410. g2D.drawLine(i*25, 0, i*25, 250); //vertical gridlines
  411. g2D.drawLine(0, i*25, 250, i*25); //horizontal gridlines
  412. }
  413. g2D.setColor(Color.black);
  414. g2D.draw3DRect(0,0,250,250,false);
  415.  
  416. g2D.setColor(new Color(0,60,60));
  417. g2D.drawString(title, 125-(title.length()*4), 268);
  418.  
  419.  
  420. }
  421.  
  422. private class MouseMovingHandler extends MouseMotionAdapter
  423. {
  424. private Rectangle lastSelected = new Rectangle();
  425.  
  426. public void mouseMoved(MouseEvent e)
  427. {
  428. int x = (int)(e.getPoint().getX()/25);
  429. int y = (int)(e.getPoint().getY()/25);
  430.  
  431. if(x<10 && y<10 && gridRects[x][y]!=lastSelected)
  432. {
  433. lastSelected = gridRects[x][y];
  434. cursorLocation = new Point(x,y);
  435. repaint();
  436. }
  437. }
  438. }
  439.  
  440. private class MouseHandler extends MouseAdapter
  441. {
  442. public void mousePressed(MouseEvent e)
  443. {
  444. if(e.getModifiers() == e.BUTTON1_MASK)
  445. {
  446. selected = cursorLocation;
  447. //mainHandle.addMessage("You selected: " + selected); //delete this
  448. }
  449. if(e.getModifiers() == e.BUTTON3_MASK)
  450. {
  451. vertical = !vertical; //toggles vertical ship placing state
  452. repaint();
  453. }
  454. }
  455. }
  456. }
  457.  
  458.  
  459.  
  460. import java.awt.Image;
  461. import java.awt.Point;
  462. import java.awt.event.MouseEvent;
  463. import java.awt.event.MouseListener;
  464. import java.awt.event.MouseMotionListener;
  465.  
  466. import javax.swing.ImageIcon;
  467.  
  468. class Ship implements MouseListener, MouseMotionListener{
  469.  
  470. static final int CARRIER = 1;
  471. static final int BATTLESHIP = 2;
  472. static final int DESTROYER = 3;
  473. static final int SUBMARINE = 4;
  474. static final int PATROLBOAT = 5;
  475.  
  476. Image image;
  477. private int type;
  478. private int size;
  479. private boolean vertical = false;
  480. private Point start;
  481. //public Point end;
  482.  
  483. public Ship(int type, boolean orientation) {
  484. vertical = orientation;
  485. if(vertical) {
  486. switch(type) {
  487. case CARRIER:
  488. image = (new ImageIcon("images/carrierV.gif")).getImage();
  489. size = 5;
  490. break;
  491. case BATTLESHIP:
  492. image = (new ImageIcon("images/battleshipV.gif")).getImage();
  493. size = 4;
  494. break;
  495. case DESTROYER:
  496. image = (new ImageIcon("images/destroyerV.gif")).getImage();
  497. size = 4;
  498. break;
  499. case SUBMARINE:
  500. image = (new ImageIcon("images/submarineV.gif")).getImage();
  501. size = 3;
  502. break;
  503. case PATROLBOAT:
  504. image = (new ImageIcon("images/patrolboatV.gif")).getImage();
  505. size = 2;
  506. break;
  507. }
  508. }
  509. else {
  510. switch(type) {
  511. case CARRIER:
  512. image = (new ImageIcon("images/carrierH.gif")).getImage();
  513. size = 5;
  514. break;
  515. case BATTLESHIP:
  516. image = (new ImageIcon("images/battleshipH.gif")).getImage();
  517. size = 4;
  518. break;
  519. case DESTROYER:
  520. image = (new ImageIcon("images/destroyerH.gif")).getImage();
  521. size = 4;
  522. break;
  523. case SUBMARINE:
  524. image = (new ImageIcon("images/submarineH.gif")).getImage();
  525. size = 3;
  526. break;
  527. case PATROLBOAT:
  528. image = (new ImageIcon("images/patrolboatH.gif")).getImage();
  529. size = 2;
  530. break;
  531. }
  532. }
  533. }
  534.  
  535. public Ship(Ship s) {
  536. image = s.image;
  537. size = s.getSize();
  538. vertical = s.getOrientation();
  539. }
  540.  
  541. public int getType() {
  542. return type;
  543. }
  544.  
  545. public int getSize() {
  546. return size;
  547. }
  548.  
  549. public void setStart(Point start) {
  550. this.start = start;
  551. }
  552.  
  553. public Point getStart() {
  554. return start;
  555. }
  556.  
  557. public boolean getOrientation() {
  558. return vertical;
  559. }
  560.  
  561. public void setOrientation(boolean vertical) {
  562. this.vertical = vertical;
  563. if(vertical)
  564. switch(type) {
  565. case CARRIER:
  566. image = (new ImageIcon("images/carrierV.gif")).getImage();
  567. break;
  568. case BATTLESHIP:
  569. image = (new ImageIcon("images/battleshipV.gif")).getImage();
  570. break;
  571. case DESTROYER:
  572. image = (new ImageIcon("images/destroyerV.gif")).getImage();
  573. break;
  574. case SUBMARINE:
  575. image = (new ImageIcon("images/submarineV.gif")).getImage();
  576. break;
  577. case PATROLBOAT:
  578. image = (new ImageIcon("images/patrolboatV.gif")).getImage();
  579. break;
  580. }
  581. else
  582. switch(type) {
  583. case CARRIER:
  584. image = (new ImageIcon("images/carrierH.gif")).getImage();
  585. break;
  586. case BATTLESHIP:
  587. image = (new ImageIcon("images/battleshipH.gif")).getImage();
  588. break;
  589. case DESTROYER:
  590. image = (new ImageIcon("images/destroyerH.gif")).getImage();
  591. break;
  592. case SUBMARINE:
  593. image = (new ImageIcon("images/submarineH.gif")).getImage();
  594. break;
  595. case PATROLBOAT:
  596. image = (new ImageIcon("images/patrolboatH.gif")).getImage();
  597. break;
  598. }
  599. }
  600.  
  601.  
  602. @Override
  603. public void mouseClicked(MouseEvent e) {
  604. if (e.isMetaDown()) {
  605. if (vertical) {
  606. setOrientation(false);
  607. System.out.print("c");
  608. }
  609. else {
  610. setOrientation(true);
  611. System.out.print("a");
  612. }
  613. }
  614. }
  615.  
  616. @Override
  617. public void mouseEntered(MouseEvent arg0) {
  618. // TODO Auto-generated method stub
  619.  
  620. }
  621.  
  622. @Override
  623. public void mouseExited(MouseEvent arg0) {
  624. // TODO Auto-generated method stub
  625.  
  626. }
  627.  
  628. @Override
  629. public void mousePressed(MouseEvent arg0) {
  630. // TODO Auto-generated method stub
  631.  
  632. }
  633.  
  634. @Override
  635. public void mouseReleased(MouseEvent arg0) {
  636. // TODO Auto-generated method stub
  637.  
  638. }
  639.  
  640. @Override
  641. public void mouseDragged(MouseEvent arg0) {
  642. // TODO Auto-generated method stub
  643.  
  644. }
  645.  
  646. @Override
  647. public void mouseMoved(MouseEvent arg0) {
  648. // TODO Auto-generated method stub
  649.  
  650. }
  651.  
  652. }
  653.  
  654.  
  655. import java.awt.Graphics;
  656. import java.awt.Graphics2D;
  657. import java.awt.Point;
  658.  
  659.  
  660. class ComputerGrid extends GridArea
  661. {
  662. public ComputerGrid(PlayArea handle)
  663. {
  664. super("Computer", handle);
  665. ships[0] = new Ship(1, false);
  666. ships[1] = new Ship(2, true);
  667. ships[2] = new Ship(3, false);
  668. ships[3] = new Ship(4, true);
  669. ships[4] = new Ship(5, true);
  670.  
  671. placeShip(ships[0], new Point(0,1));
  672. placeShip(ships[1], new Point(9,1));
  673. placeShip(ships[2], new Point(2,3));
  674. placeShip(ships[3], new Point(1,3));
  675. placeShip(ships[4], new Point(7,7));
  676. //placeShips();
  677.  
  678. }
  679.  
  680. private void placeShips() {
  681. boolean vertical;
  682. for(int i=0; i < 5; i++) {
  683. if(Math.random()%2 == 0)
  684. vertical = true;
  685. else
  686. vertical = false;
  687.  
  688. ships[i] = new Ship(i+1, vertical);
  689. do {
  690. placeShip(ships[i], new Point((int)Math.random()%10 ,(int)Math.random()%10));
  691. }while(!isValid(ships[i]));
  692.  
  693. }
  694. }
  695.  
  696. public void paintComponent(Graphics g)
  697. {
  698. super.paintComponent(g);
  699. Graphics2D g2 = (Graphics2D)g;
  700.  
  701. Ship temp;
  702.  
  703. for(int i=0; i < 5; i++) {
  704. temp = ships[i];
  705. g2.drawImage(temp.image, 25*(int)temp.getStart().getX(),
  706. 25*(int)temp.getStart().getY(), this);
  707. }
  708.  
  709. int current;
  710. for (int y=0; y<10; y++)
  711. for (int x=0; x<10; x++)
  712. {
  713. if (area[x][y]!=0)
  714. {
  715. current = area[x][y]/10;
  716.  
  717. if ((current/10)%10!=0) //or could be written, ==1
  718. {
  719. if (current%10!=0) g2.drawImage(PlayArea.hit, 25*x, 25*y, this);
  720. else g2.drawImage(PlayArea.missed, 25*x, 25*y, this);
  721. }
  722. }
  723. }
  724. if (cursorLocation!=null) g2.drawImage(PlayArea.target,
  725. 25*(int)cursorLocation.getX(), 25*(int)cursorLocation.getY(), this);
  726.  
  727.  
  728. }
  729. }

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC