私は現在、Node.jsに組み込まれたtic tac toeマルチプレイヤーゲームに取り組んでいます。現在の設定でチック・タック・トゥ・ウィンの状態を実現するにはどうしたらいいですか?
私の主な問題は、勝利条件をチェックする方法を考え出すことです。私はそれが配列を使用して、どのように動作するかを知っているが、私は私のゲームをこのようにプログラムしたい....
var mongoose = require('mongoose');
var gameSchema = new mongoose.Schema({
player1: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
player2: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
// This would be an array of selected spaces for 'x' or 'o'
placements: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Placement"
}],
// This would be the username of the current player.
currentPlayer: String
});
module.export = mongoose.model('Game', gameSchema);
配置スキーマ:
var mongoose = require('mongoose');
var placementSchema = new mongoose.Schema({
marker: String, //x or o
selectedSpace: Number // 0-8
});
module.export = mongoose.model('Placement', placementSchema);
私はモデルオブジェクトの配列として配置を使用します。 ...
このように勝利条件を確認するにはどうすればよいでしょうか?
また、このモデルの設定方法を再考する必要がありますか?
チック・タック・トゥ・グリッドなしで勝利条件をどのように確認できるのか分かりません...ああ、待ってください、それは「プレースメント」です。 –
ありがとうございます。 –
@ジャロマンダX正しい。これは、各インデックスが選択されたスペースとプレーヤーマーカーを持つプレースメントであるオブジェクト配列です。 –