Pseudo code:
Main()
- print ( 'Welcome to find the target.' )
- print ( 'try to find the target ( # ) by guessing its x and y coordinates' )
- print ( ' but avoid finding the mine ( X )! ')
- make array of size 4, and then fill it with arrays of size 4:
x = Array(4)
for i=0 to x.size do
x[i] = Array(4)
end loop
- now you have you're board!, lets fill it with teh charecters...
for i=0 to x.size do
for j=o to x[i].size do
x[i][j] = '.'
end loop
end loop
- now we need to find out where the winning place is, so lets make a random x, and a random y:
winningx = (rand * 4).upper # you're language might lack this specifically, here i expect rand to be from 0 to 1, and upper rounds up to nearest whole integer.
- do the same for winningy, and for minex and miney.
- now we call the game loop:
Game()
- while ( !gameover ) # while we haven't finished...
- call printBoard()
- call xval = DoInput('x')
- call yval = DoInput('y')
- if xval == winningx AND yval == winningy
print ('Congratulations, you found the winning target!')
exit with success.
else if minex == xval AND miney == yval
print ('you loose sucka')
exit with failure.
else
x[xval][yval] = 'o'
endif
endwhile
-> end of Game()
DoInput(ARG)
- print ('enter the ARG coord:')
- input = read line
if input > ARG.size OR input < 0 ## this line/fucntion assumes here that X and Y sizes are teh same. pascal may not be this flexible with symbols (for ARG.size), but there are simple solutions.
print('Coords must be between 0 and 4')
call DoInput()
else
return input
endif
-> end of DoInput()
PrintBoard()
- print out the top row (easy peasy):
print (' ')
for i=0 to x.size do
print (i)
end loop
- print out each of the other rows:
for i=0 to x[0].size do # note x[0].size is the height of the board, assuming each column is the same size, this could be better.
print (i)
for j=0 to x.size do # this is going accross the x'es
print (x[j][i]) # the indices are the other way round cause we're going left to right, top to bottom, rather than top to bottom left to right.
end loop
-> end of PrintBoard()