Skip to content

Commit

Permalink
feat: brain-even game
Browse files Browse the repository at this point in the history
  • Loading branch information
sazanik committed Nov 7, 2024
1 parent 42189d0 commit e0dfc90
Show file tree
Hide file tree
Showing 13 changed files with 3,046 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Automatic tests

After completing all the steps in the project, automatic tests will become available to you. Tests are run on each commit - once all tasks in the Hexlet interface are completed, make a commit, and the tests will run automatically.

The hexlet-check.yml file is responsible for running these tests - do not delete this file, edit it, or rename the repository.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
install:
npm ci

brain-games:
node bin/brain-games.js

brain-even:
node bin/brain-even.js

publish:
npm publish --dry-run

lint:
npx eslint .

lint-fix:
npx eslint --fix .

link:
npm link
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Hexlet tests and linter status:
[![Actions Status](https://github.com/sazanik/backend-project-lvl1/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/sazanik/backend-project-lvl1/actions)

[![Maintainability](https://api.codeclimate.com/v1/badges/33bad7646aa4a2a98d3e/maintainability)](https://codeclimate.com/github/sazanik/backend-project-lvl1/maintainability)

[![asciicast](https://asciinema.org/a/NHYTq1gdMy5sydEDQ1CL5RzEV.svg)](https://asciinema.org/a/NHYTq1gdMy5sydEDQ1CL5RzEV)
7 changes: 7 additions & 0 deletions bin/brain-even.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

import BrainGames from './brain-games.js';

const brainGames = new BrainGames();

brainGames.evenGame();
38 changes: 38 additions & 0 deletions bin/brain-games.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

import { ATTEMPTS_COUNT } from '../src/constants/index.js';
import { askAndGetName, askNumIsEven, congratulate } from '../src/cli.js';

class BrainGames {
attemptsCount;

name;

constructor(attemptsCount = ATTEMPTS_COUNT) {
this.attemptsCount = attemptsCount;
this.name = askAndGetName();
this.congratulate = congratulate;
}

evenGame() {
console.log('Answer "yes" if the number is even, otherwise answer "no".');

const answersArr = [];

for (let i = 0; i < this.attemptsCount; i += 1) {
const num = Math.round(Math.random() * 1000);

answersArr.push(askNumIsEven(num));
}

if (answersArr.every(Boolean)) {
this.congratulate(this.name);
return;
}

// TODO: need to replace
console.log('You\'ve lost, try again!');
}
}

export default BrainGames;
60 changes: 60 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import globals from 'globals';

import path from 'path';
import { fileURLToPath } from 'url';
import { FlatCompat } from '@eslint/eslintrc';
import pluginJs from '@eslint/js';
import importPlugin from 'eslint-plugin-import';

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: pluginJs.configs.recommended,
});

export default [
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
parserOptions: {
// Eslint doesn't supply ecmaVersion in `parser.js` `context.parserOptions`
// This is required to avoid ecmaVersion < 2015 error or 'import' / 'export' error
ecmaVersion: 'latest',
sourceType: 'module',
},
},
plugins: { import: importPlugin },
rules: {
...importPlugin.configs.recommended.rules,
},
},
...compat.extends('airbnb-base'),
{
rules: {
'max-len': ['error', { code: 120, ignoreComments: true }],
'no-underscore-dangle': [
'error',
{
allow: ['__filename', '__dirname'],
},
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'always',
},
],
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'no-console': 'off',
'import/no-extraneous-dependencies': 'off',
'import/prefer-default-export': 'off',
},
},
];
Loading

0 comments on commit e0dfc90

Please sign in to comment.