Skip to content

Commit

Permalink
Owen/game examples/rooch fish (rooch-network#2938)
Browse files Browse the repository at this point in the history
* feat: add example rooch fish contact

* feat: rooch fish add web

* feat: add License for rooch fish files

* feat: replace rooch fish player.move error

* feat: fix move-constant-errors

* feat: fix rooch_fish build warn

* feat: fixbug for example test

* feat: fix rooch fish init_test build warn

* feat: fix dependency check issue

* feat: upgrade cross-spawn version
  • Loading branch information
yubing744 authored Nov 24, 2024
1 parent fa970f7 commit d69f65c
Show file tree
Hide file tree
Showing 67 changed files with 10,618 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/rooch_fish/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
73 changes: 73 additions & 0 deletions examples/rooch_fish/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Define variables
PACKAGE_NAME = rooch_fish
GAS_BUDGET = 1000
PACKAGE_PATH = .
BUILD_DIR = $(PACKAGE_PATH)/build
SOURCES_DIR = $(PACKAGE_PATH)/sources
TESTS_DIR = $(PACKAGE_PATH)/tests

# Default target
all: build

# Build contract
build:
@echo "Building the Move package..."
rooch move build --path $(PACKAGE_PATH) --named-addresses rooch_fish=default --json

# Publish contract
publish:
@echo "Publishing the Move package..."
rooch move publish --path $(PACKAGE_PATH) --named-addresses rooch_fish=default

# Initialize game world
init-world:
@echo "Init RoochFish world..."
rooch move run --function 0xb38a327121ab8e9091a04377ec1e9af9ab4b801dbfb368f20fb0c080c763f7e8::rooch_fish::init_world --json

# View game world
view-world:
rooch state --access-path /object/0xb38a327121ab8e9091a04377ec1e9af9ab4b801dbfb368f20fb0c080c763f7e8::rooch_fish::GameState

# View game world
view-ponds:
rooch rpc request --method rooch_listFieldStates --params '["0xae308aa50bded0b341120431a9049ad1f151b345115a17bcefcad943505fa3b6", null, "8", {"decode": true, "showDisplay": true}]' --json

# Purchase fish
purchase_fish:
rooch move run --function 0xb38a327121ab8e9091a04377ec1e9af9ab4b801dbfb368f20fb0c080c763f7e8::rooch_fish::purchase_fish --args object_id:0x5e89df84a672ea3697916f3a2a2ada4c63586db573b2e8af666da7d2b1084fd6 --args u64:0 --json

# View purchased fish IDs
view_fish_ids:
rooch move view --function 0xb38a327121ab8e9091a04377ec1e9af9ab4b801dbfb368f20fb0c080c763f7e8::rooch_fish::get_pond_player_fish_ids --args object_id:0x5e89df84a672ea3697916f3a2a2ada4c63586db573b2e8af666da7d2b1084fd6 --args 0u64 --args 'address:default'

# Move fish
move_fish:
rooch move run --function 0xb38a327121ab8e9091a04377ec1e9af9ab4b801dbfb368f20fb0c080c763f7e8::rooch_fish::move_fish --args object_id:0x5e89df84a672ea3697916f3a2a2ada4c63586db573b2e8af666da7d2b1084fd6 --args u64:0 --args u64:5 --args u8:0 --json --gas-profile

# Debug contract
debug:
@echo "Running tests..."
rooch move test --path $(PACKAGE_PATH) --skip-fetch-latest-git-deps --ignore_compile_warnings --named-addresses rooch_fish=default pond

# Test contract
test:
@echo "Running tests..."
rooch move test --path $(PACKAGE_PATH) --skip-fetch-latest-git-deps --ignore_compile_warnings --named-addresses rooch_fish=default

# Clean build files
clean:
@echo "Cleaning build directory..."
rm -rf $(BUILD_DIR)

# Help information
help:
@echo "Makefile for Sui Move project"
@echo ""
@echo "Usage:"
@echo " make build - Build the Move package"
@echo " make publish - Publish the Move package"
@echo " make test - Run tests"
@echo " make clean - Clean build directory"
@echo " make help - Show this help message"

.PHONY: all build publish test clean help
17 changes: 17 additions & 0 deletions examples/rooch_fish/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "rooch_fish"
version = "0.0.1"

[dependencies]
MoveStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/move-stdlib", rev = "main" }
MoveosStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/moveos-stdlib", rev = "main" }
RoochFramework = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/rooch-framework", rev = "main" }

[addresses]
rooch_fish = "_"
std = "0x1"
moveos_std = "0x2"
rooch_framework = "0x3"

[dev-addresses]
rooch_fish = "0x42"
85 changes: 85 additions & 0 deletions examples/rooch_fish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# RoochFish

"Have You Caught Fish" is an open-source full-chain game based on the Rooch blockchain, where players can buy and control virtual fish in multiple dynamic fish ponds. The fish grow by eating other fish and food, and players can earn token rewards under specific conditions. The game introduces a stamina system, adding strategic depth and balance. The smart contract part of the project is open-source, aiming to provide developers and players with a transparent and scalable gaming environment.

## Detailed Documentation

- [Game Design Document](docs/game_design.md) - Detailed game mechanics, rules, and gameplay instructions
- [Technical Design Document](docs/tech_design.md) - Technical implementation and architecture design

## Core Features

### Multi-Pond System
- Multiple ponds with different sizes, capacities, and prices
- Each pond has a maximum fish size limit
- Specific exit areas for fish destruction and reward acquisition

### Stamina System
- Each fish has a maximum stamina of 10 points
- Each move consumes 1 stamina point
- Stamina recovers 1 point per second
- Eating food or smaller fish immediately restores 10 stamina points

### Economic System
- Use RGAS tokens to buy fish and feed food
- Rewards distribution upon fish destruction:
- 1% goes to the developer
- 20% goes to the player who fed the food
- The remaining reward goes to the fish owner

### Game Mechanics
- New fish have a 1-minute protection period
- Fish can only eat smaller fish
- Fish "burst" and turn into food when they reach the maximum size limit
- Comprehensive collision detection system

## Quick Start

### Environment Setup

1. **Install Rooch CLI**:
```bash
# Refer to the Rooch official documentation to install the CLI
```

### Using Makefile

The project provides the following Makefile commands:

```bash
make build # Build the contract
make publish # Publish the contract
make test # Run tests
make debug # Run a specific test
make clean # Clean build files
```

## Project Structure

```
rooch-fish/
├── docs/ # Project documentation
│ ├── game_design.md # Game design document
│ └── tech_design.md # Technical design document
├── sources/ # Move contract source code
├── tests/ # Test files
├── build/ # Build output
├── Move.toml # Project configuration file
└── Makefile # Build script
```

## Strategic Tips

- **Pond Selection**: Choose the appropriate pond based on strategy and funds
- **Stamina Management**: Plan movement paths wisely, rest in safe areas to recover stamina
- **Risk Assessment**: Balance the pursuit of food/smaller fish with stamina preservation
- **Optimal Timing**: Move fish to exit areas at the right time to claim rewards
- **Investment Balance**: Balance buying fish, feeding food, and claiming rewards

## Future Plans

- Introduce new pond types
- Implement special abilities for fish
- Add social features (team, guild)
- Host regular events and competitions
- Continuously optimize the stamina system balance
127 changes: 127 additions & 0 deletions examples/rooch_fish/docs/game_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
## Game Design: Have You Caught a Fish (Optimized Version)

### 1. Core Concept

"Have You Caught a Fish" is a multiplayer online game based on the Rooch blockchain, where players compete by buying and controlling virtual fish in multiple dynamic fish ponds. The game combines elements of growth, strategy, and economy. Players can grow by eating other fish or collecting food, and earn token rewards under specific conditions. Players can also feed fish ponds with food, influencing the game economy and potentially gaining profits. The game introduces a stamina system, adding depth and balance to the strategy.

### 2. Game Mechanics and Rules

#### 2.1 Fish Pond System

- **Multi-Pond Design**: The game includes multiple fish ponds, each with different sizes, capacities, and purchase prices.
- **Pond Parameters**: Each pond has fixed width, height, maximum number of fish, and maximum amount of food.
- **Maximum Fish Size Limit**: Each pond sets a maximum fish size limit. When a fish reaches or exceeds this limit, it will "burst" and disappear, generating a certain amount of food (e.g., 10 pieces), which will be randomly distributed in the pond.
- **Exit Area**: Each pond has a specific exit area where fish can be destroyed for rewards.

#### 2.2 Purchase and Generation

- **Buying Fish**: Players use RGAS tokens to buy fish in specific ponds, with different purchase prices for each pond.
- **Random Generation**: New fish are randomly generated in the pond with a fixed initial size.
- **New Fish Protection Mechanism**: Newly born fish are protected for 1 minute and cannot be eaten by other fish.

#### 2.3 Movement and Growth

- **Movement Control**:
- Players can control the fish to move up, down, left, or right in the pond.
- Each movement consumes 1 stamina point.
- When stamina is 0, the fish cannot move.
- **Stamina System**:
- Each fish has a stamina attribute with a maximum value of 10 points.
- Stamina recovers 1 point per second.
- Stamina cannot exceed the maximum value of 10 points.
- Eating food or smaller fish immediately restores 10 stamina points.
- **Growth Mechanism**:
- Eating smaller fish increases size and immediately restores 10 stamina points.
- Eating food in the pond increases size and immediately restores 10 stamina points.
- When a fish reaches the maximum size limit, it will "burst" and turn into food.
- **Boundary Limits**: Fish movement is restricted by pond boundaries.

#### 2.4 Feeding and Food System

- **Feeding Food**:
- Players can use RGAS tokens to feed food into the pond.
- The amount of food fed affects the total amount of food in the pond.
- **Food Generation**: Food is generated at random positions in the pond, with a maximum quantity.

#### 2.5 Interaction and Competition

- **Eating Rules**: Fish can only eat smaller fish, which immediately restores 10 stamina points.
- **Food Consumption**: Eating food increases size and immediately restores 10 stamina points.
- **New Fish Protection**: New fish are protected for 1 minute after birth and cannot be eaten by other fish.
- **Collision Detection**: The system automatically detects collisions between fish and fish, fish and food, and processes the results.

#### 2.6 Exit and Rewards

- **Exit Mechanism**: Fish can move to a specific exit area in the pond to be destroyed.
- **Token Rewards**:
- When a fish is destroyed at the exit, the player receives RGAS token rewards based on the fish's size.
- Reward Distribution:
- **1%** of the reward is allocated to the developers for supporting ongoing development and maintenance.
- **20%** of the reward is allocated to players who fed food, based on the proportion of food fed by each player relative to the total food eaten by the fish.
- The remaining reward goes to the owner of the fish.

#### 2.7 Economic System

- **Global Economy**: The game maintains a global player list, recording total feeding amounts and player numbers.
- **Pond Economy**: Each pond has an independent economic system, including player lists and total feeding amounts.
- **Stamina Management**: Players need to manage their fish's stamina effectively, balancing movement and rest.

### 3. Player Objectives and Strategies

#### 3.1 Main Objectives

- **Maximize Profits**: Grow large fish and destroy them at the right time to maximize RGAS token rewards.
- **Survival and Growth**: Survive and become the largest fish in a competitive environment.

#### 3.2 Strategic Considerations

- **Pond Selection**: Choose the appropriate pond based on your strategy and funds.
- **Investment Balance**: Balance buying fish, feeding food, and obtaining rewards.
- **Risk Management**: Avoid being eaten by larger fish during growth.
- **Timing**: Choose the right time to move fish to the exit area for rewards.
- **Maximum Size Management**: Decide whether to move fish to the exit area for tokens when approaching the maximum size, or risk further growth for more food.
- **Stamina Management**: Plan movement paths to avoid running out of stamina and being unable to evade danger or hunt.
- **Rest Strategy**: Rest fish in safe areas to recover stamina for future rapid movement.
- **Stamina Recovery Strategy**: Weigh the risk of eating food or smaller fish to quickly recover stamina.
- **Offense-Defense Balance**: Choose between chasing prey and conserving stamina, as successful hunting immediately restores stamina.
- **Risk Assessment**: Assess whether it's worth expending stamina to chase food or smaller fish, considering the immediate stamina recovery upon success.

### 4. Technical Implementation

#### 4.1 Smart Contracts

- Use Move language to write smart contracts, implementing core logic for ponds, fish, and food.
- Implement key functions such as purchase, movement, growth, destruction, and feeding.
- Add stamina value to fish attributes and implement stamina consumption and recovery logic.
- Include stamina checks in the movement function to ensure movement only when there is enough stamina.
- Add immediate stamina recovery in the logic for eating food or smaller fish.
- Ensure stamina recovery does not exceed the maximum value of 10 points.
- Ensure contract security and efficiency.

#### 4.2 Frontend Development

- Develop an intuitive user interface to display multiple ponds and game status.
- Implement real-time updates and interaction functions.
- Display the current stamina value of each fish in the user interface.
- Implement visual feedback for stamina recovery, allowing players to clearly know when they can move again.
- Implement visual effects for rapid stamina recovery when eating food or smaller fish, allowing players to clearly perceive stamina changes.
- Consider adding a special animation or sound effect to emphasize rapid stamina recovery.
- Integrate blockchain wallets to simplify token operations.

#### 4.3 Backend Services

- Develop backend services to handle high-frequency updates and complex calculations.
- Implement game state synchronization and persistence.
- Implement a timer function for automatic stamina recovery.
- Ensure real-time synchronization and updating of stamina values.
- Optimize the stamina recovery calculation logic to balance normal and rapid recovery.
- Implement relevant data statistics, such as the number of times players recover stamina by eating food/smaller fish, for subsequent game balance adjustments.

### 5. Future Extensions

- Introduce new pond types to increase game diversity.
- Implement special abilities or attribute systems for fish.
- Add social features such as teaming and guilds.
- Host regular events or competitions to increase game fun.
- Adjust stamina system parameters based on player feedback and data analysis to optimize game balance.
- Consider introducing more stamina-related special items or skills to increase strategic depth.
Loading

0 comments on commit d69f65c

Please sign in to comment.