Coder Social home page Coder Social logo

ninarow's Introduction

N字棋

一个棋类小游戏,用户可以通过设置N参数生成N字棋游戏(极客大学前端训练营作业)

Quick setup

我把库放到自己的cdn上了,直接<script>引用就好了
(我不会告诉你打开控制台有彩蛋👨🏿‍✈️👨🏿‍✈️👨🏿‍✈️👨🏿‍✈️👨🏿‍✈️👨🏿‍✈️👨🏿‍✈️

<script src="https://cdn.alpaca.run/js/NInARow.js" charset="utf-8"></script>

Demo

在线地址:
https://cdn.alpaca.run/js/ninarow.html

<html>
    <header>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </header>

    <body>

        <h3>N子棋demo</h1>
        <div>ps:当N>=4的时候,不建议开启AI功能,因为ai算法没优化好棋格数量大会递归到奔溃</div><br/>
        <div id="app"></div>
        
        <script src="https://cdn.alpaca.run/js/NInARow.js" charset="utf-8"></script>
        <script>
            // 生成棋盘对象
            const game = new NInARow("app")
            // 设置棋格数量
            game.N = 5
            // 设置棋格大小
            game.cellSize = 150
            // 设置AI
            game.AI = false
            // 渲染棋盘并开始游戏!!!
            game.start()
        </script>

    </body>
</html>

API

Object

首先必须得new一个NInARow对象,如下

const game = new NInARow('app');

Getters and Setters

Example setters:

game.N = 5; // 设置棋格数量(5*5)
game.cellSize = 150; // // 设置棋格大小
Property Getter Setter Description
N - 设置棋格数量
cellSize - 设置棋格大小
AI - 设置AI开关状态

Methods

Example method use:

game.start(); // 渲染棋盘并开始游戏!!!
Method Parameters Description
start() - 渲染棋盘并开始游戏!!!

Todo List

☑棋盘的绘制和下棋基本逻辑

☑增加胜利检测

☑增加AI

⬜优化AI算法(棋格数量多的时候不至于递归到奔溃)

⬜增加获胜条件设置(例如可在5*5的棋盘里使用三子棋的规则)

⬜不限于棋盘为正方形(例如可以设置5x8的棋盘)

ninarow's People

Contributors

alpacabi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.