Be A React Dev

Game View - Computer Rock Paper Scissors

29-Jun-2023


Amazon Prime

typescript plus react

What you will be building

Please check this link: Rock Paper Scissors Game

This app uses components from Chakra UI . You should check it out.

Displaying the Computer

Consider the following code:

view/computer.tsx

import React from 'react';
//  chakra-ui
import { Box, Heading, Text, VStack } from '@chakra-ui/react';
//  interfaces
import { State } from '../state/interfaces';

interface Props {
  state: State;
}

const DisplayComputer = (props: Props) => {
  const { state } = props;

  return (
    <>
      <Box
        display="flex"
        borderWidth="1px"
        borderRadius="lg"
        justifyContent="center"
        minH="120px"
        p={4}
      >
        <>
          <VStack>
            <Heading as="h2" fontSize="125%" textAlign="center">
              Computer’s
              <br />
              Choice:
            </Heading>
            <Text>{state.decision.computer}</Text>
          </VStack>
        </>
      </Box>
    </>
  );
};

export default DisplayComputer;

What This Seems Simple

Well, it is. The computer decision is handled behind the scenes in the actions. Which I will cover in more detail later.

All that needs to happen in this file is to display the results of the “computer’s” descision. If you want, let’s pretend we built a powerful AI. Ha.

Basically, all that is going on is that we are displaying a Box with a border, and within that a Heading that does not change, and Text which either contains an empty string or a non-empty string.

Ta Da! Job Done.


Get Cool Swag

If you are finding this content useful (or maybe you are just a nice person or maybe you just like my merch) I would be greatful if you headed over to my shop and make a purchase or two. All proceeds will go towards making more courses.

If there’s merch missing that you would like, let me know (click this: Make Something For Me ) and I’ll try to make it for you.

laal T-Shirt

laal T-Shirt

You can buy this product or you can check out my shop of products.


About

The Author Guy

Find Me

Rob Welan <rob.welan@beareact.dev>FacebookKo-FiLinkedInMediumPatreonRSS FeedStack OverflowX

Tech In Use

Be A React Dev

© 2024 Be A React Dev. All rights reserved.