//------------------------------------------------------ // A simple game in XJEase. // This demonstrates the use of XJEase and a // random number generator. // // The XJDemo board header is used to make it work, // but it doesn't require the demo board. // (c)2004-2006 XJTAG Limited // // Disclaimer: XJTAG makes no guarantees whatsoever // about this code. You use it at your own risk ... // This code requires XJTAG version 1.3 or later. // // If you find any problems with this file, please // contact support@xjtag.com //------------------------------------------------------ //------------------------------------------------------------------------------- // Constants //------------------------------------------------------------------------------- CONST INT ScreenWidth := 79; CONST INT WallSpacing := 15; //---------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------- CircuitTest()() INT i; INT Random; INT WallPosition WIDTH 8 := 30; INT CarPosition WIDTH 8 := 7; INT Key; INT GameOver := 0; INT Score := 0; PRINT("\n\nCar Racing game in XJEase\n\n"); PRINT("Keep your car ('*') between the walls ('#')\n\n"); PRINT(" 'z' Left 'x' Right\n\n"); DO RandomNumber() (Random); IF (Random[0] = 1) THEN IF (Random[1] = 1) THEN IF (WallPosition < ScreenWidth - WallSpacing - 3) THEN WallPosition := WallPosition + 1; CarPosition := CarPosition - 1; END; ELSIF (WallPosition > 1) THEN WallPosition := WallPosition - 1; CarPosition := CarPosition + 1; END; END; Key := GETKEY(); IF (Key = 'z') || (Key = 'Z') THEN CarPosition := CarPosition - 1; END; IF (Key = 'x') || (Key = 'X') THEN CarPosition := CarPosition + 1; END; IF (CarPosition = 0) || (CarPosition > WallSpacing) THEN GameOver := 1; END; FOR i := 0 FOR WallPosition PRINT(" "); END; PRINT("#"); FOR i := 0 FOR CarPosition PRINT(" "); END; PRINT("*"); IF (CarPosition < WallSpacing) THEN FOR i := 0 FOR WallSpacing - CarPosition PRINT(" "); END; END; PRINT("#\n"); Score := Score + 1; WHILE (Key != 27) && (GameOver = 0) END; PRINT("Game Over, Score : ",Score,"\n"); END; //------------------------------------------------------------------------------- // Random Number Generator // USAGE : RandomNumber()(Random) // Takes an existing number and moves it on to the next random number // This is a 2^32 - 1 Pseudo Random sequence (LSFR) //------------------------------------------------------------------------------- RandomNumber()(INT Random WIDTH 32) INT time := NOW() + 1; IF (Random = 0xFFFFFFFF) THEN Random := 0; END; DO Random := (Random [30..0] << 1) | ~(Random[31] ^ Random[21] ^ Random[1] ^ Random[0]); WHILE (NOW() < time) END; END;