humans-vs-aliens/src/View/BaseGUI.java (11370B)
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package View; import Controller.Controller; import Model.Alien; import Model.Human; import javax.swing.JOptionPane; /** * * @author michael */ public class BaseGUI extends javax.swing.JFrame { Controller myController = new Controller(); Human myHuman = new Human("Michael", 5, 100); Alien myAlien = new Alien("Zucky", 5, 10); /** * Creates new form BaseGUI */ public BaseGUI() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButtonAlienAttack = new javax.swing.JButton(); jButtonAlienRun = new javax.swing.JButton(); jButtonHumanRun = new javax.swing.JButton(); jButtonHumanAttack = new javax.swing.JButton(); jLabelAlien = new javax.swing.JLabel(); jLabelHuman = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButtonAlienAttack.setText("Attack"); jButtonAlienAttack.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonAlienAttackActionPerformed(evt); } }); jButtonAlienRun.setText("Run"); jButtonAlienRun.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonAlienRunActionPerformed(evt); } }); jButtonHumanRun.setText("Run"); jButtonHumanRun.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonHumanRunActionPerformed(evt); } }); jButtonHumanAttack.setText("Attack"); jButtonHumanAttack.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonHumanAttackActionPerformed(evt); } }); jLabelAlien.setText("Alien"); jLabelHuman.setText("Human"); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/zucky.PNG"))); // NOI18N jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/human.PNG"))); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(57, 57, 57) .addComponent(jLabelAlien) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabelHuman) .addGap(69, 69, 69)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(57, 57, 57) .addComponent(jButtonAlienAttack) .addGap(22, 22, 22) .addComponent(jButtonAlienRun) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1) .addGap(18, 18, 18))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jButtonHumanAttack) .addGap(28, 28, 28) .addComponent(jButtonHumanRun)) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelAlien) .addComponent(jLabelHuman)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)) .addGroup(layout.createSequentialGroup() .addGap(35, 35, 35) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButtonAlienAttack) .addComponent(jButtonAlienRun) .addComponent(jButtonHumanAttack) .addComponent(jButtonHumanRun)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButtonAlienAttackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlienAttackActionPerformed System.out.println("The alien is attacking!"); myController.AttackHuman(myHuman, myAlien); System.out.println("Human health is now " + myHuman.getHealth()); System.out.println("Alien has " + myAlien.getBolts() + " bolts"); int myWholeNumber = (int)(Math.random()*10); if (myWholeNumber < 4) { //happens when true //here we want the damage not to be allocated JOptionPane.showMessageDialog(null, "Survived"); System.out.println("The chance that the shot was successful is low"); } else { //happens when false //here we want the damage to be allocated JOptionPane.showMessageDialog(null, "Hit"); System.out.println("The chance that the shot was successful is high"); } }//GEN-LAST:event_jButtonAlienAttackActionPerformed private void jButtonHumanAttackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHumanAttackActionPerformed System.out.println("The human is attacking!"); myController.AttackAlien(myHuman, myAlien); System.out.println("Alien health is now " + myAlien.getHealth()); System.out.println("Human has " + myHuman.getRounds()+ " rounds"); int myWholeNumber = (int)(Math.random()*10); if (myWholeNumber < 4) { //happens when true //here we want the damage not to be allocated JOptionPane.showMessageDialog(null, "Survived"); System.out.println("The chance that the shot was successful is low"); } else { //happens when false //here we want the damage to be allocated JOptionPane.showMessageDialog(null, "Hit"); System.out.println("The chance that the shot was successful is high"); } }//GEN-LAST:event_jButtonHumanAttackActionPerformed private void jButtonAlienRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlienRunActionPerformed System.out.println("The alien is running!"); // TODO add your handling code here: }//GEN-LAST:event_jButtonAlienRunActionPerformed private void jButtonHumanRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHumanRunActionPerformed System.out.println("The human is running!"); // TODO add your handling code here: }//GEN-LAST:event_jButtonHumanRunActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(BaseGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(BaseGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(BaseGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(BaseGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new BaseGUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonAlienAttack; private javax.swing.JButton jButtonAlienRun; private javax.swing.JButton jButtonHumanAttack; private javax.swing.JButton jButtonHumanRun; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabelAlien; private javax.swing.JLabel jLabelHuman; // End of variables declaration//GEN-END:variables }