Honeycombs: Difference between revisions

m
syntax highlighting fixup automation
m (update for Julia 1.x)
m (syntax highlighting fixup automation)
Line 14:
 
Honeycomb class:
<syntaxhighlight lang="actionscript3">
<lang ActionScript3>
package {
Line 229:
 
}
</syntaxhighlight>
</lang>
 
Document (main) class:
<syntaxhighlight lang="actionscript3">
<lang ActionScript3>
package {
Line 399:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Discrete_Random;
 
Line 607:
Window.Finalize;
SDL.Finalise;
end Honeycombs;</langsyntaxhighlight>
=={{header|AutoHotkey}}==
Requires [https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517&start=320 Gdip Library]
<langsyntaxhighlight AutoHotkeylang="autohotkey">Columns := 5 ; cater for a different number of columns
hexPerCol := 4 ; cater for a different number of hexagons
size := 40
Line 741:
ExitApp
Return
;---------------------------------------------------------------</langsyntaxhighlight>
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> ALTERNATE = 1
VDU 23,22,252;252;8,16,16,128
*FONT Arial,24,B
Line 827:
SYS "TextOut", @memhdc%, x%-size.dx%/2, y%-size.dy%/2, text$, LEN(text$)
SYS "CreatePolygonRgn", ^pt%(0,0), 6, ALTERNATE TO hrgn%
= hrgn%</langsyntaxhighlight>
[[File:honeycombs_bbc.gif]]
 
=={{header|C}}==
 
<syntaxhighlight lang="c">
<lang C>
 
/* Program for gtk3 */
Line 1,102:
return EXIT_SUCCESS;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,302:
}
}
}</langsyntaxhighlight>
XAML:
<langsyntaxhighlight lang="xml"><Window x:Class="Honeycombs.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Line 1,316:
<Canvas x:Name="HoneycombCanvas" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Window></langsyntaxhighlight>
[[File:CSharpHoneycomb.jpg]]
 
=={{header|C++}}==
{{libheader|Qt}}
<langsyntaxhighlight lang="cpp">//
// honeycombwidget.h
//
Line 1,350:
};
 
#endif // HONEYCOMBWIDGET_H</langsyntaxhighlight>
<langsyntaxhighlight lang="cpp">//
// honeycombwidget.cpp
//
Line 1,451:
update(cell->polygon.boundingRect());
}
}</langsyntaxhighlight>
<langsyntaxhighlight lang="cpp">//
// main.cpp
//
Line 1,463:
w.show();
return a.exec();
}</langsyntaxhighlight>
 
{{out}}
Line 1,470:
=={{header|Go}}==
{{libheader|raylib-go}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,593:
 
rl.CloseWindow()
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
{{libheader|gloss}}
{{libheader|random-shuffle}}
<langsyntaxhighlight Haskelllang="haskell">import Data.Char (toUpper)
import Data.Function (on)
import Data.List (zipWith4)
Line 1,738:
(return . drawWorld)
handleInput
(\_ x -> return x)</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 1,749:
 
Label selection is straight forward. Mouse selection first determines if x,y is within the widgets rectangular outer bounds. The x,y point is then reflected into the north west quadrant of the cell and the helper data is used to calculate an abbreviated cross-product (x and y will always be 0). The direction of the resultant z indicates if the point is inside or outside of the widgets inner bounds.
<langsyntaxhighlight Iconlang="icon">link printf
 
procedure main(A)
Line 1,856:
return W
}
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 1,863:
=={{header|J}}==
 
<langsyntaxhighlight Jlang="j">require'ide/qt/gl2'
coinsert'jgl2'
 
Line 1,929:
}}
 
honeycomb''</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
Line 2,062:
g.drawString(s, x, y);
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
Uses Cairo and Gtk for graphics. Tasks done include the optional one of recording and then displaying letters as chosen with mouse or keyboard on exit once all letters are chosen.
<langsyntaxhighlight lang="julia">using Gtk.ShortNames, GtkReactive, Graphics, Cairo, Colors, Random
 
mutable struct Hexagon
Line 2,175:
exit()
 
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
This is a translation of the Java entry except that code has been added to end the program automatically when all the hexagons have been selected.
<langsyntaxhighlight lang="scala">// version 1.1.4
 
import java.awt.BasicStroke
Line 2,325:
}
}
}</langsyntaxhighlight>
 
=={{header|Liberty BASIC}}==
By Andy Amaya, Sept. 24, 2015 -- with thanks from the Liberty BASIC Community.
<syntaxhighlight lang="lb">
<lang lb>
NoMainWin
Dim hxc(20,2), ltr(26)
Line 2,467:
End If
End Function
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Two players, 5 by 4.
<langsyntaxhighlight Mathematicalang="mathematica">hexagon[{x_, y_}] :=
Polygon[Transpose[{{1/2, 1/4, -1/4, -1/2, -1/4, 1/4} +
x, {0, Sqrt[3]/4, Sqrt[3]/4, 0, -Sqrt[3]/4, -Sqrt[3]/4} + y}]];
Line 2,503:
cols, {If[blue, Blue, Red],
Nearest[locs, MousePosition["Graphics"]][[1]]}];
blue = ! blue]}]]</langsyntaxhighlight>
 
