#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
using namespace std;
int map[400][200]={};
int x=10,y=10;
int paint,colour;
char key;
void setpos(int x,int y){
COORD pos;
pos.X=y*2,pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a){
if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
}//白蓝绿紫红靛黄
int main(){
cout<<"画图软件1.0-----微光@"<<endl;
Sleep(2000);
cout<<"wasd控制光标 o键落笔 p键提笔"<<endl;
Sleep(1000);
cout<<"1234567控制颜色(白蓝绿紫红靛黄)"<<endl;
Sleep(1000);
cout<<"k键清屏";
Sleep(2000);
system("cls");
system("mode con cols=420 lines=210");
while(true){
if(kbhit()){
key=getch();
if(key=='w'&&x>=2){
x--;
if(paint==1){
color(colour);
cout<<"■";
}
}
if(key=='a'&&y>=2){
y--;
if(paint==1){
color(colour);
cout<<"■";
}
}
if(key=='s'&&x<=398){
x++;
if(paint==1){
color(colour);
cout<<"■";
}
}
if(key=='d'&&y<=198){
y++;
if(paint==1){
color(colour);
cout<<"■";
}
}
if(key=='o'){
paint=1;
}
if(key=='p'){
paint=0;
}
if(key=='1'){
colour=1;
}
if(key=='2'){
colour=2;
}
if(key=='3'){
colour=3;
}
if(key=='4'){
colour=4;
}
if(key=='5'){
colour=5;
}
if(key=='6'){
colour=6;
}
if(key=='7'){
colour=7;
}
if(key=='k'){
system("cls");
}
}
setpos(x-1,y-1);
}
return 0;
}
3 个赞
666会玩
给贴主一个新函数:
void colour_print(int colour,int colour2){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),colour+colour2*16);
}
colour是字体颜色,
colour2是背景颜色,(有点不稳定)
这是函数打印出来的效果:(第一个数是字体颜色参数,第二个数是背景颜色参数)
颜色更多,使用起来更简单。
谢谢!这段时间忙,看不了消息(* ̄3 ̄)╭