From 9cf53ae3b47282af8e034a3a40ef97942fe5c675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Hallenbarter?= Date: Wed, 13 May 2026 16:54:56 +0200 Subject: [PATCH] added upgrades --- sketches/snake.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sketches/snake.js b/sketches/snake.js index ae89cbb..3c6cd7c 100644 --- a/sketches/snake.js +++ b/sketches/snake.js @@ -14,6 +14,9 @@ let buttonAddRows = null; let buttonUpgradeAI = null; let buttonAddMoreApples = null; let AddMoreApplesPrice = 1; +let AddColoumsPrice = 1; +let AddRowsPrice = 1; +let UpgradeAIPrice = 1; function setup() { buttonAddColoums = createButton("Add coloums"); @@ -28,11 +31,42 @@ function setup() { grid[i][j] = 0; } } + buttonAddColoums.mousePressed(buttonAddColoumsPressed); + buttonAddRows.mousePressed(buttonAddRowsPressed); + buttonUpgradeAI.mousePressed(buttonUpgradeAIPressed); buttonAddMoreApples.mousePressed(buttonAddMoreApplesPressed); summonSnake(); summonApple(); drawGrid(); } +function buttonAddColoumsPressed(){ + if (eatenApples < AddColoumsPrice) { + return; + } + eatenApples -= AddColoumsPrice; + gridColumns++; + grid.push([]); + for (let i = 0; i < gridRows; i++) { + grid[grid.length - 1][i] = 0; + } +} +function buttonAddRowsPressed(){ + if (eatenApples < AddRowsPrice) { + return; + } + eatenApples -= AddRowsPrice; + gridRows++; + for (let i = 0; i < gridColumns; i++) { + grid[i].push(0); + } +} +function buttonUpgradeAIPressed(){ + if (eatenApples < UpgradeAIPrice) { + return; + } + eatenApples -= UpgradeAIPrice; + AItype = "smart"; +} function buttonAddMoreApplesPressed(){ if (eatenApples < AddMoreApplesPrice) { @@ -158,10 +192,13 @@ function draw() { buttonAddMoreApples.html("Add more apples ₴ " + AddMoreApplesPrice); buttonAddMoreApples.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 1.5); text("AI: " + AItype, gridColumns * gridSize + gridSize, _textSize * 3); + buttonUpgradeAI.html("Upgrade AI ₴ " + UpgradeAIPrice); buttonUpgradeAI.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 2.5); text("Coloums: " + gridColumns, gridColumns * gridSize + gridSize, _textSize * 4); + buttonAddColoums.html("Add coloums ₴ " + AddColoumsPrice); buttonAddColoums.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 3.5); text("Rows: " + gridRows, gridColumns * gridSize + gridSize, _textSize * 5); + buttonAddRows.html("Add rows ₴ " + AddRowsPrice); buttonAddRows.position(gridColumns * gridSize + gridSize + _textSize*6, _textSize * 4.5); }