change func PlayCraps
This commit is contained in:
parent
b0b09657c1
commit
30e837291a
12 changed files with 12 additions and 126 deletions
|
@ -1 +1 @@
|
|||
{"name":"Craps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":165,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playCraps","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"firstSum","type":"Integer"},{"name":"secondSum","type":"Integer"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
|
||||
{"name":"Craps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":313,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playCraps","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"firstSum","type":"Integer"},{"name":"secondSum","type":"Integer"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
|
|
@ -45,19 +45,19 @@ func PlayCraps(bet int, firstSum int, secondSum int) {
|
|||
}
|
||||
|
||||
func isWinner(firstSum int, secondSum int) bool {
|
||||
//if (!((firstSum >= 3 && firstSum <= 18) && (secondSum >= 3 && firstSum <= 18))){
|
||||
// panic("first and second sum should be from 3 to 18")
|
||||
//}
|
||||
crupNumber:="Crup number: "
|
||||
rundomNumber:=" Random number: "
|
||||
if (!((firstSum >= 3 && firstSum <= 18) && (secondSum >= 3 && firstSum <= 18))){
|
||||
panic("first and second sum should be from 3 to 18")
|
||||
}
|
||||
|
||||
//sum := 0
|
||||
sum := 0
|
||||
|
||||
//for i:=0; i<3; i++ {
|
||||
// crap := rand.Intn(5) + 1
|
||||
// runtime.Notify("Crup number: %d,Random Number: %d", i+1, crap)
|
||||
// sum += crap
|
||||
//}
|
||||
var sum int
|
||||
sum = runtime.GetRandom()
|
||||
for i:=0; i<3; i++ {
|
||||
crap := (runtime.GetRandom() % 6) + 1
|
||||
runtime.Notify(crupNumber, i+1, rundomNumber, crap)
|
||||
sum += crap
|
||||
}
|
||||
|
||||
return sum == firstSum || sum == secondSum
|
||||
}
|
||||
|
|
BIN
Craps/craps.nef
BIN
Craps/craps.nef
Binary file not shown.
|
@ -1,4 +0,0 @@
|
|||
module Player
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
|
||||
)
|
|
@ -1,73 +0,0 @@
|
|||
package Player
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/oracle"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/lib/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
balance int
|
||||
}
|
||||
|
||||
func _deploy(data interface{}, isUpdate bool) {
|
||||
if isUpdate {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func NewPlayer(playerName string) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
existingPlayer := storage.Get(ctx, playerName)
|
||||
if existingPlayer != nil {
|
||||
panic("player already exists")
|
||||
}
|
||||
|
||||
player := Player{
|
||||
balance: 0,
|
||||
}
|
||||
|
||||
storage.Put(ctx, playerName, std.Serialize(player))
|
||||
}
|
||||
|
||||
func ReplenishBalance(playerName string, balance int) {
|
||||
|
||||
}
|
||||
|
||||
func playCraps(plyerName string, bet int, firstSum int, secondSum int) {
|
||||
player := getPlayer(playerName)
|
||||
if bet <= player.balance {
|
||||
panic("not enough money on the balance sheet")
|
||||
}
|
||||
|
||||
crapsHash := address.ToHash160("сюда надо hash смартконтракта Craps")
|
||||
isWinner := contract.Call(crapsHash, "isWinner", contract.ReadOnly, firstSum, secondSum).(bool)
|
||||
|
||||
if isWinner {
|
||||
player.balance += bet
|
||||
}
|
||||
else {
|
||||
player.balance -= bet
|
||||
}
|
||||
}
|
||||
|
||||
func getPlayer(playerName string) Player {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
data := storage.Get(ctx, playerName)
|
||||
if data == nil {
|
||||
panic("player not found")
|
||||
}
|
||||
|
||||
return std.Deserialize(data.([]byte)).(Player)
|
||||
}
|
||||
|
||||
func Balance(playerName string) int {
|
||||
p := getPlayer(playerName)
|
||||
return p.balance
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
name: Player
|
||||
sourceurl: http://example.com/
|
||||
safemethods: []
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: Hello world!
|
||||
parameters:
|
||||
- name: args
|
||||
type: Array
|
||||
permissions:
|
||||
- methods: '*'
|
|
@ -1,13 +0,0 @@
|
|||
package coin
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
)
|
||||
|
||||
func IsWinner(playerName string) bool {
|
||||
if playerName == "demo" {
|
||||
return true
|
||||
}
|
||||
random := runtime.GetRandom()
|
||||
return random%2 == 0
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
{"name":"Coin","abi":{"methods":[{"name":"isWinner","offset":0,"parameters":[{"name":"playerName","type":"String"}],"returntype":"Boolean","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":[]}],"supportedstandards":[],"trusts":[],"extra":null}
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
name: "Coin"
|
||||
supportedstandards: []
|
||||
events:
|
||||
permissions:
|
||||
- methods: []
|
|
@ -1,5 +0,0 @@
|
|||
module coin
|
||||
|
||||
go 1.21.4
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231113195319-de2a44508893
|
|
@ -1,2 +0,0 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231113195319-de2a44508893 h1:1VpHe/QRrEWTyIaRG7lv372cbJavg63enFxtIMAIfXs=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231113195319-de2a44508893/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
Loading…
Reference in a new issue