It's a very abstract question, so this is an abstract answer.
This contract is not production-ready. Some concerns are set aside to focus on your variable prize concern and help you get started. The game itself isn't carefully thought through. Creators produce guessing games with arbitrary prize money. Contestants try to guess the secret word.
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.6;
contract XPrize {
struct Contest {
uint prizeMoney;
bool claimed;
}
mapping(bytes32 => Contest) public contests;
event NewContest(address sender, bytes32 contestId, uint prizeMoney);
event PrizeClaimed(address winner,bytes32 secret, bytes32 contestId, uint prizeMoney);
// STEP 2 - contest creator creates a contest with an arbitrary anount of funding.
function newContest(bytes32 contestId) public payable { // anyone can create a contest and fund it
Contest storage c = contests[contestId];
require(c.prizeMoney == 0, "contest is already defined.");
require(msg.value > 0, "send money");
c.prizeMoney = msg.value;
emit NewContest(msg.sender, contestId, msg.value);
}
// STEP 3 - guess the secret, claim the money
function claimPrize(bytes32 secret) public {
bytes32 key = hashHelper(secret);
Contest storage c = contests[key];
require(c.prizeMoney > 0, "there is no prize money there");
require(!c.claimed, "already paid out");
c.claimed = true;
emit PrizeClaimed(msg.sender,secret, key, c.prizeMoney);
msg.sender.transfer(c.prizeMoney);
}
// STEP 1 - contest creator generates a key with a secret that is hard to guess
function hashHelper(bytes32 secret) public view returns(bytes32) {
return keccak256(abi.encodePacked(secret, address(this)));
}
}
The contract is acting as a vending machine in that it holds the money as well as the mechanism for its release. Notice that it records the prize money liability in a data structure. There is a pile of cash "in the box" - this a protocol-level accounting that Ethereum handles - it knows how much money is parked in the address. The internal accounting requirements, e.g. how much is owed per user or per game, are internal accounting concerns.
Hope it helps.