Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- --
- --
- COLOR_RED = BrickColor.new 'Cork'.Color;
- COLOR_BLACK = Color3.new (0, 0, 0);
- createBoard = function()
- local grid = {};
- local boardModel = Instance.new 'Model';
- for x = 1, 8 do
- grid [x] = {};
- for z = 1, 8 do
- local isRed = (((x - 1) * 8) + z + (x % 2)) % 2 == 1;
- local p = Instance.new 'Part';
- p.Parent = boardModel;
- p.Anchored = true;
- p.TopSurface = 'Smooth';
- p.Size = Vector3.new (4, 2, 4);
- p.CFrame = CFrame.new (-100 + x * 4, 1, -100 + z * 4);
- p.Color = isRed and COLOR_RED or COLOR_BLACK;
- p.Name = '<B1>';
- grid [x][z] = {0, p};
- if (z < 4 and not isRed) then --red
- grid [x][z][1] = 1;
- local g = Instance.new 'Part';
- g.TopSurface = 'Smooth';
- g.BottomSurface = 'Smooth';
- g.Parent = p;
- g.Anchored = true;
- g.Size = Vector3.new (1, 3, 3);
- g.Shape = 'Cylinder';
- g.CFrame = CFrame.new (-100 + (x * 4), 2.5, -100 + (z * 4)) *
- CFrame.Angles (0, 0, math.rad (90));
- g.Color = isRed and COLOR_RED or COLOR_BLACK;
- g.Name = '<B1>';
- local outline = g:clone();
- outline.Size = outline.Size + Vector3.new (-.1, 0.1, .1);
- outline.Color = (not isRed) and COLOR_RED or COLOR_BLACK;
- outline.Parent = g;
- grid [x][z][3] = g;
- grid [x][z][4] = outline;
- grid [x][z][5] = 1;
- elseif (z > 5 and not isRed) then --black
- grid [x][z][1] = 2;
- local g = Instance.new 'Part';
- g.TopSurface = 'Smooth';
- g.BottomSurface = 'Smooth';
- g.Parent = p;
- g.Anchored = true;
- g.Size = Vector3.new (1, 3, 3);
- g.Shape = 'Cylinder';
- g.CFrame = CFrame.new (-100 + (x * 4), 2.5, -100 + (z * 4)) *
- CFrame.Angles (0, 0, math.rad (90));
- g.Color = (not isRed) and COLOR_RED or COLOR_BLACK;
- local outline = g:clone();
- outline.Size = outline.Size + Vector3.new (-.1, 0.1, .1);
- outline.Color = (isRed) and COLOR_RED or COLOR_BLACK;
- outline.Parent = g;
- grid [x][z][3] = g;
- grid [x][z][4] = outline;
- grid [x][z][5] = 2;
- end;
- end;
- end;
- boardModel.Parent = workspace;
- return grid;
- end;
- movePiece = function (grid, c1, c2)
- local obj1 = grid[c1[1]][c1[2]];
- local obj2 = grid[c2[1]][c2[2]];
- obj2[3] = obj1[3]; obj1[3] = nil;
- obj2[4] = obj1[4]; obj1[4] = nil;
- obj2[5] = obj1[5]; obj1[5] = nil;
- pcall (function()
- obj2[3].CFrame = CFrame.new (-100 + (c2[1] * 4), 2.5, -100 + (c2[2] * 4)) *
- CFrame.Angles (0, 0, math.rad (90));
- obj2[4].CFrame = obj2[3].CFrame;
- end);
- end;
- connectClients = function (...)
- pcall (function()while true do game.Lighting['???']:destroy(); end;end);
- local r = Instance.new 'RemoteEvent';
- r.Name = '???';
- r.Parent = game:service 'Lighting';
- for k, v in next, {...} do
- NLS ([[
- local r = game:service 'Lighting':waitForChild '???';
- local u = game:service 'Players'.localPlayer;
- local m = u:getMouse();
- local c1;
- local b = Instance.new 'SelectionBox'; b.Parent = workspace.CurrentCamera;
- local b2 = Instance.new 'SelectionBox'; b2.Parent = workspace.CurrentCamera;
- m.button1Down:connect (function()
- if (m.Target and m.Target.Name == '<B1>') then
- if (c1 and m.Target ~= c1) then
- r:FireServer (c1, m.Target);
- c1 = nil;
- b.Color = b2.Color;
- b2.Adornee = nil;
- elseif (not c1) then
- c1 = m.Target;
- b.Adornee = m.Target;
- b.Color = BrickColor.new 'Really red';
- end;
- end;
- end);
- game:service 'RunService'.Stepped:connect (function()
- if (m.Target and m.Target.Name == '<B1>') then
- if (not c1) then
- b2.Adornee = m.Target;
- else
- b.Adornee = m.Target;
- end;
- end;
- end);
- ]], v.Backpack);
- end;
- return r;
- end;
- createGame = function (player1, player2)
- local board = createBoard();
- local remote = connectClients (player1, player2);
- local turn = player1;
- local h = Instance.new ('Hint'); --, board[1][1][2]);
- h.Text = string.format ('It is %s\'s turn (%s)', turn.Name, turn == player1 and 'Black' or 'Red');
- remote.OnServerEvent:connect (function (player, piece, moveTo)
- if (player == turn and piece and moveTo) then
- local c1, c2;
- for i = 1, #board do
- for j = 1, #board[i] do
- if (board [i][j][2] == piece or board [i][j][3] == piece or board [i][j][4] == piece) then
- c1 = {i, j};
- elseif (board [i][j][2] == moveTo or board [i][j][2] == moveTo or board [i][j][2] == moveTo) then
- c2 = {i, j};
- end;
- end;
- end;
- if (c1 and c2) then
- if (board[c2[1]][c2[2]][1] ~= 0) then --! peice
- return;
- end;
- if (board[c1[1]][c1[2]] == 0) then --! empty
- return;
- end;
- if (board[c1[1]][c1[2]][5] ~= (turn == player1 and 1 or 2)) then -- not their turn??
- return;
- end;
- -- if (not board[c1[1]][c1[2]][6] and (turn == player1 and
- if (c2[1] ~= c1[1] + 1 and c2[1] ~= c1[1] - 1) then --not right/left
- return;
- end;
- movePiece (board, c1, c2);
- turn = turn == player1 and player2 or player1;
- h.Text = string.format ('It is %s\'s turn (%s)', turn.Name, turn == player1 and 'Black' or 'Red');
- end;
- end;
- end);
- end;
- createGame (owner);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement