From e0c2e150060b96bea872be882d66ad111279b56a Mon Sep 17 00:00:00 2001 From: hemantsharma98 Date: Fri, 30 Apr 2021 00:27:42 +0530 Subject: [PATCH 1/3] new game on click of reset --- src/main/java/game/Board.java | 78 +++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/src/main/java/game/Board.java b/src/main/java/game/Board.java index 513a720..8b9e81c 100644 --- a/src/main/java/game/Board.java +++ b/src/main/java/game/Board.java @@ -6,7 +6,10 @@ package game; import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.IOException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import javax.swing.*; @@ -31,6 +34,18 @@ public class Board extends JPanel { Field collisionField; private boolean isSelected = false; + + JFrame movesFrame = new JFrame("No. of Moves"); /**(); @@ -151,6 +166,9 @@ private class BoardListener implements java.awt.event.ActionListener { /* * Executed when a field is pressed */ + int noOfMovesBlack = 0; /** Date: Fri, 30 Apr 2021 00:30:09 +0530 Subject: [PATCH 2/3] New game started --- src/main/java/game/Main.java | 44 +++++++----------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/main/java/game/Main.java b/src/main/java/game/Main.java index 33c7654..6e0f694 100644 --- a/src/main/java/game/Main.java +++ b/src/main/java/game/Main.java @@ -1,3 +1,4 @@ + /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates @@ -5,48 +6,25 @@ */ package game; -import java.awt.BorderLayout; import java.awt.EventQueue; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; /** * * @author gersc */ public class Main extends JFrame { - public Main() { - /// \ref T7_1 Popup will ask users to choose the number of players - int playerChoice = getNumberOfPlayers(); - - if(playerChoice == 1) { - startOnePlayer(); - } - else { - startTwoPlayer(); - } - - } - - - public void startOnePlayer() { - System.out.println("TODO"); - } - - - public void startTwoPlayer() { try { this.add( new Board()); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } + //this.setSize(10000,10000); this.pack(); this.setResizable(false); this.setTitle( "CHESS" ); @@ -54,23 +32,17 @@ public void startTwoPlayer() { this.setLocationRelativeTo( null ); } - /// \ref T7_2 Popup for users to choose number of players - //will return 1 for One player, 2 for Two player - public int getNumberOfPlayers() { - String[] options = {"1 Player", "2 Players"}; - int playerChoice = JOptionPane.showOptionDialog(null, "Please choose number of Players", - "How Many Players?", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); - return playerChoice + 1; + public void newGame() throws Exception{ + Main main = new Main(); + main.setVisible(true); } - + public static void main(String[] args) { - EventQueue.invokeLater(() -> { Main main = new Main(); - main.setVisible( true ); + main.setVisible(true); }); } - + } From 76d344211bb61be92503680e88cde0e9ee497f39 Mon Sep 17 00:00:00 2001 From: hemantsharma98 Date: Fri, 30 Apr 2021 00:34:35 +0530 Subject: [PATCH 3/3] resent button clicked --- src/main/java/game/Board.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/game/Board.java b/src/main/java/game/Board.java index 8b9e81c..f40735b 100644 --- a/src/main/java/game/Board.java +++ b/src/main/java/game/Board.java @@ -398,7 +398,6 @@ public void actionPerformed(ActionEvent e) { ++r; if(r==1){ newGameFrame.newGame(); - timer.stop(); movesFrame.setVisible(false); } }catch(Exception ex){ @@ -417,9 +416,6 @@ public void actionPerformed(ActionEvent e) { } - - - public Field[][] getArrayChessBoard() { return arrayBoard; }