-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path]
143 lines (126 loc) · 2.64 KB
/
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import 'package:flutter/material.dart';
import 'dart:math';
int matriz = 10;
int nbombas = 5;
int matrizElements() => matriz*matriz;
List bombas = <int> [];
List bombCart = [];
List detecsCar = [];
List detecsInt = [];
void main () {
minando();
runApp(Arthur());
}
void minando () {
sorteando();
listingBombs();
distribute();
}
class Calcs {
static List convToCart (int numero) {
int Valuex = numero%matriz;
int Valuey = numero~/matriz;
return [Valuex,Valuey];
}
static int convToId (List<int> ll)
=> (ll[1]*matriz) + ll[0];
static int count (cTest, cList) {
int i = 0;
for (var cItem in cList) {
if (cTest == cItem) {
i++;
}
}
return i;
}
}
void sorteando(){
for (int i = 0; i < nbombas;) {
int bomba = new Random().nextInt((matrizElements()-1));
if (bombas.contains(bomba)==false) {
bombas.add(bomba);
i++;
}
}
}
void listingBombs () {
for (var i in bombas){
bombCart.add(Calcs.convToCart(i));
}
}
void distribute () {
for (List bmb in bombCart) {
for (var x = -1; x <= 1; x++) {
for (var y = -1 ; y <= 1; y++) {
int xax = bmb[0] + x;
int yax = bmb[1] + y;
List res = <int> [xax , yax];
detecsCar.add(res);
}
}
}
for (List<int> dc in detecsCar) {
if (dc[0]<matriz && dc[1]<matriz){
int intver = Calcs.convToId(dc);
detecsInt.add(intver);
}
}
}
void reacao(index) {
print('escreveste $index');
if (bombas.contains(index)==true) {
print('perdeste');
}
}
Widget casa (index){
if (bombas.contains(index)==true) {
return Icon(Icons.dangerous);
}
else {
return Text('${Calcs.count(index, detecsInt)}');
}
}
Widget Casinha extends ButtonTheme () =>
@override
var? Teste;
minWidth = 200.0;
height = 100.0;
Casinha () {
var this.Teste = 'a';
}
}
dynamic albert =
List.generate(matrizElements(), (index) {
return Casinha(
child: RaisedButton(
onPressed: ()=>reacao(index),
padding: EdgeInsets.all(0),
child: SizedBox(
width:30.0,
height:30.0,
child: casa(index),
),
),
);
});
class Arthur extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title:'Campo Minado',
home: Scaffold(
appBar: AppBar(
title: const Text('Campo Minado'),
),
body: Center(
child:GridView.count(
crossAxisSpacing: 0,
mainAxisSpacing: 0,
crossAxisCount: 10,
children: albert,
)
)
),
);
}
}