=={{header|MATLAB}}==
Line 2,514:
*Works for up to 26 hexagons before using lowercase labels, 52 hexagons before repeating letters
*Works off of mouse-click events, so program doesn't need to "quit" as it is not really running constantly
<langsyntaxhighlight MATLABlang="matlab">function Honeycombs
nRows = 4; % Number of rows
nCols = 5; % Number of columns
Line 2,570:
set(axesH, 'UserData', newList)
title(newList)
end</langsyntaxhighlight>
 
=={{header|Nim}}==
Line 2,576:
This program is largely inspired by the C version, but this is not a direct translation. We have reused many parts of the C version, for instance the computations and the way to draw the cells. But we have also introduced a “honeycomb” object, improved somewhat the drawing of the labels and taken advantage of the high level binding to Gtk3 provided by “gintro”.
 
<langsyntaxhighlight Nimlang="nim">import lenientops, math, random, sequtils, strutils, tables
 
import gintro/[gobject, gdk, gtk, gio, cairo]
Line 2,764:
let app = newApplication(Application, "Rosetta.honeycombs")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
 
Line 2,771:
The programme uses the ''Tk'' GUI toolkit.
 
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
use warnings;
use strict;
Line 2,860:
)->pack;
$mw->bind('<Alt-q>', sub { $btn->invoke });
MainLoop();</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 2,866:
In the 2 player game, the string chosen contains the selections of both players: odd chars = player 1, even chars = player 2.<br>
Included in the distribution as demo\rosetta\honeycomb.exw
<langsyntaxhighlight Phixlang="phix">include ..\arwen\arwen.ew
include ..\arwen\axtra.ew
 
Line 3,056:
setHandler(main,routine_id("mainHandler"))
 
WinMain(main, SW_NORMAL)</langsyntaxhighlight>
 
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<langsyntaxhighlight Prologlang="prolog">honeycomb :-
new(W, window('Honeycomb')),
new(Counter, counter(20)),
Line 3,275:
:- pce_end_class(cell).
 
</syntaxhighlight>
</lang>
[[File:Prolog_honeycombs.png|400px]]
 
=={{header|PureBasic}}==
Requires PureBasic v4.60. Screen controls in PureBasic are referred to as 'gadgets'.
<langsyntaxhighlight PureBasiclang="purebasic">Structure hexGadget
text.s
Status.i ;nonselected = 0, selected = 1
Line 3,482:
FreeGadget(honeycomb\gadgetID)
CloseWindow(0)
EndIf</langsyntaxhighlight>
[[File:PureBasic_Honeycomb.png]]
 
Line 3,489:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(struct Hex (x y letter clicked?) #:mutable #:transparent)
Line 3,549:
 
(displayln "The letters were chosen in the order:")
(for-each display (add-between (reverse letters-chosen) " "))</langsyntaxhighlight>
 
=={{header|Ruby}}==
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app(title: "Honeycombs", height: 700, width: 700) do
C = Math::cos(Math::PI/3)
S = Math::sin(Math::PI/3)
Line 3,687:
end
end
end</langsyntaxhighlight>
 
=={{header|Scala}}==
Line 3,693:
{{libheader|Scala Java Swing interoperability}}
{{works with|Scala|2.13}}
<langsyntaxhighlight Scalalang="scala">import java.awt.{BasicStroke, BorderLayout, Color, Dimension,
Font, FontMetrics, Graphics, Graphics2D, Point, Polygon, RenderingHints}
import java.awt.event.{KeyAdapter, KeyEvent, MouseAdapter, MouseEvent}
Line 3,783:
}
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Perl}}
[[File:Honeycombs_sidef.png|250px|thumb|right]]
<langsyntaxhighlight lang="ruby">require('Tk')
 
class Honeycombs(
Line 3,871:
}
 
Honeycombs().display(title: 'Honeycombs')</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk
 
Line 3,961:
tkwait window .c
puts "overall list of characters: $chosen"
exit</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 3,970:
 
The following script uses a font called ''memory.ttf''. If this is not present in your DOME distribution, it can be downloaded from [https://github.com/domeengine/dome/raw/main/examples/fonts/memory.ttf here] and should be placed in the same directory as the script itself.
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window, Process
import "math" for Math
Line 4,082:
}
 
var Game = Honeycombs.new(600, 500)</langsyntaxhighlight>
 
=={{header|XPL0}}==
[[File:HoneyXPL0.gif|right]]
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\stdlib; \(color definitions, etc.)
 
proc DrawHexagon(X0, Y0, Side, Color); \Draw a filled hexagon centered at X0,Y0
Line 4,127:
until Counter >= Cols*Rows;
SetVid($03); \restore normal text display
]</langsyntaxhighlight>
 
{{omit from|ACL2}}
10,327

edits