커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
숙제관련 질문도 되나요?
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반
1주차
북마크
윤*승
댓글
10
추천
0
조회수
22
조회수
22
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


새게임 버튼 클릭시 화면 초기화 부분이 잘 처리가 안되어서 질문합니다.

새게임 버튼 클릭하면 score와 trycount는 0으로 초기화 되는데,

카드화면이 초기화 되지 않습니다.

home.dart부분입니다.

import 'package:flutter/material.dart';
import 'package:memory_matching_game/src/card_model.dart';
import 'package:memory_matching_game/src/card_boards.dart';
import 'package:memory_matching_game/src/header.dart';


class Home extends StatefulWidget {
  @override
  State<Home> createState() => _HomeState();
}


class _HomeState extends State<Home> {
  int tryCount = 0; 
  int score = 0;
  late List<CardModel> cards;


 //추가
  void updateTryCount() {
  // print('시도 횟수를 업데이트합니다.');
  setState(() {
    tryCount++;
  });
}


  void updateScore() {
    setState(() {
    score+=100;
    print('현재 점수: $score'); // 디버깅용 출력
  });
}
  void resetGame() {
    setState(() {
      tryCount = 0;
      score = 0;
      List<int> cardsValues = [1, 5, 2, 6, 3, 4, 3, 2, 6, 1, 4, 5];
  cardsValues.shuffle();
  cards = List.generate(cardsValues.length, (index) {
    return CardModel(
      index: index,
      cardValue: cardsValues[index],
    );
  });
    });
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffECE7E4),
      appBar: AppBar(
        title: const Text('짝맞추기 게임'),
        backgroundColor: const Color(0xff92CBFF),
      ),
      body: Padding(
        padding: EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Header(tryCount: tryCount, score:score, resetGame: resetGame),
            SizedBox(height: 20),
            Expanded(
              child: CardBoards(
                updateTryCount: updateTryCount,
                updateScore: updateScore,
              ),
            ),
          ],
        ),
      ),
    );
  }
}



스파르타 즉문즉답







취소
 공유
취소
댓글 0
댓글 알림
나의얼굴