This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io-client') | |
let socket = io.connect('http://localhost:3000') | |
socket.on('connect', (data) => { | |
let playerId | |
console.log('connected') | |
socket.on('success', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("Welcome to the Qritter Wars Client") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
host: "qlikathon.qlik.com", | |
socketPort: 3000, | |
apiPort: 8080, | |
apiId: "<id>", | |
apiSecret: "<secret>" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the api key passed to the Qritter Wars REST API in the Authorization header | |
// for authentication | |
// format: base64 encoded value of <apiId>:<apiSecret> | |
const apiKey = new Buffer(`${config.apiId}:${config.apiSecret}`).toString('base64') | |
let createOptions = (endpoint, method, body) => { | |
// we need to return all options that the request module expects | |
// for an http request. 'uri' is the location of the request, 'method' | |
// is what http method we want to use (most likely GET or POST). headers | |
// are the http headers we want attached to our request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getGame = (gameId) => { | |
return new Promise((resolve, reject) => { | |
// we want to perform a GET request to the games/:id API | |
// to retrieve information about the given game | |
let options = createOptions(`games/${gameId}`, "GET") | |
request.get(options, (error, res, body) => { | |
if (error || res.statusCode !== 200) { | |
console.error("Error Getting Game", error || res.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require("socket.io-client") | |
const request = require("request") | |
const config = require("./config") | |
console.log("Welcome to the Qritter Wars Client") | |
// This is the api key passed to the Qritter Wars REST API in the Authorization header | |
// for authentication | |
// format: base64 encoded value of <apiId>:<apiSecret> | |
const apiKey = new Buffer(`${config.apiId}:${config.apiSecret}`).toString('base64') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let performMove = () => { | |
// this is where we would put our logic for deciding which move to make | |
// here we are just attacking all the time. We should probably be more | |
// creative than this. If we don't heal our Qritter will most likely be | |
// defeated in no time. | |
let body = {action: "attack"} | |
let options = createOptions("moves", "POST", body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('move played', (move) => { | |
// someone has played a move in our game | |
// if the move just played wasn't by us, it is now | |
// our turn to play. | |
if (move.player != playerId) { | |
console.log(`opponent performed ${move.result}`) | |
performMove() | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cheerio = require('cheerio') | |
const request = require('request') | |
const mongoose = require('mongoose') | |
const config = require('config') | |
const Publication = require('./server/models/publication') | |
mongoose.Promise = global.Promise | |
let archives = [ | |
["2016", "12"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Repo { | |
name: string; | |
forks_count: number; | |
open_issues: number; | |
constructor(json: {}) { | |
this.name = json.name; | |
this.forks_count = json.forks_count; | |
this.open_issues = json.open_issues; | |
} |
OlderNewer