%###########################################################################################################################
%#### Created by : n I $ ####
%#### September 26, 2003 ####
%###########################################################################################################################
%The Main Screen
const MWinX := 550
const MWinY := 528
var MWin : int := Window.Open ("graphics:" + intstr (MWinX) + ";" + intstr (MWinY) + ", position:top;left,title:BattleShip,offscreenonly")
%Keyboard
var ch : array char of boolean
%Player
var Column_Position, Row_Position : int := 1
%The Board
const Num_Of_Horizontal_Boxes : int := 100 %The smaller the number the bigger the boxes
const Num_Of_Verticle_Boxes : int := 100 %The smaller the number the bigger the boxes
const SpaceSize : int := 1 %Determains the amount of grid spaces between the boxes
%Calculates the coordinates of the verticle lines of the grid (Up and Down)
function Verticle_Line (num : int) : int
result ((maxx div Num_Of_Verticle_Boxes) * num)
end Verticle_Line
%Calculates the coordinates of the horizontal lines of the grid (Left and right)
function Horizontal_Line (num : int) : int
result ((maxy div Num_Of_Horizontal_Boxes) * num)
end Horizontal_Line
%Decides if the grid is shown or not
var Show_Grid : boolean := true
%Draws the Grid
for col : 1 .. Num_Of_Verticle_Boxes
drawline (Verticle_Line (col), 0, Verticle_Line (col), maxy, 7)
end for
for row : 1 .. Num_Of_Horizontal_Boxes
drawline (0, Horizontal_Line (row), maxx, Horizontal_Line (row), 7)
end for
%Draws the Box
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, brightred)
View.Update
loop
delay (30) %Slows Down the loop
Input.KeyDown (ch) %Get all keys that are being pressed (Allows for multiple keyboard inputs
if ch (KEY_UP_ARROW) then %If the up arrow key is pressed
%Erases current box
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, 0)
Row_Position += SpaceSize %Brings box up desired number of spaces on the grid
if Row_Position > Num_Of_Verticle_Boxes - 1 then %If the box is past the top part of the grid bring to the top row
Row_Position := Num_Of_Verticle_Boxes - 1
end if
%draws the box in its place
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, brightred)
View.Update %redraws the screen
end if
if ch (KEY_DOWN_ARROW) then %If the down arrow key is pressed
%Erases current box
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, 0)
Row_Position -= SpaceSize %Brings box down desired number of spaces on the grid
if Row_Position < 1 then
Row_Position := 1
end if
%draws the box in its place
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, brightred)
View.Update %redraws the screen
end if
if ch (KEY_RIGHT_ARROW) then %If the right arrow key is pressed
%Erases current box
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, 0)
Column_Position += SpaceSize %Brings box right desired number of spaces on the grid
if Column_Position > Num_Of_Horizontal_Boxes - 1 then
Column_Position := Num_Of_Horizontal_Boxes - 1
end if
%draws the box in its place
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, brightred)
View.Update %redraws the screen
end if
if ch (KEY_LEFT_ARROW) then %If the left arrow key is pressed
%Erases current box
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, 0)
Column_Position -= SpaceSize %Brings box left desired number of spaces on the grid
if Column_Position < 1 then
Column_Position := 1
end if
%draws the box in its place
drawfillbox (Verticle_Line (Column_Position) + 1, Horizontal_Line (Row_Position) + 1, Verticle_Line (Column_Position + 1) - 1, Horizontal_Line (Row_Position + 1) - 1, brightred)
View.Update %redraws the screen
end if
if ch ('g') or ch ('G') then %If g is pressed
if Show_Grid = false then %If grid is not being shown then show it
Show_Grid := true
for row : 1 .. Num_Of_Verticle_Boxes
drawline (Verticle_Line (row), 0, Verticle_Line (row), maxy, 7)
end for
for col : 1 .. Num_Of_Horizontal_Boxes
drawline (0, Horizontal_Line (col), maxx, Horizontal_Line (col), 7)
end for
else %If grid is being shown then hide
Show_Grid := false
for row : 1 .. Num_Of_Verticle_Boxes
drawline (Verticle_Line (row), 0, Verticle_Line (row), maxy, 0)
end for
for col : 1 .. Num_Of_Horizontal_Boxes
drawline (0, Horizontal_Line (col), maxx, Horizontal_Line (col), 0)
end for
end if
View.Update %redraw the screen
delay (500) %Stops the grid from switching between being shown and not being shown to quickly
end if
end loop
|