Skip to content

Commit

Permalink
dekorasi lengkap
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanasegaf committed Nov 28, 2024
1 parent 808b128 commit 5c29a8f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 57 deletions.
20 changes: 4 additions & 16 deletions lib/logicGame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,12 @@ class _LogicGameState extends State<LogicGame> {
onPressed: () => checkAnswer(true),
icon: const Icon(
Icons.check_circle_outline,
color: Colors.white,
),
label: const Text(
'Benar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
fontWeight: FontWeight.bold,
),
),
),
),
Expand All @@ -228,18 +222,12 @@ class _LogicGameState extends State<LogicGame> {
onPressed: () => checkAnswer(false),
icon: const Icon(
Icons.cancel_outlined,
color: Colors.white,
),
label: const Text(
'Salah',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
fontWeight: FontWeight.bold,
),
),
),
),
Expand Down
56 changes: 36 additions & 20 deletions lib/mathGame.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore_for_file: library_private_types_in_public_api, file_names

import 'package:flutter/material.dart';

import 'dart:async';
import 'dart:math';

Expand All @@ -23,7 +22,6 @@ class MathGameScreen extends StatefulWidget {

class _MathGameScreenState extends State<MathGameScreen> {
int _score = 0;
// ignore: prefer_final_fields
int _timePerQuestion = 5; // waktu untuk menjawab setiap soal dalam detik
int _currentTime = 5;
late Timer _timer;
Expand All @@ -33,7 +31,6 @@ class _MathGameScreenState extends State<MathGameScreen> {
late String _operator;
late int _correctAnswer;

// ignore: prefer_final_fields
TextEditingController _answerController = TextEditingController();

bool _gameStarted = false; // Flag untuk menandakan permainan telah dimulai
Expand Down Expand Up @@ -96,17 +93,14 @@ class _MathGameScreenState extends State<MathGameScreen> {
}
}

// Increment the question count
setState(() {
_questionCount++;
});

// Stop the game after 10 questions
if (_questionCount >= 10) {
_timer.cancel();
_showScoreDialog(); // Show the score dialog
_showScoreDialog();
} else {
// Reset timer dan generate soal baru
_answerController.clear();
_generateQuestion();
setState(() {
Expand All @@ -120,16 +114,16 @@ class _MathGameScreenState extends State<MathGameScreen> {
_score = 0;
_gameStarted = false;
_currentTime = _timePerQuestion;
_questionCount = 0; // Reset question count
_questionCount = 0;
});
_generateQuestion();
}

void _startGame() {
setState(() {
_gameStarted = true; // Mulai permainan
_gameStarted = true;
});
_startTimer(); // Mulai timer
_startTimer();
}

void _showScoreDialog() {
Expand All @@ -143,7 +137,7 @@ class _MathGameScreenState extends State<MathGameScreen> {
TextButton(
onPressed: () {
Navigator.of(context).pop();
_resetGame(); // Reset game after showing score
_resetGame();
},
child: const Text('Main Lagi'),
),
Expand All @@ -157,7 +151,11 @@ class _MathGameScreenState extends State<MathGameScreen> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Permainan Matematika Cepat'),
backgroundColor: Colors.blueAccent,
title: const Text(
'Permainan Matematika Cepat',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
Expand All @@ -171,31 +169,43 @@ class _MathGameScreenState extends State<MathGameScreen> {
padding: EdgeInsets.all(8.0),
child: Text(
"Tekan Tombol untuk Memulai Game",
style: const TextStyle(fontSize: 18),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
ElevatedButton(
ElevatedButton.icon(
onPressed: _startGame,
child: const Text('Start Game'),
icon: const Icon(Icons.play_arrow),
label: const Text('Mulai Permainan'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 15),
textStyle: const TextStyle(fontSize: 18),
),
),
] else ...[
// Tampilan permainan setelah game dimulai
Text(
'Waktu Tersisa: $_currentTime detik',
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.red),
),
const SizedBox(height: 20),
Text(
'Skor: $_score',
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.blue),
),
const SizedBox(height: 40),
Text(
'$_number1 $_operator $_number2 = ?',
style: const TextStyle(
fontSize: 32, fontWeight: FontWeight.bold),
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.black),
),
const SizedBox(height: 20),
TextField(
Expand All @@ -205,13 +215,19 @@ class _MathGameScreenState extends State<MathGameScreen> {
decoration: const InputDecoration(
hintText: 'Masukkan jawaban',
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(vertical: 10),
),
onSubmitted: (_) => _checkAnswer(),
),
const SizedBox(height: 20),
ElevatedButton(
ElevatedButton.icon(
onPressed: _checkAnswer,
child: const Text('Kirim Jawaban'),
icon: const Icon(Icons.check),
label: const Text('Kirim Jawaban'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 15),
),
),
const SizedBox(height: 40),
]
Expand Down
30 changes: 24 additions & 6 deletions lib/memoryGames.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class _MemoryGamePageState extends State<MemoryGamePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Permainan Memori'),
backgroundColor: const Color.fromARGB(255, 255, 127, 7),
title: const Text(
'Permainan Memori',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
),
),
body: Center(
child: Column(
Expand All @@ -101,7 +105,7 @@ class _MemoryGamePageState extends State<MemoryGamePage> {
padding: EdgeInsets.all(8.0),
child: Text(
"Tekan Tombol untuk Memulai Game",
style: TextStyle(fontSize: 18),
style: TextStyle(fontSize: 18, color: Colors.blueAccent),
),
),
ElevatedButton(
Expand All @@ -111,18 +115,21 @@ class _MemoryGamePageState extends State<MemoryGamePage> {
] else if (showSequence) ...[
const Text(
'Ingat Urutan Ini:',
style: TextStyle(fontSize: 18),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Text(
sequence.join(' '),
style:
const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.deepPurple,
),
),
] else if (isUserTurn) ...[
const Text(
'Masukkan Urutan:',
style: TextStyle(fontSize: 18),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Center(
Expand All @@ -139,6 +146,17 @@ class _MemoryGamePageState extends State<MemoryGamePage> {
}),
),
),
],
if (gameStarted) ...[
const SizedBox(height: 20),
Text(
'Level: $currentLevel',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.green,
),
),
]
],
),
Expand Down
27 changes: 15 additions & 12 deletions lib/reactionTimeGame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ class ReactionTimeApp extends StatefulWidget {
const ReactionTimeApp({super.key});

@override
// ignore: library_private_types_in_public_api
_ReactionTimeAppState createState() => _ReactionTimeAppState();
}

class _ReactionTimeAppState extends State<ReactionTimeApp> {
Color _screenColor = Color.fromARGB(255, 119, 255, 255);
late Timer _timer;
DateTime? _startTime;
// ignore: prefer_final_fields
List<int> _reactionTimes = [];
bool _waitingForTap = false;
bool _gameStarted = false;
bool _gameFinished = false; // <--- Flag untuk menandai akhir permainan
bool _gameFinished = false;

void _startRound() {
if (_reactionTimes.length == 5) {
// <--- Cek apakah sudah 5 ronde selesai
setState(() {
_gameFinished = true; // Tandai bahwa game selesai
_gameFinished = true;
_gameStarted = false;
_waitingForTap = false;
});
Expand Down Expand Up @@ -103,7 +100,11 @@ class _ReactionTimeAppState extends State<ReactionTimeApp> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Permainan Reaction Time'),
title: const Text(
'Permainan Reaction Time',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.deepPurple,
),
body: GestureDetector(
onTap: _handleTap,
Expand All @@ -127,25 +128,27 @@ class _ReactionTimeAppState extends State<ReactionTimeApp> {
? 'Tap Now!'
: 'Wait for the screen to turn green!')
: 'Tekan tombol untuk memulai ronde',
style: const TextStyle(fontSize: 18),
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
if (!_gameStarted) ...[
ElevatedButton(
ElevatedButton.icon(
onPressed: _startRound,
child: const Text('Start Round'),
icon: const Icon(Icons.play_arrow),
label: const Text('Start Round'),
),
],
] else ...[
// <--- Tombol 'Main Lagi' setelah 5 ronde
const Text(
'Permainan Selesai!',
style: TextStyle(fontSize: 18),
),
const SizedBox(height: 10),
ElevatedButton(
ElevatedButton.icon(
onPressed: _restartGame,
child: const Text('Main Lagi'),
icon: const Icon(Icons.refresh),
label: const Text('Main Lagi'),
),
],
],
Expand Down
12 changes: 9 additions & 3 deletions lib/wordsGame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ class _GameScreenState extends State<WordsGameScreen> {
}

return Scaffold(
appBar: AppBar(title: const Text("Tebak Kata")),
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 53, 197, 65),
title: const Text(
"Tebak Kata",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
)),
body: Stack(
children: [
Padding(
Expand Down Expand Up @@ -138,9 +143,10 @@ class _GameScreenState extends State<WordsGameScreen> {
),
),
const SizedBox(height: 20),
ElevatedButton(
ElevatedButton.icon(
onPressed: checkAnswer,
child: const Text("Submit"),
icon: const Icon(Icons.play_arrow), // Menambahkan ikon play
label: const Text("Submit"),
),
const SizedBox(height: 20),
Text(
Expand Down

0 comments on commit 5c29a8f

Please sign in to comment.