-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c84652f
commit f970cdd
Showing
15 changed files
with
1,627 additions
and
2 deletions.
There are no files selected for viewing
459 changes: 459 additions & 0 deletions
459
manifests/dev/base/abis/models/bytebeasts-Game-e91217d7.json
Large diffs are not rendered by default.
Oops, something went wrong.
407 changes: 407 additions & 0 deletions
407
manifests/dev/base/abis/models/bytebeasts-GameId-344511d3.json
Large diffs are not rendered by default.
Oops, something went wrong.
439 changes: 439 additions & 0 deletions
439
manifests/dev/base/abis/models/bytebeasts-GamePlayer-596ef4a1.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
kind = "DojoModel" | ||
class_hash = "0x14996dadc46ccc2e22fa71e614ea4a158f91fd919429d00a0e36a4a4314bdd8" | ||
original_class_hash = "0x14996dadc46ccc2e22fa71e614ea4a158f91fd919429d00a0e36a4a4314bdd8" | ||
abi = "manifests/dev/base/abis/models/bytebeasts-Game-e91217d7.json" | ||
tag = "bytebeasts-Game" | ||
manifest_name = "bytebeasts-Game-e91217d7" | ||
|
||
[[members]] | ||
name = "game_id" | ||
type = "u128" | ||
key = true | ||
|
||
[[members]] | ||
name = "player_1" | ||
type = "ContractAddress" | ||
key = false | ||
|
||
[[members]] | ||
name = "player_2" | ||
type = "ContractAddress" | ||
key = false | ||
|
||
[[members]] | ||
name = "player_3" | ||
type = "ContractAddress" | ||
key = false | ||
|
||
[[members]] | ||
name = "player_4" | ||
type = "ContractAddress" | ||
key = false | ||
|
||
[[members]] | ||
name = "status" | ||
type = "GameStatus" | ||
key = false | ||
|
||
[[members]] | ||
name = "is_private" | ||
type = "bool" | ||
key = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
kind = "DojoModel" | ||
class_hash = "0x6a3b296e3483766bd71a615fe01cf34ec0300356ed2971289fa54b236f47958" | ||
original_class_hash = "0x6a3b296e3483766bd71a615fe01cf34ec0300356ed2971289fa54b236f47958" | ||
abi = "manifests/dev/base/abis/models/bytebeasts-GameId-344511d3.json" | ||
tag = "bytebeasts-GameId" | ||
manifest_name = "bytebeasts-GameId-344511d3" | ||
|
||
[[members]] | ||
name = "id" | ||
type = "u32" | ||
key = true | ||
|
||
[[members]] | ||
name = "game_id" | ||
type = "u128" | ||
key = false |
56 changes: 56 additions & 0 deletions
56
manifests/dev/base/models/bytebeasts-GamePlayer-596ef4a1.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
kind = "DojoModel" | ||
class_hash = "0x62792f6e33268b9969eb392c92b70ef6729e674fd204b324f22a2615c1d22a7" | ||
original_class_hash = "0x62792f6e33268b9969eb392c92b70ef6729e674fd204b324f22a2615c1d22a7" | ||
abi = "manifests/dev/base/abis/models/bytebeasts-GamePlayer-596ef4a1.json" | ||
tag = "bytebeasts-GamePlayer" | ||
manifest_name = "bytebeasts-GamePlayer-596ef4a1" | ||
|
||
[[members]] | ||
name = "address" | ||
type = "ContractAddress" | ||
key = true | ||
|
||
[[members]] | ||
name = "game_id" | ||
type = "u128" | ||
key = true | ||
|
||
[[members]] | ||
name = "beast_1" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "beast_2" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "beast_3" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "beast_4" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "bag_id" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "active_mount" | ||
type = "u8" | ||
key = false | ||
|
||
[[members]] | ||
name = "mounts" | ||
type = "Array<u8>" | ||
key = false | ||
|
||
[[members]] | ||
name = "position" | ||
type = "Array<u8>" | ||
key = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use starknet::ContractAddress; | ||
use dojo::model::Model; | ||
|
||
#[derive(Drop, Serde, Debug)] | ||
#[dojo::model] | ||
pub struct GamePlayer { | ||
#[key] | ||
pub address: ContractAddress, | ||
#[key] | ||
pub game_id: u128, | ||
pub beast_1: u8, | ||
pub beast_2: u8, | ||
pub beast_3: u8, | ||
pub beast_3: u8, | ||
pub bag_id: u8, | ||
pub active_mount: u8, | ||
pub mounts: Array<u8>, | ||
pub position: Array<u8> | ||
} | ||
|
||
pub trait GamePlayerTrait { | ||
fn new(game_id: u128, address: ContractAddress) -> GamePlayer; | ||
} | ||
|
||
impl GamePlayerImpl of GamePlayerTrait { | ||
// logic to create an instance of a game player | ||
fn new(game_id: u128, address: ContractAddress) -> GamePlayer { | ||
let game_player = GamePlayer { | ||
address: address, | ||
game_id: game_id, | ||
beast_1: 0_u8, | ||
beast_2: 0_u8, | ||
beast_3: 0_u8, | ||
beast_4: 0_u8, | ||
bag_id: 0_u8, | ||
active_mount: 0_u8, | ||
mounts: ArrayTrait::new(), | ||
position: ArrayTrait::new(), | ||
}; | ||
game_player | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use starknet::ContractAddress; | ||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
|
||
use bytebeasts::models::GameId | ||
use bytebeasts::models::GameStatus | ||
use bytebeasts::models::Game | ||
use bytebeasts::models::GamePlayer | ||
|
||
#[dojo::interface] | ||
trait IActions { | ||
fn create_initial_game_id(ref world: IWorldDispatcher); | ||
fn create_game(ref world: IWorldDispatcher) -> Game; | ||
fn join_game(ref world: IWorldDispatcher, game_id: u128, player_two_address: ContractAddress); | ||
} | ||
|
||
#[dojo::contract] | ||
mod actions { | ||
use starknet::{ContractAddress, get_caller_address, SyscallResultTrait}; | ||
use starknet::{get_tx_info, get_block_number}; | ||
use bytebeasts::models::{GameId, GameStatus, Game, GamePlayer}; | ||
|
||
use super::IActions; | ||
|
||
#[abi(embed_v0)] | ||
impl ActionsImpl of IActions<ContractState> { | ||
fn create_initial_game_id(ref world: IWorldDispatcher) { | ||
let existing_game_id = get!(world, 1, (GameId)); | ||
if (existing_game_id.game_id > 0) { | ||
panic!("error global game id already created"); | ||
} | ||
let game_id: GameId = GameId { id: 1, game_id: 1 }; | ||
set!(world, (game_id)); | ||
} | ||
|
||
fn create_game(ref world: IWorldDispatcher) -> Game { | ||
let player_1_address = get_caller_address(); | ||
let mut game_id: GameId = get!(world, 1, (GameId)); | ||
let player_1 = GamePlayerTrait::new(game_id.game_id, player_1_address); | ||
let game: Game = GameTrait::new(game_id.game_id, player_1_address); | ||
game_id.game_id += 1; | ||
set!(world, (player_1, game, game_id)); | ||
game | ||
} | ||
|
||
fn join_game( | ||
ref world: IWorldDispatcher, game_id: u128, player_2_address: ContractAddress | ||
) { | ||
let mut game = get!(world, game_id, (Game)); | ||
assert!( | ||
game.player_2 == core::num::traits::Zero::<ContractAddress>::zero(), | ||
"player_2 already set" | ||
); | ||
let player_2 = GamePlayerTrait::new(game.game_id, player_2_address); | ||
game.join_game(player_2); | ||
let player_2 = GamePlayerTrait::new(game.game_id, player_2_address); | ||
set!(world, (player_2, game)); | ||
} | ||
|
||
fn is_game_finished(ref world: IWorldDispatcher, game_id: u128) -> bool { | ||
let mut game: Game = get!(world, game_id, (Game)); | ||
let player_1: GamePlayer = get!(world, (game.player_1, game.game_id), (GamePlayer)); | ||
let player_2: GamePlayer = get!(world, (game.player_2, game.game_id), (GamePlayer)); | ||
game.is_game_finished(player_1, player_2) | ||
} | ||
} | ||
} |