0
已解决
王梓澳
中级光能
中级光能
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int x,y,lx,ly;
void color(int a) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a)
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)
{
COORD pos={i, j};
SetPos(pos);
}
void control() {//控制函数
lx=x,ly=y;
if (KEY_DOWN('W')&&x-1>=0) x--;
if (KEY_DOWN('S')&&x+1<16) x++;
if (KEY_DOWN('A')&&y-2>=0) y-=2;
if (KEY_DOWN('D')&&y+2<16) y+=2;
}
string a[17];
int main () {
for (int i=1;i<=16;i++) {
for (int j=1;j<=16;j++) {
cout<<"+ ";
a[i]+='+';
}
cout<<endl;
}
x=0,y=0,lx=0,ly=0;
while (true) {
control();
SetPos(ly,lx);color(7);
cout<<"+";
SetPos(y,x);color(14);
cout<<"+";color(7);
Sleep(100);
}
return 0;
}
/*VK_LEFT 左箭头键 0x25
VK_UP 上箭头键 0x26
VK_RIGHT 右箭头键 0x27
VK_DOWN 下箭头键
*/
王梓澳在2021-12-02 11:41:22追加了内容
调试代码2保存:
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int x,y,lx,ly;
bool Maker=false;
bool Player1[17][17],Player2[17][17];
void color(int a) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a)
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)
{
COORD pos={i, j};
SetPos(pos);
}
void control() {//控制函数
lx=x,ly=y;
if (KEY_DOWN('W')&&x-1>=0&&!Player1[x-1][(y+1)/2]&&!Pla(y+1)er2[x-1][(y+1)/2]) x--;
if (KEY_DOWN('S')&&x+1<16&&!Pla(y+1)er1[x+1][(y+1)/2]&&!Pla(y+1)er2[x+1][(y+1)/2]) x++;
if (KEY_DOWN('A')&&y-2>=0&&!Player1[x][(y+1)/2]&&!Player2[x][(y+1)-2]) y-=2;
if (KEY_DOWN('D')&&y+2<16&&!Player1[x][(y+1)/2]&&!Player2[x][(y+1)+2]) y+=2;
}
void sure(int x,int y) {
if (KEY_DOWN(VK_SPACE)) {
if (!Maker) {color()}
}
}
string a[17];
int main () {
for (int i=1;i<=16;i++) {
for (int j=1;j<=16;j++) {
cout<<"+ ";
a[i]+='+';
}
cout<<endl;
}
x=0,y=0,lx=0,ly=0;
while (true) {
control();
SetPos(ly,lx);color(7);
cout<<"+";
SetPos(y,x);color(14);
cout<<"+";color(7);
color(112);
Sleep(100);
}
return 0;
}
/*VK_LEFT 左箭头键 0x25
VK_UP 上箭头键 0x26
VK_RIGHT 右箭头键 0x27
VK_DOWN 下箭头键
*/
王梓澳在2021-12-02 17:27:33追加了内容
半成品2:
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int x,y,lx,ly;
bool Maker=false;
bool Player1[17][17],Player2[17][17];
void color(int a) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a)
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)
{
COORD pos={i, j};
SetPos(pos);
}
void control() {//控制函数
lx=x,ly=y;
if (KEY_DOWN('W')&&x-1>=0) x--;
if (KEY_DOWN('S')&&x+1<16) x++;
if (KEY_DOWN('A')&&y-2>=0) y-=2;
if (KEY_DOWN('D')&&y+2<32) y+=2;
}
void sure(int x,int y) {
if (KEY_DOWN(VK_SPACE)) {
SetPos(17,17);cout<<" ";
if (Player1[x][(y+1)/2]||Player2[x][(y+1)/2]) {
SetPos(17,17);
// cout<<"这里已经下过了";
return ;
}
if (!Maker&&!Player1[x][(y+1)/2]) {
Player1[x][(y+1)/2]=true;
SetPos(y,x);color(10);
cout<<"0";
Maker=!Maker;
return ;
}
if (Maker&&!Player2[x][(y+1)/2]) {
Player2[x][(y+1)/2]=true;
SetPos(y,x);color(12);
cout<<"0";
Maker=!Maker;
return ;
}
}
}
bool dfs(int x,int y,int dir,int cnt) {
if (cnt>=5) return true;
}
string a[17];
int main () {
for (int i=1;i<=16;i++) {
for (int j=1;j<=16;j++) {
cout<<"+ ";
a[i]+='+';
}
cout<<endl;
}
x=0,y=0,lx=0,ly=0;
while (true) {
color(122);
control();
SetPos(ly,lx);color(7);
cout<<"+";
sure(x,y);
for (int i=0;i<16;i++)
for (int j=0;j<16;j++) {
if (Player1[i][j]) {
SetPos(j*2,i);color(10);
cout<<"0";
}
if (Player2[i][j]) {
SetPos(j*2,i);color(12);
cout<<"0";
}
}
SetPos(y,x);color(14);
if (Player1[x][(y+1)/2]) color(10);
if (Player2[x][(y+1)/2]) color(12);
cout<<"^";color(7);
Sleep(100);
}
return 0;
}
/*VK_LEFT 左箭头键 0x25
VK_UP 上箭头键 0x26
VK_RIGHT 右箭头键 0x27
VK_DOWN 下箭头键
*/