Test.dart aktualisiert
This commit is contained in:
parent
13a09bb8a9
commit
d4b26fa674
69
Test.dart
69
Test.dart
@ -1,48 +1,31 @@
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
}
|
||||
import random
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Color Changer'),
|
||||
),
|
||||
body: ColorChanger(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
def guess_the_number():
|
||||
secret_number = random.randint(1, 100)
|
||||
attempts = 0
|
||||
|
||||
class ColorChanger extends StatefulWidget {
|
||||
@override
|
||||
_ColorChangerState createState() => _ColorChangerState();
|
||||
}
|
||||
print("Welcome to Guess the Number Game!")
|
||||
print("I'm thinking of a number between 1 and 100.")
|
||||
print("Can you guess it?")
|
||||
|
||||
class _ColorChangerState extends State<ColorChanger> {
|
||||
Color _backgroundColor = Colors.white;
|
||||
while True:
|
||||
try:
|
||||
guess = int(input("Enter your guess: "))
|
||||
attempts += 1
|
||||
|
||||
void changeBackgroundColor() {
|
||||
setState(() {
|
||||
_backgroundColor = Color(Random().nextInt(0xFFFFFFFF));
|
||||
});
|
||||
}
|
||||
if guess == secret_number:
|
||||
print(f"Congratulations! You guessed the number {secret_number} in {attempts} attempts.")
|
||||
break
|
||||
elif guess < secret_number:
|
||||
print("Try a higher number.")
|
||||
else:
|
||||
print("Try a lower number.")
|
||||
except ValueError:
|
||||
print("Invalid input. Please enter a valid number.")
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => changeBackgroundColor(),
|
||||
child: Container(
|
||||
color: _backgroundColor,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Tap to Change Color',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
if __name__ == "__main__":
|
||||
guess_the_number()
|
||||
|
||||
Copy and paste the above code into a Python environment or a Python file (e.g., guess_the_number.py) and run the script. The game will prompt you to guess the randomly generated number, providing hints whether the correct number is higher or lower than your guess. Keep guessing until you find the correct number.
|
||||
|
||||
This is just a basic example, but you can expand on it to create more complex games with graphics, levels, and other features using game development engines like Unity, Unreal Engine, Godot, or others I mentioned earlier. Creating a full-fledged video game often involves a team of developers, artists, designers, and more, depending on the scope and complexity of the game.
|
||||
|
Loading…
Reference in New Issue
Block a user