这是我初学C++时的黑历史渣作
当时貌似只学到定义变量,数组随机数啥的我都是问老师
根本没用到啥结构体啥指针
不喜勿喷呀
Memory
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
cout << "Memory\nASDW移动,Q选择" ;
srand((unsigned)time(0));
int t[4][6]={0},m[4][6]={0},x,y,xx=0,yy=0,xxx=1,yyy=0,state=0,n1,n2,n1x,n1y,n2x,n2y,time,step=0,ti;
//create
char key;
for(int i = 1;i < 13;i++){
for(int j = 1;j < 3;j++){
x = int(rand())%6;
y = int(rand())%4;
while(t[y][x] != 0){
x = int(rand())%6;
y = int(rand())%4;
}
t[y][x] = i;
}
}
//playing
while(ti<12)
{
//draw
if(m[yy][xx]==0){m[yy][xx] = 99;}
if(m[yyy][xxx]==99){m[yyy][xxx] = 0;}
for(int j = 0 ;j < 4;j++){
cout<<endl;
for(int i = 0 ;i < 6;i++){
cout<<m[j][i]<<" ";
}
}
cout<<endl;
//key
cin >> key;
if(key=='w'){xxx = xx;yyy = yy;yy--;}
if(key=='s'){xxx = xx;yyy = yy;yy++;}
if(key=='a'){xxx = xx;yyy = yy;xx--;}
if(key=='d'){xxx = xx;yyy = yy;xx++;}
if(xx>5)xx=0;
if(xx<0)xx=5;
if(yy>3)yy=0;
if(yy<0)yy=3;
if(key=='q' and state == 1){
m[yy][xx] = t[yy][xx];
n2 = t[yy][xx];
n2x = xx;
n2y = yy;
state = 2;
step++;
}
if(key=='q' and state == 0){
m[yy][xx] = t[yy][xx];
n1 = t[yy][xx];
n1x = xx;
n1y = yy;
state = 1;
step++;
}
//test
if(state == 2){
if(n1 == n2){
state = 0;
ti++;
}
else{
system("cls");
for(int j = 0 ;j < 4;j++){
cout<<endl;
for(int i = 0 ;i < 6;i++){
cout<<t[j][i]<<" ";
}
}
//time frozen
for(int time = 0;time <= 100000000;time++){}
m[n1y][n1x] = 0;
m[n2y][n2x] = 0;
state = 0;
}
}
//clear
system("cls");
}
//end
cout<<"You Win"<<endl;
cout<<"Step: "<<step;
return 0;
}
五子棋
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
cout << "Chess\nASDW移动,J选择" ;
int m[20][20]={0},x,y,xx=0,yy=0,xxx=1,yyy=0,n=1,tx=0,ty=0,t=0,tt=0;
char key;
//playing
while(tt!=1)
{
//draw
if(m[yy][xx]==0){m[yy][xx] = n;}
if(m[yyy][xxx]==1 or m[yyy][xxx]==2){m[yyy][xxx] = 0;}
for(int j = 0 ;j < 20;j++){
cout<<endl;
for(int i = 0 ;i < 20;i++){
cout<<m[j][i]<<" ";
}
}
cout<<endl;
//key
cin >> key;
if(key=='w'){xxx = xx;yyy = yy;yy--;}
if(key=='s'){xxx = xx;yyy = yy;yy++;}
if(key=='a'){xxx = xx;yyy = yy;xx--;}
if(key=='d'){xxx = xx;yyy = yy;xx++;}
if(xx>19)xx=0;
if(xx<0)xx=19;
if(yy>19)yy=0;
if(yy<0)yy=19;
//change
if(key=='j'){
m[yy][xx] = 10+n;
ty=0;tx=0;t=0;tt=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty++;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;tx++;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty--;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;tx--;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty++,tx++;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty++;tx--;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty--;tx--;}
if(t==5)tt=1;
ty=0;tx=0;t=0;
while(m[yy+ty][xx+tx]==10+n){t++;ty--;tx++;}
if(t==5)tt=1;
if(n==1)n=2;
else{n=1;}
}
//clear
system("cls");
}
//end
if(n==1)n=2;
else{n=1;}
cout << "Player" << n << " Wins!";
return 0;
}