Skip to content

Commit 71cec25

Browse files
committed
Adding the model and system tournament blueprint
1 parent d088b3b commit 71cec25

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/models/tournament.cairo

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::player::Player;
2+
3+
#[derive(Serde, Copy, Drop, Introspect, PartialEq)]
4+
pub enum TournamentStatus {
5+
Pending,
6+
Ongoing,
7+
Completed,
8+
}
9+
10+
11+
#[derive(Copy, Drop, Serde)]
12+
#[dojo::model]
13+
pub struct Tournament {
14+
#[key]
15+
pub tournament_id: u32,
16+
pub name: felt252,
17+
pub status: TournamentStatus,
18+
pub entry_fee: u32,
19+
pub max_participants: u32,
20+
pub current_participants: Array<Player>,
21+
pub prize_pool: u32,
22+
}
23+

src/systems/tournament.cairo

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
2+
use bytebeasts::{
3+
models::{player::Player, tournament::Tournament, tournament::TournamentStatus},
4+
};
5+
6+
#[dojo::interface]
7+
trait ITournamentAction {
8+
fn create_tournament(ref world: IWorldDispatcher, tournament_id: u32, name: felt252,
9+
status: TournamentStatus,
10+
entry_fee: u32,
11+
max_participants: u32,
12+
current_participants: Array<Player>,
13+
prize_pool: u32) -> Tournament;
14+
fn register_player(ref world: IWorldDispatcher, tournament_id: u32, player_id: u32);
15+
fn start_tournament(ref world: IWorldDispatcher, tournament_id: u32, player_id: u32);
16+
fn complete_torunament(ref world: IWorldDispatcher, tournament_id: u32, player_id: u32);
17+
fn get_tournament(ref world: IWorldDispatcher, tournament_id: u32) -> Tournament;
18+
}
19+
20+
21+
#[dojo::contract]
22+
mod spawn_action {
23+
use super::ITournamentAction;
24+
use bytebeasts::{
25+
models::{player::Player, tournament::Tournament},
26+
};
27+
28+
#[abi(embed_v0)]
29+
impl TournamentActionImpl of ITournamentAction<ContractState> {
30+
fn get_tournament(world: @IWorldDispatcher, tournament_id: u32) -> Tournament {
31+
let tournament_from_world = get!(world, tournament_id, (Tournament));
32+
tournament_from_world
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)