📄 fivestone.c
字号:
#include<stdio.h>
#include "keyboard.h"//可能有问题
#include "screen.h"
#include "MyComputer.h"
#include "readfile.h"
#include "MyCharLib.h"
#define MAX_ROW_LINE 15
#define EMPTY 0
#define BLACK 1
#define WHITE 2
#define CASE_WIDTH 27//格子的宽度
#define COLOR_YELLOW 23333 //棋盘的底色
#define COLOR_BLACK 0 //黑色棋子的值
#define COLOR_WHITE 65535//白色棋子的值
#define COLOR_RED 32
#define RADIUS 13 //棋子的半径
#define HEIGHT 6
#define UP '8' //键盘按下8
#define DOWN '2' //键盘按下2
#define LEFT '4' //键盘按下4
#define RIGHT '6' //键盘按下6
#define KEYPRESS '5' //键盘按下5
#define HELP '1'
#define BACK '3'
#define START '7'
#define HEIGTH 480
#define WIDTH 640
#define CAHRROW 30
#define CAHRLINE 20
int point_x = 0; //选择框的坐标
int point_y = 0; //选择框的坐标
int old_point_x = 0; //选择框的坐标
int old_point_y = 0; //选择框的坐标
int count = 0; //游戏机进行的步数
int people = 0;
int computer = 0;
int winner = 0;
int chess[MAX_ROW_LINE][MAX_ROW_LINE];
///////////////////////////////////////////////////////////////////////////////////////
void Init(void);
void KbdOpen(void);
void KbdClose(void);
char GetKey(void);
void DrewHelp(void);
void DrewPicture(char *filename);
void DrawChessboard(void);
void MyPrintf(int point_x,int point_y,int color,char *buffer ,int length);
//void DrawSeletor(int now_point_y ,int now_point_x ,int color);
/////////////////////////////////////////////////////////////////////////////////////////
void MyPrintf(int point_x,int point_y,int color,char *buffer ,int length)
{
int mychar[CAHRROW][CAHRLINE]={0};
int i = 0;
for(i = 0;i<length;i++,buffer++)
{
getChar(*buffer,mychar);
DrawChar((point_x+i)*CAHRLINE,point_y,mychar,color);
}
}
///////////////////////////////////////////////////////////////////////////////////////////
void DrawChessboard(void)
{
int Chessboard=0;
DrawRectangle(0,0,640,480,COLOR_BLACK);//画棋盘的底色
DrawRectangle(30,30,450,450,COLOR_YELLOW);//画棋盘的底色
for(Chessboard=0;Chessboard<MAX_ROW_LINE;Chessboard++)
{
//画棋盘上的格子
DrawRectangle(50+Chessboard*CASE_WIDTH,50,50+Chessboard*CASE_WIDTH+3,430,COLOR_BLACK);
DrawRectangle(50,50+Chessboard*CASE_WIDTH,430,50+Chessboard*CASE_WIDTH+3,COLOR_BLACK);
}
}
//////////////////////////////////////////////////////////////////////////////////
void DrawChess(void)
{
int row = 0;
int line = 0;
for(row=0;row<MAX_ROW_LINE;row++)
{
for(line=0;line<MAX_ROW_LINE;line++)
{
//画棋子
if(chess[row][line]==BLACK )
DrawRound(row*CASE_WIDTH+50,line*CASE_WIDTH+50,RADIUS, COLOR_BLACK);
if(chess[row][line]==WHITE )
DrawRound(row*CASE_WIDTH+50,line*CASE_WIDTH+50,RADIUS,COLOR_WHITE);
}
}
}
////////////////////////////////////////////////////////////////////////////////
void DrawSeletor(int now_point_x ,int now_point_y ,int color)
{
DrawRectangle(50+now_point_x*CASE_WIDTH-RADIUS-2,
50+now_point_y*CASE_WIDTH-RADIUS-2,
50+now_point_x*CASE_WIDTH-RADIUS,
50+now_point_y*CASE_WIDTH-RADIUS-2+HEIGHT,
color );//|
DrawRectangle(50+now_point_x*CASE_WIDTH-RADIUS-2,
50+now_point_y*CASE_WIDTH-RADIUS-2,
50+now_point_x*CASE_WIDTH-RADIUS+HEIGHT,
50+now_point_y*CASE_WIDTH-RADIUS,
color );//-
DrawRectangle(50+now_point_x*CASE_WIDTH+RADIUS+2,
50+now_point_y*CASE_WIDTH-RADIUS-2,
50+now_point_x*CASE_WIDTH+RADIUS-HEIGHT,
50+now_point_y*CASE_WIDTH-RADIUS,
color );// -
DrawRectangle(50+now_point_x*CASE_WIDTH+RADIUS+2,
50+now_point_y*CASE_WIDTH-RADIUS-2,
50+now_point_x*CASE_WIDTH+RADIUS,
50+now_point_y*CASE_WIDTH-RADIUS+HEIGHT,
color );// |
DrawRectangle(50+now_point_x*CASE_WIDTH-RADIUS-2,
50+now_point_y*CASE_WIDTH+RADIUS+2,
50+now_point_x*CASE_WIDTH-RADIUS,
50+now_point_y*CASE_WIDTH+RADIUS-HEIGHT,
color );//||
DrawRectangle(50+now_point_x*CASE_WIDTH-RADIUS-2,
50+now_point_y*CASE_WIDTH+RADIUS+2,
50+now_point_x*CASE_WIDTH-RADIUS+HEIGHT,
50+now_point_y*CASE_WIDTH+RADIUS,
color );//--
DrawRectangle(50+now_point_x*CASE_WIDTH+RADIUS+2,
50+now_point_y*CASE_WIDTH+RADIUS+2,
50+now_point_x*CASE_WIDTH+RADIUS-HEIGHT,
50+now_point_y*CASE_WIDTH+RADIUS,
color );// --
DrawRectangle(50+now_point_x*CASE_WIDTH+RADIUS+2,
50+now_point_y*CASE_WIDTH+RADIUS+2,
50+now_point_x*CASE_WIDTH+RADIUS,
50+now_point_y*CASE_WIDTH+RADIUS-HEIGHT,
color);// ||
}
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void Init(void)
{
int row = 0;
int line = 0;
for(row=0;row<MAX_ROW_LINE;row++)
for(line=0;line<MAX_ROW_LINE;line++)
{
chess[row][line] = EMPTY;
}
point_x = 7;
point_y = 7;
old_point_x = 7; //选择框的坐标
old_point_y =7;
count = 255;
people = 1;
computer = 0;
winner = 0;
}
/////////////////////////////////////////////////////////////////////////////////
void KbdOpen(void)
{
if (KBD_Open() < 0)
printf("Can't open keyboard!\n");
}
void KbdClose(void)
{
KBD_Close();
}
char GetKey(void)
{
int keydown=0;
char key=0;
char temp=0;
unsigned int modifiers;
unsigned short scancode;
keydown=KBD_Read(&key, &modifiers, &scancode);
if(keydown==1)
return key;
else
return temp;
}
void DealWithKey(char key)
{
if(key == UP)
point_y --;
if(key == DOWN)
point_y ++;
if(key == LEFT)
point_x --;
if(key == RIGHT)
point_x ++;
if(point_y == -1)
point_y = 14;
if(point_y == 15)
point_y = 0;
if(point_x == -1)
point_x = 14;
if(point_x == 15)
point_x = 0;
}
/////////////////////////////////////////////////////////////////////////////////////
void DrewPicture(char *filename)
{
int buffer[WIDTH]={0};
int picture[HEIGTH][WIDTH];
int offset=0;
int width=0;
int length=0;
int image_confectionary=0;
int row = 0;
int line =0 ;
int read_row = 0;
int read_line = 0;
unsigned int position=0;
if(fileopen(filename)==1)
{
width = GetWidth();
length =GetLength();
offset=GetOffSet();
image_confectionary=GetConfectionary();
position+=offset;
read_line=length<HEIGTH ? length:HEIGTH;
for( line=0 ;line<read_line ;line++)
{
if(width<WIDTH)
{
fileread(buffer,width,position, image_confectionary);
}
else
{
fileread(buffer,WIDTH,position, image_confectionary);
}
position+=width*image_confectionary/8;
// Screen_Color_Ctrl(buffer,HEIGTH-line-1);
for(row = 0;row < WIDTH ;row++)
picture[HEIGTH-line-1][row] = buffer[row];
}
ShowPicture(picture);
// Screen_Color_Ctrl(buffer,0);
// Screen_Color_Ctrl(buffer,2);
fileclose();
}
else
{
printf("Unable to open file!!!!!\n");
}
}
/////////////////////////////////////////////////////////////////////////////////////
int main(void)
{
int intput =0 ;
int temp =0;
char key;
int mode = 0;
mode = 0 ;
framebuffer_open ();
KbdOpen();
do
{
Init();
mode=0;
temp=0;
do{
key=GetKey();
if(mode == 0&&temp==0)
{
DrewPicture("welcome.bmp");
temp=1;
//MyPrintf(100,100,65535,"Help",4);
}
if(key == HELP && mode==1)
{
mode = 2 ;
DrewPicture("help.bmp");
}
if((key == BACK && mode==2)||(key == START && mode==0))
{
mode = 1 ;
DrawChessboard();
DrawChess();
}
if(key!=0&&mode==1)
{
DealWithKey(key);
DrawSeletor(old_point_x,old_point_y,COLOR_YELLOW);
DrawSeletor(point_x,point_y,COLOR_RED);
old_point_x=point_x;
old_point_y=point_y;
}
if(people==1&&key==KEYPRESS&&chess[point_x][point_y]==EMPTY&&mode==1)
{
chess[point_x][point_y] = BLACK;
// DrawChess();
DrawRound(point_x*CASE_WIDTH+50,point_y*CASE_WIDTH+50,RADIUS, COLOR_BLACK);
winner = IsGameOver(chess);
if(winner ==0)
{
people=0;
computer =1;
count--;
}
}
if(computer==1&&mode==1)
{
ComputerThink(chess);
DrawChess();
winner = IsGameOver(chess);
if(winner ==0)
{
people=1;
computer =0;
count--;
}
}
}while(count!=0&&winner==0);
if(count==0)
printf("GAME DRAW!!!!\n");
if(winner==1)
printf("YOU ARE THE WINNER!!!\n");
if(winner==2)
printf("I AM THE WINTEER!!!\n");
printf("GAME OVER 1>EXIT 2>RESTART\nSELECT:");
scanf("%d",&intput);
}while(intput==2);
KbdClose();
framebuffer_close();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -