Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include<iostream>

#include<stack>
#include <stdio.h>
#include <string>
using namespace std;
#include<windows.h>
COORD coord;
HANDLE ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
#define x coord.X
#define y coord.Y
#define set SetConsoleCursorPosition(ConsoleHandle,coord)

void build_tower(int n) {
int i = 0;
x = i * n;
y = n - 1;
set;
cout << " ";
for (; i < 3; i++) {
for (int j = 0; j < 2 * n; j++)
cout << "-";
cout << " ";
}
for (int i = 0; i < n; i++) {
x = 1 + i; y = n - i; set;
for (int j = 0; j < n - i; j++)
cout << "一";
}
x = n; y = n + 2; set;
cout << "A";
x = 3 * n + 2; set;
cout << "B";
x = 5 * n + 4; set;
cout << "C";
Sleep(500);
}

void auto_move(int n, int n1, stack<int>& A, stack<int>& B, stack<int>& C, int x1,


int x2, int x3) {
x = x1 - A.top() + 1; y = n1 - A.size() + 1; set;
for (int i = 0; i < A.top(); i++)
cout << " ";
C.push(A.top());
x = x3 - C.top() + 1; y = n1 - C.size() + 1; set;
for (int i = 0; i < C.top(); i++)
cout << "一";
A.pop();
Sleep(500);
}
void auto_play(int n, int n1, stack<int>& A, stack<int>& B, stack<int>& C, int x1,
int x2, int x3) {
if (n == 1)
auto_move(n, n1, A, B, C, x1, x2, x3);
else {
auto_play(n - 1, n1, A, C, B, x1, x3, x2);
auto_move(n, n1, A, B, C, x1, x2, x3);
auto_play(n - 1, n1, B, A, C, x2, x1, x3);
}
}

int main() {
while (true) {
cout << " _______
河" << endl;
cout << " / \\
" << endl;
cout << " / _ _ \\
" << endl;
cout << " | / \\ / \\
| 內" << endl;
cout << " | _______ |
" << endl;
cout << " \\ \\_____/ /
" << endl;
cout << " \\_______/
塔" << endl;
std::cout << endl<<"輸入 enter 開始遊戲";
std::string temp;
std::getline(std::cin, temp);
cout << "請輸入樓層數:";
int n = 0;
cin >> n;
build_tower(n);
stack <int> A, B, C;

for (int i = n; i > 0; i--)


A.push(i);
int x1 = n, x2 = 3 * n + 2, x3 = 5 * n + 4, n1 = n;
auto_play(n, n1, A, B, C, x1, x2, x3);
x = 0; y = n + 3; set;
system("pause");
system("cls");
}
}

You might also like