2013-11-05 98 views
-3
include <cstdlib> 
#include <iostream> 
#include <ctime> 

#include "sweeper.h" 

using namespace std; 

int main(int argc, char *argv[]) 
{ 
int mineGrid[MAX_GRID_SIZE][MAX_GRID_SIZE]; 
int n = 8; 

//seed the random number generator 
srand(time(NULL)); 


nukeGrid(mineGrid); 
printGrid(mineGrid, n); 

cout << endl << endl; 

placeBombs(mineGrid, n, 8); 
printGrid(mineGrid, n); 

cout << endl << endl; 

printBombCount(mineGrid, n); 

int row, col; 

cout << "enter a move\n"; 
cin >> row >> col; 

if (mineGrid[row][col] == MINE){ 
    cout << "game over\n"; 
}else{ 
    takeMove(mineGrid, n, row, col); 
} 
printGrid(mineGrid, n); 
system("PAUSE"); 
return EXIT_SUCCESS; 
} 

nukeGrid - 用空格(-1s)取代2D網格掃雷算法UI問題

printGrid - 輸出電網

placeBombs - 隨機將放置炸彈在網格

printBombCount - 說一個廣場周圍有多少枚炸彈

這些是爲了看看網格中發生了什麼。我現在的目標是擁有一個用戶剛剛看到的界面,並且可以輸入一個點,但不知道那裏有什麼(如實際的掃雷遊戲)。我不知道如何實現這一點,我試圖將網格複製到另一個網格,然後在那裏修改網格,但它不起作用,所以現在我非常困惑。提前致謝!

+0

不要發佈重複的問題。你期望人們會回答什麼?爲你創建一個界面?我不信。有很多關於用C++在線創建GUI的信息。在這裏轉儲並不容易 - 您需要閱讀一些教程。現在你的帖子中沒有問題。 – sashkello

+0

我的其他帖子被擱置了,所以我上傳了這個。我不需要GUI,我只需要了解在終端窗口中創建一個GUI的邏輯。 – user2950697

+1

「但它沒有工作」不是一個具體的問題。 (從技術上講,這甚至不是問題。) –

回答

0

要只打印網格,像這樣的工作:

void printGrid(int mineGrid[MAX_GRID_SIZE][MAX_GRID_SIZE], int n, int x, y) 
{ 
    cout << "Grid is as follows:" << endl; 
    for (int row=0; row<n; row++) 
    { 
     int dy = row-y; 
     if (dy < 0) dy = -dy; // dy is the distance between current row and specified row 

     for (int col=0; col<n; col++) 
     { 
     int dx = col-x; 
     if (dx < 0) dx = -dx; // dx is the distance between current column and specified column 

     if ((dx < 2) && (dy < 2)) 
     { 
      // this item is adjacent to the specific point, so don't show its contents 
      cout << "?"; 
     } 
     else 
     { 
      cout << mineGrid[row][col]; 
     } 
     cout << " "; 
     } 
     cout << endl; 
    } 
} 
+0

我有一個printGrid函數,我需要爲用戶打印一個不顯示所有值的網格。我不知道如何創建這個,也讓用戶能夠輸入可以與原文進行通信的內容。 – user2950697

+0

你不想顯示哪些值? –

+0

圍繞某個點的炸彈。 – user2950697