Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/achievements/achievement.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Mock Task module for demonstration (replace with actual import if available)


// Import the Task and TaskTrait (adjust path based on your project structure)
use dojo_starter::types::task::{Task, TaskTrait};

Expand Down Expand Up @@ -115,11 +114,26 @@ pub impl SnookerAchievementImpl of SnookerAchievementTrait {
fn tasks(self: SnookerAchievement) -> Span<Task> {
match self {
SnookerAchievement::None => array![].span(), // Explicitly empty array
SnookerAchievement::FirstPot => array![TaskTrait::new('First Pot', 1, "Pot a ball in a game")].span(),
SnookerAchievement::BreakMaster => array![TaskTrait::new('Break Master', 1, "Score a break of 50+")].span(),
SnookerAchievement::CenturyMaker => array![TaskTrait::new('Century Maker', 1, "Score a century break")].span(),
SnookerAchievement::MaximumBreak => array![TaskTrait::new('Maximum Break', 1, "Score a 147 break")].span(),
SnookerAchievement::LegendShot => array![TaskTrait::new('Legend Shot', 10, "Win 10 frames with a century")].span(),
SnookerAchievement::FirstPot => array![
TaskTrait::new('First Pot', 1, "Pot a ball in a game"),
]
.span(),
SnookerAchievement::BreakMaster => array![
TaskTrait::new('Break Master', 1, "Score a break of 50+"),
]
.span(),
SnookerAchievement::CenturyMaker => array![
TaskTrait::new('Century Maker', 1, "Score a century break"),
]
.span(),
SnookerAchievement::MaximumBreak => array![
TaskTrait::new('Maximum Break', 1, "Score a 147 break"),
]
.span(),
SnookerAchievement::LegendShot => array![
TaskTrait::new('Legend Shot', 10, "Win 10 frames with a century"),
]
.span(),
}
}

Expand Down Expand Up @@ -166,4 +180,4 @@ pub impl IntoU8SnookerAchievement of Into<u8, SnookerAchievement> {
_ => SnookerAchievement::None,
}
}
}
}
1 change: 0 additions & 1 deletion src/errors/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl SnooknetErrorIntoFelt252 of Into<SnooknetError, felt252> {
SnooknetError::MatchNotPending => 'Match Not Pending',
SnooknetError::MatchNotInProgress => 'Match Not In Progress',
SnooknetError::MatchNotInProgressOrPaused => 'Match Not In Progress Or Paused',

}
}
}
6 changes: 3 additions & 3 deletions src/interfaces/ISnooknet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub trait ISnooknet<T> {
fn end_match(ref self: T, game_id: u256, winner: ContractAddress);
fn retrieve_game(ref self: T, game_id: u256) -> Game;


fn join_tournament(ref self: T, tournament_id: u256);
fn start_match(ref self: T, game_id: u256) -> bool;

// Pause an ongoing match, updating its status
fn pause_match(ref self: T, game_id: u256) -> bool;
// fn pot_ball(ref self: T, game_id: u256, ball_type: felt252, is_cue_foul: bool);
// End a match, setting the winner and finalizing the game
// fn pot_ball(ref self: T, game_id: u256, ball_type: felt252, is_cue_foul: bool);
// End a match, setting the winner and finalizing the game
// fn mint_nft(ref self: T, asset_type: AssetType, rarity: Rarity) -> u256;
// fn lease_nft(ref self: T, asset_id: u256, leasee: ContractAddress);
// fn submit_proposal(ref self: T, proposal_id: u256);
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/ITournaments.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub trait ITournaments<T> {
max_players: u8,
start_date: u64,
end_date: u64,
rewards: Array<TournamentReward>
rewards: Array<TournamentReward>,
) -> u256;
fn register_player(ref self: T, tournament_id: u256);
fn start_tournament(ref self: T, tournament_id: u256, end_date: u64);
fn end_tournament(ref self: T, tournament_id: u256);
fn cancel_tournament(ref self: T, tournament_id: u256);
fn is_player_registered(self: @T, tournament_id: u256, player: ContractAddress) -> bool;
fn update_player_stats(
fn update_player_stats(
ref self: T,
tournament_id: u256,
player: ContractAddress,
Expand All @@ -28,14 +28,14 @@ pub trait ITournaments<T> {
lost: bool,
nft_coins_delta: u256,
level_delta: u32,
tournament_won: bool
tournament_won: bool,
);
fn update_match_stats(
ref self: T,
tournament_id: u256,
player: ContractAddress,
won: bool,
xp_delta: u256,
elo_delta: u256
elo_delta: u256,
);
}
}
3 changes: 2 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub mod types {
pub mod achievements {
pub mod achievement;
}

// pub mod tokens {
// pub mod mock_erc20;
// }


12 changes: 10 additions & 2 deletions src/model/game_model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,21 @@ pub struct Game {
pub trait GameTrait {
// Create and return a new game with default snooker setup
fn new(
id: u256,tournament_id: u256, player1: ContractAddress, player2: ContractAddress, stake_amount: u256,
id: u256,
tournament_id: u256,
player1: ContractAddress,
player2: ContractAddress,
stake_amount: u256,
) -> Game;
}

impl GameImpl of GameTrait {
fn new(
id: u256, tournament_id: u256, player1: ContractAddress, player2: ContractAddress, stake_amount: u256,
id: u256,
tournament_id: u256,
player1: ContractAddress,
player2: ContractAddress,
stake_amount: u256,
) -> Game {
let zero_address = contract_address_const::<0x0>();
let current_time = get_block_timestamp();
Expand Down
2 changes: 1 addition & 1 deletion src/model/new_tourn_models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TournamentImpl of TournamentTrait {
end_date,
status: TournamentStatus::Pending,
rewards,
players: ArrayTrait::new()
players: ArrayTrait::new(),
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/model/player_model.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;

#[derive(Copy, Drop, Serde, Debug)]
#[derive(Copy, Drop, Serde, Debug, Introspect, PartialEq)]
#[dojo::model]
pub struct Player {
#[key]
Expand All @@ -25,7 +25,7 @@ pub trait PlayerTrait {
games_lost: u64,
nft_coins_available: u256,
level: u32,
tournaments_won: u64, // Added parameter
tournaments_won: u64 // Added parameter
) -> Player;
}

Expand All @@ -39,7 +39,7 @@ impl PlayerImpl of PlayerTrait {
games_lost: u64,
nft_coins_available: u256,
level: u32,
tournaments_won: u64, // Added parameter
tournaments_won: u64 // Added parameter
) -> Player {
Player {
contract_address,
Expand All @@ -50,7 +50,7 @@ impl PlayerImpl of PlayerTrait {
games_lost,
nft_coins_available,
level,
tournaments_won, // Initialize new field
tournaments_won // Initialize new field
}
}
}
Expand Down Expand Up @@ -86,7 +86,9 @@ mod tests {
);

assert(player.contract_address == contract_address, 'Contract address mismatch');
assert(player.leaderboard_position == leaderboard_position, 'Leaderboard position mismatch');
assert(
player.leaderboard_position == leaderboard_position, 'Leaderboard position mismatch',
);
assert(player.xp == xp, 'XP mismatch');
assert(player.elo_rating == elo_rating, 'Elo rating mismatch');
assert(player.games_won == games_won, 'Games won mismatch');
Expand Down Expand Up @@ -124,7 +126,15 @@ mod tests {
let max_u32 = 4294967295_u32;

let player = PlayerImpl::new(
contract_address, max_u64, max_u256, max_u256, max_u64, max_u64, max_u256, max_u32, max_u64,
contract_address,
max_u64,
max_u256,
max_u256,
max_u64,
max_u64,
max_u256,
max_u32,
max_u64,
);

assert(player.contract_address == contract_address, 'Contract address mismatch');
Expand All @@ -137,4 +147,4 @@ mod tests {
assert(player.level == max_u32, 'Level should be max');
assert(player.tournaments_won == max_u64, 'Tournaments won should be max'); // Added
}
}
}
1 change: 1 addition & 0 deletions src/model/skiil.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading