首页 > 解决方案 > 使用 Java 和处理连接 5 游戏实现

问题描述

我正在开发一款 Connect 5 游戏。这里有一个这样的游戏的例子。即使它不是最好的解决方案,我也会使用 Java 和Processing for GUI。我想创建一个二维数组,其中每个元素为零、一或二。最初,每个元素都是零,然后我将根据它的移动将值更新为 1 或 2。我打算把它分解成几个功能:

boolean gameEnd(int move){
    // returns true is player 1 or player 2 just won
    // else return false
}

void makeMove(int column, int player){
    // checks the first available square in the columns and updates the value with 1 or 2
}

void drawMap(int [][] map){
    // draws a map using processing depending on the current state of map
}

int getMove(){
    // Depending on the coordinate of the click calculate the column where the move was made
}

void setup(){
    // initialize array
    // call draw function
}

我对这个想法有点怀疑,觉得它可以以更好的方式实现。另外,我不确定实现 drawMap 函数的最佳方法。对于如何使用 Java 和 Processing 实现游戏,我将不胜感激。

标签: javaprocessing

解决方案


推荐阅读