Windows 10 – Universal Windows Platform – Lucky Bingo

Step 1

Download Visual Studio Community 2015 and install it onto your computer, if it’s already downloaded and installed select Launch to start Visual Studio Community 2015 or if it has already been downloaded and installed then start the application you may also need to Enable your device for development.

2015-visual-studio

Step 2

Once Visual Studio Community 2015 has started select File, then New, then Project… from the Menu.

2015-file-new-project

Step 3

From the New Project window select Visual C# from Installed, Templates then select Blank App (Windows Universal) from the list, then type in a Name and select a Location to save to before selecting Ok to create the Project.

2015-new-project

Step 4

Once done select from the Menu, Project, then Add New Item…

2015-project-add-new-item

Step 5

From the Add New Item window select Visual C# from Installed and select Code then select Code File from the list, then type in the Name as Library.cs before selecting Add to add the file to the Project

2015-add-new-item-library

Step 6

Once in the Code View for Library.cs the following should be entered:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;

public class Library
{
    private int index = 0;
    private List<int> numbers = null;
    private ObservableCollection<Grid> items = new ObservableCollection<Grid>();
    private Random random = new Random((int)DateTime.Now.Ticks);

    private List<int> select(int start, int finish, int total)
    {
        int number;
        List<int> numbers = new List<int>();
        while ((numbers.Count < total)) // Select Numbers
        {
            // Random Number between Start and Finish
            number = random.Next(start, finish + 1);
            if ((!numbers.Contains(number)) || (numbers.Count < 1))
            {
                numbers.Add(number); // Add if number Chosen or None
            }
        }
        return numbers;
    }

    private void pick(ref GridView grid)
    {
        if (index < numbers.Count)
        {
            int number = numbers[index];
            TextBlock text = new TextBlock()
            {
                Foreground = new SolidColorBrush(Colors.White),
                FontSize = 24,
                Text = number.ToString(),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            Grid container = new Grid()
            {
                Margin = new Thickness(2),
                Width = 48,
                Height = 48
            };
            Ellipse ball = new Ellipse();
            Color fill;
            ball.Width = container.Width;
            ball.Height = container.Height;
            if (number >= 1 && number <= 10)
            {
                fill = Colors.Magenta;
            }
            else if (number >= 11 && number <= 20)
            {
                fill = Colors.Blue;
            }
            else if (number >= 21 && number <= 30)
            {
                fill = Colors.DarkGreen;
            }
            else if (number >= 31 && number <= 40)
            {
                fill = Colors.YellowGreen;
            }
            else if (number >= 41 && number <= 50)
            {
                fill = Colors.Orange;
            }
            else if (number >= 51 && number <= 60)
            {
                fill = Colors.DarkBlue;
            }
            else if (number >= 61 && number <= 70)
            {
                fill = Colors.Red;
            }
            else if (number >= 71 && number <= 80)
            {
                fill = Colors.DarkCyan;
            }
            else if (number >= 81 && number <= 90)
            {
                fill = Colors.Purple;
            }
            ball.Fill = new SolidColorBrush(fill);
            container.Children.Add(ball);
            container.Children.Add(text);
            items.Add(container);
            index++;
            grid.ItemsSource = items;
        }
    }

    private void layout(ref GridView grid)
    {
        grid.ItemsSource = null;
        items = new ObservableCollection<Grid>();
        index = 0;
        numbers = select(1, 90, 90);
    }

    public void New(GridView grid)
    {
        layout(ref grid);
    }

    public void Pick(GridView grid)
    {
        if (numbers == null) layout(ref grid);
        pick(ref grid);
    }
}

It should then appear as such:

2015-lucky-bingo-library

Step 7

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 8

Select from the Menu, View then Designer

2015-view-designer

Step 9

The Design View will be displayed along with the XAML View and in this above <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

<Page.BottomAppBar>
	<AppBar IsOpen="True" IsSticky="True">
		<StackPanel Orientation="Horizontal">
			<AppBarButton Icon="Page" Label="New" Click="New_Click"/>
			<AppBarButton Icon="Accept" Label="Pick" Click="Pick_Click"/>
		</StackPanel>
	</AppBar>
</Page.BottomAppBar>

While still in the XAML View below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

<GridView Name="Display" HorizontalAlignment="Center" VerticalAlignment="Center">
	<GridView.ItemsPanel>
		<ItemsPanelTemplate>
			<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="10"/>
		</ItemsPanelTemplate>
	</GridView.ItemsPanel>
</GridView>

It should appear as such:

2015-lucky-bingo-mainpage-xaml

Step 10

Select from the Menu, View then Code

2015-view-code

Step 11

Once in the Code View below the public MainPage() { … } the following should be entered:

public Library Library = new Library();

private void New_Click(object sender, RoutedEventArgs e)
{
	Library.New(Display);
}

private void Pick_Click(object sender, RoutedEventArgs e)
{
	Library.Pick(Display);
}

It should then appear as such:

2015-lucky-bingo-mainpage-code

Step 12

That completes the Universal Windows Application so Save the Project then select the Debug and Simulator option to run the Application

2015-simulator

Step 13

Once the Simulator has started the Application should then appear

2015-lucky-bingo-simulator-run

Step 14

After the Application has started running you can use Pick to start selecting Bingo numbers or you can use New to reset the Application

2015-lucky-bingo-simulator-ran

Step 15

To Exit the application select Stop Debugging in Visual Studio Community 2015

2015-stop

Step 16

Another option is to run as a Windows 10 Mobile application, select Debug and select Emulator 10.0.10586.0 WVGA 4 inch 512MB option to run the Application

2015-emulator

Step 17

Once the Emulator has started the Application should then appear

2015-lucky-bingo-emulator-run

Step 18

After the Application has started running you can use Pick to start selecting Bingo numbers or you can use New to reset the Application

2015-lucky-bingo-emulator-ran

Step 19

To Exit the application select Stop Debugging in Visual Studio Community 2015

2015-stop

Creative Commons License

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s