![]() ![]() This code is a basic implementation of snake in Ada using the command prompt - feel free to improve it! - Snake.ads with Ada.Containers use Ada.Containers with package Snake is - copy from 2048 game ( - Keyboard management type directions is ( Up, Down, Right, Left, Quit, Restart, Invalid ) - Redefining this standard procedure as function to allow Get_Keystroke as an expression function function Get_Immediate return Character Arrow_Prefix : constant Character := Character ' Val ( 224 ) - works for windows function Get_Keystroke return directions - ) - The container for game data type gameBoard is array ( Natural range, Natural range ) of Character - Initilize the board procedure init - Run the game procedure run - Displaying the board procedure Display_Board - Clear the board from content procedure ClearBoard - coordinates data structure type coord is tagged record X, Y : Integer end record - list of coordinate (one coordinate for each body part of the snake) package snakeBody is new (Natural, coord ) use snakeBody - update snake's part depending on the snakeDirection and checking colicion (with borders and snak's part) function moveSnake return Boolean - generate food if it was eaten procedure generateFood - Add snake and food to the board procedure addDataToBoard - generate random integer between 1 and upperBound to generate random food position function getRandomInteger ( upperBound : Integer ) return Integer private width, height : Positive := 10 board : gameBoard := ( 0.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |