コード例 #1
0
ファイル: MainActivity.java プロジェクト: MrLJones/Emote
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dbhelper = new DatabaseHelper(getApplicationContext());
    setContentView(R.layout.activity_main);

    beaconManager = new BeaconManager(getApplicationContext());
    beaconManager.connect(
        new BeaconManager.ServiceReadyCallback() {
          @Override
          public void onServiceReady() {
            beaconManager.startMonitoring(new Region("monitored region", null, null, null));
          }
        });

    dbhelper.addUser(new UserBean(1, "Player", 0));

    user = dbhelper.getUserByID(1);

    Log.i(APP_NAME, user.getUsername() + ", " + user.getLevel() + ", " + user.getId());

    Button run = (Button) findViewById(R.id.myRunButton);
    run.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            runaway();
          }
        });

    // set up listeners
    beaconManager.setMonitoringListener(
        new BeaconManager.MonitoringListener() {
          @Override
          public void onEnteredRegion(Region region, List<Beacon> list) {
            try {
              new HttpGetJsonTask()
                  .execute(
                      new URL("http://192.168.224.130:5000/monsters?userlevel=" + user.getLevel()));

            } catch (Exception e) {

            }
            showNotification(
                "You have entered a battle",
                "You have entered a battle with a monster click to fight and check it out.");
          }

          @Override
          public void onExitedRegion(Region region) {
            Toast.makeText(getApplicationContext(), "Exited a beacon", Toast.LENGTH_SHORT).show();
          }
        });
    // end of listeners
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: MrLJones/Emote
  public void runBattle() {

    if (fightingMonster != null) {

      // load monster on screen
      int counter = 0;
      while (fightingMonster.getImage() == null && counter != 1000) {}

      final ProgressBar progBar = (ProgressBar) findViewById(R.id.progressBar);
      progBar.setMax(fightingMonster.getHealth());
      progBar.setProgress(fightingMonster.getHealth());
      ImageView imgV = (ImageView) findViewById(R.id.myImageView);

      final ProgressBar userHealthBar = (ProgressBar) findViewById(R.id.userHealthBar);
      user.setHealth(12 * user.getLevel());
      userHealthBar.setMax(user.getHealth());
      userHealthBar.setProgress(user.getHealth());
      Random rndNumGen = new Random();
      // Generate 2 numbers (one for each combatant) who ever gets higher wins
      int playerScore = rndNumGen.nextInt(10);
      int monsterScore = rndNumGen.nextInt(9);
      imgV.setImageBitmap(fightingMonster.getImage());
      imgV.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Random rndNumGen = new Random();
              // Generate 2 numbers (one for each combatant) who ever gets higher wins
              int playerScore = rndNumGen.nextInt(10);
              int monsterScore = rndNumGen.nextInt(9);
              if (playerScore >= monsterScore) {
                fightingMonster.hit();
                userHealthBar.setProgress(user.getHealth());
              } else if (monsterScore >= playerScore) {
                user.hit();
                progBar.setProgress(fightingMonster.getHealth());
              }
              if (fightingMonster.getHealth() == 0) {
                Toast.makeText(MainActivity.this, "Health 0", Toast.LENGTH_LONG).show();
                user.increaseLevel();
                dbhelper.updateUser(user);

                loadMainPage(
                    "Congratulations you defeated "
                        + fightingMonster.getName()
                        + " your new level is "
                        + user.getLevel());
              }
            }
          });
    }
  }
