Repository Public License
1{2 "schemaVersion": 1,3 "id": "app_arcade",4 "name": "Pocket Arcade",5 "summary": "Tic-tac-toe with a play clock, built from an on-demand component.",6 "version": 1,7 "entrypoint": "home",8 "permissions": [9 "logic.scripts"10 ],11 "theme": {12 "preset": "candy",13 "accent": "#FF2D92"14 },15 "state": {16 "games": 0,17 "seconds": 0,18 "running": true19 },20 "icon": {21 "background": {22 "colors": [23 "#FF2D92",24 "#7C4DFF",25 "#00C2FF"26 ],27 "style": "mesh",28 "pattern": "dots"29 },30 "layers": [31 {32 "shape": "roundedRect",33 "width": 64,34 "height": 64,35 "radius": 14,36 "fill": "#FFFFFF",37 "shadow": true38 },39 {40 "path": "M39.5 22 V78 M60.5 22 V78 M22 39.5 H78 M22 60.5 H78",41 "stroke": "#E9D5FF",42 "strokeWidth": 343 },44 {45 "path": "M25 25 L34 34 M34 25 L25 34",46 "stroke": "#FF2D92",47 "strokeWidth": 448 },49 {50 "shape": "ring",51 "size": 13,52 "x": 50,53 "y": 50,54 "ringWidth": 3.2,55 "fill": "#7C4DFF"56 },57 {58 "path": "M65.5 65.5 L74.5 74.5 M74.5 65.5 L65.5 74.5",59 "stroke": "#FF2D92",60 "strokeWidth": 461 }62 ],63 "finish": "glass"64 },65 "objects": [66 {67 "id": "home",68 "type": "prism.page",69 "name": "Arcade",70 "children": [71 "root"72 ]73 },74 {75 "id": "root",76 "type": "prism.stack",77 "props": {78 "align": "stretch",79 "grow": true,80 "spacing": 1681 },82 "children": [83 "title",84 "stats",85 "board",86 "clock"87 ]88 },89 {90 "id": "title",91 "type": "prism.heading",92 "props": {93 "text": "Pocket Arcade",94 "level": 195 }96 },97 {98 "id": "stats",99 "type": "prism.grid",100 "props": {101 "columns": 2102 },103 "children": [104 "s1",105 "s2"106 ]107 },108 {109 "id": "s1",110 "type": "prism.aggregation",111 "props": {112 "label": "Games finished",113 "value": {114 "$expr": "state.games"115 },116 "icon": "trophy",117 "tone": "accent"118 }119 },120 {121 "id": "s2",122 "type": "prism.aggregation",123 "props": {124 "label": "Seconds played",125 "value": {126 "$expr": "state.seconds"127 },128 "icon": "timer"129 }130 },131 {132 "id": "board",133 "type": "custom.tictactoe",134 "name": "Board",135 "props": {136 "first": "X",137 "second": "O"138 },139 "events": {140 "complete": [141 {142 "type": "showNotification",143 "message": "Game over!",144 "tone": "success"145 }146 ]147 }148 },149 {150 "id": "clock",151 "type": "prism.timer",152 "props": {153 "interval": 1,154 "running": {155 "$expr": "state.running"156 }157 },158 "events": {159 "tick": [160 {161 "type": "setState",162 "key": "seconds",163 "value": {164 "$expr": "state.seconds + 1"165 }166 }167 ]168 }169 },170 {171 "id": "tictactoe",172 "type": "prism.component",173 "name": "Tic-tac-toe board",174 "provenance": {175 "source": "agent",176 "generated": true177 },178 "props": {179 "summary": "A playable 3×3 board for two players.",180 "events": [181 "complete"182 ],183 "props": [184 {185 "name": "first",186 "kind": "string",187 "summary": "Mark of the first player.",188 "default": "X"189 },190 {191 "name": "second",192 "kind": "string",193 "summary": "Mark of the second player.",194 "default": "O"195 }196 ],197 "source": "\nfunction cells() { return app.local('cells', [0,0,0,0,0,0,0,0,0]); }\nfunction winner(c) {\n var lines = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]];\n for (var i = 0; i < lines.length; i++) { var l = lines[i]; if (c[l[0]] && c[l[0]] === c[l[1]] && c[l[1]] === c[l[2]]) return c[l[0]]; }\n return 0;\n}\nfunction render(props) {\n var c = cells(), w = winner(c), turn = app.local('turn', 1);\n var marks = ['', props.first, props.second];\n return { type: 'vstack', spacing: 14, align: 'center', animate: true, children: [\n { type: 'text', text: w ? marks[w] + ' wins!' : (c.indexOf(0) < 0 ? 'Draw' : 'Turn: ' + marks[turn]), size: 20, weight: 'bold', color: w ? 'success' : 'text' },\n { type: 'grid', columns: 3, spacing: 8, width: 264, children: c.map(function (v, i) {\n return { type: 'zstack', id: i, width: 80, height: 80, background: v ? 'surface' : 'background', cornerRadius: 14, borderColor: 'border', shadow: v ? 4 : 0,\n label: 'Cell ' + (i + 1) + (v ? ' ' + marks[v] : ' empty'), onTap: { call: 'play', args: [i] },\n children: [{ type: 'text', text: marks[v], size: 40, weight: 'heavy', font: 'rounded', color: v === 1 ? 'accent' : 'info' }] };\n }) },\n { type: 'button', title: 'New game', symbol: 'arrow.counterclockwise', onTap: 'reset' } ] };\n}\nfunction play(i, event) {\n var c = cells().slice(), turn = app.local('turn', 1);\n if (c[i] || winner(c)) return;\n c[i] = turn; app.setLocal('cells', c); app.setLocal('turn', turn === 1 ? 2 : 1);\n if (winner(c)) { app.set('games', app.get('games') + 1); app.emit('complete', turn); }\n}\nfunction reset() { app.setLocal('cells', [0,0,0,0,0,0,0,0,0]); app.setLocal('turn', 1); }\n"198 }199 }200 ]201}