Duplicate and shuffle tiles
This commit is contained in:
parent
1cfa3f0b53
commit
308ac5746c
23
src/main.rs
23
src/main.rs
@ -1,5 +1,24 @@
|
|||||||
slint::include_modules!();
|
use ::rand::seq::SliceRandom;
|
||||||
|
use ::slint::include_modules;
|
||||||
|
use ::slint::{Model, VecModel};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
include_modules!();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
MainWindow::new().unwrap().run().unwrap();
|
let main_window = MainWindow::new().unwrap();
|
||||||
|
|
||||||
|
// Fetch the tiles from the model
|
||||||
|
let mut tiles: Vec<TileData> = main_window.get_memory_tiles().iter().collect();
|
||||||
|
// Duplicate the list of tiles so we have pairs
|
||||||
|
tiles.extend(tiles.clone());
|
||||||
|
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
tiles.shuffle(&mut rng);
|
||||||
|
|
||||||
|
// Update the model
|
||||||
|
let tiles_model = Rc::new(VecModel::from(tiles));
|
||||||
|
main_window.set_memory_tiles(tiles_model.into());
|
||||||
|
|
||||||
|
main_window.run().unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user