Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agrha #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 59 additions & 9 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class RNG {
static roll() {
const tiers = [1, 2, 3, 4, 5];
let num = Math.floor(Math.random() * 100) + 1;
let result = 'UNKNOWN';
let result = 0;
if(num > 60) {
result = tiers[0];
} else if(num > 40) {
Expand All @@ -14,11 +14,50 @@ class RNG {
} else {
result = tiers[4];
}
return result
}

return result;
static gatchaRoll(times,callback){
let best = 0
var counter = setInterval(function(){
if(times === 0){
callback(best)
clearInterval(counter)
} else {
let a = RNG.roll()
// console.log(`dapet kocokan ${a}`);
if(a > best) {
best = a
}
times -= 1
}
},1000)
return ''
}

static gatchaRollPromise(times){
return new Promise((resolve, reject) => {
let best = 0
let count = setInterval(() => {
if (times < 0) {
resolve(viewGachaResult(best));
clearInterval(count);
} else {
let a = RNG.roll()
// console.log(`dapet kocokan ${a}`);
if(a > best) {
best = a
}
times -= 1
}
}, 1000);
})
}
}




function viewGachaResult(best) {
console.log(`YOUR BEST GATCHA ROLL RESULT IS ${best}`);
}
Expand All @@ -29,23 +68,34 @@ function viewGachaFailure() {

// RELEASE 0 TEST CASES
RNG.gatchaRoll(5, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
RNG.gatchaRoll(1, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
RNG.gatchaRoll(0, function(result) { viewGachaResult(result) }); // output: 0
// RNG.gatchaRoll(1, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik
// RNG.gatchaRoll(0, function(result) { viewGachaResult(result) }); // output: 0

// RELEASE 1 TEST CASES
RNG.gatchaRollPromise(5)
.then(function(result) { viewGachaResult(result) })
.catch(function(err) { viewGachaFailure() };
// RNG.gatchaRollPromise(5)
// .then(function(result) { viewGachaResult(result) })
// .catch(function(err) { viewGachaFailure() });

// akan menampilkan di log: YOUR BEST GATCHA ROLL RESULT IS <angka antara 1-5>

RNG.gatchaRollPromise(0)
.then(function(result) { viewGachaResult(result) })
.catch(function(err) { viewGachaFailure() };
.catch(function(err) { viewGachaFailure() });

// akan menampilkan di log: YAKIN NGGAK MAU NGE-ROLL?


// RELEASE 2 PROMISE(S)
let arr = []
for(let i = 0;i<10;i++){
arr.push(RNG.gatchaRollPromise(5))
}

// code here...
Promise.all(arr)
.then(function(data){
data
})
.catch(function(err){
console.log(err);
})
// code here...
16 changes: 16 additions & 0 deletions oop/autobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Robot = require('./robot.js')

class Autobot extends Robot {
constructor(name) {
super(name)
this.purpose = 'defend'
}
defend(){
console.log("AutoBot, let's roll!")
}
}

// var a = new Autobot('Bee','defender')
// a.defend()

module.exports = Autobot;
15 changes: 15 additions & 0 deletions oop/baymax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Robot = require('./robot.js')

class Baymax extends Robot {
constructor(name) {
super(name)
this.purpose = 'medic'
}
heal(){
console.log('Hi, I am BayMax, how may I help you?')
}
}

// let a = new Baymax('baymax')
// a.heal()
module.exports = Baymax;
Empty file added oop/index.js
Empty file.
7 changes: 7 additions & 0 deletions oop/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Robot {
constructor(name) {
this.name = name
}
}

module.exports = Robot;
45 changes: 45 additions & 0 deletions oop/robot_factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Wall = require('./wall-e.js')
const Baymax = require('./baymax.js')
const Autobot = require('./autobot.js')

class RobotFactory {
constructor() {
}

static produceRobot(name,amount){
let arr = []
if(name === 'wall-e'){
for(let i =0;i<amount;i++){
let robot = new Wall(name)
arr.push(robot)
}
} else if(name === 'baymax'){
for(let i =0;i<amount;i++){
let robot = new Baymax(name)
arr.push(robot)
}
} else if(name === 'autobot'){
for(let i =0;i<amount;i++){
let robot = new Autobot(name)
arr.push(robot)
}
}
return arr
}
}

let wall_e = RobotFactory.produceRobot('wall-e', 6);
let baymax = RobotFactory.produceRobot('baymax', 5);
let autobot = RobotFactory.produceRobot('autobot', 3);

for (var i = 0; i < wall_e.length; i++) {
wall_e[i].work()
}

for (var i = 0; i < baymax.length; i++) {
baymax[i].heal();
}

for (var i = 0; i < autobot.length; i++) {
autobot[i].defend();
}
16 changes: 16 additions & 0 deletions oop/wall-e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Robot = require('./robot.js')

class Wall extends Robot {
constructor(name) {
super(name)
this.purpose = 'worker'
}
work(){
console.log('Wall-E cleans the planet')
}
}

// let a = new Wall('wall-e')
// a.heal()

module.exports = Wall;
Binary file modified query/database.db
Binary file not shown.
37 changes: 37 additions & 0 deletions query/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('database.db');

// release 0
function sortPlayer(){
db.all(` SELECT title, point, level, Players.name, Players.age, Players.gender FROM Status
LEFT JOIN Players ON Players.id = Status.playerId
ORDER BY Status.level DESC`,(err,data)=>{
if(!err){
console.log(data)
}else{
console.log(err)
}
})
}



// sortPlayer()
function cardCount(){
db.all(` SELECT COUNT(Cards.PlayerId) As totalcard,
Cards.playerId, Players.name,Players.age,Players.gender
FROM Cards
LEFT JOIN Players ON Players.id = Cards.playerId
WHERE Players.gender = 'Male'
GROUP BY Cards.playerId
ORDER by totalcard DESC
LIMIT 3
`,(err,data)=>{
if(!err){
console.log(data)
}else{
console.log(err)
}
})
}
cardCount()