Skip to content

Commit

Permalink
Merge pull request #1074 from Ayushkumargit7/fourgame
Browse files Browse the repository at this point in the history
Added Connect Four Game
  • Loading branch information
panwar8279 authored Aug 10, 2023
2 parents a3ea62f + 173a997 commit a5ced1e
Show file tree
Hide file tree
Showing 127 changed files with 43,752 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Games/Connect Four Game/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

*.txt

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions src/Games/Connect Four Game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
9 changes: 9 additions & 0 deletions src/Games/Connect Four Game/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
150 changes: 150 additions & 0 deletions src/Games/Connect Four Game/cypress/e2e/pvpmodec_spec..cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
describe('empty spec', () => {
before(() => {
cy.visit('http://localhost:3000/');
});

it('should open rules page and close page', () => {
cy.findByRole('button', { name: /game rules/i }).click();
cy.url().should('include', '/rules');
cy.findByRole('heading', {
name: /rules/i,
}).should('have.length', 1);
cy.findByTestId(/confirm-button/i).click();
cy.url().should('include', '/');
});
it('should start game in PvpP mode', () => {
cy.findByRole('button', { name: /play vs player/i }).click();
});

it('shouild show correct players turn in beggining', () => {
cy.findByRole('heading', {
name: /player 1's turn/i,
});
});

it('should show corect score at beggining', () => {
cy.findByTestId('player1-score').should('have.text', '0');
cy.findByTestId('player2-score').should('have.text', '0');
});

it('should render red pointer', () => {
cy.findByTestId(/color-red/i).should('exist');
});

it('should bea ble to place counter', () => {
cy.findByTestId('column0').click();
});

it('shouild change players turn and color of pointer after move', () => {
cy.findByRole('heading', {
name: /player 2's turn/i,
});
cy.findByTestId(/color-yellow/i).should('exist');
});

it('should pause game and show winner when player 1 wins', () => {
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
});

it('should show corect score after player 1 winns', () => {
cy.findByTestId('player1-score').should('have.text', '1');
cy.findByTestId('player2-score').should('have.text', '0');
});

it('should render winner component with right text', () => {
cy.findByTestId('winner-name').should('have.text', 'Player 1');
cy.findByTestId('game-status').should('have.text', 'wins');
});

it('should be able play again', () => {
cy.findByRole('button', { name: /play again/i }).click();
});
it("should have yellow pointer and 'player 2 turn' text after starting new game", () => {
cy.findByRole('heading', {
name: /player 2's turn/i,
});
cy.findByTestId(/color-yellow/i).should('exist');
});
it('should pause game and show winner when player 2 wins', () => {
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column0').click();
cy.wait(400);
cy.findByTestId('column1').click();
});

it('should show corect score after player 1 winns', () => {
cy.findByTestId('player1-score').should('have.text', '1');
cy.findByTestId('player2-score').should('have.text', '1');
});

it('should render winner component with right text', () => {
cy.findByTestId('winner-name').should('have.text', 'Player 2');
cy.findByTestId('game-status').should('have.text', 'wins');
});

it('should restart game after reastart button click', () => {
cy.findByRole('button', { name: /play again/i }).click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column1').click();

cy.findAllByTestId(/empty/i).should('have.length', 40);
cy.findByRole('button', { name: /restart/i }).click();
cy.findAllByTestId(/empty/i).should('have.length', 42);
cy.findByTestId(/color-red/i).should('exist');
});

it('should open menu after menu btn click', () => {
cy.findByRole('heading', {
name: /pause/i,
}).should('not.exist');
cy.findByRole('button', { name: /menu/i }).click();
cy.findByRole('heading', {
name: /pause/i,
}).should('exist');
});
it('should continue game after continue bt click', () => {
cy.findByRole('button', { name: /continue game/i }).click();
cy.findByRole('heading', {
name: /pause/i,
}).should('not.exist');
});
it('should restart game after clikcing restart btn in menu ', () => {
cy.wait(400);
cy.findByTestId('column1').click();
cy.wait(400);
cy.findByTestId('column1').click();
cy.findAllByTestId(/empty/i).should('have.length', 40);
cy.findByRole('button', { name: /menu/i }).click();
cy.findByRole('heading', { name: /Restart/i }).click();
cy.findAllByTestId(/empty/i).should('have.length', 42);
});

it('should quit game and retrun to main menu', () => {
cy.findByRole('button', { name: /menu/i }).click();
cy.findByRole('button', { name: /quit game/i }).click();
cy.url().should('include', '/');
});
});
5 changes: 5 additions & 0 deletions src/Games/Connect Four Game/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
38 changes: 38 additions & 0 deletions src/Games/Connect Four Game/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="cypress" />
import '@testing-library/cypress/add-commands';
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions src/Games/Connect Four Game/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
10 changes: 10 additions & 0 deletions src/Games/Connect Four Game/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "@testing-library/cypress"]
},
"include": ["../node_modules/cypress", "./**/*.ts"]
}
Loading

0 comments on commit a5ced1e

Please sign in to comment.