started making the game
This commit is contained in:
@@ -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) {
|
||||||
|
if self.first_frame {
|
||||||
|
self.first_frame = false;
|
||||||
|
self.taquin_game.init_grid();
|
||||||
|
}
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.heading("My egui Application");
|
egui::Grid::new("taquin_grid").show(ui, |ui| {
|
||||||
ui.horizontal(|ui| {
|
for row in self.taquin_game.grid() {
|
||||||
let name_label = ui.label("Your name: ");
|
for column in row {
|
||||||
ui.text_edit_singleline(&mut self.name)
|
let text = match column {
|
||||||
.labelled_by(name_label.id);
|
0 => "".to_string(),
|
||||||
|
_ => column.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
egui::Frame::default().show(ui, |ui| {
|
||||||
|
ui.label(egui::RichText::new(text).strong().size(20.0));
|
||||||
});
|
});
|
||||||
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));
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user