Advertisement
csojunior1996

Image Resize

Nov 9th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Button,
  8. Image
  9. } from 'react-native';
  10. class appTesteWork extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = { roundUser : '', roundComputer: '', result : '' }
  14. }
  15. showSelectedOption(roundUser) {
  16. // generate random number (0,1,3)
  17. var randomNumber = Math.floor(Math.random() * 3);
  18. var roundComputer = '';
  19. switch (randomNumber) {
  20. case 0: roundComputer = 'piedra'; break;
  21. case 1: roundComputer = 'papel'; break;
  22. case 2: roundComputer = 'tijera'; break;
  23. }
  24. var result = '';
  25. if (roundComputer == 'piedra') {
  26. if(roundUser == 'piedra') {
  27. result = 'Empate';
  28. }
  29. if (roundUser == 'papel') {
  30. result = 'Usuario gano';
  31. }
  32. if (roundUser == 'tijera') {
  33. result = 'Computadora gano';
  34. }
  35. }
  36. if (roundComputer == 'papel') {
  37. if(roundUser == 'piedra') {
  38. result = 'Computadora gano';
  39. }
  40. if (roundUser == 'papel') {
  41. result = 'Empate';
  42. }
  43. if (roundUser == 'tijera') {
  44. result = 'Usuario gano';
  45. }
  46. }
  47. if (roundComputer == 'tijera') {
  48. if(roundUser == 'piedra') {
  49. result = 'Usuario gano';
  50. }
  51. if (roundUser == 'papel') {
  52. result = 'Computadora gano';
  53. }
  54. if (roundUser == 'tijera') {
  55. result = 'Empate';
  56. }
  57. }
  58. this.setState({ roundUser: roundUser,
  59. roundComputer: roundComputer,
  60. result: result});
  61. }
  62. render() {
  63. return (
  64. <View>
  65. <View>
  66. <Topo></Topo>
  67. </View>
  68. <View style = { styles.panelButtons } >
  69. <View style = { styles.btnStyle }>
  70. <Button title="piedra" onPress={ () => { this.showSelectedOption('piedra') } } />
  71. </View>
  72. <View style = { styles.btnStyle }>
  73. <Button title="papel" onPress={ () => { this.showSelectedOption('papel') } } />
  74. </View>
  75. <View style = { styles.btnStyle }>
  76. <Button title="tijera" onPress={ () => { this.showSelectedOption('tijera') } } />
  77. </View>
  78. </View>
  79. <View></View>
  80. <Text>Escolta do computador: { this.state.roundComputer }</Text>
  81. <Text>Escolta do usuario: { this.state.roundUser }</Text>
  82. <Text>Resultado: { this.state.result }</Text>
  83. </View>
  84. );
  85. }
  86. }
  87. class Topo extends Component {
  88. render() {
  89. return(
  90. <View>
  91. <Image
  92. resizeMode='cover'
  93. source = { require('./imgs/jokenpo.png') }
  94. />
  95. </View>
  96. );
  97. }
  98. }
  99. const styles = StyleSheet.create({
  100. btnStyle: {
  101. width: 90
  102. },
  103. panelButtons: {
  104. flexDirection: 'row',
  105. justifyContent: 'space-between',
  106. marginTop: 10
  107. }
  108. });
  109.  
  110. AppRegistry.registerComponent('appTesteWork', () => appTesteWork);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement