Giter Site home page Giter Site logo

gobanggame's Introduction

有暇,做了个五子棋大战的小游戏送给各位小伙伴!

用到的知识点有:

1.JavaWeb基础知识(懂jsp,servlet足够)
2.JavaScript和jQuery基本用法
3.了解WebSocket的基本用法

OK,关于第三点,如果小伙伴们之前没有接触过WebSocket,或者对WebSocket并不太熟悉,可以先阅读这三篇文章学习下:

1.WebSocket刨根问底(一)

2.WebSocket刨根问底(二)

3.WebSocket刨根问底(三)之群聊

游戏效果图

1.登录效果

这里写图片描述

2.游戏进行时效果

这里写图片描述

3.房间满员后,再进入,会有错误提示,如下:

这里写图片描述

核心思路

1.该游戏本质上就是两个人聊天,只不过聊天的内容为棋盘上的坐标
2.用户点击棋盘,根据点击的位置,算出离点击位置最近的一个字的坐标作为此次点击事件的坐标,将之传递给WebSocket服务端
3.当有两个人已经连接上服务端的时候,此时如果有第三个人连接服务端,则服务端返回一条消息告诉该客户端房间人已满,并且让该客户端主动关闭连接
4.每下一子,都去判断一下该子的上\下,左\右,左上\右下,左下\右上四个方向上同类型的子是否已满5个,满5个表示此次落子的用户赢
5.游戏进行过程中,有一方关闭浏览器,会提示另一方某某人已经下线

源码地址:https://github.com/lenve/GobangGame

博客地址:WebSocket刨根问底(四)之五子棋大战江湖

欢迎小伙伴们fork,star。

更多JavaEE资料请关注公众号:

这里写图片描述

以上。

gobanggame's People

Contributors

qwe12369 avatar

Watchers

James Cloos 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.