| Crates.io | rock-paper-scissors |
| lib.rs | rock-paper-scissors |
| version | 0.5.0 |
| created_at | 2025-02-07 03:59:08.457867+00 |
| updated_at | 2025-02-15 00:58:45.40075+00 |
| description | rock-paper-scissors is an open-source Rust game API that allows users to create custom implementations of the classic game 'Rock, Paper, Scissors'. |
| homepage | |
| repository | https://github.com/hijknight/rock-paper-scissors |
| max_upload_size | |
| id | 1546482 |
| size | 48,308 |
rock-paper-scissors is an open-source Rust library and interactive game designed for developers to create or customize implementations of the classic "Rock, Paper, Scissors" game. It adheres to clean design principles, offering modular functionality, safe initialization, and robust error handling.
Enhancements to MoveType:
User Experience Improvements:
Expanded Customization:
GameSettings now supports user-defined rules with increased flexibility.Error Handling Overhaul:
Performance & Code Quality:
Library Version Update:
Customizable Game Logic:
Flexible Winner Determination:
PlayerMoves::check_who_wins_round method.Score Tracking:
Scores struct.Scores::check_for_winner) or resetting scores (Scores::reset).Game Settings:
GameSettings::first_to(first_to) for quick and easy implementation.Output Improvements:
MoveType and Winner.To use or play the rock-paper-scissors library, ensure the following are installed:
To use the library in your Rust project, add the following line to your Cargo.toml:
[dependencies]
rock-paper-scissors = "0.5.0"
To play the game directly:
Clone the repository:
git clone https://github.com/hijknight/rock-paper-scissors.git
cd rock-paper-scissors
Run the game with Cargo:
cargo run
WinnerUser, Enemy, or Tie.MoveTypeNone).random_move: Generates a random move.from_user_input: Validates and converts strings to moves.PlayerMovesbuild) and winner determination.ScoresGameSettingsHere's a simple example of playing Rock-Paper-Scissors programmatically:
use rock_paper_scissors::{PlayerMoves, Scores, Winner, MoveType, GameSettings};
fn main() {
let mut scores = Scores::new();
let game_settings = GameSettings::first_to(3); // First to 3 wins.
println!("Welcome to Rock-Paper-Scissors!");
while scores.check_for_winner(&game_settings).is_err() {
let player_moves = PlayerMoves::build();
let round_winner = player_moves.check_who_wins_round();
println!(
"You chose: {}, Enemy chose: {}.",
player_moves.user_move.convert_to_string(),
player_moves.enemy_move.convert_to_string(),
);
println!("Result: {}", round_winner.convert_to_string());
match round_winner {
Winner::User => scores.user_wins += 1,
Winner::Enemy => scores.enemy_wins += 1,
Winner::Tie => (),
}
println!(
"Current Scores -> User: {}, Enemy: {}",
scores.user_wins, scores.enemy_wins
);
}
let final_winner = scores.check_for_winner(&game_settings).unwrap();
println!("Game Over! {}", final_winner.convert_to_string());
}
The library provides robust error management:
Invalid Input Handling:
Edge Case Management:
Do you have ideas, bug fixes, or improvements? Contributions are welcome! Here's how to get involved:
For issues and feature requests, please open a ticket on GitHub.
Distributed under the MIT License. See the LICENSE file for more information.