Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import {
- AppRegistry,
- StyleSheet,
- Text,
- View,
- Button,
- Image
- } from 'react-native';
- class appTesteWork extends Component {
- constructor(props) {
- super(props);
- this.state = { roundUser : '', roundComputer: '', result : '' }
- }
- showSelectedOption(roundUser) {
- // generate random number (0,1,3)
- var randomNumber = Math.floor(Math.random() * 3);
- var roundComputer = '';
- switch (randomNumber) {
- case 0: roundComputer = 'piedra'; break;
- case 1: roundComputer = 'papel'; break;
- case 2: roundComputer = 'tijera'; break;
- }
- var result = '';
- if (roundComputer == 'piedra') {
- if(roundUser == 'piedra') {
- result = 'Empate';
- }
- if (roundUser == 'papel') {
- result = 'Usuario gano';
- }
- if (roundUser == 'tijera') {
- result = 'Computadora gano';
- }
- }
- if (roundComputer == 'papel') {
- if(roundUser == 'piedra') {
- result = 'Computadora gano';
- }
- if (roundUser == 'papel') {
- result = 'Empate';
- }
- if (roundUser == 'tijera') {
- result = 'Usuario gano';
- }
- }
- if (roundComputer == 'tijera') {
- if(roundUser == 'piedra') {
- result = 'Usuario gano';
- }
- if (roundUser == 'papel') {
- result = 'Computadora gano';
- }
- if (roundUser == 'tijera') {
- result = 'Empate';
- }
- }
- this.setState({ roundUser: roundUser,
- roundComputer: roundComputer,
- result: result});
- }
- render() {
- return (
- <View>
- <View>
- <Topo></Topo>
- </View>
- <View style = { styles.panelButtons } >
- <View style = { styles.btnStyle }>
- <Button title="piedra" onPress={ () => { this.showSelectedOption('piedra') } } />
- </View>
- <View style = { styles.btnStyle }>
- <Button title="papel" onPress={ () => { this.showSelectedOption('papel') } } />
- </View>
- <View style = { styles.btnStyle }>
- <Button title="tijera" onPress={ () => { this.showSelectedOption('tijera') } } />
- </View>
- </View>
- <View></View>
- <Text>Escolta do computador: { this.state.roundComputer }</Text>
- <Text>Escolta do usuario: { this.state.roundUser }</Text>
- <Text>Resultado: { this.state.result }</Text>
- </View>
- );
- }
- }
- class Topo extends Component {
- render() {
- return(
- <View>
- <Image
- resizeMode='cover'
- source = { require('./imgs/jokenpo.png') }
- />
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- btnStyle: {
- width: 90
- },
- panelButtons: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- marginTop: 10
- }
- });
- AppRegistry.registerComponent('appTesteWork', () => appTesteWork);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement