Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #5317

Open
outb90510 opened this issue Feb 21, 2025 · 0 comments
Open

Feedback #5317

outb90510 opened this issue Feb 21, 2025 · 0 comments
Assignees
Labels

Comments

@outb90510
Copy link

Type of issue

Code doesn't work

Feedback

"use strict".

//
// Dependencies and configuration
//
const mysql = require("mysql2/promise");

// Instead of include 'config.php', we create the equivalent configuration here.
// Please adjust these connection settings as needed.
const koneksi = mysql.createPool({
host: "localhost",
user: "root",
password: "",
database: "my_database", // Replace with your database name
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
});

// Main async function to simulate the PHP script
(async function () {
// ID game yang dimainkan
const game_id = 1;
// ID pengguna (bisa diambil dari sesi/login)
const user_id = 1;

// Ambil RTP dari database
// Equivalent of: $game = $koneksi->query("SELECT * FROM games WHERE id='$game_id'")->fetch_assoc();
let [gameRows] = await koneksi.query("SELECT * FROM games WHERE id='" + game_id + "'");
const game = gameRows[0];
const rtp = game.rtp;

// Simbol permainan slot
const symbols = ["Cherry", "Bell", "Bar", "7", "Scatter", "Wild"];
const reels = [];
let free_spins = 0;
let jackpot = false;

// Spin setiap reel
for (let i = 0; i < 3; i++) {
// array_rand equivalent in JavaScript using random index
reels.push(symbols[Math.floor(Math.random() * symbols.length)]);
}

// Cek jika mendapatkan Scatter untuk Free Spin
if (reels.includes("Scatter")) {
// Mendapatkan 1-5 free spins (rand(1, 5))
free_spins = Math.floor(Math.random() * 5) + 1;
}

// Cek jika mendapatkan Jackpot (3 simbol "7")
if (new Set(reels).size === 1 && reels[0] === "7") {
jackpot = true;
}

// Simulasi RTP & kemenangan
const random_chance = Math.floor(Math.random() * 100) + 1;
let amount_won, result;
if (jackpot) {
// Jackpot menang maksimal
amount_won = game.max_win;
result = "Jackpot!";
} else if (random_chance <= rtp) {
// Menang biasa, random number antara 100 dan game.max_win/2
const min = 100;
const max = Math.floor(game.max_win / 2);
amount_won = Math.floor(Math.random() * (max - min + 1)) + min;
result = "Menang";
} else {
amount_won = 0;
result = "Kalah";
}

// Simpan hasil spin ke database
const query = "INSERT INTO spin_results (user_id, game_id, result, amount_won) " +
"VALUES ('" + user_id + "', '" + game_id + "', '" + result + "', '" + amount_won + "')";
await koneksi.query(query);

// Kembalikan hasil ke UI
console.log(JSON.stringify({
reels: reels,
result: result,
amount_won: amount_won,
free_spins: free_spins
}));
})().catch(err => {
console.error(err);
process.exit(1);
});

Page URL

https://learn.microsoft.com/en-gb/windows/dev-home/extensions

Content source URL

https://github.com/MicrosoftDocs/windows-dev-docs/blob/docs/hub/dev-home/extensions.md

Author

@mattwojo

Document Id

672f603e-cc47-9fb6-14d4-43f327b74ebb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants