started making the game

This commit is contained in:
thatscringebro
2025-07-16 10:06:01 -04:00
parent 7417a1b6b2
commit c93c5c3134

View File

@@ -1,4 +1,4 @@
use taquin_lib; use taquin_lib::{self, TaquinGame};
use eframe::egui; use eframe::egui;
@@ -8,40 +8,62 @@ fn main() -> eframe::Result {
..Default::default() ..Default::default()
}; };
eframe::run_native( eframe::run_native(
"My egui App", "Taquin Game",
options, options,
Box::new(|cc| Ok(Box::<MyApp>::default())), Box::new(|cc| Ok(Box::<TaquinGUI>::default())),
) )
} }
struct MyApp { struct TaquinGUI {
name: String, first_frame: bool,
age: u32, taquin_game: TaquinGame,
} }
impl Default for MyApp { impl Default for TaquinGUI {
fn default() -> Self { fn default() -> Self {
Self { Self {
name: "Arthur".to_owned(), first_frame: true,
age: 42, taquin_game: TaquinGame::new(),
} }
} }
} }
impl eframe::App for MyApp { impl eframe::App for TaquinGUI {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { if self.first_frame {
ui.heading("My egui Application"); self.first_frame = false;
ui.horizontal(|ui| { self.taquin_game.init_grid();
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
self.age += 1;
} }
ui.label(format!("Hello '{}', age {}", self.name, self.age)); egui::CentralPanel::default().show(ctx, |ui| {
egui::Grid::new("taquin_grid").show(ui, |ui| {
for row in self.taquin_game.grid() {
for column in row {
let text = match column {
0 => "".to_string(),
_ => column.to_string(),
};
egui::Frame::default().show(ui, |ui| {
ui.label(egui::RichText::new(text).strong().size(20.0));
});
}
ui.end_row();
}
});
if ui.button("up").clicked() {
self.taquin_game.move_to(taquin_lib::Directions::Up);
};
if ui.button("down").clicked() {
self.taquin_game.move_to(taquin_lib::Directions::Down);
};
if ui.button("left").clicked() {
self.taquin_game.move_to(taquin_lib::Directions::Left);
};
if ui.button("right").clicked() {
self.taquin_game.move_to(taquin_lib::Directions::Right);
};
}); });
} }
} }