Created
September 28, 2013 08:33
-
-
Save kuoe0/6739927 to your computer and use it in GitHub Desktop.
http://bbs.csdn.net/topics/320147085 在 EFI 下完貪食蛇...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "efi.h" | |
#include "efilib.h" | |
#include "she.h" | |
#include <atk_libc.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "Bmp.h" | |
#include "Hii.h" | |
#include "ConsoleControl.h" | |
#include "GraphicsOutput.h" | |
#define Out ST->ConOut | |
#define In ST->ConIn | |
#define SCAN_CODE_UP 0x01 | |
#define SCAN_CODE_DOWN 0x02 | |
#define SCAN_CODE_RIGHT 0x03 | |
#define SCAN_CODE_LEFT 0x04 | |
#define SCAN_CODE_ESC 0x17 | |
#define N 200 | |
EFI_GUID gEfiConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | |
EFI_GUID gEfiGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; | |
EFI_GUID gEfiHiiProtocolGuid = EFI_HII_PROTOCOL_GUID; | |
EFI_GUID gEfiUgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID; | |
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; | |
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; | |
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color; | |
EFI_HII_PROTOCOL *mHii; | |
EFI_UGA_DRAW_PROTOCOL *UgaDraw; | |
EFI_SYSTEM_TABLE *gST; | |
EFI_BOOT_SERVICES *gBS; | |
EFI_RUNTIME_SERVICES *gRT; | |
#define _Clrscr(); ST->ConOut->ClearScreen(ST->ConOut); | |
static EFI_UGA_PIXEL EfiColors[16] = { | |
0x00, 0x00, 0x00, 0x00, // BLACK | |
0x98, 0x00, 0x00, 0x00, // BLUE | |
0x00, 0x98, 0x00, 0x00, // GREEN | |
0x98, 0x98, 0x00, 0x00, // CYAN | |
0x00, 0x00, 0x98, 0x00, // RED | |
0x98, 0x00, 0x98, 0x00, // MAGENTA | |
0x00, 0x98, 0x98, 0x00, // BROWN | |
0x98, 0x98, 0x98, 0x00, // LIGHTGRAY | |
0x30, 0x30, 0x30, 0x00, // DARKGRAY - BRIGHT BLACK | |
0xff, 0x00, 0x00, 0x00, // LIGHTBLUE - ? | |
0x00, 0xff, 0x00, 0x00, // LIGHTGREEN - ? | |
0xff, 0xff, 0x00, 0x00, // LIGHTCYAN | |
0x00, 0x00, 0xff, 0x00, // LIGHTRED | |
0xff, 0x00, 0xff, 0x00, // LIGHTMAGENTA | |
0x00, 0xff, 0xff, 0x00, // LIGHTBROWN | |
0xff, 0xff, 0xff, 0x00, // WHITE | |
}; | |
UINTN Node; | |
EFI_INPUT_KEY Key; | |
UINTN Score = 0; | |
UINT8 Barrier = 1; | |
UINTN Gamespeed = 100000; | |
struct Food { | |
INTN x; | |
INTN y; | |
UINTN yes; | |
} food; | |
struct Snake { | |
INTN x[N]; | |
INTN y[N]; | |
UINTN node; | |
UINTN direction; | |
UINTN life; | |
} snake; | |
VOID DrawData(IN UINT8 *ImageBuffer, IN UINTN Col, IN UINTN Row); | |
VOID DrawWord(IN CHAR16 *Value, IN UINT16 X, IN UINT16 Y, IN UINT16 Background, IN UINT16 WordCount); | |
UINT8 Rand(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable); | |
EFI_STATUS Init(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable); | |
EFI_STATUS DrawK(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable); | |
VOID PrintScore(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { | |
CHAR16 Str1[50]; | |
UINT8 Count1; | |
ValueToString(Str1,0,Score); | |
Count1 = (UINT8)StrLen(Str1); | |
DrawWord(ImageHandle, SystemTable, Str1, 160, 65, 3, Count1); | |
return; | |
} | |
VOID GameOver(VOID); | |
EFI_STATUS GamePlay(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable); | |
Main(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { | |
EFI_STATUS Status; | |
UINT8 Count,Countsize; | |
UINTN i,j,k; | |
CHAR16 *Str = L"Start Load"; | |
CHAR16 *Str2 = L"JJDD"; | |
Count = 11; | |
//--- if(Barrier == 1) | |
//--- { | |
Init(ImageHandle,SystemTable); | |
ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics); | |
// UgaDraw->Blt(UgaDraw,&EfiColors[0],EfiUgaVideoFill,0,0,0,0,800,600,0); | |
// | |
if (GraphicsOutput != NULL) { | |
Status = GraphicsOutput->Blt(GraphicsOutput, &EfiColors[0], EfiBltVideoFill, 0, 0, 0, 0, 800, 600, 0); | |
} | |
else { | |
Status = UgaDraw->Blt(UgaDraw, &EfiColors[0], EfiUgaVideoFill, 0, 0, 0, 0, 800, 600, 0); | |
} | |
DrawData(sheData, 350, 250); | |
getchar(); | |
//- DrawWord(Str,340,520,0,Count); | |
//- getchar(); | |
k = 0; | |
for(j = 0; j < 14; j++) { | |
for(i = 0; i < 6; i++) | |
{ | |
//- UgaDraw->Blt(UgaDraw,&EfiColors[15], EfiUgaVideoFill,0,0,k,565,8,16,0); | |
// I use Red color | |
Color.Green = 0; | |
Color.Blue = 0; | |
Color.Red = 255; | |
if (GraphicsOutput != NULL) { | |
Status = GraphicsOutput->Blt(GraphicsOutput, &EfiColors[6], EfiBltVideoFill, 0, 0, k, 565, 8, 16, 0); | |
} | |
else { | |
Status = UgaDraw->Blt(UgaDraw, &EfiColors[6], EfiUgaVideoFill, 0, 0, k, 565, 8, 16, 0); | |
} | |
k = k + 9; | |
BS->Stall(500000); | |
} | |
} | |
getchar(); | |
//--- } | |
//- DrawK(ImageHandle,SystemTable); | |
/* | |
if(Barrier = =1) | |
Str2 = L"The First Barrier" ; | |
else if(Barrier = =2) | |
Str2 = L"The Second Barrier" ; | |
else if(Barrier = =3) | |
Str2 = L"The Third Barrier" ; | |
Countsize = (UINT8)StrLen(Str2); | |
*/ | |
//- DrawWord(ImageHandle,SystemTable,Str2,300,45,3,Countsize); | |
//- GamePlay(ImageHandle,SystemTable); | |
getchar(); | |
ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); | |
return EFI_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment