Exemple #1
0
 public void takeDamage() {
   if (!hurtAnimating) {
     if (user.getHealth() == 0) gameOver = true;
     else {
       hurtAnimating = true;
       user.setHealth(user.getHealth() - 1);
       healthHandLabel[user.getHealth()].setVisible(false);
       hurtAnimation();
     }
   }
 }
  private User makeUser(Properties p) {
    User user = new User();
    String username = p.getProperty("username");
    String password = p.getProperty("password");
    String name = p.getProperty("name");
    String type = p.getProperty("type");

    user.setUsername(username);
    user.setPassword(password);
    user.setName(name);
    user.setType(type);
    return user;
  }
  /**
   * Compares two User objects.
   *
   * @return 0 Users are equal.
   * @return -1 User A is greater than User B.
   * @return 1 User B is greater than User A.
   */
  public int compareTo(User otherU) {
    // ugly, but works. :)
    int result = getID().compareToIgnoreCase(otherU.getID());
    if (result == 0) {
      result = getPoints() - otherU.getPoints();
      if (result == 0) {
        result = getLastName().compareToIgnoreCase(otherU.getLastName());
        if (result == 0) {
          result = getFirstName().compareToIgnoreCase(otherU.getLastName());
        }
      }
    }

    return result;
  }
 public Appointment(
     int appointmentId,
     String title,
     String description,
     long startTime,
     long finishTime,
     Room room,
     User owner) {
   this.appointmentId = appointmentId;
   this.title = title;
   this.description = description;
   this.startTime = new GregorianCalendar();
   this.startTime.setTimeInMillis(startTime);
   this.finishTime = new GregorianCalendar();
   this.finishTime.setTimeInMillis(finishTime);
   this.room = room;
   if (room != null) {
     room.addAppointment(this);
   }
   this.owner = owner;
   if (owner != null) {
     owner.addOwnership(this);
   }
   participants = new ArrayList<Participant>();
   pcs = new PropertyChangeSupport(this);
 }
 public void remove() {
   if (owner != null) {
     owner.removeOwnership(this);
   }
   if (room != null) {
     room.removeAppointment(this);
   }
 }
Exemple #6
0
 public void gameOver() {
   gameOver = false;
   System.out.println("Game Over");
   music.stop();
   clearScreen();
   user.setHealth(3);
   playLevel(currentLevel);
 }
Exemple #7
0
 public void mousePressed(MouseEvent e) {
   if (onTitleScreen) { // Game is not currently playing
     // Title screen buttons are 54 x 61
     // Mouse is clicking load button - at point (55, 695)
     if (e.getX() >= 55 && e.getX() <= 55 + 54 && e.getY() >= 695 && e.getY() <= 695 + 61) {
       System.out.println("Load feature accessed.");
       music.stop();
       playLevel(user.getMaxLevel());
     }
     // Mouse is clicking new game button - at point (725, 695)
     else if (e.getX() >= 725 && e.getX() <= 725 + 54 && e.getY() >= 695 && e.getY() <= 695 + 61) {
       music.stop();
       user.setHealth(3);
       playLevel(1);
     }
   } else if (!gameCursorLabelAnimating && ableToAttack && !gameOver) // Attack sequence
   swatAnimation();
 }
 public Appointment(
     int appointmentId, String title, Calendar startTime, Calendar finishTime, User owner) {
   this.appointmentId = appointmentId;
   this.title = title;
   this.startTime = startTime;
   this.finishTime = finishTime;
   this.owner = owner;
   if (owner != null) {
     owner.addOwnership(this);
   }
   participants = new ArrayList<Participant>();
   pcs = new PropertyChangeSupport(this);
 }
 public ArrayList<Event> queryEvents(User user) {
   ArrayList<Event> events = new ArrayList<Event>();
   String query =
       String.format(
           SELECT_FROM_WHERE,
           "event." + FIELDS_EVENT,
           TABLE_EVENT + " JOIN " + TABLE_IS_OWNER + " ON event.eventID=isOwner.eventID ",
           "username='******'");
   ArrayList<Properties> pl = dbComm.query(query);
   for (Properties p : pl) {
     events.add(makeEvent(p, true));
   }
   return events;
 }
