fix: craps, slot fixed checks, added logs

This commit is contained in:
shashkevichfrida 2024-01-03 15:29:52 +03:00
parent 52f40c6b72
commit 94ad40bb4b
4 changed files with 27 additions and 1 deletions

View file

@ -33,6 +33,17 @@ func _deploy(data interface{}, isUpdate bool) {
func PlayCraps(bet int, firstSum int, secondSum int) { func PlayCraps(bet int, firstSum int, secondSum int) {
ctx := storage.GetContext() ctx := storage.GetContext()
playerOwner := runtime.GetScriptContainer().Sender playerOwner := runtime.GetScriptContainer().Sender
if bet <= 0 {
panic("Invalid bet amount")
}
zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160)
playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
if playerBalance < bet {
panic("Insufficient funds")
}
isWin := isWinner(firstSum, secondSum) isWin := isWinner(firstSum, secondSum)
if (isWin){ if (isWin){
changePlayerBalance(ctx, playerOwner, bet) changePlayerBalance(ctx, playerOwner, bet)
@ -49,6 +60,7 @@ func isWinner(firstSum int, secondSum int) bool {
sum := 0 sum := 0
for i:=0; i<2; i++ { for i:=0; i<2; i++ {
crap := (runtime.GetRandom() % 6) + 1 crap := (runtime.GetRandom() % 6) + 1
runtime.Log("Crup number " + string(i+1) + " Rundom number " + string(crap))
runtime.Notify("Crup number", i+1) runtime.Notify("Crup number", i+1)
runtime.Notify("Random number", crap) runtime.Notify("Random number", crap)
sum += crap sum += crap

View file

@ -1 +1 @@
{"name":"SlotMashine","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":328,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"rollSlot","offset":95,"parameters":[{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"wheelNumber","parameters":[{"name":"int","type":"Integer"}]},{"name":"value","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} {"name":"SlotMashine","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":548,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"rollSlot","offset":95,"parameters":[{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"wheelNumber","parameters":[{"name":"int","type":"Integer"}]},{"name":"value","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

View file

@ -34,6 +34,17 @@ func _deploy(data interface{}, isUpdate bool) {
func RollSlot(bet int) { func RollSlot(bet int) {
ctx := storage.GetContext() ctx := storage.GetContext()
playerOwner := runtime.GetScriptContainer().Sender playerOwner := runtime.GetScriptContainer().Sender
if bet <= 0 {
panic("Invalid bet amount")
}
zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160)
playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
if playerBalance < bet {
panic("Insufficient funds")
}
res := roll() res := roll()
if (res == 0){ if (res == 0){
changePlayerBalance(ctx, playerOwner, -bet) changePlayerBalance(ctx, playerOwner, -bet)
@ -48,14 +59,17 @@ func roll() int {
firstWheel := (runtime.GetRandom() % 8) + 1 firstWheel := (runtime.GetRandom() % 8) + 1
runtime.Notify("wheelNumber", 1) runtime.Notify("wheelNumber", 1)
runtime.Notify("value", firstWheel) runtime.Notify("value", firstWheel)
runtime.Log("WheelNumber 1, value="+string(firstWheel))
secondWheel := (runtime.GetRandom() % 8) + 1 secondWheel := (runtime.GetRandom() % 8) + 1
runtime.Notify("wheelNumber", 2) runtime.Notify("wheelNumber", 2)
runtime.Notify("value", secondWheel) runtime.Notify("value", secondWheel)
runtime.Log("WheelNumber 2, value="+string(secondWheel))
thirdWheel := (runtime.GetRandom() % 8) + 1 thirdWheel := (runtime.GetRandom() % 8) + 1
runtime.Notify("wheelNumber", 3) runtime.Notify("wheelNumber", 3)
runtime.Notify("value", thirdWheel) runtime.Notify("value", thirdWheel)
runtime.Log("WheelNumber 3, value="+string(thirdWheel))
if (firstWheel == secondWheel && firstWheel == thirdWheel){ if (firstWheel == secondWheel && firstWheel == thirdWheel){
return firstWheel return firstWheel

Binary file not shown.