Skip to content

Commit

Permalink
livecode
Browse files Browse the repository at this point in the history
  • Loading branch information
Fachrizal Gita authored and Fachrizal Gita committed Feb 23, 2018
1 parent 9aae033 commit bbd1775
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 3 deletions.
34 changes: 31 additions & 3 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ class RNG {

return result;
}
static gatchaRoll(times, callback){
let data
if(times === 0){
data = 0
}
else{
let arr = []
for(let i=0; i<times; i++){
arr.push(RNG.roll())
}
arr.sort()
data = arr[arr.length-1]
}
callback(data)
}
static gatchaRollPromise(times){
let arr = []
if(times === 0){
return 0
}
else{
for(let i=0; i<times; i++){
arr.push(RNG.roll())
}
arr.sort()
return arr[arr.length-1]
}
}
}

function viewGachaResult(best) {
Expand All @@ -35,17 +63,17 @@ 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() };
.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)

// code here...
// code here...
24 changes: 24 additions & 0 deletions oop/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const WallE = require('./wall-e')
const BayMax = require('./baymax')
const AutoBot = require('./autobot')
const RobotFactory = require('./robotfactory')

let Walle = new WallE
let Baymax = new BayMax
let Autobot = new AutoBot

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();
}
13 changes: 13 additions & 0 deletions oop/autobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class Autobot extends Robot {
constructor() {
super()
this.name = 'AutoBot'
this.purpose = 'defender'
}
defend(){
console.log(`${this.name}, let's roll!`)
}
}
module.exports = Autobot
13 changes: 13 additions & 0 deletions oop/baymax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class Baymax extends Robot {
constructor() {
super()
this.name = 'BayMax'
this.purpose = 'medic'
}
heal(){
console.log(`Hi, I'm ${this.name}, how may I help you?`)
}
}
module.exports = Baymax
8 changes: 8 additions & 0 deletions oop/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Robot {
constructor(name, purpose) {
this.name = name
this.purpose = purpose
}
}

module.exports = Robot
35 changes: 35 additions & 0 deletions oop/robotfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Robot = require('./robot')
const WallE = require('./wall-e')
const BayMax = require('./baymax')
const AutoBot = require('./autobot')

class RobotFactory {
constructor() {

}
static produceRobot(robotName, totalRobot){
let robot
let result = []
if(robotName === 'wall-e'){
for(let i=0; i<totalRobot; i++){
robot = new WallE
result.push(robot)
}
}
else if(robotName === 'baymax'){
for(let i=0; i<totalRobot; i++){
robot = new BayMax
result.push(robot)
}
}
else if(robotName === 'autobot'){
for(let i=0; i<totalRobot; i++){
robot = new AutoBot
result.push(robot)
}
}
return result
}
}

module.exports = RobotFactory
13 changes: 13 additions & 0 deletions oop/wall-e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Robot = require('./robot')

class WallE extends Robot {
constructor() {
super()
this.name = 'Wall-E'
this.purpose = 'worker'
}
work(){
console.log(`${this.name} cleans the planet`)
}
}
module.exports = WallE
Binary file modified query/database.db
Binary file not shown.
13 changes: 13 additions & 0 deletions query/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "Erwin W Ramadhan <[email protected]>",
"license": "ISC",
"dependencies": {
"cli-table": "^0.3.1",
"sqlite3": "^3.1.13"
}
}
35 changes: 35 additions & 0 deletions query/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const sqlite3 = require('sqlite3').verbose()
const db = new sqlite3.Database('database.db')
const Table = require('cli-table')

db.serialize(function(){
db.all(`SELECT title, point, level, name, age, gender FROM Status
INNER JOIN Players ON Status.playerId = Players.id
ORDER BY level DESC`, (error, data) => {
if(!data){
console.log(error);
}else{
console.log(data);
}
})
db.all(`SELECT COUNT(*) as totalcard, Players.id, Players.name, age, gender FROM Players
INNER JOIN Cards ON Players.id = Cards.playerId
WHERE gender = 'Male'
LIMIT 3`, (error, data) => {
if(!data){
console.log(error);
}else{
let table = new Table({
head: ['totalcard', 'id', 'name', 'age', 'gender'],
colWidths: [15, 5, 10, 5, 10]
})

for(let i=0; i<data.length; i++){
table.push([data[i].totalcard, data[i].id, data[i].name, data[i].age, data[i].gender])
}
console.log(table.toString())
}
})
})

db.close()

0 comments on commit bbd1775

Please sign in to comment.