From 5321e62abbb934422ed116b2eae9ca4e56576700 Mon Sep 17 00:00:00 2001 From: hemantsharma98 Date: Fri, 30 Apr 2021 00:16:27 +0530 Subject: [PATCH 1/3] Listener added to the new frame --- src/main/java/game/Board.java | 64 ++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/src/main/java/game/Board.java b/src/main/java/game/Board.java index 513a720..33f19a4 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:18:24 +0530 Subject: [PATCH 2/3] logic for new game on reset button click checked --- src/main/java/game/Board.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/game/Board.java b/src/main/java/game/Board.java index 33f19a4..3b34d3a 100644 --- a/src/main/java/game/Board.java +++ b/src/main/java/game/Board.java @@ -385,7 +385,7 @@ private void noOfMoves(){ } private void newFrame(int whiteTurn,int blackTurn){ - + Main newGameFrame = new Main(); label.setText("Black: "+blackTurn+" "+"White: "+whiteTurn); label.setBounds(50,50, 150,20); resetButton.setBounds(50,250,95,30); @@ -393,7 +393,14 @@ private void newFrame(int whiteTurn,int blackTurn){ resetButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - System.out.println("Listener added"); + try{ + ++r; + if(r==1){ + System.out.println("new game"); + } + }catch(Exception ex){ + System.out.println("Exception occured in reset button "+ex.getMessage()); + } } }); movesFrame.add(timeLabel); From 10de9d603b2b4d213120212ac57e43776d94ab90 Mon Sep 17 00:00:00 2001 From: hemantsharma98 Date: Fri, 30 Apr 2021 00:21:56 +0530 Subject: [PATCH 3/3] new function for new game in main --- src/main/java/game/Main.java | 43 ++++++------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/src/main/java/game/Main.java b/src/main/java/game/Main.java index 33c7654..248e335 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,16 @@ 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{ + } - + public static void main(String[] args) { - EventQueue.invokeLater(() -> { Main main = new Main(); - main.setVisible( true ); + main.setVisible(true); }); } - + }