我想从对象中提取数据但输出不合适。
我以admin
的形式从ajax帖子传递了 11 的ID。
// Computer Tic tac toe,
// Include the iostream library
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <limits>
// Using the standard namespace
using namespace std;
// declare global variables
char Board [9];
// Declare Functions
void showBoard ( );
bool moveIsValid (int m );
int whoWon();
int playerScore = 0;
int computerScore = 0;
int ties = 0;
void playAgain();
void startGame();
int main ( )
{
void startGame();
{
// Seed the random number
srand (time (NULL) );
// Declare Global Variables
int Whose_Turn = 1; // 1 means players turn and 2 means player 2 turns
int Move; // Store where the players wants to move
int Total_Moves = 0;
int num_players = 0;
// Assigns values to the playing board
Board[0] = '0';
Board[1] = '1';
Board[2] = '2';
Board[3] = '3';
Board[4] = '4';
Board[5] = '5';
Board[6] = '6';
Board[7] = '7';
Board[8] = '8';
cout << "Welcome to Tic Tac Toe.\n Enter 0 to watch computers duke it the fuck out in some good old tic tacers, bro" << endl;
cin >> num_players;
if (num_players == 0) {
while (whoWon ( ) ==0 && Total_Moves < 9) {
do {
// Show the board
showBoard ();
// Tell which player to move
if (Whose_Turn ==1) {
cout << "The First Computer's move is: " << Move << endl;
Move = rand() % 9;
} else {
Move = rand() % 9;
cout << "The Second Computer's move is: " << Move << endl;
}
// Get move
// cout << "Enter the number of spot you'd like to move" << endl;
// cin >> Move;
} while (moveIsValid (Move) != true);
// Add 1 to Total_Moves
Total_Moves++;
// Change whose turn it is
switch (Whose_Turn) {
case (1): {
Board[Move] = 'x';
Whose_Turn = 2;
break;
}
case (2): {
Board[Move] = 'o';
Whose_Turn = 1;
}
}
}
// show the board
showBoard ();
if (whoWon () == 1) {
// show the board
showBoard();
cout << "Computer 1 has won the game!" << endl;
++playerScore;
}
if (whoWon () == 2) {
// Show the board
showBoard();
cout << " The Second Computer has won the game! " << endl;
++computerScore;
}
if (Total_Moves==9 && !whoWon()) {
// Show the board
showBoard();
cout << "It's a tie game!" << endl;
++ties;
}
cout << "Computer 1: " << playerScore << " "<< "Computer 2: " << computerScore << " Ties: "<< ties << endl;
}
system ("Pause");
return 0;
}
}
void showBoard ( ) {
cout << endl;
cout << Board[0] << " | " << Board[1] << " | " << Board[2] << endl;
cout << "--+---+--" << endl;
cout << Board[3] << " | " << Board[4] << " | " << Board[5] << endl;
cout << "--+---+--" << endl;
cout << Board[6] << " | " << Board[7] << " | " << Board[8] << endl;
cout << endl;
}
bool moveIsValid (int m ) {
if (Board[m] != 'x' && Board[m] != 'o') {
return true;
} else {
return false;
}
}
int whoWon ( ) {
if (Board[0] == Board[1] && Board[1] == Board[2]) {
if (Board[0] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[3] == Board[4] && Board[4] == Board[5]) {
if (Board[3] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[6] == Board[7] && Board[7] == Board[8]) {
if (Board[6] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[0] == Board[3] && Board[3] == Board[6]) {
if (Board[0] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[1] == Board[4] && Board[4] == Board[7]) {
if (Board[1] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[2] == Board[5] && Board[5] == Board[8]) {
if (Board[2] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[0] == Board[4] && Board[4] == Board[8]) {
if (Board[0] == 'x') {
return 1;
} else {
return 2;
}
}
if (Board[2] == Board[4] && Board[4] == Board[6]) {
if (Board[2] == 'x') {
return 1;
} else {
return 2;
}
}
return 0;
}
void playAgain()
{
char answer;
int Whose_Turn;
int Total_Moves;
cout << "Would you like to play again? (Y/N)" << endl;
while (cin >> answer)
{
if (answer == 'Y' || answer == 'y')
{
Whose_Turn = 1;
Total_Moves = 0;
cout << endl;
startGame();
}
else if (answer == 'N' || answer == 'n')
{
cout << endl << "Bye!" << endl;
break;
}
else
{
cout << "Please enter a correct input: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string str;
getline(cin, str);
answer = str[0];
}
}
}
如何从对象获取 ID ?
答案 0 :(得分:1)
而不是代码
string a = ID.ToString(); // Getting:`System.Object[]` instead of my id `11`
使用此代码并查看您是否可以获取ID
string a = ID["FileID"];
或
string a = ID["FileID"].ToString();
希望这会对你有所帮助。