Behind Coleus

大学生なのに特別大学で楽しいことが一 つもない。虐待と男子校病のせいにしてみる。→日本脱出しました 今ジャカルタにいます。→ジャカルタから帰ってきました。→6月19日から小笠原沖で、インドネシア人とメカジキ漁

命をかけた戦い1KNOW ABOUT ME

今日は6時15分に目が覚めて、10分くらい散歩した。

炊飯器のタイマーが6:50分になってたから 朝飯前に作業を始めてる。


今回の目標、カードをエンティティとして生成してみる。

 

まず、カードEntityにコンポーネントとして以下の4つの情報を与えたいです。

name

energy

power

location

 

#[derive(Component)]
struct Health {
    hp: f32,
    extra: f32,
}

#[derive(Component)]
enum AiMode {
    Passive,
    ChasingPlayer,
}

 

bevy-cheatbook.github.io

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, show_information)
        .run();
}

#[derive(Component)]
struct Card {
    power: u32,
    name: String,
    energy: u32,
}

#[derive(Component, Default)]
enum Location {
    InHand,
    SZone,
    XZone,
    FZone,
    #[default]
    InLibrary,
}

fn setup(mut commands: Commands) {
    // create a new entity
    let my_entity = commands
        .spawn*1
        .id();

    println!("{:?} is spawned", my_entity)
}

fn show_information(query: Query<(&Card, &Location)>){
    for (card, location) in query.iter(){

        let location_str = match location {
            Location::InHand => "InHand",
            Location::SZone => "SZone",
            Location::XZone => "XZone",
            Location::FZone => "FZone",
            Location::InLibrary => "InLibrary",
        };

        println!("Card Name: {}, Power: {}, Energy: {}, Location:{}", card.name, card.power, card.energy, location_str);
    }
}

取り敢えず、カード1枚を追加してそのidを表示し、カードの情報を取得するシステム作り終わった。

let my_entity = commands.spawn*2

        .id();

    println!("{:?} is spawned", my_entity);

    let my_entity = commands
    .spawn*3
    .id();

println!("{:?} is spawned", my_entity);

let my_entity = commands
.spawn*4
.id();

println!("{:?} is spawned", my_entity);

let my_entity = commands
.spawn*5
.id();

println!("{:?} is spawned", my_entity);

let my_entity = commands
.spawn*6
.id();

println!("{:?} is spawned", my_entity);


}

fn show_information(query: Query<(&Card, &Location)>){
    for (card, location) in query.iter(){

        let location_str = match location {
            Location::InHand => "InHand",
            Location::SZone => "SZone",
            Location::XZone => "XZone",
            Location::FZone => "FZone",
            Location::InLibrary => "InLibrary",
        };

        println!("Card Name: {}, Power: {}, Energy: {}, Location:{}", card.name, card.power, card.energy, location_str);
    }
}


取り敢えず、カードを5枚追加してみました。

先ほどは、Update関数にしてたので、PostSetupスケジュールを使って、連続で動かないようにした。

とりあえず、5つ生成することには生成した。

 

そのあと、F zoneにあるカードの合計エナジーを計算する。

そして、山札にあるカードを表示する。

fn sum_energy_in_Szone(query: Query<(&Card, &Location)>){
    let usable_energy = 0;
    for (card, location) in query.iter(){

            if Location::SZone {
                usable_energy+=card.energy
            };

}
}

このようなコードを書いたがAIにダメだしされて、

mutを使えと、言われた。

fn sum_energy_in_szone(query: Query<(&Card, &Location)>) {
    let mut usable_energy = 0;
    for (card, location) in query.iter() {
        if let Location::SZone = location {
            usable_energy += card.energy; // energyを加算
        }
    }
    println!("Total usable energy in SZone: {}", usable_energy); // 結果を表示
}
これにした。 同様に、
 

fn cards_in_deck(query: Query<(&Card, &Location)>){
    print!("cards in your deck are ");
    for(card, location) in query.iter(){
        if let Location::InLibrary = location{
            println!("{}, ", card.name);
        }
    }
}
できた。
 
最後に必要な関数は入力を受け取って、選択してエンティティの位置を移動する関数を作る。

まず、手札にあるカードをいくつか追加する。
    let my_entity = commands
        .spawn*7
        .id();

    println!("{:?} is spawned", my_entity);

    let my_entity = commands
        .spawn*8
        .id();

    println!("{:?} is spawned", my_entity);

    let my_entity = commands
        .spawn*9
        .id();

    println!("{:?} is spawned", my_entity);