コード例 #3
0
  public HashMap<Integer, Integer> GetUserShoppinCart(UserBean ub) {
    PreparedStatement preparedStatement = null;

    HashMap<Integer, Integer> CartList = new HashMap<Integer, Integer>();

    int uId = ub.getId();

    try {
      // connect to DB
      currentCon = DBUtil.getConnection();

      preparedStatement = currentCon.prepareStatement("select * from shopping_cart where u_id=?");
      System.out.println("Query: " + preparedStatement);
      preparedStatement.setInt(1, uId);

      rs = preparedStatement.executeQuery();

      boolean more = rs.next();
      if (more) {

        while (more) {

          CartList.put(rs.getInt("pro_id"), rs.getInt("quantity"));
        }

        ub.setValid(true);
      }
      // if user does not exist set the isValid variable to false
      else {
        System.out.println("Sorry,Can't get Your cart data");
        ub.setValid(false);
      } // if user exists set the isValid variable to true

    } catch (Exception ex) {
      System.out.println("Load data failed: An Exception has occurred! " + ex);
    } // some exception handling
    finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (Exception e) {
        }
        rs = null;
      }

      if (preparedStatement != null) {
        try {
          preparedStatement.close();
        } catch (Exception e) {
        }
      }

      if (currentCon != null) {
        try {
          currentCon.close();
        } catch (Exception e) {
        }

        currentCon = null;
      }
    }

    return CartList;
  }
コード例 #4
0
  public String execute() {
    UserManager userMng = new UserManager();
    User user = new User();
    Branch branch = new Branch();
    Role role = new Role();
    HashUtil hashUtil = new HashUtil();

    branch.setId(bean.getBranchID());
    role.setId(bean.getRoleID());
    user.setFullName(bean.getFullName());
    user.setUserName(bean.getUsername());
    user.setPhoto(bean.getPhoto());
    user.setPass(hashUtil.md5(bean.getPass()));
    user.setBirthDate(bean.getBirthDate());
    user.setEmail(bean.getEmail());
    user.setGender(bean.getGender());
    user.setAddress(bean.getAddress());
    user.setBranch(branch);
    user.setRole(role);
    user.setActive(bean.isActive());

    boolean isExistUser = false;
    boolean isExistMail = false;

    isExistUser = userMng.checkExistRecord(bean.getUsername());
    isExistMail = userMng.checkExistUserEmail(bean.getEmail());

    if (isExistUser == false && isExistMail == false) {
      userMng.insert(user);
      addActionMessage("Insert User Successfully !!!");
      return SUCCESS;
    } else if (isExistMail == true) {
      addActionError("Email of this User already exists !!! Please enter another one!!!");
      return ERROR;
    } else {
      addActionError("User already exists !!!");
      return ERROR;
    }
  }
コード例 #5
0
  public UserBean GetUserData(UserBean ub) {
    PreparedStatement preparedStatement = null;

    String email = ub.getEmail();

    try {
      // connect to DB
      currentCon = DBUtil.getConnection();

      preparedStatement = currentCon.prepareStatement("select * from user where u_email=?");
      System.out.println("Query: " + preparedStatement);
      preparedStatement.setString(1, email);

      rs = preparedStatement.executeQuery();

      boolean more = rs.next();

      // if user does not exist set the isValid variable to false
      if (!more) {
        System.out.println("Sorry, you are not a registered user! Please sign up first");
        ub.setValid(false);
      } // if user exists set the isValid variable to true
      else if (more) {
        ub.setId(rs.getInt("u_id"));
        ub.setName(rs.getString("u_name"));
        ub.setEmail(rs.getString("u_email"));
        ub.setPassword(rs.getString("u_password"));
        ub.setJob(rs.getString("u_job"));
        ub.setAddress(rs.getString("u_address"));
        ub.setBirthDate(rs.getDate("u_bdate"));
        ub.setCardId(rs.getInt("cart_id"));
        ub.setCardLimit(rs.getInt("u_credit_limit"));
      }
    } catch (Exception ex) {
      System.out.println("Log In failed: An Exception has occurred! " + ex);
    } // some exception handling
    finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (Exception e) {
        }
        rs = null;
      }

      if (preparedStatement != null) {
        try {
          preparedStatement.close();
        } catch (Exception e) {
        }
      }

      if (currentCon != null) {
        try {
          currentCon.close();
        } catch (Exception e) {
        }

        currentCon = null;
      }
    }

    return ub;
  }