Exemple #10
0
  // ====== TEST DRIVER ===== //
  public static void main(String[] args) {
    User u = null;
    try {
      u = new User("bob", "builder", "bbuilde");
    } catch (InvalidFieldException e) {
    }

    Contestant c = new Contestant();
    Contestant ul = new Contestant();
    try {
      c.setID("aa");
      ul.setID("ab");
      u.setWeeklyPick(c);
      u.setUltimatePick(ul);
    } catch (InvalidFieldException e1) {
      e1.printStackTrace();
    }

    try {
      System.out.println(u.toJSONObject().toString());
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
Exemple #11
0
  public String getLinkedClubsCombobox(final User user) {
    String result = "";
    final List<Club> clubs = user.getAllClubs();

    result += "<script>$(function(){$('.chosen').select2();});</script>";
    result += "<style>#s2id_autogen1 > a { height: 48px; }</style>";

    result += "<select name='id' class='chosen' style='width: 600px'>";
    for (final Club club : clubs) {
      result += String.format("<option value='%s'>%s</option>", club.getId(), club.prettyName());
    }
    result += "</select>";

    return result;
  }
Exemple #12
0
 private Alarm queryAlarm(User user, int eventID) {
   ArrayList<Properties> pl =
       dbComm.query(
           String.format(
               SELECT_FROM_WHERE,
               FIELDS_ALARM,
               TABLE_ALARM,
               "username='******' and eventID=" + eventID));
   if (pl.size() > 0) {
     Properties p = pl.get(0);
     return makeAlarm(p, false);
   } else {
     return null;
   }
 }
  @Override
  public void delete(User user) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {

      session.beginTransaction();
      Query query = session.createQuery("DELETE FROM  User where id=" + user.getId());
      query.executeUpdate();
      session.getTransaction().commit();
    } catch (HibernateException e) {
      log.error("Transaction failed");
      session.getTransaction().rollback();
    } finally {
      session.close();
    }
  }
  @Override
  public void update(User user) {
    // update(product)
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {

      session.beginTransaction();
      Query query =
          session.createQuery(
              "update Product set name='" + "lalala" + "' where id=" + user.getId());
      query.executeUpdate();
      session.getTransaction().commit();
      //   session.save(product);
    } catch (HibernateException e) {
      log.error("Transaction failed");
      session.getTransaction().rollback();
    } finally {
      if (session != null) session.close();
    }
  }
  private void saveAppointment() {
    String title = titleField.getText();
    String descr = descriptionField.getText();

    // construct starttime
    int syear = startTime.getDate().getYear();
    int smonth = startTime.getDate().getMonth();
    int sddate = startTime.getDate().getDate();
    int sh = (Integer) startHourSpinner.getValue();
    int sm = (Integer) startMinuteSpinner.getValue();
    Date sDate = new Date(syear, smonth, sddate, sh, sm);

    // set startTime
    Calendar start = new GregorianCalendar();
    start.setTime(sDate);

    // construct endTime
    int eyear = endTime.getDate().getYear();
    int emonth = endTime.getDate().getMonth();
    int eddate = endTime.getDate().getDate();
    int eh = (Integer) endHourSpinner.getValue();
    int em = (Integer) endMinuteSpinner.getValue();
    Date eDate = new Date(eyear, emonth, eddate, eh, em);

    // set endTime
    Calendar finish = new GregorianCalendar();
    finish.setTime(eDate);

    User owner = main.getUser();
    Room r = (Room) roomList.getSelectedValue();
    Appointment saveApp;

    if (isNull) {
      saveApp = new Appointment(0, title, start, finish, owner);
    } else {
      saveApp = new Appointment(model.getAppointmentId(), title, start, finish, owner);
    }

    // legg til participants
    ArrayList<Participant> deletablePart = new ArrayList<Participant>();

    Map<String, User> userMap = new HashMap<String, User>();
    userMap.put(owner.getUsername(), owner);
    for (int i = 0; i < personListModel.getSize(); i++) {
      userMap.put(((User) personListModel.get(i)).getUsername(), ((User) personListModel.get(i)));
    }

    // fra gruppe
    for (int i = 0; i < groupListModel.getSize(); i++) {
      ArrayList<Member> members = ((Group) groupListModel.get(i)).getMembers();
      for (int j = 0; j < members.size(); j++) {
        userMap.put(members.get(j).getUser().getUserName(), members.get(j).getUser());
      }
    }

    ArrayList<User> allPart = new ArrayList<User>(userMap.values());

    for (int i = 0; i < allPart.size(); i++) {
      deletablePart.add(new Participant(saveApp, allPart.get(i)));
    }

    saveApp.setRoom(r);
    saveApp.setDescription(descr);

    if (isNull) {
      main.getServer().insertAppointment(saveApp);
    } else {
      main.getServer().updateAppointment(saveApp, model);
    }

    // delete participants
    for (int i = 0; i < deletablePart.size(); i++) {
      deletablePart.get(i).remove();
    }
    saveApp.remove();
  }
Exemple #16
0
  /**
   * Updates the stored user with any not null information in the passed user
   *
   * @param u The user to update from.
   * @throws InvalidFieldException Thrown if anything is of the wrong format.
   */
  public void update(User u) throws InvalidFieldException {
    if (u.getFirstName() != null) {
      setFirstName(u.getFirstName());
    }

    if (u.getLastName() != null) {
      setLastName(u.getLastName());
    }

    if (u.getID() != null) {
      setID(u.getID());
    }

    if (u.getPoints() != getPoints()) {
      setPoints(u.getPoints());
    }

    if (u.getWeeklyPick() != null && !u.getWeeklyPick().isNull()) {
      setWeeklyPick(u.getWeeklyPick());
    }

    if (u.getUltimatePick() != null && !u.getUltimatePick().isNull()) {
      setUltimatePickNoSetPts(u.getUltimatePick());
    }

    if (u.getUltimatePoints() != getUltimatePoints()) {
      setUltimatePoints(u.getUltimatePoints());
    }
  }
Exemple #17
0
  public void playLevel(int level) { // Run the game
    System.out.println("Starting level " + level);
    onTitleScreen = false;
    toBeKilled = 100; // Game is intended to be run at 100
    timer = 0;
    onScreen = 0;

    // Updates level information and saves to User
    currentLevel = level;
    if (currentLevel > user.getMaxLevel()) user.setMaxLevel(currentLevel);
    Data.save(user);

    // Making appropriate adjustments to game screen
    backgroundLabel.setIcon(backgroundIcon[(currentLevel - 1) % 3 + 1]);

    counterLabel[0].setIcon(counterIcon[1]);
    counterLabel[1].setIcon(counterIcon[0]);
    counterLabel[2].setIcon(counterIcon[0]);

    for (int i = 0; i < counterLabel.length; i++) counterLabel[i].setVisible(true);
    for (int i = 0; i < user.getHealth(); i++) // Adjust health hands accordingly
    healthHandLabel[i].setVisible(true);

    // Switch to game cursor
    menuCursorLabel.setVisible(false);
    gameCursorLabel.setVisible(true);

    new Thread(
            new Runnable() {
              public void run() {
                try {
                  Thread.currentThread().sleep(500);
                  music.playLevelMusic(
                      (currentLevel - 1) % 3 + 1); // First three songs continuously looped
                  Thread.currentThread().sleep(2500);
                  while (toBeKilled > 0) { // Level is over when all are dead
                    if (gameOver) {
                      gameOver();
                      return;
                    }
                    if (onScreen < 2 * ((currentLevel - 1) % 3 + 1)
                        && timer > 10
                        && (onScreen % 20 != toBeKilled % 20
                            || onScreen == 0)) { // Limits number on screen and when they appear
                      onScreen++;
                      timer = (int) Math.round(Math.random() * 5);

                      if (toBeKilled > 80) createBug(SMALLFLY);
                      else if (toBeKilled > 60) {
                        if (Math.random() > .6) createBug(SMALLFLY);
                        else createBug(BLUEFLY);
                      } else if (toBeKilled > 40) {
                        if (Math.random() > .6) createBug(SMALLFLY);
                        else createBug(WASP);
                      } else if (toBeKilled > 20) {
                        createBug(BLUEFLY);
                      } else {
                        if (Math.random() > .5) createBug(WASP);
                        else createBug(BLUEFLY);
                      }
                    }
                    for (int j = 0; j < aLabel.size(); j++) aLabel.get(j).step();
                    Thread.currentThread().sleep(40);
                    timer++;
                  }
                } catch (Exception exc) {
                }
                if (!gameOver) {
                  System.out.println("Level beaten.  Moving to next level.");
                  music.stop();
                  clearScreen();
                  playLevel(currentLevel + 1);
                }
              }
            })
        .start();
  }
  public PickScreen(int voteType) {
    super();
    this.voteType = voteType;

    VerticalFieldManager vertFieldManager =
        new VerticalFieldManager(
            VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLLBAR) {
          // Override the paint method to draw the background image.
          public void paint(Graphics graphics) {
            graphics.setColor(Color.BLACK);
            graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
            super.paint(graphics);
          }
        };
    ;

    try { // set up the smaller list font
      ff1 = FontFamily.forName("Verdana");
      font2 = ff1.getFont(Font.BOLD, 20);
    } catch (final ClassNotFoundException cnfe) {
    }

    Vector contList = GameData.getCurrentGame().getActiveContestants();

    Contestant[] contArray = new Contestant[contList.size()];
    contList.copyInto(contArray);
    ocfActiveContestant = new ObjectChoiceField(" Cast your " + voteType + " vote: ", contArray);
    User user = GameData.getCurrentGame().getCurrentUser();
    if (voteType == T_WEEKLY && user.getWeeklyPick() != null) {
      ocfActiveContestant.setSelectedIndex(user.getWeeklyPick());
    } else if (voteType == T_ULTIMATE && user.getUltimatePick() != null) {
      ocfActiveContestant.setSelectedIndex(user.getUltimatePick());
    }

    list = new RichList(vertFieldManager, true, 3, 0);

    // get all contestants for list
    contList = GameData.getCurrentGame().getAllContestants();
    for (int i = 0; i < contList.size(); i++) {
      Contestant cont = (Contestant) contList.elementAt(i);
      /* list contains labels so that the text colour can change */
      lblContName =
          new LabelField(cont.getFirstName() + " " + cont.getLastName(), LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);

      labelContTribe =
          new LabelField(cont.getTribe(), LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);

      String tempString = "";

      if (cont.isCastOff()) tempString = "Castoff";
      else tempString = "Active";

      labelTempStatus =
          new LabelField(tempString, LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);
      Bitmap imgContestant = getImage(cont.getPicture());
      list.add(new Object[] {imgContestant, lblContName, labelContTribe, labelTempStatus});
    }

    HorizontalFieldManager horFieldManager =
        new HorizontalFieldManager(
            HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.FIELD_HCENTER) {
          // Override the paint method to draw the background image.
          public void paint(Graphics graphics) {
            graphics.setColor(Color.GREEN);
            graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
            super.paint(graphics);
          }
        };
    ;

    String voted = "Vote";
    user = GameData.getCurrentGame().getCurrentUser();
    System.out.println(user.getWeeklyPick() + " " + this.voteType);
    if ((this.voteType == T_WEEKLY && user.getWeeklyPick() != null)
        || (this.voteType == T_ULTIMATE && user.getUltimatePick() != null)) voted = "Revote";
    btnVoted = new ButtonField(voted);
    btnVoted.setChangeListener(this);

    horFieldManager.add(btnVoted);
    horFieldManager.add(ocfActiveContestant);
    horFieldManager.setFont(font2);

    this.setTitle(horFieldManager);
    this.add(vertFieldManager);
    this.setStatus(Common.getToolbar("Log Out"));
    vertFieldManager.setFocus(); // THIS NEEDS TO BE HERE. APP CRASHES WITHOUT IT
  }
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed

    try {
      String status = null;
      if (jRadioButton1.isSelected()) status = "Student";
      else if (jRadioButton2.isSelected()) status = "Teacher";

      User u = new User();
      u.setUsername(jTextField8.getText());
      u.setPassword(jPasswordField1.getText());
      u.setFirstname(jTextField1.getText());
      u.setLastname(jTextField2.getText());
      u.setStudentID(jTextField3.getText());
      u.setBirthDay(jTextField4.getText());
      u.setTelephone(jTextField5.getText());
      u.setEmail(jTextField6.getText());
      u.setFacebook(jTextField7.getText());
      u.setStatus(status);

      SQLConnection MyCon = new SQLConnection();
      Connection c = MyCon.getConnection("journal");
      Statement stmt = c.createStatement();
      // String name = MyCon.getUsername();
      String checkname, checkid;
      int foundname = 0, foundid = 0;
      String SQL = "select * from profile ;";
      ResultSet rs = stmt.executeQuery(SQL);
      while (rs.next()) {
        checkname = rs.getString("username");
        if (checkname.toUpperCase().equals(jTextField8.getText().toUpperCase())) {
          foundname = 1;
          break;
        }
        checkid = rs.getString("studentID");
        if (checkid.toUpperCase().equals(jTextField3.getText().toUpperCase())) {
          foundid = 1;
          break;
        }
      }

      if (u.getUsername().equalsIgnoreCase("")) {
        jLabel12.setVisible(true);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (foundname == 1) {
        JOptionPane.showMessageDialog(null, "Username " + jTextField8.getText() + " is already");
        jLabel12.setVisible(true);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getPassword().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(true);
      } else if (u.getFirstname().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(true);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getLastname().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(true);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getStudentID().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(true);
        jLabel18.setVisible(false);
      } else if (foundid == 1) {
        JOptionPane.showMessageDialog(null, "StudentID " + jTextField3.getText() + " is already");
      } else {
        SQLConnection mycon = new SQLConnection();
        mycon.SQLInsertProfile(u);
        mycon.SQLcreateTableForUser(jTextField8.getText());
        mycon.useUsername(jTextField8.getText());
        new ShowProfile().show();
        this.dispose();
      }
    } catch (SQLException ex) {
      Logger.getLogger(CreateProfile.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_jButton1ActionPerformed
Exemple #20
0
 public User makeUser(String id) {
   User user = new User();
   user.ID = id;
   return user;
 }