Copy and Paste  -   An Application to Copy/Paste Text  

 
S.No 5356 Name new Date/Time 03-Nov-2022 10:12:56 AM

Copy text from below
import React, { useState } from 'react';
import {
  Text,
  View,
  Image,
  StyleSheet,
  TouchableOpacity,
} from 'react-native';

const CHOICES = [
  {
    name: 'WOOD',
    uri: 'https://i.ibb.co/TRjfP6w/istockphoto-106548715-612x612.jpg'
  },
  {
    name: 'WATER',
    uri: 'https://i.ibb.co/6HSds21/pexels-matthias-cooper-1147124.jpg'
  },
  {
    name: 'FIRE',
    uri: 'https://i.ibb.co/LdD1McC/download.jpg'
  },
];

const randomComputerChoice = () => CHOICES[Math.floor(Math.random() * CHOICES.length)];

const getRoundOutcome = (userChoice) => {
  const computerChoice = randomComputerChoice().name;
  let result;

  if (userChoice === 'WOOD') {
    result = computerChoice === 'WATER' ? 'Victory!' : 'Defeat!';
  };
  if (userChoice === 'WATER') {
    result = computerChoice === 'FIRE' ? 'Victory!' : 'Defeat!';
  };
  if (userChoice === 'FIRE') {
    result = computerChoice === 'FIRE' ? 'Victory!' : 'Defeat!';
  };

  if (userChoice === computerChoice) result = 'Tie game!';
  return [result, computerChoice];
};

const Button = (props) => (
  <TouchableOpacity
    style={styles.buttonStyle}
    onPress={() => props.onPress(props.name)}
  >
    <Text style={styles.buttonText}>
      {props.name.charAt(0).toUpperCase() + props.name.slice(1)}
    </Text>
  </TouchableOpacity>
);

const ChoiceCard = ({ player, choice: { uri, name }}) => {
  const title = name && name.charAt(0).toUpperCase() + name.slice(1);

  return (
    <View style={styles.choiceContainer}>
      <Text style={styles.choiceDescription}>
        {player}
      </Text>
      <Image
        source={{ uri }}
        resizeMode="contain"
        style={styles.choiceImage}
      />
      <Text style={styles.choiceCardTitle}>
        {title}
      </Text>
    </View>
  );
};

export default function App() {
  const [gamePrompt, setGamePrompt] = useState('Chose your weapon!');
  const [userChoice, setUserChoice] = useState({});
  const [computerChoice, setComputerChoice] = useState({});

  const onPress = (playerChoice) => {
    const [result, compChoice] = getRoundOutcome(playerChoice);
   
    const newUserChoice = CHOICES.find(choice => choice.name === playerChoice);
    const newComputerChoice = CHOICES.find(choice => choice.name === compChoice);

    setGamePrompt(result);
    setUserChoice(newUserChoice);
    setComputerChoice(newComputerChoice);
  };

  const getResultColor = () => {
    if (gamePrompt === 'Victory!') return 'green';
    if (gamePrompt === 'Defeat!') return 'red';
    return null;
  };

  return (
    <View style={styles.container}>
      <Text style={{ fontSize: 35, color: getResultColor() }}>
        {gamePrompt}
      </Text>
      <View style={styles.choicesContainer}>
        <ChoiceCard
          player="Player"
          choice={userChoice}
        />
        <Text style={{ color: 'green' }}>vs</Text>
        <ChoiceCard
          player="Computer"
          choice={computerChoice}
        />
      </View>
      {CHOICES.map(choice => {
        return (
          <Button
            key={choice.name}
            name={choice.name}
            onPress={onPress}
          />
        )
      })}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#e9ebee'
  },
  buttonContainer: {
    alignItems: 'center',
    justifyContent: 'center',
  },
  buttonStyle: {
    width: 200,
    margin: 10,
    height: 50,
    borderRadius: 10,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'blue',
  },
  buttonText: {
    fontSize: 25,
    color: 'white',
    fontWeight: 'bold',
  },
  choicesContainer: {
    margin: 10,
    borderWidth: 2,
    paddingTop: 100,
    shadowRadius: 5,
    paddingBottom: 100,
    borderColor: 'grey',
    shadowOpacity: 0.90,
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: 'white',
    justifyContent: 'space-around',
    shadowColor: 'rgba(0,0,0,0.2)',
    shadowOffset: { height: 5, width: 5 },
  },
  choiceContainer: {
    flex: 1,
    alignItems: 'center',
  },
  choiceDescription: {
&am




comments powered by Disqus
NEW ENTRIES
S.No Name Entry Time/Date
5549 MET Feb8 07-Feb-2023 04:25:44 PM
5548 Test12 Feb8 07-Feb-2023 04:24:15 PM
5547 Test8 Feb8 07-Feb-2023 04:21:12 PM
5546 Test11 Feb8 07-Feb-2023 04:20:25 PM
5545 Test5 Feb8 07-Feb-2023 04:17:39 PM
5544 Test4 Feb8 07-Feb-2023 04:16:37 PM
5543 Test3 Feb8 07-Feb-2023 04:13:50 PM
5542 Test 2 Feb8 07-Feb-2023 04:11:23 PM
5541 Test 1 Feb8 07-Feb-2023 04:07:22 PM
5540 rstf 07-Feb-2023 04:06:59 PM
5539 anf 07-Feb-2023 04:06:42 PM
5538 pplgc 07-Feb-2023 04:06:30 PM
5537 nfwa 07-Feb-2023 04:06:17 PM
5536 asdf 07-Feb-2023 04:05:56 PM
5535 asdf 07-Feb-2023 04:05:46 PM
5534 paf 07-Feb-2023 04:05:35 PM
5533 npshf 07-Feb-2023 04:05:24 PM
5532 asdf 07-Feb-2023 04:05:09 PM
5531 HOT SEXY 07-Feb-2023 08:35:42 AM
5530 . 06-Feb-2023 08:19:39 PM
5529 Korea Sexy 02-Feb-2023 09:16:33 AM
5528 MET Feb1 31-Jan-2023 08:35:06 PM
5527 Test12 Feb1 31-Jan-2023 08:30:52 PM
5526 Test11 Feb1 31-Jan-2023 08:13:39 PM
5525 Test 8 Feb1 31-Jan-2023 08:06:15 PM
5524 Test5 Feb1 31-Jan-2023 07:58:32 PM
5523 Test 4 Feb1 31-Jan-2023 07:55:20 PM
5522 Test 3 feb1 31-Jan-2023 07:51:14 PM
5521 Test 2 Feb1 31-Jan-2023 07:47:23 PM
5520 Test 1 feb1 31-Jan-2023 07:46:16 PM

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 [Next] [Last]
 
web counter
web counter


To report any error messages or bugs, or other issues, please send email at: info@pakproject.com