import 'package:flutter/material.dart'; import 'dart:math'; void main() { runApp(LabiryntApp()); } class LabiryntApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: StartScreen(), ); } } class StartScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Labirynt'), ), body: Center( child: ElevatedButton( onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => LabiryntScreen()), ); }, child: Text('Start Game'), ), ), ); } } class LabiryntScreen extends StatefulWidget { @override _LabiryntScreenState createState() => _LabiryntScreenState(); } class _LabiryntScreenState extends State { final List> maze = [ [10, 8, 10, 9], [28, 1, 0, 12], [12, 10, 9, 13], [6, 5, 6, 5] ]; int x = 0; int y = 0; void move(int dx, int dy) { setState(() { x += dx; y += dy; if (maze[y][x] == 0) { Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => EndScreen()), ); } }); } @override Widget build(BuildContext context) { int room = maze[y][x]; return Scaffold( appBar: AppBar( title: Text('Labirynt - Komnata ($x, $y)'), ), body: Stack( children: [ Positioned( left: 20, top: MediaQuery.of(context).size.height / 2 - 20, child: ElevatedButton( onPressed: (room & 1) != 0 ? () => move(-1, 0) : null, child: Text('Lewo'), style: ElevatedButton.styleFrom( backgroundColor: (room & 1) != 0 ? Colors.green : Colors.grey, ), ), ), Positioned( right: 20, top: MediaQuery.of(context).size.height / 2 - 20, child: ElevatedButton( onPressed: (room & 2) != 0 ? () => move(1, 0) : null, child: Text('Prawo'), style: ElevatedButton.styleFrom( backgroundColor: (room & 2) != 0 ? Colors.green : Colors.grey, ), ), ), Positioned( left: MediaQuery.of(context).size.width / 2 - 30, top: 20, child: ElevatedButton( onPressed: (room & 4) != 0 ? () => move(0, -1) : null, child: Text('Góra'), style: ElevatedButton.styleFrom( backgroundColor: (room & 4) != 0 ? Colors.green : Colors.grey, ), ), ), Positioned( left: MediaQuery.of(context).size.width / 2 - 30, bottom: 20, child: ElevatedButton( onPressed: (room & 8) != 0 ? () => move(0, 1) : null, child: Text('Dół'), style: ElevatedButton.styleFrom( backgroundColor: (room & 8) != 0 ? Colors.green : Colors.grey, ), ), ), ], ), ); } } class EndScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Koniec Gry'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Gratulacje! Dotarłeś do końca labiryntu!', textAlign: TextAlign.center, style: TextStyle(fontSize: 24), ), SizedBox(height: 20), ElevatedButton( onPressed: () { Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => StartScreen()), ); }, child: Text('Zagraj ponownie'), ), ], ), ), ); } }