Now with 100% more Blockchain!
@@ -43,3 +43,80 @@ flycheck_*.el
|
||||
|
||||
# directory configuration
|
||||
.dir-locals.el
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
@@ -3,3 +3,5 @@
|
||||
CEIDEC-Pong Web is a Pong-like game programmed in Javascript with the [[https://phaser.io/][Phaser.io]] framework. It was developed for a game programming course to be taught during the [[https://twitter.com/Noticienciasucv/status/1056776035214258176/][CEIDEC 2018]] week at the [[http://www.ucv.ve/][Universidad Central de Venezuela]].
|
||||
|
||||
CEIDEC-Pong is [[https://people.freebsd.org/~phk/][Beerware]]. Check the LICENSE file for more details.
|
||||
|
||||
*Now with 100% more Blockchain!*
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"server": {
|
||||
"baseDir": ["./src", "./build/contracts"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
{
|
||||
"contractName": "Ownable",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x6080604052348015600f57600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550603580605d6000396000f3006080604052600080fd00a165627a7a72305820629a36d6fc1082985acd0c13429616c48678a6c3a9219ea0df2bfd67cc94be130029",
|
||||
"deployedBytecode": "0x6080604052600080fd00a165627a7a72305820629a36d6fc1082985acd0c13429616c48678a6c3a9219ea0df2bfd67cc94be130029",
|
||||
"sourceMap": "26:2580:1:-;;;2554:50;8:9:-1;5:2;;;30:1;27;20:12;5:2;2554:50:1;2589:10;2581:5;;:18;;;;;;;;;;;;;;;;;;26:2580;;;;;;",
|
||||
"deployedSourceMap": "26:2580:1:-;;;;;",
|
||||
"source": "pragma solidity ^0.4.24;\n\ncontract Ownable {\n // .d8888b. 888 888 d8b 888 888 \n // d88P Y88b 888 888 Y8P 888 888 \n // Y88b. 888 888 888 888 \n // \"Y888b. 888888 8888b. 888888 .d88b. 888 888 8888b. 888d888 888 8888b. 88888b. 888 .d88b. .d8888b \n // \"Y88b. 888 \"88b 888 d8P Y8b 888 888 \"88b 888P\" 888 \"88b 888 \"88b 888 d8P Y8b 88K \n // \"888 888 .d888888 888 88888888 Y88 88P .d888888 888 888 .d888888 888 888 888 88888888 \"Y8888b. \n // Y88b d88P Y88b. 888 888 Y88b. Y8b. Y8bd8P 888 888 888 888 888 888 888 d88P 888 Y8b. X88 \n // \"Y8888P\" \"Y888 \"Y888888 \"Y888 \"Y8888 Y88P \"Y888888 888 888 \"Y888888 88888P\" 888 \"Y8888 88888P' \n\n address owner;\n\n \n // 888b d888 888 d8b .d888 d8b \n // 8888b d8888 888 Y8P d88P\" Y8P \n // 88888b.d88888 888 888 \n // 888Y88888P888 .d88b. .d88888 888 888888 888 .d88b. 888d888 .d8888b \n // 888 Y888P 888 d88\"\"88b d88\" 888 888 888 888 d8P Y8b 888P\" 88K \n // 888 Y8P 888 888 888 888 888 888 888 888 88888888 888 \"Y8888b. \n // 888 \" 888 Y88..88P Y88b 888 888 888 888 Y8b. 888 X88 \n // 888 888 \"Y88P\" \"Y88888 888 888 888 \"Y8888 888 88888P' \n \n modifier onlyOwner() {\n require(msg.sender == owner);\n _;\n }\n\n // 888 888 \n // 888 888 \n // 888 888 \n // .d8888b .d88b. 88888b. .d8888b 888888 888d888 888 888 .d8888b 888888 .d88b. 888d888 \n // d88P\" d88\"\"88b 888 \"88b 88K 888 888P\" 888 888 d88P\" 888 d88\"\"88b 888P\" \n // 888 888 888 888 888 \"Y8888b. 888 888 888 888 888 888 888 888 888 \n // Y88b. Y88..88P 888 888 X88 Y88b. 888 Y88b 888 Y88b. Y88b. Y88..88P 888 \n // \"Y8888P \"Y88P\" 888 888 88888P' \"Y888 888 \"Y88888 \"Y8888P \"Y888 \"Y88P\" 888 \n \n constructor() public {\n owner = msg.sender;\n }\n}\n",
|
||||
"sourcePath": "/home/miky/Documentos/Game/contracts/Ownable.sol",
|
||||
"ast": {
|
||||
"absolutePath": "/home/miky/Documentos/Game/contracts/Ownable.sol",
|
||||
"exportedSymbols": {
|
||||
"Ownable": [
|
||||
81
|
||||
]
|
||||
},
|
||||
"id": 82,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 58,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"^",
|
||||
"0.4",
|
||||
".24"
|
||||
],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:24:1"
|
||||
},
|
||||
{
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 81,
|
||||
"linearizedBaseContracts": [
|
||||
81
|
||||
],
|
||||
"name": "Ownable",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
{
|
||||
"constant": false,
|
||||
"id": 60,
|
||||
"name": "owner",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 81,
|
||||
"src": "1032:13:1",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"typeName": {
|
||||
"id": 59,
|
||||
"name": "address",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "1032:7:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"body": {
|
||||
"id": 70,
|
||||
"nodeType": "Block",
|
||||
"src": "1709:46:1",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"arguments": [
|
||||
{
|
||||
"argumentTypes": null,
|
||||
"commonType": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"id": 66,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"leftExpression": {
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 63,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 161,
|
||||
"src": "1723:3:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 64,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "sender",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "1723:10:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"nodeType": "BinaryOperation",
|
||||
"operator": "==",
|
||||
"rightExpression": {
|
||||
"argumentTypes": null,
|
||||
"id": 65,
|
||||
"name": "owner",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 60,
|
||||
"src": "1737:5:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"src": "1723:19:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": [
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
],
|
||||
"id": 62,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
164,
|
||||
165
|
||||
],
|
||||
"referencedDeclaration": 164,
|
||||
"src": "1715:7:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
|
||||
"typeString": "function (bool) pure"
|
||||
}
|
||||
},
|
||||
"id": 67,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"kind": "functionCall",
|
||||
"lValueRequested": false,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "1715:28:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_tuple$__$",
|
||||
"typeString": "tuple()"
|
||||
}
|
||||
},
|
||||
"id": 68,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "1715:28:1"
|
||||
},
|
||||
{
|
||||
"id": 69,
|
||||
"nodeType": "PlaceholderStatement",
|
||||
"src": "1749:1:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 71,
|
||||
"name": "onlyOwner",
|
||||
"nodeType": "ModifierDefinition",
|
||||
"parameters": {
|
||||
"id": 61,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "1706:2:1"
|
||||
},
|
||||
"src": "1688:67:1",
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"body": {
|
||||
"id": 79,
|
||||
"nodeType": "Block",
|
||||
"src": "2575:29:1",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 77,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"leftHandSide": {
|
||||
"argumentTypes": null,
|
||||
"id": 74,
|
||||
"name": "owner",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 60,
|
||||
"src": "2581:5:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"nodeType": "Assignment",
|
||||
"operator": "=",
|
||||
"rightHandSide": {
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 75,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 161,
|
||||
"src": "2589:3:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 76,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "sender",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "2589:10:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"src": "2581:18:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"id": 78,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "2581:18:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 80,
|
||||
"implemented": true,
|
||||
"isConstructor": true,
|
||||
"isDeclaredConst": false,
|
||||
"modifiers": [],
|
||||
"name": "",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters": {
|
||||
"id": 72,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "2565:2:1"
|
||||
},
|
||||
"payable": false,
|
||||
"returnParameters": {
|
||||
"id": 73,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "2575:0:1"
|
||||
},
|
||||
"scope": 81,
|
||||
"src": "2554:50:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"superFunction": null,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 82,
|
||||
"src": "26:2580:1"
|
||||
}
|
||||
],
|
||||
"src": "0:2607:1"
|
||||
},
|
||||
"legacyAST": {
|
||||
"absolutePath": "/home/miky/Documentos/Game/contracts/Ownable.sol",
|
||||
"exportedSymbols": {
|
||||
"Ownable": [
|
||||
81
|
||||
]
|
||||
},
|
||||
"id": 82,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 58,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"^",
|
||||
"0.4",
|
||||
".24"
|
||||
],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:24:1"
|
||||
},
|
||||
{
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 81,
|
||||
"linearizedBaseContracts": [
|
||||
81
|
||||
],
|
||||
"name": "Ownable",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
{
|
||||
"constant": false,
|
||||
"id": 60,
|
||||
"name": "owner",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 81,
|
||||
"src": "1032:13:1",
|
||||
"stateVariable": true,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"typeName": {
|
||||
"id": 59,
|
||||
"name": "address",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "1032:7:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"body": {
|
||||
"id": 70,
|
||||
"nodeType": "Block",
|
||||
"src": "1709:46:1",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"arguments": [
|
||||
{
|
||||
"argumentTypes": null,
|
||||
"commonType": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"id": 66,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"leftExpression": {
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 63,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 161,
|
||||
"src": "1723:3:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 64,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "sender",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "1723:10:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"nodeType": "BinaryOperation",
|
||||
"operator": "==",
|
||||
"rightExpression": {
|
||||
"argumentTypes": null,
|
||||
"id": 65,
|
||||
"name": "owner",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 60,
|
||||
"src": "1737:5:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"src": "1723:19:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": [
|
||||
{
|
||||
"typeIdentifier": "t_bool",
|
||||
"typeString": "bool"
|
||||
}
|
||||
],
|
||||
"id": 62,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
164,
|
||||
165
|
||||
],
|
||||
"referencedDeclaration": 164,
|
||||
"src": "1715:7:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$",
|
||||
"typeString": "function (bool) pure"
|
||||
}
|
||||
},
|
||||
"id": 67,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"kind": "functionCall",
|
||||
"lValueRequested": false,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "1715:28:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_tuple$__$",
|
||||
"typeString": "tuple()"
|
||||
}
|
||||
},
|
||||
"id": 68,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "1715:28:1"
|
||||
},
|
||||
{
|
||||
"id": 69,
|
||||
"nodeType": "PlaceholderStatement",
|
||||
"src": "1749:1:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 71,
|
||||
"name": "onlyOwner",
|
||||
"nodeType": "ModifierDefinition",
|
||||
"parameters": {
|
||||
"id": 61,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "1706:2:1"
|
||||
},
|
||||
"src": "1688:67:1",
|
||||
"visibility": "internal"
|
||||
},
|
||||
{
|
||||
"body": {
|
||||
"id": 79,
|
||||
"nodeType": "Block",
|
||||
"src": "2575:29:1",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 77,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"leftHandSide": {
|
||||
"argumentTypes": null,
|
||||
"id": 74,
|
||||
"name": "owner",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 60,
|
||||
"src": "2581:5:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"nodeType": "Assignment",
|
||||
"operator": "=",
|
||||
"rightHandSide": {
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 75,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 161,
|
||||
"src": "2589:3:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 76,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "sender",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "2589:10:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"src": "2581:18:1",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"id": 78,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "2581:18:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 80,
|
||||
"implemented": true,
|
||||
"isConstructor": true,
|
||||
"isDeclaredConst": false,
|
||||
"modifiers": [],
|
||||
"name": "",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters": {
|
||||
"id": 72,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "2565:2:1"
|
||||
},
|
||||
"payable": false,
|
||||
"returnParameters": {
|
||||
"id": 73,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "2575:0:1"
|
||||
},
|
||||
"scope": 81,
|
||||
"src": "2554:50:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"superFunction": null,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 82,
|
||||
"src": "26:2580:1"
|
||||
}
|
||||
],
|
||||
"src": "0:2607:1"
|
||||
},
|
||||
"compiler": {
|
||||
"name": "solc",
|
||||
"version": "0.4.24+commit.e67f0147.Emscripten.clang"
|
||||
},
|
||||
"networks": {},
|
||||
"schemaVersion": "2.0.1",
|
||||
"updatedAt": "2018-10-31T09:33:41.481Z"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
pragma solidity ^0.4.23;
|
||||
|
||||
contract Migrations {
|
||||
address public owner;
|
||||
uint public last_completed_migration;
|
||||
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
modifier restricted() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function setCompleted(uint completed) public restricted {
|
||||
last_completed_migration = completed;
|
||||
}
|
||||
|
||||
function upgrade(address new_address) public restricted {
|
||||
Migrations upgraded = Migrations(new_address);
|
||||
upgraded.setCompleted(last_completed_migration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
contract Ownable {
|
||||
// .d8888b. 888 888 d8b 888 888
|
||||
// d88P Y88b 888 888 Y8P 888 888
|
||||
// Y88b. 888 888 888 888
|
||||
// "Y888b. 888888 8888b. 888888 .d88b. 888 888 8888b. 888d888 888 8888b. 88888b. 888 .d88b. .d8888b
|
||||
// "Y88b. 888 "88b 888 d8P Y8b 888 888 "88b 888P" 888 "88b 888 "88b 888 d8P Y8b 88K
|
||||
// "888 888 .d888888 888 88888888 Y88 88P .d888888 888 888 .d888888 888 888 888 88888888 "Y8888b.
|
||||
// Y88b d88P Y88b. 888 888 Y88b. Y8b. Y8bd8P 888 888 888 888 888 888 888 d88P 888 Y8b. X88
|
||||
// "Y8888P" "Y888 "Y888888 "Y888 "Y8888 Y88P "Y888888 888 888 "Y888888 88888P" 888 "Y8888 88888P'
|
||||
|
||||
address owner;
|
||||
|
||||
|
||||
// 888b d888 888 d8b .d888 d8b
|
||||
// 8888b d8888 888 Y8P d88P" Y8P
|
||||
// 88888b.d88888 888 888
|
||||
// 888Y88888P888 .d88b. .d88888 888 888888 888 .d88b. 888d888 .d8888b
|
||||
// 888 Y888P 888 d88""88b d88" 888 888 888 888 d8P Y8b 888P" 88K
|
||||
// 888 Y8P 888 888 888 888 888 888 888 888 88888888 888 "Y8888b.
|
||||
// 888 " 888 Y88..88P Y88b 888 888 888 888 Y8b. 888 X88
|
||||
// 888 888 "Y88P" "Y88888 888 888 888 "Y8888 888 88888P'
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner);
|
||||
_;
|
||||
}
|
||||
|
||||
// 888 888
|
||||
// 888 888
|
||||
// 888 888
|
||||
// .d8888b .d88b. 88888b. .d8888b 888888 888d888 888 888 .d8888b 888888 .d88b. 888d888
|
||||
// d88P" d88""88b 888 "88b 88K 888 888P" 888 888 d88P" 888 d88""88b 888P"
|
||||
// 888 888 888 888 888 "Y8888b. 888 888 888 888 888 888 888 888 888
|
||||
// Y88b. Y88..88P 888 888 X88 Y88b. 888 Y88b 888 Y88b. Y88b. Y88..88P 888
|
||||
// "Y8888P "Y88P" 888 888 88888P' "Y888 888 "Y88888 "Y8888P "Y888 "Y88P" 888
|
||||
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <miguel.astor@ciens.ucv.ve> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Miguel Angel Astor
|
||||
* -----------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "./Ownable.sol";
|
||||
|
||||
contract Pong is Ownable {
|
||||
uint256 timesPlayed;
|
||||
|
||||
event CanPlayTheGame(address indexed player);
|
||||
|
||||
constructor() public {
|
||||
timesPlayed = 0;
|
||||
}
|
||||
|
||||
function kill() public onlyOwner {
|
||||
selfdestruct(owner);
|
||||
}
|
||||
|
||||
function howManytimesPlayed() public view returns (uint256) {
|
||||
return timesPlayed;
|
||||
}
|
||||
|
||||
function play() payable public {
|
||||
require(msg.value == 1000000000000000000);
|
||||
owner.transfer(msg.value);
|
||||
timesPlayed += 1;
|
||||
emit CanPlayTheGame(msg.sender);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 732 B After Width: | Height: | Size: 732 B |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 552 B After Width: | Height: | Size: 552 B |
|
Before Width: | Height: | Size: 555 B After Width: | Height: | Size: 555 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>CEIDEC-Pong on the Web!</title>
|
||||
<style>
|
||||
* {
|
||||
padding: 0; margin: 0;
|
||||
}
|
||||
.main_table {
|
||||
background: rgba(255, 255, 255, 0.45);
|
||||
padding:10px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
</style>
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/web3.min.js"></script>
|
||||
<script src="js/truffle-contract.js"></script>
|
||||
<script src="js/phaser.min.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/eth.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<table class="main_table">
|
||||
<tr>
|
||||
<td>
|
||||
<p>Your ETH balance: <span id="balance">NOT LOADED</span></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div id="game_container"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p id="times_played"></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p id="can_play"></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,78 @@
|
||||
myWeb3 = null;
|
||||
myWeb3Provider = null;
|
||||
pong = null;
|
||||
myAccount = null;
|
||||
|
||||
function canIPlayTheGame() {
|
||||
pong.deployed().then(function(instance) {
|
||||
return instance.play({from: myAccount, value: web3.toWei(1, "ether"), gas: 500000});
|
||||
}).then(function(result) {
|
||||
if (result.logs[0].args.player === myAccount) {
|
||||
$('#can_play').text(myAccount + ' can play the game!');
|
||||
getTimesPlayed();
|
||||
playTheGame();
|
||||
} else {
|
||||
alert("Whoops! An error ocurred.\nThanks for your money, though :P");
|
||||
}
|
||||
}).catch(function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
function loadBalance() {
|
||||
myWeb3.eth.getCoinbase(function(err, account) {
|
||||
if (err === null) {
|
||||
myAccount = account;
|
||||
myWeb3.eth.getBalance(account, function(err, balance) {
|
||||
if (err === null) {
|
||||
$('#balance').text(myWeb3.fromWei(balance, "ether") + " ETH");
|
||||
$('#can_play').text(myAccount + " can't play the game... so sad!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getTimesPlayed() {
|
||||
pong.deployed().then(function(instance) {
|
||||
return instance.howManytimesPlayed();
|
||||
}).then(function(timesPlayed) {
|
||||
$('#times_played').text("The game has been played " + timesPlayed.toNumber() + " times!");
|
||||
}).catch(function(error) {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function initWeb3() {
|
||||
// Initialize web3
|
||||
if (typeof web3 !== 'undefined') {
|
||||
// Reuse the provider of the web3 object injected by Metamask
|
||||
console.log("Using injected web3 provider");
|
||||
myWeb3Provider = web3.currentProvider;
|
||||
} else {
|
||||
// Create a new provider and plug it directed in our local node
|
||||
console.log("Creating new web3 provider");
|
||||
myWeb3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
|
||||
}
|
||||
myWeb3 = new Web3(myWeb3Provider);
|
||||
|
||||
$.getJSON('Pong.json', function(pongArtifact) {
|
||||
// Get the contract artifact file and use it to instantiate a truffle contract abstraction
|
||||
pong = TruffleContract(pongArtifact);
|
||||
// Set the provider for our contract
|
||||
pong.setProvider(myWeb3Provider);
|
||||
|
||||
// update UI
|
||||
loadBalance();
|
||||
getTimesPlayed();
|
||||
|
||||
// Register call and listen for events.
|
||||
ethCallback = canIPlayTheGame;
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$(window).load(function() {
|
||||
initWeb3();
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,8 @@ var textStyle = {
|
||||
fill: "#FFFFFF",
|
||||
}
|
||||
|
||||
var ethCallback = null;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Helper functions. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -37,6 +39,14 @@ function randSig() {
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
if (ethCallback !== null) {
|
||||
canIPlayTheGame()
|
||||
} else {
|
||||
alert("Can't play the game\nWeb3 not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
function playTheGame() {
|
||||
startButton.destroy();
|
||||
ball.body.velocity.set(randSig() * 150, randSig() * 150);
|
||||
playing = true;
|
||||
@@ -106,8 +116,8 @@ function ballLeaveScreen() {
|
||||
function preload() {
|
||||
// Set basic game properties
|
||||
//game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
|
||||
game.scale.pageAlignHorizontally = true;
|
||||
game.scale.pageAlignVertically = true;
|
||||
//game.scale.pageAlignHorizontally = true;
|
||||
//game.scale.pageAlignVertically = true;
|
||||
game.stage.backgroundColor = "#eee";
|
||||
|
||||
// Set basic game properties
|
||||
@@ -1,13 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>CEIDEC-Pong on the Web!</title>
|
||||
<style>* { padding: 0; margin: 0; }</style>
|
||||
<script src="js/phaser.min.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game_container"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
Copyright JS Foundation and other contributors, https://js.foundation/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,5 @@
|
||||
var Migrations = artifacts.require("./Migrations.sol");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Migrations);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
var Pong = artifacts.require("./Pong.sol");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Pong);
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "ceidec-pong-web",
|
||||
"version": "0.0.1",
|
||||
"description": "Pong in the Blockchain!",
|
||||
"main": "truffle-config.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "lite-server",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"CEIDEC",
|
||||
"pong",
|
||||
"ethereum"
|
||||
],
|
||||
"author": "Miguel Angel Astor Romero",
|
||||
"license": "Beerware",
|
||||
"dependencies": {
|
||||
"lite-server": "^2.4.0",
|
||||
"truffle-contract": "^3.0.6",
|
||||
"web3": "^1.0.0-beta.36"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 732 B |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 552 B |
|
After Width: | Height: | Size: 555 B |
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>CEIDEC-Pong on the Web!</title>
|
||||
<style>
|
||||
* {
|
||||
padding: 0; margin: 0;
|
||||
}
|
||||
.main_table {
|
||||
background: rgba(255, 255, 255, 0.45);
|
||||
padding:10px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
</style>
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/web3.min.js"></script>
|
||||
<script src="js/truffle-contract.js"></script>
|
||||
<script src="js/phaser.min.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/eth.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<table class="main_table">
|
||||
<tr>
|
||||
<td>
|
||||
<p>Your ETH balance: <span id="balance">NOT LOADED</span></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div id="game_container"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p id="times_played"></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p id="can_play"></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,78 @@
|
||||
myWeb3 = null;
|
||||
myWeb3Provider = null;
|
||||
pong = null;
|
||||
myAccount = null;
|
||||
|
||||
function canIPlayTheGame() {
|
||||
pong.deployed().then(function(instance) {
|
||||
return instance.play({from: myAccount, value: web3.toWei(1, "ether"), gas: 500000});
|
||||
}).then(function(result) {
|
||||
if (result.logs[0].args.player === myAccount) {
|
||||
$('#can_play').text(myAccount + ' can play the game!');
|
||||
getTimesPlayed();
|
||||
playTheGame();
|
||||
} else {
|
||||
alert("Whoops! An error ocurred.\nThanks for your money, though :P");
|
||||
}
|
||||
}).catch(function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
function loadBalance() {
|
||||
myWeb3.eth.getCoinbase(function(err, account) {
|
||||
if (err === null) {
|
||||
myAccount = account;
|
||||
myWeb3.eth.getBalance(account, function(err, balance) {
|
||||
if (err === null) {
|
||||
$('#balance').text(myWeb3.fromWei(balance, "ether") + " ETH");
|
||||
$('#can_play').text(myAccount + " can't play the game... so sad!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getTimesPlayed() {
|
||||
pong.deployed().then(function(instance) {
|
||||
return instance.howManytimesPlayed();
|
||||
}).then(function(timesPlayed) {
|
||||
$('#times_played').text("The game has been played " + timesPlayed.toNumber() + " times!");
|
||||
}).catch(function(error) {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function initWeb3() {
|
||||
// Initialize web3
|
||||
if (typeof web3 !== 'undefined') {
|
||||
// Reuse the provider of the web3 object injected by Metamask
|
||||
console.log("Using injected web3 provider");
|
||||
myWeb3Provider = web3.currentProvider;
|
||||
} else {
|
||||
// Create a new provider and plug it directed in our local node
|
||||
console.log("Creating new web3 provider");
|
||||
myWeb3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
|
||||
}
|
||||
myWeb3 = new Web3(myWeb3Provider);
|
||||
|
||||
$.getJSON('Pong.json', function(pongArtifact) {
|
||||
// Get the contract artifact file and use it to instantiate a truffle contract abstraction
|
||||
pong = TruffleContract(pongArtifact);
|
||||
// Set the provider for our contract
|
||||
pong.setProvider(myWeb3Provider);
|
||||
|
||||
// update UI
|
||||
loadBalance();
|
||||
getTimesPlayed();
|
||||
|
||||
// Register call and listen for events.
|
||||
ethCallback = canIPlayTheGame;
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$(window).load(function() {
|
||||
initWeb3();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <miguel.astor@ciens.ucv.ve> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Miguel Angel Astor
|
||||
* -----------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Global variables. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var player = null;
|
||||
var computer = null;
|
||||
var ball = null;
|
||||
var playing = false;
|
||||
var lives = 3;
|
||||
var c_lives = 3;
|
||||
var startButton = null;
|
||||
var livesText = null;
|
||||
var cLivesText = null;
|
||||
var lifeLostText = null;
|
||||
var successText = null;
|
||||
var textStyle = {
|
||||
font: "18px Arial",
|
||||
fill: "#FFFFFF",
|
||||
}
|
||||
|
||||
var ethCallback = null;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Helper functions. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function randSig() {
|
||||
var signs = [-1, 1];
|
||||
return signs[Math.floor(signs.length * Math.random())];
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
if (ethCallback !== null) {
|
||||
canIPlayTheGame()
|
||||
} else {
|
||||
alert("Can't play the game\nWeb3 not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
function playTheGame() {
|
||||
startButton.destroy();
|
||||
ball.body.velocity.set(randSig() * 150, randSig() * 150);
|
||||
playing = true;
|
||||
}
|
||||
|
||||
function ballHitPaddle(ball, paddle) {
|
||||
ball.animations.play("wobble");
|
||||
ball.body.velocity.x = 1.15 * ball.body.velocity.x;
|
||||
}
|
||||
|
||||
function ballLeaveScreen() {
|
||||
// Pause the game
|
||||
playing = false;
|
||||
|
||||
if (ball.x < 0) {
|
||||
// If the ball left by the left side of the screen
|
||||
// then reduce player lives
|
||||
lives--;
|
||||
|
||||
// Then show the defeat text
|
||||
lifeLostText.visible = true;
|
||||
|
||||
// And update the player lives counter
|
||||
livesText.setText("Your lives: " + lives);
|
||||
|
||||
if (!lives) {
|
||||
alert("Game over, dude!");
|
||||
location.reload();
|
||||
}
|
||||
} else if (ball.x > game.world.width) {
|
||||
// If the ball left by the right side of the screen
|
||||
// then reduce computer lives
|
||||
c_lives--;
|
||||
|
||||
// Then show the victory text
|
||||
successText.visible = true;
|
||||
|
||||
// And update the computer lives counter
|
||||
cLivesText.setText("Computer lives: " + c_lives);
|
||||
|
||||
if (!c_lives) {
|
||||
alert("A winner is you!");
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset all positions
|
||||
// Resetting the ball sets it's velocity to 0
|
||||
ball.reset(game.world.width * 0.5, game.world.height * 0.5);
|
||||
player.reset(20, game.world.height * 0.5);
|
||||
computer.reset(game.world.width - 20, game.world.height * 0.5);
|
||||
|
||||
// Add an event listener for one event
|
||||
game.input.onDown.addOnce(function() {
|
||||
// Unpause the game
|
||||
ball.body.velocity.set(randSig() * 150, randSig() * 150);
|
||||
playing = true;
|
||||
lifeLostText.visible = false;
|
||||
successText.visible = false;
|
||||
}, this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Loads all assets and sets up the game. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function preload() {
|
||||
// Set basic game properties
|
||||
//game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
|
||||
//game.scale.pageAlignHorizontally = true;
|
||||
//game.scale.pageAlignVertically = true;
|
||||
game.stage.backgroundColor = "#eee";
|
||||
|
||||
// Set basic game properties
|
||||
game.load.image("bckg", "img/bckg.png");
|
||||
game.load.image("paddle", "img/paddle.png");
|
||||
game.load.image("computer", "img/computer.png");
|
||||
game.load.spritesheet("ball", "img/wobble.png", 20, 20);
|
||||
game.load.spritesheet("button", "img/button.png", 144, 40);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Creates all game objects //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function create() {
|
||||
// Initialize the physics engine
|
||||
game.physics.startSystem(Phaser.Physics.ARCADE);
|
||||
game.physics.arcade.checkCollision.left = false;
|
||||
game.physics.arcade.checkCollision.right = false;
|
||||
|
||||
// Create the background
|
||||
bckg = game.add.sprite(0, 0, "bckg");
|
||||
|
||||
// Create the ball sprite and set it"s properties
|
||||
ball = game.add.sprite(game.world.width * 0.5, game.world.height * 0.5, "ball");
|
||||
ball.animations.add("wobble", [0, 1, 0, 2, 0, 1, 0, 2, 0], 24);
|
||||
ball.anchor.set(0.5);
|
||||
game.physics.enable(ball, Phaser.Physics.ARCADE);
|
||||
ball.body.bounce.set(1);
|
||||
ball.body.collideWorldBounds = true;
|
||||
ball.checkWorldBounds = true;
|
||||
ball.events.onOutOfBounds.add(ballLeaveScreen, this);
|
||||
|
||||
// Create the player sprite and set it"s properties
|
||||
player = game.add.sprite(20, game.world.height * 0.5, "paddle");
|
||||
player.anchor.set(0.5, 0.5);
|
||||
game.physics.enable(player, Phaser.Physics.ARCADE);
|
||||
player.body.immovable = true;
|
||||
|
||||
// Create the computer sprite and set it"s properties
|
||||
computer = game.add.sprite(game.world.width - 20, game.world.height * 0.5, "computer");
|
||||
computer.anchor.set(0.5, 0.5);
|
||||
game.physics.enable(computer, Phaser.Physics.ARCADE);
|
||||
computer.body.immovable = true;
|
||||
|
||||
// Create the start button
|
||||
startButton = game.add.button(game.world.width * 0.5, game.world.height * 0.5, "button", startGame, this, 1, 0, 2);
|
||||
startButton.anchor.set(0.5);
|
||||
|
||||
// Create text elements
|
||||
livesText = game.add.text(7, 5, "Your lives: " + lives, textStyle);
|
||||
livesText.anchor.set(0, 0);
|
||||
cLivesText = game.add.text(game.world.width - 7, 5, "Computer lives: " + c_lives, textStyle);
|
||||
cLivesText.anchor.set(1, 0);
|
||||
lifeLostText = game.add.text(game.world.width * 0.5, game.world.height * 0.5, 'Got you!, click to continue', textStyle);
|
||||
lifeLostText.anchor.set(0.5);
|
||||
lifeLostText.visible = false;
|
||||
successText = game.add.text(game.world.width * 0.5, game.world.height * 0.5, 'You got me!, click to continue', textStyle);
|
||||
successText.anchor.set(0.5);
|
||||
successText.visible = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Implements the game logic //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function update() {
|
||||
// Do collition detection
|
||||
game.physics.arcade.collide(ball, player, ballHitPaddle);
|
||||
game.physics.arcade.collide(ball, computer, ballHitPaddle);
|
||||
|
||||
if (playing) {
|
||||
// If the game is on, move the player with the mouse
|
||||
player.y = game.input.y;
|
||||
|
||||
// Set the computer's speed so it moves in the direction of the ball
|
||||
if (ball.y > computer.y)
|
||||
computer.body.velocity.y = 65;
|
||||
else if (ball.y < computer.y)
|
||||
computer.body.velocity.y = -65;
|
||||
else
|
||||
computer.body.velocity.y = 0;
|
||||
|
||||
} else {
|
||||
// If the game is off, fix the position of player and computer
|
||||
player.y = game.world.height * 0.5;
|
||||
computer.y = game.world.height * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Game initialization //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Function references for Phaser.
|
||||
functions = {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
};
|
||||
|
||||
// Set the game canvas and play
|
||||
game = new Phaser.Game(480, 320, Phaser.CANVAS, 'game_container', functions);
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a
|
||||
* function when declaring them. Failure to do so will cause commands to hang. ex:
|
||||
* ```
|
||||
* mainnet: {
|
||||
* provider: function() {
|
||||
* return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/<infura-key>')
|
||||
* },
|
||||
* network_id: '1',
|
||||
* gas: 4500000,
|
||||
* gasPrice: 10000000000,
|
||||
* },
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
// See <http://truffleframework.com/docs/advanced/configuration>
|
||||
// to customize your Truffle configuration!
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a
|
||||
* function when declaring them. Failure to do so will cause commands to hang. ex:
|
||||
* ```
|
||||
* mainnet: {
|
||||
* provider: function() {
|
||||
* return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/<infura-key>')
|
||||
* },
|
||||
* network_id: '1',
|
||||
* gas: 4500000,
|
||||
* gasPrice: 10000000000,
|
||||
* },
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
// See <http://truffleframework.com/docs/advanced/configuration>
|
||||
// to customize your Truffle configuration!
|
||||
|
||||
networks: {
|
||||
ganache: {
|
||||
host: "localhost",
|
||||
port: 7545,
|
||||
network_id: "*" // Match any network id
|
||||
}
|
||||
}
|
||||
};
|
||||