验证中...
Languages: C/C++
Categories: 编程语言基础
Latest update 2019-11-01 09:59
gistfile1.txt
Raw Copy
// text.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "conio.h"
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#define ROW 28
#define COLUMN 40
#define INTERVAL 1500
char screen_model[ROW*COLUMN];
int source = 3;
void init_screen(){
memset(screen_model,NULL,ROW*COLUMN);
char command[32];
sprintf(command,"mode con lines=%d cols=%d",ROW+10,COLUMN+10);
system(command);
system("color 0F");
}
void clear_screen(){
system("cls");
}
void refresh_screen(){
clear_screen();
printf("得分:%d\n",source);
char current;
int row,col;
for(row=0;row<ROW;row++){
if(row==0){
for(col=0;col<COLUMN;col++){
putchar('_');
}
printf("\n");
}
for(col=0;col<COLUMN;col++){
current=screen_model[row * COLUMN + col];
putchar(current);
}
printf("|\n");
if(row==ROW - 1){
for(col=0;col<COLUMN;col++){
putchar('_');
}
putchar('|');
}
}
}
void put_screen_model(int row,int col,char value){
screen_model[ROW * row + col] = value;
}
void print_screen_model(int row,int col,char* value){
int len=strlen(value);
for(int i=0;i < len;i++){
put_screen_model(row,col+i,value[i]);
}
}
void clear_screen_model(int row,int col,int length){
for(int i=0;i<length;i++){
put_screen_model(row,col+i,'\0');
}
}
struct RandChar{
bool init;
int last_row;
int last_col;
int row;
int col;
char value;
};
void RandChar_create(RandChar*randChar){
if(randChar->init!=true){
randChar->init=true;
randChar->last_row=0;
randChar->last_col=0;
randChar->row = 0;
randChar->col = 0;
}
int r,c;
r=rand()%ROW;
c=rand()%COLUMN;
char value = 97+rand()%26;
randChar->last_col=randChar->col;
randChar->last_row=randChar->row;
randChar->row=r;
randChar->col=c;
randChar->value=value;
}
int main (int argc, char* argv[])
{
init_screen();
clock_t tick = clock() + INTERVAL;
int count = 0;
srand(time(NULL));
RandChar randChar;
while(true){
clock_t current = clock();
if(current>tick){
tick=current+INTERVAL;
count++;
RandChar_create(&randChar);
put_screen_model(randChar.last_row,randChar.last_col,'\0');
put_screen_model(randChar.row,randChar.col,randChar.value);
refresh_screen();
}
if(kbhit()){
char key=getch();
if(key == randChar.value){
char*success="+1 Good!";
putchar('\a');
print_screen_model(randChar.row,randChar.col,success);
source++;
refresh_screen();
clear_screen_model(randChar.row,randChar.col,strlen(success));
if(source>13){
clear_screen();
printf("\n");
printf("\n");
printf("\n");
printf("恭喜你!成功入围青铜级别!\n");
break;
}
}else{
char*error="-1 Error!";
print_screen_model(randChar.row,randChar.col,error);
source--;
refresh_screen();
clear_screen_model(randChar.row,randChar.col,strlen(error));
if(source<0){
clear_screen();
printf("\n");
printf("\n");
printf("\n");
printf("很遗憾!挑战失败了!\n");
break;
}
}
}
}
printf("下一关正在开发中,请耐心等待!\n");
return 0;
}

Comment list( 0 )

Sign in for post a comment

Help Search