Modify the War Game program to play until the player hands a
Modify the War Game program to play until the player hands are empty. That is, after the deck is empty, the players must continue playing until they have played the three remaining cards in their hands.
Your modifications must be minimal. 30% of your grade is based on how minimal and correct is your solution.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Random.cpp
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Deck.cpp
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Card.cpp
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I originally thought that I could edit the player class by adding in a function that stores the number of cards the player has, and in the main function once the deck is empty it checks to see if the player hands is empty and if it isn\'t then it starts subtracting the number of cards in the players hand. I altered the while to determine if the deck is empty and one of the players hands are empty then it displays the score. Unfortunately everytime I would try to do something like this it just fails and is limited by the deck. Maybe you guys might be able to help me out because I am desprate to figure this out, because it\'s due Monday and I\'ve been trying for three days now. It might be a simple fix that I\'m not seeing so please someone help me understand how to do this. Thank you in advance for the help.
Solution
import javax.swing.*;
import javax.swing.plaf.metal.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.beans.*;
import java.sql.*;
/*
import com.incors.plaf.*;
import com.incors.plaf.kunststoff.*;
import com.incors.plaf.kunststoff.themes.*;
*/
public class MainForm extends JFrame implements WindowListener{
/************************ Variable declaration start **********************/
//The form container variable
JPanel Panel1;
JDesktopPane Desk1 = new JDesktopPane();
JLabel StatusLabel = new JLabel(\"Copyright © 2004 by Philip V. Naparan. All Rights Reserved. Visit http://www.naparansoft.cjb.net.\",JLabel.CENTER);
JLabel BusinessTitleLabel = new JLabel();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
String StrBusinesTitle;
String DBDriver = \"sun.jdbc.odbc.JdbcOdbcDriver\";
String DBSource = \"jdbc:odbc:NaparansoftInventory\";
String DBUserName = \"Admin\";
String DBPassword = \"philip121\";
Connection CN;
//--Start variable the contains forms
FrmCustomer FormCustomer;
FrmSupplier FormSupplier;
FrmSalesRep FormSalesRep;
FrmWarehouse FormWarehouse;
FrmProduct FormProduct;
FrmInvoice FormInvoice;
FrmSplash FormSplash = new FrmSplash();
//--End variable the contains forms
Thread ThFormSplash = new Thread(FormSplash);
//End the form container variable
/********************** End variable declaration start ********************/
/************************ MainForm constructor start **********************/
public MainForm(){
//Set the main form title
super(\"Naparansoft Inventory System version 1.1\");
//End set the main form title
loadSplashScreen();
//We will dispose now the FormSplash because it is now useless
FormSplash.dispose();
//StatusLabel.setBorder(BorderFactory.createTitledBorder(\"\"));
StatusLabel.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
StrBusinesTitle = \"Your Business Name\";
BusinessTitleLabel.setText(StrBusinesTitle);
BusinessTitleLabel.setHorizontalAlignment(JLabel.LEFT);
BusinessTitleLabel.setForeground(new Color(166,0,0));
//Set the main form properties
addWindowListener(this);
Desk1.setBackground(Color.gray);
Desk1.setBorder(BorderFactory.createEmptyBorder());
//Most fastest drag mode
Desk1.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
Panel1 = new JPanel(new BorderLayout());
Panel1.setBackground(Color.gray);
Panel1.setBorder(BorderFactory.createLoweredBevelBorder());
Panel1.add(new JScrollPane(Desk1),BorderLayout.CENTER);
getContentPane().add(CreateJToolBar(),BorderLayout.PAGE_START);
getContentPane().add(Panel1,BorderLayout.CENTER);
getContentPane().add(StatusLabel,BorderLayout.PAGE_END);
setJMenuBar(CreateJMenuBar());
setExtendedState(this.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setIconImage(new ImageIcon(\"images/appicon.png\").getImage());
setLocation(0,0);
setSize(screen);
setResizable(true);
setVisible(true);
show();
try{
Class.forName(DBDriver);
CN = DriverManager.getConnection(DBSource,DBUserName ,DBPassword);
}catch(ClassNotFoundException e) {
System.err.println(\"Failed to load driver\");
e.printStackTrace();
System.exit(1);
}
catch(SQLException e){
System.err.println(\"Unable to connect\");
e.printStackTrace();
System.exit(1);
}
//End set the main form properties
}
/********************** End MainForm constructor start ********************/
/*********************** Custom class creation start **********************/
//Create menu bar
protected JMenuBar CreateJMenuBar(){
JMenuBar NewJMenuBar = new JMenuBar();
//Setup file menu
JMenu MnuFile = new JMenu(\"File\");
MnuFile.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
MnuFile.setMnemonic(\'F\');
MnuFile.setBackground(new Color(255,255,255));
NewJMenuBar.add(MnuFile);
//End setup file menu
//Set file sub menu
JMenuItem ItmLockApp = new JMenuItem(\"lock Application\");
ItmLockApp.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmLockApp.setMnemonic(\'L\');
ItmLockApp.setIcon(new ImageIcon(\"images/lockapplication.png\"));
ItmLockApp.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_L,ActionEvent.CTRL_MASK
)
);
ItmLockApp.setActionCommand(\"lockapp\");
ItmLockApp.addActionListener(JMenuActionListener);
ItmLockApp.setBackground(new Color(255,255,255));
JMenuItem ItmLoggOff = new JMenuItem(\"Logg Off\");
ItmLoggOff.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmLoggOff.setMnemonic(\'O\');
ItmLoggOff.setIcon(new ImageIcon(\"images/loggoff.png\"));
ItmLoggOff.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_O,ActionEvent.CTRL_MASK
)
);
ItmLoggOff.setActionCommand(\"loggoff\");
ItmLoggOff.addActionListener(JMenuActionListener);
ItmLoggOff.setBackground(new Color(255,255,255));
JMenuItem ItmExit = new JMenuItem(\"Exit\");
ItmExit.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmExit.setMnemonic(\'E\');
ItmExit.setIcon(new ImageIcon(\"images/exit.png\"));
ItmExit.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_E,ActionEvent.CTRL_MASK
)
);
ItmExit.setActionCommand(\"exit\");
ItmExit.addActionListener(JMenuActionListener);
ItmExit.setBackground(new Color(255,255,255));
MnuFile.add(ItmLockApp);
MnuFile.addSeparator();
MnuFile.add(ItmLoggOff);
MnuFile.add(ItmExit);
//End set file sub menu
//Setup records menu
JMenu MnuRec = new JMenu(\"Records\");
MnuRec.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
MnuRec.setMnemonic(\'R\');
MnuRec.setBackground(new Color(255,255,255));
NewJMenuBar.add(MnuRec);
//End records menu
//Set records sub menu
//-- For Customer
JMenuItem ItmCustomer = new JMenuItem(\"Customers\");
ItmCustomer.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmCustomer.setMnemonic(\'C\');
ItmCustomer.setIcon(new ImageIcon(\"images/customer.png\"));
ItmCustomer.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_C,ActionEvent.CTRL_MASK
)
);
ItmCustomer.setActionCommand(\"cus\");
ItmCustomer.addActionListener(JMenuActionListener);
ItmCustomer.setBackground(new Color(255,255,255));
MnuRec.add(ItmCustomer);
//-- For Supplier
JMenuItem ItmSupplier = new JMenuItem(\"Suppliers\");
ItmSupplier.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmSupplier.setMnemonic(\'S\');
ItmSupplier.setIcon(new ImageIcon(\"images/supplier.png\"));
ItmSupplier.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_S,ActionEvent.CTRL_MASK
)
);
ItmSupplier.setActionCommand(\"sup\");
ItmSupplier.addActionListener(JMenuActionListener);
ItmSupplier.setBackground(new Color(255,255,255));
MnuRec.add(ItmSupplier);
//-- For SalesRep
JMenuItem ItmSalesRep = new JMenuItem(\"SalesRep\");
ItmSalesRep.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmSalesRep.setMnemonic(\'R\');
ItmSalesRep.setIcon(new ImageIcon(\"images/SalesRep.png\"));
ItmSalesRep.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_B,ActionEvent.CTRL_MASK
)
);
ItmSalesRep.setActionCommand(\"bran\");
ItmSalesRep.addActionListener(JMenuActionListener);
ItmSalesRep.setBackground(new Color(255,255,255));
MnuRec.add(ItmSalesRep);
//-- For Warehouse
JMenuItem ItmWarehouse = new JMenuItem(\"Warehouse\");
ItmWarehouse.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmWarehouse.setMnemonic(\'W\');
ItmWarehouse.setIcon(new ImageIcon(\"images/Warehouse.png\"));
ItmWarehouse.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_B,ActionEvent.CTRL_MASK
)
);
ItmWarehouse.setActionCommand(\"wareh\");
ItmWarehouse.addActionListener(JMenuActionListener);
ItmWarehouse.setBackground(new Color(255,255,255));
MnuRec.add(ItmWarehouse);
MnuRec.addSeparator();
//-- For Products
JMenuItem ItmProduct = new JMenuItem(\"Products\");
ItmProduct.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmProduct.setMnemonic(\'P\');
ItmProduct.setIcon(new ImageIcon(\"images/product.png\"));
ItmProduct.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_P,ActionEvent.CTRL_MASK
)
);
ItmProduct.setActionCommand(\"prod\");
ItmProduct.addActionListener(JMenuActionListener);
ItmProduct.setBackground(new Color(255,255,255));
MnuRec.add(ItmProduct);
//-- For Categories
JMenuItem ItmCategory = new JMenuItem(\"Categories\");
ItmCategory.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmCategory.setMnemonic(\'T\');
ItmCategory.setIcon(new ImageIcon(\"images/categories.png\"));
ItmCategory.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_T,ActionEvent.CTRL_MASK
)
);
ItmCategory.setActionCommand(\"cat\");
ItmCategory.addActionListener(JMenuActionListener);
ItmCategory.setBackground(new Color(255,255,255));
MnuRec.add(ItmCategory);
//-- For Stock Adjustment
JMenuItem ItmStockAdj = new JMenuItem(\"Stock Adjustment\");
ItmStockAdj.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmStockAdj.setMnemonic(\'A\');
ItmStockAdj.setIcon(new ImageIcon(\"images/adjustment.png\"));
ItmStockAdj.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_A,ActionEvent.CTRL_MASK
)
);
ItmStockAdj.setActionCommand(\"stockadj\");
ItmStockAdj.addActionListener(JMenuActionListener);
ItmStockAdj.setBackground(new Color(255,255,255));
MnuRec.add(ItmStockAdj);
MnuRec.addSeparator();
//-- For Invoices
JMenuItem ItmInv = new JMenuItem(\"Invoices\");
ItmInv.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmInv.setMnemonic(\'I\');
ItmInv.setIcon(new ImageIcon(\"images/invoice.png\"));
ItmInv.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_I,ActionEvent.CTRL_MASK
)
);
ItmInv.setActionCommand(\"invoice\");
ItmInv.addActionListener(JMenuActionListener);
ItmInv.setBackground(new Color(255,255,255));
MnuRec.add(ItmInv);
//-- For Purchase Orders
JMenuItem ItmPO = new JMenuItem(\"Purchase Orders\");
ItmPO.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmPO.setMnemonic(\'O\');
ItmPO.setIcon(new ImageIcon(\"images/purchaseorder.png\"));
ItmPO.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_O,ActionEvent.CTRL_MASK
)
);
ItmPO.setActionCommand(\"PO\");
ItmPO.addActionListener(JMenuActionListener);
ItmPO.setBackground(new Color(255,255,255));
MnuRec.add(ItmPO);
//-- For Purchase Receipt
JMenuItem ItmRecieve = new JMenuItem(\"Purchase Receipt\");
ItmRecieve.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmRecieve.setMnemonic(\'R\');
ItmRecieve.setIcon(new ImageIcon(\"images/recieve.png\"));
ItmRecieve.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_R,ActionEvent.CTRL_MASK
)
);
ItmRecieve.setActionCommand(\"preceipt\");
ItmRecieve.addActionListener(JMenuActionListener);
ItmRecieve.setBackground(new Color(255,255,255));
MnuRec.add(ItmRecieve);
//-- For Expenses
JMenuItem ItmExpense = new JMenuItem(\"Expenses\");
ItmExpense.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
ItmExpense.setMnemonic(\'E\');
ItmExpense.setIcon(new ImageIcon(\"images/expense.png\"));
ItmExpense.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_E,ActionEvent.CTRL_MASK
)
);
ItmExpense.setActionCommand(\"expense\");
ItmExpense.addActionListener(JMenuActionListener);
ItmExpense.setBackground(new Color(255,255,255));
MnuRec.add(ItmExpense);
//End records sub menu
//Setup proccess menu
JMenu MnuProccess = new JMenu(\"Proccess\");
MnuProccess.setFont(new Font(\"Dialog\", Font.PLAIN, 12));
MnuProccess.setMnemonic(\'P\');
MnuProccess.setBackground(new Color(255,255,255));
NewJMenuBar.add(MnuProccess);
//End records menu
//Set proccess sub menu






