-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
112 lines (89 loc) · 2.46 KB
/
index.android.js
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
} from 'react-native';
import Topo from './src/components/topo.js';
import Icone from './src/components/Icone.js'
const estilos = {
botao: {
padding: 10,
width: 120,
},
principal: {
flexDirection: 'row',
justifyContent: 'center'
},
texto: {
alignItems: 'center',
marginTop: 10,
},
resultado: {
fontSize: 25,
marginBottom: 10,
color: 'red',
},
textoNome: {
alignSelf: 'center',
marginBottom: 20,
fontWeight: 'bold',
marginTop: 10,
}
}
class ServosTeste extends Component{
constructor(props){
super(props);
this.state = {user:'',comp: '', resu: ''};
}
jokenpo(user){
this.setState({user : user});
let a = Math.random() * 3;
let b = Math.floor(a);
switch(b){
case 0 : this.setState({comp: 'Pedra'}); break;
case 1 : this.setState({comp: 'Papel'}); break;
case 2 : this.setState({comp: 'Tesoura'}); break;
}
if (b==0 && user == 'Pedra' || b == 1 && user == 'Papel' || b == 2 && user == 'Tesoura'){
this.setState({resu: 'Empatou!'});
}
else if (b == 1 && user == 'Pedra' || b == 0 && user == 'Tesoura' || b == 2 && user == 'Papel'){
this.setState({resu: 'Computador Venceu!'});
}
else if (b == 2 && user == 'Pedra' || b == 1 && user == 'Tesoura' || b == 0 && user == 'Papel'){
this.setState({resu: 'Você ganhou!'});
}
}
render(){
return(
<View>
<Topo></Topo>
<View style={estilos.principal}>
<View style = {estilos.botao}>
<Button title='Pedra' onPress={() => {this.jokenpo('Pedra')}}/>
</View>
<View style = {estilos.botao}>
<Button title='Papel' onPress={() => {this.jokenpo('Papel')}}/>
</View>
<View style = {estilos.botao}>
<Button title='Tesoura' onPress={() => {this.jokenpo('Tesoura')}}/>
</View>
</View>
<View style={estilos.texto}>
<Text style={estilos.resultado}> {this.state.resu}</Text>
<Icone escolha={this.state.comp} jogador='Computador'></Icone>
<Icone escolha={this.state.user} jogador='Usuario'></Icone>
</View>
</View>
);
};
}
AppRegistry.registerComponent('ServosTeste', () => ServosTeste);