-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathslotgame.js
108 lines (94 loc) · 3.65 KB
/
slotgame.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const fs = require('fs');
const path = require('path');
const fruits = ['🍇', '🍉', '🍋', '🍒', '🍓', '🍍', '🥭', '🥝'];
const MIN_BET = 50;
const MAX_BET = 1000000000;
// Function to generate a random pattern for the slot game
function generatePattern() {
let pattern = [];
for (let i = 0; i < 3; i++) {
let row = [];
for (let j = 0; j < 3; j++) {
const randomFruit = fruits[Math.floor(Math.random() * fruits.length)];
row.push(randomFruit);
}
pattern.push(row);
}
return pattern;
}
// Function to check if there are two or three of the same fruits in the middle row
function checkMiddleRow(pattern) {
const middleRow = pattern[1];
let consecutiveCount = 1;
let maxConsecutiveCount = 1;
let currentFruit = middleRow[0];
// Iterate through the middle row to count consecutive fruits
for (let i = 1; i < middleRow.length; i++) {
if (middleRow[i] === currentFruit) {
consecutiveCount++;
if (consecutiveCount > maxConsecutiveCount) {
maxConsecutiveCount = consecutiveCount;
}
} else {
consecutiveCount = 1;
currentFruit = middleRow[i];
}
}
// Return the number of consecutive fruits in the middle row
return maxConsecutiveCount;
}
// Function to calculate winnings based on the number of consecutive fruits in the middle row
function calculateWinnings(consecutiveCount, betAmount) {
// Award winnings based on the number of consecutive fruits
switch (consecutiveCount) {
case 2:
return betAmount * 7;
case 3:
return betAmount * 13;
default:
return 0;
}
}
module.exports = {
name: 'slot',
description: 'Play the slot game by betting coins.',
role: 'user',
cooldown: 0, // 1 minute cooldown
credits: 'rejardgwapo',
execute(api, event, args, command) {
const userId = event.senderID;
const coinBalanceFile = path.join(__dirname, `../database/coin_balances/${userId}.json`);
const betAmount = parseInt(args[0]);
/**----HAHAHAHAH***/
if (isNaN(betAmount) || betAmount < MIN_BET || betAmount > MAX_BET) {
api.sendMessage(`Please enter bet amount between ${MIN_BET} and ${MAX_BET}.`, event.threadID, event.messageID);
return;
}
if (isNaN(betAmount) || betAmount <= 0) {
api.sendMessage('Please enter a valid bet amount.', event.threadID, event.messageID);
return;
}
let coinBalance = 0;
if (fs.existsSync(coinBalanceFile)) {
coinBalance = JSON.parse(fs.readFileSync(coinBalanceFile, 'utf8'));
}
if (coinBalance < betAmount) {
api.sendMessage(`You don't have enough coins to bet ${betAmount}.`, event.threadID, event.messageID);
return;
}
const pattern = generatePattern();
const consecutiveCount = checkMiddleRow(pattern);
const winnings = calculateWinnings(consecutiveCount, betAmount);
// Update the coin balance based on the winnings
coinBalance += winnings;
fs.writeFileSync(coinBalanceFile, JSON.stringify(coinBalance));
let patternMessage = 'Here is the slot pattern:\n';
pattern.forEach(row => {
patternMessage += row.join(' ') + '\n';
});
let resultMessage = winnings > 0
? `Congratulations! You won ${winnings} coins!`
: 'Sorry, you did not win anything.';
api.sendMessage(`${patternMessage}\n${resultMessage}\nYou now have ${coinBalance} coins.`, event.threadID, event.messageID);
}
};