Chess Board
Author |
Message |
illu45
![](http://img9.exs.cx/img9/1348/roadavvy2ht.png)
|
Posted: Mon Mar 28, 2005 1:10 am Post subject: Chess Board |
|
|
Hey guys,
I'm trying to make a chess board, however, I'm having some trouble with the loactation of the numbers on the left hand side of the board...
Here is my code:
code: |
setscreen ("graphics:400, 400")
procedure DrawTheCell (x, y, w, h : int)
var clr : int := 255
if (x + y) mod 2 = 0 then
clr := 0
end if
drawfillbox (x * w, (y + 1) * h, (x + 1) * w, (y) * h, clr)
end DrawTheCell
var w : int := 40
var h : int := 40
drawfillbox (0, 0, maxx, maxy, 50)
var letters : array 1 .. 8 of string
letters (1) := "a"
letters (2) := "b"
letters (3) := "c"
letters (4) := "d"
letters (5) := "e"
letters (6) := "f"
letters (7) := "g"
letters (8) := "h"
for i : 1 .. 8
locatexy (i * w + w div 2, h div 2)
colorback (50)
put letters (i)
end for
for decreasing j : 8 .. 1
locatexy (w div 2, j * h + (h div 2))
colorback (50)
put j
end for
for i : 1 .. 8
for decreasing j : 8 .. 1
DrawTheCell (i, j, w, h)
end for
end for
|
I don't see any real errors in the code, though maybe I'm blind ... It seems like there may be a problem with the locatexy command...
Any ideas? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Mon Mar 28, 2005 6:25 am Post subject: (No subject) |
|
|
locatexy doesn't draw your text with the bottom-left corner at (x,y), it draws it at the closest row and column to (x,y). It "snaps-to", if you will.
To fix your problem, use fonts.
Turing: |
setscreen ("graphics:400, 400")
var fontNumbers := Font.New ("Times New Roman:12")
procedure DrawTheCell (x, y, w, h : int)
var clr : int := 255
if (x + y ) mod 2 = 0 then
clr := 0
end if
drawfillbox (x * w, (y + 1) * h, (x + 1) * w, (y ) * h, clr )
end DrawTheCell
var w : int := 40
var h : int := 40
drawfillbox (0, 0, maxx, maxy, 50)
%You don't have to go through the whole list like that. The first thing to do is try to recognize a pattern in your initialized array.
%in this case, it's the letters of the alaphbet. Open up your ASCII chart, we're going to make this shorter!
var letters : array 1 .. 8 of string
for i : 1 .. upper (letters )
letters (i ) := chr (64 + i ) %or for lowercase letters, (96 + i)
end for
%if you don't like that, you could always use init.
%var letters : array 1 .. of of string := init ("A", "B", "C", "D", "E", "F", "G", "H")
for i : 1 .. 8
locatexy (i * w + w div 2, h div 2)
colorback (50)
put letters (i )
end for
for decreasing j : 8 .. 1
%Font.Draw (intstr (j), w div 2, j * h + h div 2, fontNumbers, black) %-- this is using the code you used for locatexy.
% I modified it a bit to centre the numbers
Font.Draw (intstr (j ), w div 2, j * h + h div 2 - 6, fontNumbers, black) %the -6 is to centre the numbers. I'm using 12 point font,
% which means that each "tall" character (such as "h", "1", or "t") is 12 pixels high. So, we want half the number above the
% centre-line, and half below, so we subtract 6.
end for
for i : 1 .. 8
for decreasing j : 8 .. 1
DrawTheCell (i, j, w, h )
end for
end for
|
|
|
|
|
|
![](images/spacer.gif) |
|
|