これでOK
fn select_a_card_in_hand(query: Query<(Entity, &Card, &Location)>) {
    let mut cards_in_hand = Vec::new();

    println!("Cards in your hand are:");
   
    for (index, (entity, card, location)) in query.iter().enumerate() {
        if let Location::InHand = location {
            println!("{}: {}", cards_in_hand.len()+1, card.name); // 番号を振って表示
            cards_in_hand.push(entity); // エンティティIDを保存
        }
    }

    if cards_in_hand.is_empty() {
        println!("No cards in hand.");
        return;
    }

    println!("Select a card by number (1-{}):", cards_in_hand.len());

    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");

    if let Ok(selected_index) = input.trim().parse::<usize>() {
        if selected_index > 0 && selected_index <= cards_in_hand.len() {
            let selected_entity = cards_in_hand[selected_index - 1]; // 選択したエンティティIDを取得
            println!("You selected card with Entity ID: {:?}", selected_entity);
        } else {
            println!("Invalid selection.");
        }
    } else {
        println!("Please enter a valid number.");
    }
}
ChatGptに作ってもらった
手札のカード1枚を選択して、それのEntity IDを返す関数が以上になります。

これを改造して、指定したIDのエンティティのコンポーネントを変更します。
            commands.entity(selected_entity).insert(Location::FZone);
これにより、指定したエンティティにをFzoneに移動します。

少なくとも入力に合わせて、カードの名前を取得したり、Locationを変更したりすることが出来た。
これで操作の7割くらいは終わったと言える。
次は、カードのスピンリスピンを実装したい。

#[derive(Component, Default)]
enum SpinCondition {
    Spin,
    #[default]
    ReSpin,
}
これで、状態を宣言し、
数字を選択し、Sゾーンにあるリスピン状態のカードを数字以上のエナジーになるように
スピンさせる関数を作る。
 
明日教授と面談なので、結婚観について考えておく。

news.yahoo.co.jp

https://www.cfa.go.jp/assets/contents/node/basic_page/field_ref_resources/f27802a2-0546-424d-ac61-ac0641d67d38/0a71a82d/20240725_councils_lifedesign-wg_f27802a2_04.pdf

https://www.nga.gr.jp/committee_pt/item/04_shiryou2_1.pdf

manma.co

dentsu-wakamon.com子ども家庭庁 の協賛?やばくねぇか

dentsu-wakamon.comこれが、悪人の顔です。

 

www.yomiuri.co.jp

www.jstage.jst.go.jp

目的3

明日朝やる課題の内容を明らかにしておく。

山札や手札をシャッフルする方法、順序を保持する方法

裏向き表向きの情報

ドロー機能
撤退機能

 

*1:

            // Initialize all your components and bundles here
            Card {
                power: 100,
                name: String::from("リトルナイト"),
                energy: 1,
            },
            Location::InLibrary,
       

*2:)).id();でentityidを入手できる。

 

次の目標

特定の要素だけを持つものについての演算を行うシステムを作る。

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_systems(Startup, setup)
        .add_systems(PostStartup, show_information)
        .run();
}

#[derive(Component)]
struct Card {
    power: u32,
    name: String,
    energy: u32,
}

#[derive(Component, Default)]
enum Location {
    InHand,
    SZone,
    XZone,
    FZone,
    #[default]
    InLibrary,
}

fn setup(mut commands: Commands) {
    let my_entity = commands
        .spawn((
            Card {
                power: 1000,
                name: String::from("リトルナイト"),
                energy: 1,
            },
            Location::InLibrary,
       

*3:

        Card {
            power: 500,
            name: String::from("なまけ騎士 ハームゥ"),
            energy: 0,
        },
        Location::FZone,
   

*4:

    Card {
        power: 2000,
        name: String::from("アサシン・タイクーン"),
        energy: 2,
    },
    Location::InLibrary,

*5:

    Card {
        power: 2000,
        name: String::from("騎士ニャタタ・ビィ"),
        energy: 3,
    },
    Location::InLibrary,

*6:

    Card {
        power: 1000,
        name: String::from("密林の騎士リンキー"),
        energy: 2,
    },
    Location::InLibrary,

*7:

            Card {
                power: 1000,
                name: String::from("ワンダフル・ウィザード ドギィ"),
                energy: 4,
            },
            Location::InHand,
       

*8:

            Card {
                power: 1000,
                name: String::from("ワンダフルウィザード・ワッチチ"),
                energy: 3,
            },
            Location::InHand,
       

*9:

            Card {
                power: 500,
                name: String::from("ワンダフル・ウィザード ゴン"),
                energy: 3,
            },
            Location::InHand,