fixes
This commit is contained in:
parent
84f8fad0a1
commit
5a54d13f8f
6 changed files with 47 additions and 5 deletions
1
RPS/config.json
Normal file
1
RPS/config.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"rps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":684,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playRPS","offset":95,"parameters":[{"name":"playerChoice","type":"String"},{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"computerChoice","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerChoice","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
|
5
RPS/go.mod
Normal file
5
RPS/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module rps
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
2
RPS/go.sum
Normal file
2
RPS/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 h1:N+dMIBmteXjJpkH6UZ7HmNftuFxkqszfGLbhsEctnv0=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
23
RPS/rps.go
23
RPS/rps.go
|
@ -1,4 +1,4 @@
|
|||
package RPS
|
||||
package rps
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
@ -34,16 +34,26 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
storage.Put(ctx, zaCoinHashKey, args.zaCoinHash)
|
||||
}
|
||||
|
||||
func PlayRPS(playerChoice string, ctx storage.Context, playerOwner interop.Hash160, bet int) {
|
||||
func PlayRPS(playerChoice string, bet int) {
|
||||
|
||||
ctx := storage.GetContext()
|
||||
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")
|
||||
}
|
||||
|
||||
if playerChoice != "rock" && playerChoice != "paper" && playerChoice != "scissors" {
|
||||
panic("invalid player choice")
|
||||
}
|
||||
if bet <= 0 {
|
||||
panic("bet must be positive")
|
||||
}
|
||||
|
||||
computerChoice := (runtime.GetRandom() % 3) + 1
|
||||
runtime.Notify("computerChoice", computerChoice)
|
||||
|
||||
var computerChoiceString string
|
||||
switch computerChoice {
|
||||
|
@ -64,6 +74,9 @@ func PlayRPS(playerChoice string, ctx storage.Context, playerOwner interop.Hash1
|
|||
} else {
|
||||
panic("player lost: player chose " + playerChoice + ", computer chose " + computerChoiceString)
|
||||
}
|
||||
|
||||
playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
|
||||
runtime.Notify("playerBalance", playerBalance)
|
||||
}
|
||||
|
||||
func isWinner(playerChoice, computerChoice string) Result {
|
||||
|
|
BIN
RPS/rps.nef
Normal file
BIN
RPS/rps.nef
Normal file
Binary file not shown.
21
RPS/rps.yml
Normal file
21
RPS/rps.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
name: rps
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: "computerChoice"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
- name: "playerChoice"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
- name: "playerBalance"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
permissions:
|
||||
- methods: '*'
|
||||
events:
|
||||
- "computerChoice"
|
||||
- "playerChoice"
|
||||
- "playerBalance"
|
Loading…
Reference in a new issue