started making the game
This commit is contained in:
parent
7417a1b6b2
commit
c93c5c3134
@ -1,4 +1,4 @@
|
||||
use taquin_lib;
|
||||
use taquin_lib::{self, TaquinGame};
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
@ -8,40 +8,62 @@ fn main() -> eframe::Result {
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"My egui App",
|
||||
"Taquin Game",
|
||||
options,
|
||||
Box::new(|cc| Ok(Box::<MyApp>::default())),
|
||||
Box::new(|cc| Ok(Box::<TaquinGUI>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
name: String,
|
||||
age: u32,
|
||||
struct TaquinGUI {
|
||||
first_frame: bool,
|
||||
taquin_game: TaquinGame,
|
||||
}
|
||||
|
||||
impl Default for MyApp {
|
||||
impl Default for TaquinGUI {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "Arthur".to_owned(),
|
||||
age: 42,
|
||||
first_frame: true,
|
||||
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) {
|
||||
if self.first_frame {
|
||||
self.first_frame = false;
|
||||
self.taquin_game.init_grid();
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("My egui Application");
|
||||
ui.horizontal(|ui| {
|
||||
let name_label = ui.label("Your name: ");
|
||||
ui.text_edit_singleline(&mut self.name)
|
||||
.labelled_by(name_label.id);
|
||||
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();
|
||||
}
|
||||
});
|
||||
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));
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user